# FIGURE OUT THE OS WE'RE RUNNING UNDER - from CGI.pm 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 11 Apr 2004 14:36:18 -0000 @@ -30,10 +30,10 @@ use vars qw( @activePluginWebs @activePluginTopics @instPlugins @registrableHandlers %registeredHandlers %onlyOnceHandlers - $VERSION + $VERSION $initialisationErrors ); -$VERSION = '1.021'; +$VERSION = '1.022'; @registrableHandlers = ( # VERSION: 'earlyInitPlugin', # ( ) 1.020 @@ -49,6 +49,8 @@ '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 @@ -110,6 +112,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 +170,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 +179,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 +187,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 +207,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 +345,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 +480,7 @@ &applyHandlers; $_[0] =~ s/%PLUGINDESCRIPTIONS%/&handlePluginDescription()/geo; $_[0] =~ s/%ACTIVATEDPLUGINS%/&handleActivatedPlugins()/geo; + $_[0] =~ s/%FAILEDPLUGINS%/&handleFailedPlugins()/geo; } # ========================= @@ -550,7 +602,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 +616,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 Index: lib/TWiki/Store.pm =================================================================== RCS file: /cvsroot/twiki/twiki/lib/TWiki/Store.pm,v retrieving revision 1.86 diff -u -r1.86 Store.pm --- lib/TWiki/Store.pm 6 Apr 2004 12:14:39 -0000 1.86 +++ lib/TWiki/Store.pm 11 Apr 2004 14:36:18 -0000 @@ -714,9 +714,21 @@ { my( $web, $topic, $text, $saveCmd, $attachment, $dontLogSave, $doUnlock, $dontNotify, $theComment, $theTmpFilename, $forceDate) = @_; - + + writeDebug("saveAttachment"); + my %attachmentAtt = ( attachment => $attachment, + tmpFilename => $theTmpFilename, + comment => $theComment, + user => $TWiki::userName + ); # pass a hash of stuff using keys + my $topicHandler = _getTopicHandler( $web, $topic, $attachment ); + TWiki::Plugins::beforeAttachmentSaveHandler( \%attachmentAtt, $topic, $web ); + + $theComment = $attachmentAtt{comment}; my $error = $topicHandler->addRevision( $theTmpFilename, $theComment, $TWiki::userName ); + TWiki::Plugins::afterAttachmentSaveHandler( \%attachmentAtt, $topic, $web, $error ); + $topicHandler->setLock( ! $doUnlock ); return $error;