Changeset 1151


Ignore:
Timestamp:
12/03/08 18:47:37 (4 years ago)
Author:
CrawfordCurrie
Message:

Item6109: removed unpublished API calls

Location:
trunk/SignaturePlugin
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SignaturePlugin/data/TWiki/SignaturePlugin.txt

    r899 r1151  
    2727      * Set SHORTDESCRIPTION = Supports electronic signatures 
    2828 
    29    * Debug plugin: (See output in =data/debug.txt=) 
    30       * Set DEBUG = 0 
     29---++ Plugin Installation Instructions 
     30%$INSTALL_INSTRUCTIONS% 
    3131 
    32 ---++ Plugin Installation Instructions 
    33  
    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. 
    4432        * If installed correctly you should see a button with the label indicated by the setting below. 
    4533 
     
    5341|  Plugin Version: | 19 Nov 2006 | 
    5442|  Change History: | <!-- versions below in reverse order -->&nbsp; | 
     43|  03 Dec 2008: | FoswikibugLItem6109: recoded to avoid use of unpublished APIs (Crawford Currie) | 
    5544|  19 Nov 2006: | Support user designation and user-specific format. | 
    5645|  01 Aug 2006: | Initial release | 
  • trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin.pm

    r1050 r1151  
    2222# $VERSION is referred to by TWiki, and is the only global variable that 
    2323# *must* exist in this package 
    24 use vars qw( $VERSION $RELEASE $debug $pluginName ); 
     24use vars qw( $VERSION $RELEASE $pluginName ); 
    2525 
    2626# This should always be $Rev: 0$ so that TWiki can determine the checked-in 
     
    3232# It is *not* used by the build automation tools, but is reported as part 
    3333# of the version number in PLUGINDESCRIPTIONS. 
    34 $RELEASE = 'Dakar'; 
     34$RELEASE = 'Foswiki'; 
    3535 
    3636# Name of this Plugin, only used in this module 
     
    3838 
    3939sub initPlugin { 
    40     my( $topic, $web, $user, $installWeb ) = @_; 
     40    my ( $topic, $web, $user, $installWeb ) = @_; 
    4141 
    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."); 
    4445        return 0; 
    4546    } 
    4647 
    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 ); 
    5249    return 1; 
    5350 
    5451} 
    5552 
    56 sub preRenderingHandler 
    57 { 
     53sub preRenderingHandler { 
    5854### my ( $text ) = @_;   # do not uncomment, use $_[0], $_[1] instead 
    59  
    60     &TWiki::Func::writeDebug( "- $pluginName::preRenderingHandler" ) if $debug; 
    6155 
    6256    # This handler is called by getRenderedVersion just before the line loop 
    6357    # 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 ); 
    6559 
    6660    my $cnt; 
     
    7064 
    7165sub 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 
     70sub sign { 
     71    require TWiki::Plugins::SignaturePlugin::Signature; 
     72    TWiki::Plugins::SignaturePlugin::Signature::sign(@_); 
    7473} 
    7574 
  • trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin/MANIFEST

    r300 r1151  
    22lib/TWiki/Plugins/SignaturePlugin.pm 0440 
    33lib/TWiki/Plugins/SignaturePlugin/Signature.pm 0440 
    4 bin/digisign 0550 
    54templates/oopsgeneric.pattern.tmpl_twiki40 0440 
    65templates/oopsgeneric.tmpl_twiki40 0440 
  • trunk/SignaturePlugin/lib/TWiki/Plugins/SignaturePlugin/Signature.pm

    r300 r1151  
    66# Always use strict to enforce variable scoping 
    77use strict; 
     8use TWiki::Attrs; 
    89 
    910sub handleSignature { 
    10   my ( $cnt, $attr ) = @_; 
    11   my $session = $TWiki::Plugins::SESSION; 
     11    my ( $cnt, $attr ) = @_; 
     12    my $session = $TWiki::Plugins::SESSION; 
    1213 
    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'; 
    1518 
    16   my $name = ''; 
    17   $name = '_('.$attr->{name}.')_ &nbsp;' if $attr->{name}; 
     19    my $name = ''; 
     20    $name = '_(' . $attr->{name} . ')_ &nbsp;' if $attr->{name}; 
    1821 
    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>"; 
    2026 
    2127} 
    2228 
    2329sub 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); 
    2834 
    29   my $cnt = $query->param( 'nr' ); 
     35    my $cnt = $query->param('nr'); 
    3036 
    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}; 
    3540 
    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' ) ); 
    3844 
    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 
    4961} 
    5062 
    5163sub replaceSignature { 
    52   my ( $dont, $user, $attr ) = @_; 
     64    my ( $dont, $user, $attr ) = @_; 
    5365 
    54   return ( ($attr)?"%SIGNATURE{$attr}%":'%SIGNATURE%' ) if $dont; 
     66    return ( ($attr) ? "%SIGNATURE{$attr}%" : '%SIGNATURE%' ) if $dont; 
    5567 
    56   $attr = new TWiki::Attrs($attr); 
     68    $attr = new TWiki::Attrs($attr); 
    5769 
    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    } 
    6789 
    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'; 
    6994 
    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 ); 
    7499 
    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; 
    80105 
    81   return $fmt; 
     106    return $fmt; 
    82107 
    83108} 
    84109 
    85 sub doEnableEdit 
    86 { 
     110sub doEnableEdit { 
    87111    my ( $theWeb, $theTopic, $user, $query ) = @_; 
    88112 
    89     if( ! &TWiki::Func::checkAccessPermission( "change", $user, "", $theTopic, $theWeb ) ) { 
     113    if ( 
     114        !&TWiki::Func::checkAccessPermission( 
     115            "change", $user, "", $theTopic, $theWeb 
     116        ) 
     117      ) 
     118    { 
     119 
    90120        # 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; 
    97130    } 
    98131 
    99132    ## 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; 
    105140    } 
    106141    TWiki::Func::setTopicEditLock( $theWeb, $theTopic, 1 ); 
Note: See TracChangeset for help on using the changeset viewer.