Index: lib/TWiki/Plugins.pm =================================================================== RCS file: /cvsroot/twiki/twiki/lib/TWiki/Plugins.pm,v retrieving revision 1.35 diff -u -r1.35 Plugins.pm --- lib/TWiki/Plugins.pm 28 Mar 2004 02:42:36 -0000 1.35 +++ lib/TWiki/Plugins.pm 12 Apr 2004 05:59:08 -0000 @@ -30,10 +30,10 @@ use vars qw( @activePluginWebs @activePluginTopics @instPlugins @registrableHandlers %registeredHandlers %onlyOnceHandlers - $VERSION + $VERSION $initialisationErrors ); -$VERSION = '1.021'; +$VERSION = '1.023'; @registrableHandlers = ( # VERSION: 'earlyInitPlugin', # ( ) 1.020 @@ -49,11 +49,14 @@ 'afterEditHandler', # ( $text, $topic, $web ) 1.010 'beforeSaveHandler', # ( $text, $topic, $web ) 1.010 'afterSaveHandler', # ( $text, $topic, $web, $errors ) 1.020 + 'beforeAttachmentSaveHandler', # ( $text, $topic, $web ) 1.022 + 'afterAttachmentSaveHandler', # ( $text, $topic, $web,$error ) 1.022 'writeHeaderHandler', # ( $query ) 1.010 'redirectCgiQueryHandler', # ( $query, $url ) 1.010 'getSessionValueHandler', # ( $key ) 1.010 'setSessionValueHandler', # ( $key, $value ) 1.010 'renderFormFieldForEditHandler', # ( $name, $type, $size, $value, $attributes, $output ) + 'renderWikiWordHandler', # text 1.023 ); %onlyOnceHandlers = ( 'initializeUserHandler' => 1, @@ -62,7 +65,8 @@ 'redirectCgiQueryHandler' => 1, 'getSessionValueHandler' => 1, 'setSessionValueHandler' => 1, - 'renderFormFieldForEditHandler' => 1 + 'renderFormFieldForEditHandler' => 1, + 'renderWikiWordHandler' => 1 ); %registeredHandlers = (); @@ -110,6 +114,20 @@ # ========================= =pod +---++ sub initialisationError + +Internal routine called every time a plugin fails to laod + +=cut + +sub initialisationError +{ + my ($error) = @_; + $initialisationErrors .= $error."\n"; + &TWiki::writeWarning($error); +} + +=pod ---++ sub registerPlugin ( $plugin, $topic, $web, $user, $theLoginName, $theUrl, $thePathInfo ) Not yet documented. @@ -154,7 +172,7 @@ $installWeb = $web; } else { # not found - &TWiki::writeWarning( "Plugins: couldn't register $plugin, no plugin topic" ); + initialisationError( "Plugins: couldn't register $plugin, no plugin topic" ); return; } } @@ -163,7 +181,7 @@ if ( $plugin =~ m/^([A-Za-z0-9_]+Plugin)$/ ) { $plugin = $1; } else { - # invalid topic name for plugin + initialisationError("$plugin - invalid topic name for plugin"); return; } @@ -171,7 +189,7 @@ eval "use $p;"; if ($@) { - TWiki::writeWarning("Plugin \"$p\" could not be loaded by Perl. Errors were:\n----\n$@----"); + initialisationError("Plugin \"$p\" could not be loaded by Perl. Errors were:\n----\n$@----"); return; } @@ -191,6 +209,7 @@ $sub = $p.'::initPlugin'; # we register a plugin ONLY if it defines initPlugin AND it returns true if( ! defined( &$sub ) ) { + initialisationError("Plugin $p iniPlugin did not return true"); return; } # read plugin preferences before calling initPlugin @@ -328,6 +347,40 @@ # ========================= =pod + +--++ sub handleFailedPlugins () + +%FAILEDPLUGINS reports reasons why plugins failed to load + +=cut + +sub handleFailedPlugins +{ + my $text; + + $text .= "---++ Plugins defined\n"; + + foreach my $plugin (@instPlugins) { + $text .= " * $plugin\n"; + } + + $text.="\n\n"; + + foreach my $handler (@registrableHandlers) { + $text .= "| $handler |"; + $text .= join "
", @{$registeredHandlers{$handler}}; + $text .= "|\n"; + } + + + $text .="
\n---++ Errors\n
".$initialisationErrors.""; + + + + return $text; +} + +=pod ---++ sub handlePluginDescription () Not yet documented. @@ -429,6 +482,7 @@ &applyHandlers; $_[0] =~ s/%PLUGINDESCRIPTIONS%/&handlePluginDescription()/geo; $_[0] =~ s/%ACTIVATEDPLUGINS%/&handleActivatedPlugins()/geo; + $_[0] =~ s/%FAILEDPLUGINS%/&handleFailedPlugins()/geo; } # ========================= @@ -550,7 +604,13 @@ &applyHandlers; } -### RafaelAlvarez 2004-01-13 +=pod +---++ sub afterSaveHandler () + +Not yet documented. + +=cut + sub afterSaveHandler { # Called by TWiki::Store::saveTopic after the save action @@ -558,7 +618,38 @@ unshift @_, ( 'afterSaveHandler' ); &applyHandlers; } -### RafaelAlvarez 2004-01-13 + +=pod +---++ sub beforeAttachmentSaveHandler () + +Not yet documented. + +=cut + +sub beforeAttachmentSaveHandler +{ + # Called by TWiki::Store::saveAttachment before the save action +# my ( $theText, $theTopic, $theWeb ) = @_; + unshift @_, ( 'beforeAttachmentSaveHandler' ); + &applyHandlers; +} + +=pod +---++ sub afterAttachmentSaveHandler () + +Not yet documented. + +=cut + +sub afterAttachmentSaveHandler +{ +# Called by TWiki::Store::saveAttachment after the save action +# my ( $theText, $theTopic, $theWeb ) = @_; + unshift @_, ( 'afterAttachmentSaveHandler' ); + &applyHandlers; +} + + # ========================= =pod @@ -638,4 +729,21 @@ unshift @_, ( 'renderFormFieldForEditHandler' ); return &applyHandlers; } + +=pod +---++ sub renderFormFieldForEditHandler () + +Called by TWiki::internalLink to change how a WikiWord is rendered + +Originated from the TWiki:Plugins.SpacedWikiWordPlugin hack + +=cut + +sub renderWikiWordHandler +{ + unshift @_, ( 'renderWikiWordHandler' ); + return &applyHandlers; +} + + 1;