Ignore:
Timestamp:
11/19/08 15:00:00 (4 years ago)
Author:
CrawfordCurrie
Message:

Item175: port a subset of the standard extensions over to the new namespace to make a working system with mixed TWiki and Foswiki plugins

Location:
trunk/EmptyPlugin/lib/Foswiki
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm

    r781 r811  
    33# Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it 
    44# Copyright (C) 2001-2006 Peter Thoeny, peter@thoeny.org 
    5 # and TWiki Contributors. All Rights Reserved. TWiki Contributors 
     5# and Foswiki Contributors. All Rights Reserved. Foswiki Contributors 
    66# are listed in the AUTHORS file in the root of this distribution. 
    77# NOTE: Please extend that file, not this notice. 
     
    2828 
    2929This version of the !EmptyPlugin documents the handlers supported 
    30 by revision 1.2 of the Plugins API. See the documentation of =TWiki::Func= 
     30by revision 1.2 of the Plugins API. See the documentation of =Foswiki::Func= 
    3131for more information about what this revision number means, and how a 
    3232plugin can check it. 
    3333 
    3434__NOTE:__ To interact with TWiki use ONLY the official API functions 
    35 in the TWiki::Func module. Do not reference any functions or 
     35in the Foswiki::Func module. Do not reference any functions or 
    3636variables elsewhere in TWiki, as these are subject to change 
    3737without prior warning, and your plugin may suddenly stop 
     
    6464 
    6565# change the package name and $pluginName!!! 
    66 package TWiki::Plugins::EmptyPlugin; 
     66package Foswiki::Plugins::EmptyPlugin; 
    6767 
    6868# Always use strict to enforce variable scoping 
    6969use strict; 
    7070 
    71 require TWiki::Func;    # The plugins API 
    72 require TWiki::Plugins; # For the API version 
     71require Foswiki::Func;    # The plugins API 
     72require Foswiki::Plugins; # For the API version 
    7373 
    7474# $VERSION is referred to by TWiki, and is the only global variable that 
     
    9393# stored in the plugin topic. This default is required for compatibility with 
    9494# older plugins, but imposes a significant performance penalty, and 
    95 # is not recommended. Instead, use $TWiki::cfg entries set in LocalSite.cfg, or 
     95# is not recommended. Instead, use $Foswiki::cfg entries set in LocalSite.cfg, or 
    9696# if you want the users to be able to change settings, then use standard TWiki 
    9797# preferences that can be defined in your %USERSWEB%.SitePreferences and overridden 
     
    114114Called to initialise the plugin. If everything is OK, should return 
    115115a non-zero value. On non-fatal failure, should write a message 
    116 using TWiki::Func::writeWarning and return 0. In this case 
     116using Foswiki::Func::writeWarning and return 0. In this case 
    117117%FAILEDPLUGINS% will indicate which plugins failed. 
    118118 
     
    121121will be trapped and reported in the browser. 
    122122 
    123 You may also call =TWiki::Func::registerTagHandler= here to register 
     123You may also call =Foswiki::Func::registerTagHandler= here to register 
    124124a function to handle variables that have standard TWiki syntax - for example, 
    125125=%MYTAG{"my param" myarg="My Arg"}%. You can also override internal 
     
    138138 
    139139    # check for Plugins.pm versions 
    140     if( $TWiki::Plugins::VERSION < 1.026 ) { 
    141         TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); 
     140    if( $Foswiki::Plugins::VERSION < 1.026 ) { 
     141        Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); 
    142142        return 0; 
    143143    } 
     
    147147 
    148148    # Set plugin preferences in LocalSite.cfg, like this: 
    149     # $TWiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} = 1; 
     149    # $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} = 1; 
    150150    # Always provide a default in case the setting is not defined in 
    151151    # LocalSite.cfg. See %SYSTEMWEB%.Plugins for help in adding your plugin 
    152152    # configuration to the =configure= interface. 
    153     my $setting = $TWiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0; 
    154     $debug = $TWiki::cfg{Plugins}{EmptyPlugin}{Debug} || 0; 
     153    my $setting = $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0; 
     154    $debug = $Foswiki::cfg{Plugins}{EmptyPlugin}{Debug} || 0; 
    155155 
    156156    # register the _EXAMPLETAG function to handle %EXAMPLETAG{...}% 
    157157    # This will be called whenever %EXAMPLETAG% or %EXAMPLETAG{...}% is 
    158158    # seen in the topic text. 
    159     TWiki::Func::registerTagHandler( 'EXAMPLETAG', \&_EXAMPLETAG ); 
     159    Foswiki::Func::registerTagHandler( 'EXAMPLETAG', \&_EXAMPLETAG ); 
    160160 
    161161    # Allow a sub to be called from the REST interface  
    162162    # using the provided alias 
    163     TWiki::Func::registerRESTHandler('example', \&restExample); 
     163    Foswiki::Func::registerRESTHandler('example', \&restExample); 
    164164 
    165165    # Plugin correctly initialized 
     
    173173    # $session  - a reference to the TWiki session object (if you don't know 
    174174    #             what this is, just ignore it) 
    175     # $params=  - a reference to a TWiki::Attrs object containing parameters. 
     175    # $params=  - a reference to a Foswiki::Attrs object containing parameters. 
    176176    #             This can be used as a simple hash that maps parameter names 
    177177    #             to values, with _DEFAULT being the name for the default 
     
    215215This handler is called very early, immediately after =earlyInitPlugin=. 
    216216 
    217 *Since:* TWiki::Plugins::VERSION = '1.010' 
     217*Since:* Foswiki::Plugins::VERSION = '1.010' 
    218218 
    219219=cut 
     
    223223    ### my ( $loginName, $url, $pathInfo ) = @_; 
    224224 
    225     TWiki::Func::writeDebug( "- ${pluginName}::initializeUserHandler( $_[0], $_[1] )" ) if $debug; 
     225    Foswiki::Func::writeDebug( "- ${pluginName}::initializeUserHandler( $_[0], $_[1] )" ) if $debug; 
    226226} 
    227227 
     
    235235Called when a new user registers with this TWiki. 
    236236 
    237 *Since:* TWiki::Plugins::VERSION = '1.010' 
     237*Since:* Foswiki::Plugins::VERSION = '1.010' 
    238238 
    239239=cut 
     
    243243    ### my ( $web, $wikiName, $loginName ) = @_; 
    244244 
    245     TWiki::Func::writeDebug( "- ${pluginName}::registrationHandler( $_[0], $_[1] )" ) if $debug; 
     245    Foswiki::Func::writeDebug( "- ${pluginName}::registrationHandler( $_[0], $_[1] )" ) if $debug; 
    246246} 
    247247 
     
    259259 
    260260For variables with trivial syntax it is far more efficient to use 
    261 =TWiki::Func::registerTagHandler= (see =initPlugin=). 
     261=Foswiki::Func::registerTagHandler= (see =initPlugin=). 
    262262 
    263263Plugins that have to parse the entire topic content should implement 
    264264this function. Internal TWiki 
    265 variables (and any variables declared using =TWiki::Func::registerTagHandler=) 
     265variables (and any variables declared using =Foswiki::Func::registerTagHandler=) 
    266266are expanded _before_, and then again _after_, this function is called 
    267267to ensure all %<nop>TAGS% are expanded. 
     
    274274handler. Use the =$meta= object. 
    275275 
    276 *Since:* $TWiki::Plugins::VERSION 1.000 
     276*Since:* $Foswiki::Plugins::VERSION 1.000 
    277277 
    278278=cut 
     
    288288    #   } 
    289289 
    290     TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 
     290    Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    291291 
    292292    # do custom extension rule, like for example: 
     
    322322    ### my ( $text, $topic, $web, $meta ) = @_; 
    323323 
    324     TWiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
     324    Foswiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    325325} 
    326326 
     
    349349    ### my ( $text, $topic, $web, $meta ) = @_; 
    350350 
    351     TWiki::Func::writeDebug( "- ${pluginName}::afterCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
     351    Foswiki::Func::writeDebug( "- ${pluginName}::afterCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    352352} 
    353353 
     
    395395handler. 
    396396 
    397 Since TWiki::Plugins::VERSION = '1.026' 
     397Since Foswiki::Plugins::VERSION = '1.026' 
    398398 
    399399=cut 
     
    415415handler. 
    416416 
    417 Since TWiki::Plugins::VERSION = '1.026' 
     417Since Foswiki::Plugins::VERSION = '1.026' 
    418418 
    419419=cut 
     
    436436(using %META: tags) 
    437437 
    438 *Since:* TWiki::Plugins::VERSION = '1.010' 
     438*Since:* Foswiki::Plugins::VERSION = '1.010' 
    439439 
    440440=cut 
     
    444444    ### my ( $text, $topic, $web ) = @_; 
    445445 
    446     TWiki::Func::writeDebug( "- ${pluginName}::beforeEditHandler( $_[2].$_[1] )" ) if $debug; 
     446    Foswiki::Func::writeDebug( "- ${pluginName}::beforeEditHandler( $_[2].$_[1] )" ) if $debug; 
    447447} 
    448448 
     
    462462handler. Use the =$meta= object. 
    463463 
    464 *Since:* $TWiki::Plugins::VERSION 1.010 
     464*Since:* $Foswiki::Plugins::VERSION 1.010 
    465465 
    466466=cut 
     
    470470    ### my ( $text, $topic, $web ) = @_; 
    471471 
    472     TWiki::Func::writeDebug( "- ${pluginName}::afterEditHandler( $_[2].$_[1] )" ) if $debug; 
     472    Foswiki::Func::writeDebug( "- ${pluginName}::afterEditHandler( $_[2].$_[1] )" ) if $debug; 
    473473} 
    474474 
     
    479479   * =$topic= - the name of the topic in the current CGI query 
    480480   * =$web= - the name of the web in the current CGI query 
    481    * =$meta= - the metadata of the topic being saved, represented by a TWiki::Meta object. 
     481   * =$meta= - the metadata of the topic being saved, represented by a Foswiki::Meta object. 
    482482 
    483483This handler is called each time a topic is saved. 
     
    490490text format. 
    491491 
    492 *Since:* TWiki::Plugins::VERSION = '1.010' 
     492*Since:* Foswiki::Plugins::VERSION = '1.010' 
    493493 
    494494=cut 
     
    498498    ### my ( $text, $topic, $web ) = @_; 
    499499 
    500     TWiki::Func::writeDebug( "- ${pluginName}::beforeSaveHandler( $_[2].$_[1] )" ) if $debug; 
     500    Foswiki::Func::writeDebug( "- ${pluginName}::beforeSaveHandler( $_[2].$_[1] )" ) if $debug; 
    501501} 
    502502 
     
    509509   * =$web= - the name of the web in the current CGI query 
    510510   * =$error= - any error string returned by the save. 
    511    * =$meta= - the metadata of the saved topic, represented by a TWiki::Meta object  
     511   * =$meta= - the metadata of the saved topic, represented by a Foswiki::Meta object  
    512512 
    513513This handler is called each time a topic is saved. 
     
    515515__NOTE:__ meta-data is embedded in $text (using %META: tags) 
    516516 
    517 *Since:* TWiki::Plugins::VERSION 1.025 
     517*Since:* Foswiki::Plugins::VERSION 1.025 
    518518 
    519519=cut 
     
    523523    ### my ( $text, $topic, $web, $error, $meta ) = @_; 
    524524 
    525     TWiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( $_[2].$_[1] )" ) if $debug; 
     525    Foswiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( $_[2].$_[1] )" ) if $debug; 
    526526} 
    527527 
     
    539539This handler is called just after the rename/move/delete action of a web, topic or attachment. 
    540540 
    541 *Since:* TWiki::Plugins::VERSION = '1.11' 
     541*Since:* Foswiki::Plugins::VERSION = '1.11' 
    542542 
    543543=cut 
     
    547547    ### my ( $oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment ) = @_; 
    548548 
    549     TWiki::Func::writeDebug( "- ${pluginName}::afterRenameHandler( " . 
     549    Foswiki::Func::writeDebug( "- ${pluginName}::afterRenameHandler( " . 
    550550                             "$_[0].$_[1] $_[2] -> $_[3].$_[4] $_[5] )" ) if $debug; 
    551551} 
     
    566566   * =tmpFilename= - name of a temporary file containing the attachment data 
    567567 
    568 *Since:* TWiki::Plugins::VERSION = 1.025 
     568*Since:* Foswiki::Plugins::VERSION = 1.025 
    569569 
    570570=cut 
     
    573573    # do not uncomment, use $_[0], $_[1]... instead 
    574574    ###   my( $attrHashRef, $topic, $web ) = @_; 
    575     TWiki::Func::writeDebug( "- ${pluginName}::beforeAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
     575    Foswiki::Func::writeDebug( "- ${pluginName}::beforeAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
    576576} 
    577577 
     
    589589   * =user= - the user id 
    590590 
    591 *Since:* TWiki::Plugins::VERSION = 1.025 
     591*Since:* Foswiki::Plugins::VERSION = 1.025 
    592592 
    593593=cut 
     
    596596    # do not uncomment, use $_[0], $_[1]... instead 
    597597    ###   my( $attrHashRef, $topic, $web ) = @_; 
    598     TWiki::Func::writeDebug( "- ${pluginName}::afterAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
     598    Foswiki::Func::writeDebug( "- ${pluginName}::afterAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
    599599} 
    600600 
     
    641641required to resolve concurrent edits on a topic. 
    642642 
    643 *Since:* TWiki::Plugins::VERSION = 1.1 
     643*Since:* Foswiki::Plugins::VERSION = 1.1 
    644644 
    645645=cut 
     
    663663Note that this is the HTTP header which is _not_ the same as the HTML 
    664664&lt;HEAD&gt; tag. The contents of the &lt;HEAD&gt; tag may be manipulated 
    665 using the =TWiki::Func::addToHEAD= method. 
    666  
    667 *Since:* TWiki::Plugins::VERSION 1.1 
     665using the =Foswiki::Func::addToHEAD= method. 
     666 
     667*Since:* Foswiki::Plugins::VERSION 1.1 
    668668 
    669669=cut 
     
    672672    my ( $headers, $query ) = @_; 
    673673 
    674     TWiki::Func::writeDebug( "- ${pluginName}::modifyHeaderHandler()" ) if $debug; 
     674    Foswiki::Func::writeDebug( "- ${pluginName}::modifyHeaderHandler()" ) if $debug; 
    675675} 
    676676 
     
    687687the others will be ignored. 
    688688 
    689 *Since:* TWiki::Plugins::VERSION 1.010 
     689*Since:* Foswiki::Plugins::VERSION 1.010 
    690690 
    691691=cut 
     
    695695    ### my ( $query, $url ) = @_; 
    696696 
    697     TWiki::Func::writeDebug( "- ${pluginName}::redirectCgiQueryHandler( query, $_[1] )" ) if $debug; 
     697    Foswiki::Func::writeDebug( "- ${pluginName}::redirectCgiQueryHandler( query, $_[1] )" ) if $debug; 
    698698} 
    699699 
     
    717717continues by considering the built-in types. 
    718718 
    719 *Since:* TWiki::Plugins::VERSION 1.1 
     719*Since:* Foswiki::Plugins::VERSION 1.1 
    720720 
    721721Note that since TWiki-4.2, you can also extend the range of available 
    722 types by providing a subclass of =TWiki::Form::FieldDefinition= to implement 
    723 the new type (see =TWiki::Plugins.JSCalendarContrib= and 
    724 =TWiki::Plugins.RatingContrib= for examples). This is the preferred way to 
     722types by providing a subclass of =Foswiki::Form::FieldDefinition= to implement 
     723the new type (see =Foswiki::Plugins.JSCalendarContrib= and 
     724=Foswiki::Plugins.RatingContrib= for examples). This is the preferred way to 
    725725extend the form field types, but does not work for TWiki < 4.2. 
    726726 
     
    743743Return the new link text. 
    744744 
    745 *Since:* TWiki::Plugins::VERSION 1.1 
     745*Since:* Foswiki::Plugins::VERSION 1.1 
    746746 
    747747=cut 
     
    764764     the page is actually written. This is a string, which must end in \n\n. 
    765765 
    766 *Since:* TWiki::Plugins::VERSION 1.2 
     766*Since:* Foswiki::Plugins::VERSION 1.2 
    767767 
    768768=cut 
     
    784784For more information, check %SYSTEMWEB%.CommandAndCGIScripts#rest 
    785785 
    786 *Since:* TWiki::Plugins::VERSION 1.1 
     786*Since:* Foswiki::Plugins::VERSION 1.1 
    787787 
    788788=cut 
Note: See TracChangeset for help on using the changeset viewer.