Changeset 1151
- Timestamp:
- 12/03/08 18:47:37 (4 years ago)
- Location:
- trunk/SignaturePlugin
- Files:
-
- 1 deleted
- 4 edited
-
bin/digisign (deleted)
-
data/TWiki/SignaturePlugin.txt (modified) (2 diffs)
-
lib/TWiki/Plugins/SignaturePlugin.pm (modified) (4 diffs)
-
lib/TWiki/Plugins/SignaturePlugin/MANIFEST (modified) (1 diff)
-
lib/TWiki/Plugins/SignaturePlugin/Signature.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/SignaturePlugin/data/TWiki/SignaturePlugin.txt
r899 r1151 27 27 * Set SHORTDESCRIPTION = Supports electronic signatures 28 28 29 * Debug plugin: (See output in =data/debug.txt=) 30 * Set DEBUG = 0 29 ---++ Plugin Installation Instructions 30 %$INSTALL_INSTRUCTIONS% 31 31 32 ---++ Plugin Installation Instructions33 34 * This plugin works only with TWiki 4 and beyond.35 * Download the ZIP file from the Plugin web (see below)36 * Unzip ==%TOPIC%.zip== in your twiki installation directory. Content:37 | *File:* | *Description:* |38 | ==data/System/%TOPIC%.txt== | Plugin topic |39 | ==lib/Foswiki/Plugins/%TOPIC%.pm== | Plugin Perl module |40 | ==lib/bin/digisign== | Support script |41 | ==templates/oopsgeneric.tmpl_twiki40== | Rename to ==templates/oopsgeneric.tmpl== if you are using a TWiki 4.0 installation |42 | ==templates/oopsgeneric.pattern.tmpl_twiki40== | Rename to ==templates/oopsgeneric.pattern.tmpl== if you are using a TWiki 4.0 installation |43 * Ensure that the script =lib/bin/digisign= is executable and authorized as desired.44 32 * If installed correctly you should see a button with the label indicated by the setting below. 45 33 … … 53 41 | Plugin Version: | 19 Nov 2006 | 54 42 | Change History: | <!-- versions below in reverse order --> | 43 | 03 Dec 2008: | FoswikibugLItem6109: recoded to avoid use of unpublished APIs (Crawford Currie) | 55 44 | 19 Nov 2006: | Support user designation and user-specific format. | 56 45 | 01 Aug 2006: | Initial release | -
trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin.pm
r1050 r1151 22 22 # $VERSION is referred to by TWiki, and is the only global variable that 23 23 # *must* exist in this package 24 use vars qw( $VERSION $RELEASE $ debug $pluginName );24 use vars qw( $VERSION $RELEASE $pluginName ); 25 25 26 26 # This should always be $Rev: 0$ so that TWiki can determine the checked-in … … 32 32 # It is *not* used by the build automation tools, but is reported as part 33 33 # of the version number in PLUGINDESCRIPTIONS. 34 $RELEASE = ' Dakar';34 $RELEASE = 'Foswiki'; 35 35 36 36 # Name of this Plugin, only used in this module … … 38 38 39 39 sub initPlugin { 40 my ( $topic, $web, $user, $installWeb ) = @_;40 my ( $topic, $web, $user, $installWeb ) = @_; 41 41 42 if( $TWiki::Plugins::VERSION < 1.1 ) { 43 TWiki::Func::writeWarning( "This version of $pluginName works only with TWiki 4 and greater." ); 42 if ( $TWiki::Plugins::VERSION < 1.1 ) { 43 TWiki::Func::writeWarning( 44 "This version of $pluginName works only with TWiki 4 and greater."); 44 45 return 0; 45 46 } 46 47 47 # Get plugin debug flag 48 $debug = TWiki::Func::getPreferencesFlag( "\U$pluginName\E_DEBUG" ); 49 50 # Plugin correctly initialized 51 TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; 48 TWiki::Func::registerRESTHandler( 'sign', \&sign ); 52 49 return 1; 53 50 54 51 } 55 52 56 sub preRenderingHandler 57 { 53 sub preRenderingHandler { 58 54 ### my ( $text ) = @_; # do not uncomment, use $_[0], $_[1] instead 59 60 &TWiki::Func::writeDebug( "- $pluginName::preRenderingHandler" ) if $debug;61 55 62 56 # This handler is called by getRenderedVersion just before the line loop 63 57 # Only bother with this plugin if viewing (i.e. not searching, etc) 64 return unless ( $0 =~ m/view|viewauth|render/o);58 return unless ( $0 =~ m/view|viewauth|render/o ); 65 59 66 60 my $cnt; … … 70 64 71 65 sub handleSignature { 72 require TWiki::Plugins::SignaturePlugin::Signature; 73 return TWiki::Plugins::SignaturePlugin::Signature::handleSignature(@_); 66 require TWiki::Plugins::SignaturePlugin::Signature; 67 return TWiki::Plugins::SignaturePlugin::Signature::handleSignature(@_); 68 } 69 70 sub sign { 71 require TWiki::Plugins::SignaturePlugin::Signature; 72 TWiki::Plugins::SignaturePlugin::Signature::sign(@_); 74 73 } 75 74 -
trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin/MANIFEST
r300 r1151 2 2 lib/TWiki/Plugins/SignaturePlugin.pm 0440 3 3 lib/TWiki/Plugins/SignaturePlugin/Signature.pm 0440 4 bin/digisign 05505 4 templates/oopsgeneric.pattern.tmpl_twiki40 0440 6 5 templates/oopsgeneric.tmpl_twiki40 0440 -
trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin/Signature.pm
r300 r1151 6 6 # Always use strict to enforce variable scoping 7 7 use strict; 8 use TWiki::Attrs; 8 9 9 10 sub handleSignature { 10 my ( $cnt, $attr ) = @_;11 my $session = $TWiki::Plugins::SESSION;11 my ( $cnt, $attr ) = @_; 12 my $session = $TWiki::Plugins::SESSION; 12 13 13 $attr = new TWiki::Attrs($attr); 14 my $lbl = TWiki::Func::getPreferencesValue( "\U$TWiki::Plugins::SignaturePlugin::pluginName\E_SIGNATURELABEL" ) || 'Sign'; 14 $attr = new TWiki::Attrs($attr); 15 my $lbl = TWiki::Func::getPreferencesValue( 16 "\U$TWiki::Plugins::SignaturePlugin::pluginName\E_SIGNATURELABEL") 17 || 'Sign'; 15 18 16 my $name = '';17 $name = '_('.$attr->{name}.')_ ' if $attr->{name};19 my $name = ''; 20 $name = '_(' . $attr->{name} . ')_ ' if $attr->{name}; 18 21 19 return "<noautolink> $name </noautolink><form action=\"" . &TWiki::Func::getScriptUrl($session->{webName}, $session->{topicName}, 'digisign') . "\" /><input type=\"hidden\" name=\"nr\" value=\"$cnt\" /><input type=\"submit\" value=\"$lbl\" /></form>"; 22 return 23 "<noautolink> $name </noautolink><form action=\"" 24 . &TWiki::Func::getScriptUrl( 'SignaturePlugin', 'sign', 'rest' ) 25 . "\" /><input type=\"hidden\" name=\"nr\" value=\"$cnt\" /><input type=\"submit\" value=\"$lbl\" /><input type=\"hidden\" name=\"topic\" value=\"$session->{webName}.$session->{topicName}\" /></form>"; 20 26 21 27 } 22 28 23 29 sub sign { 24 my $session = shift;25 $TWiki::Plugins::SESSION = $session;26 my $query = $session->{cgiQuery};27 return unless ( $query);30 my $session = shift; 31 $TWiki::Plugins::SESSION = $session; 32 my $query = $session->{cgiQuery}; 33 return unless ($query); 28 34 29 my $cnt = $query->param( 'nr');35 my $cnt = $query->param('nr'); 30 36 31 my $webName = $session->{webName}; 32 my $topic = $session->{topicName}; 33 my $user = $session->{user}; 34 return unless ( &doEnableEdit ($webName, $topic, $user, $query, 'editTableRow') ); 37 my $webName = $session->{webName}; 38 my $topic = $session->{topicName}; 39 my $user = $session->{user}; 35 40 36 my ( $meta, $text ) = &TWiki::Func::readTopic( $webName, $topic ); 37 $text =~ s/%SIGNATURE(?:{(.*)})?%/&replaceSignature($cnt--, $user, $1)/geo; 41 return 42 unless ( 43 &doEnableEdit( $webName, $topic, $user, $query, 'editTableRow' ) ); 38 44 39 my $error = &TWiki::Func::saveTopicText( $webName, $topic, $text, 1 ); 40 TWiki::Func::setTopicEditLock( $webName, $topic, 0 ); # unlock Topic 41 if( $error ) { 42 TWiki::Func::redirectCgiQuery( $query, $error ); 43 return 0; 44 } else { 45 # and finally display topic 46 TWiki::Func::redirectCgiQuery( $query, &TWiki::Func::getViewUrl( $webName, $topic ) ); 47 } 48 45 my ( $meta, $text ) = &TWiki::Func::readTopic( $webName, $topic ); 46 $text =~ s/%SIGNATURE(?:{(.*)})?%/&replaceSignature($cnt--, $user, $1)/geo; 47 48 my $error = &TWiki::Func::saveTopicText( $webName, $topic, $text, 1 ); 49 TWiki::Func::setTopicEditLock( $webName, $topic, 0 ); # unlock Topic 50 if ($error) { 51 TWiki::Func::redirectCgiQuery( $query, $error ); 52 return 0; 53 } 54 else { 55 56 # and finally display topic 57 TWiki::Func::redirectCgiQuery( $query, 58 &TWiki::Func::getViewUrl( $webName, $topic ) ); 59 } 60 49 61 } 50 62 51 63 sub replaceSignature { 52 my ( $dont, $user, $attr ) = @_;64 my ( $dont, $user, $attr ) = @_; 53 65 54 return ( ($attr)?"%SIGNATURE{$attr}%":'%SIGNATURE%' ) if $dont;66 return ( ($attr) ? "%SIGNATURE{$attr}%" : '%SIGNATURE%' ) if $dont; 55 67 56 $attr = new TWiki::Attrs($attr);68 $attr = new TWiki::Attrs($attr); 57 69 58 unless ( ! $attr->{name} || $user->isInList( $attr->{name} )) { 59 my $session = $TWiki::Plugins::SESSION; 60 TWiki::Func::setTopicEditLock( $session->{webName}, $session->{topicName}, 0 ); # unlock Topic 61 throw TWiki::OopsException( 'generic', 62 web => $session->{webName}, 63 topic => $session->{topicName}, 64 params => [ 'Attention', $user->wikiName.' is not permitted to sign here.', 'Please go back in your browser and sign at the correct spot.', ' ' ] ); 65 exit; 66 } 70 my $wuser = TWiki::Func::getWikiName($user); 71 my %list = map { s/.*\.//; $_ => 1 } split( /[, ]+/, $attr->{name} ); 72 unless ( !$attr->{name} || $list{$wuser} ) { 73 my $session = $TWiki::Plugins::SESSION; 74 TWiki::Func::setTopicEditLock( $session->{webName}, 75 $session->{topicName}, 0 ); # unlock Topic 76 throw TWiki::OopsException( 77 'generic', 78 web => $session->{webName}, 79 topic => $session->{topicName}, 80 params => [ 81 'Attention', 82 $wuser . ' is not permitted to sign here.', 83 'Please go back in your browser and sign at the correct spot.', 84 ' ' 85 ] 86 ); 87 exit; 88 } 67 89 68 my $fmt = $attr->{format} || TWiki::Func::getPreferencesValue( "\U$TWiki::Plugins::SignaturePlugin::pluginName\E_SIGNATUREFORMAT" ) || '$wikiusername - $date'; 90 my $fmt = $attr->{format} 91 || TWiki::Func::getPreferencesValue( 92 "\U$TWiki::Plugins::SignaturePlugin::pluginName\E_SIGNATUREFORMAT") 93 || '$wikiusername - $date'; 69 94 70 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);71 my ($d, $m, $y) = (localtime)[3, 4, 5];72 $y += 1900;73 my $ourDate = sprintf('%02d %s %d', $d, $months[$m], $y);95 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); 96 my ( $d, $m, $y ) = (localtime)[ 3, 4, 5 ]; 97 $y += 1900; 98 my $ourDate = sprintf( '%02d %s %d', $d, $months[$m], $y ); 74 99 75 $fmt =~ s/\$quot/\"/go;76 $fmt =~ s/\$wikiusername/$user->webDotWikiName()/geo;77 $fmt =~ s/\$wikiname/$user->wikiName()/geo;78 $fmt =~ s/\$username/$user->login()/geo;79 $fmt =~ s/\$date/$ourDate/geo;100 $fmt =~ s/\$quot/\"/go; 101 $fmt =~ s/\$wikiusername/$user->webDotWikiName()/geo; 102 $fmt =~ s/\$wikiname/$user->wikiName()/geo; 103 $fmt =~ s/\$username/$user->login()/geo; 104 $fmt =~ s/\$date/$ourDate/geo; 80 105 81 return $fmt;106 return $fmt; 82 107 83 108 } 84 109 85 sub doEnableEdit 86 { 110 sub doEnableEdit { 87 111 my ( $theWeb, $theTopic, $user, $query ) = @_; 88 112 89 if( ! &TWiki::Func::checkAccessPermission( "change", $user, "", $theTopic, $theWeb ) ) { 113 if ( 114 !&TWiki::Func::checkAccessPermission( 115 "change", $user, "", $theTopic, $theWeb 116 ) 117 ) 118 { 119 90 120 # user does not have permission to change the topic 91 throw TWiki::OopsException( 'accessdenied', 92 def => 'topic_access', 93 web => $_[2], 94 topic => $_[1], 95 params => [ 'Edit topic', 'You are not permitted to edit this topic' ] ); 96 return 0; 121 throw TWiki::OopsException( 122 'accessdenied', 123 def => 'topic_access', 124 web => $_[2], 125 topic => $_[1], 126 params => 127 [ 'Edit topic', 'You are not permitted to edit this topic' ] 128 ); 129 return 0; 97 130 } 98 131 99 132 ## SMELL: Update for TWiki 4.1 =checkTopicEditLock= 100 my( $oopsUrl, $lockUser ) = &TWiki::Func::checkTopicEditLock( $theWeb, $theTopic, 'edit' ); 101 if( $lockUser && ! ( $lockUser eq $user->login ) ) { 102 # warn user that other person is editing this topic 103 &TWiki::Func::redirectCgiQuery( $query, $oopsUrl ); 104 return 0; 133 my ( $oopsUrl, $lockUser ) = 134 &TWiki::Func::checkTopicEditLock( $theWeb, $theTopic, 'edit' ); 135 if ( $lockUser && !( $lockUser eq $user->login ) ) { 136 137 # warn user that other person is editing this topic 138 &TWiki::Func::redirectCgiQuery( $query, $oopsUrl ); 139 return 0; 105 140 } 106 141 TWiki::Func::setTopicEditLock( $theWeb, $theTopic, 1 );
Note: See TracChangeset
for help on using the changeset viewer.
