Changeset 1318


Ignore:
Timestamp:
12/13/08 15:44:10 (3 years ago)
Author:
CrawfordCurrie
Message:

Item255: doc cleanups and corrections

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/EmptyPlugin/data/System/EmptyPlugin.txt

    r1223 r1318  
    1 %META:TOPICINFO{author="ProjectContributor" date="1111929255" format="1.0" version="$Rev: 14040 $"}% 
    21---+ Empty Plugin 
    32 
    4 This is an empty Plugin you can use as a template to build your own [[%SYSTEMWEB%.Plugins][Plugins]]. This Plugin does nothing, but is ready to be used. 
     3This Plugin does nothing. 
    54 
    6 To create your own Plugin: 
     5This is an empty Plugin topic you can use as a template for your own Plugin 
     6documentation topic. 
    77 
    8    * Copy file ==lib/Foswiki/Plugins/EmptyPlugin.pm== to ==lib/Foswiki/Plugins/<name>Plugin.pm==. 
    9    * Create a  ==<name>Plugin== topic in the %SYSTEMWEB% web. Do so by visiting http://foswiki.org/Extensions/PluginPackage#NewPlugin and starting a new topic to get the default plugin topic text (don't save the topic). Customize your plugin topic to your needs. 
    10    * See details in [[%SYSTEMWEB%.DevelopingPlugins][DevelopingPlugins]]. 
    11  
    12 ---++ Plugin Handlers 
    13 The following plugin handlers are defined. 
    14  
    15 %INCLUDE{"doc:Foswiki::Plugins::EmptyPlugin" level="3"}% 
     8Learn how to create your own plugin in %SYSTEMWEB%.DevelopingPlugins. 
    169 
    1710---++ Plugin Preferences 
    1811 
    19 Preference settings specific to your plugin can be stored as [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. Default values for these preferences can be set in plugin topics; for example: 
     12Settings specific to your plugin can be stored as [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. Default values for these preferences can be set in plugin topics; for example: 
    2013   * One line description, used by other tools: 
    2114      * Set SHORTDESCRIPTION = Empty Plugin used as a template for new Plugins 
     
    2518      * <nop>Set EMPTYPLUGIN_MYPREFERENCE = my preference 
    2619 
     20---++ Installation 
     21%$INSTALL_INSTRUCTIONS% 
     22 
    2723---++ Plugin Info 
    2824 
    29 Plugin Author: | Foswiki:Main.AndreaSterbini, TWiki:Main.PeterThoeny, Foswiki:Main.CrawfordCurrie | 
    30 |  Copyright: | &copy; 2008, Foswiki Contributors<br>&copy; 2001-2007, TWiki Contributors | 
     25Author: | Foswiki:Main.PluginAuthor| 
     26|  Copyright: | &copy; 2008, Foswiki Contributors | 
    3127|  License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 
    32 |  Plugin Version: | %$VERSION% | 
     28|  Version: | %$VERSION% | 
     29|  Home: | Foswiki:Extensions.EmptyPlugin | 
    3330 
    3431 
    35  
  • trunk/EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm

    r1316 r1318  
    44 
    55---+ package EmptyPlugin 
     6 
     7Foswiki plugins 'listen' to events happening in the core by registering an 
     8interest in those events. They do this by declaring 'plugin handlers'. These 
     9are simply functions with a particular name that, if they exist in your 
     10plugin, will be called by the core. 
    611 
    712This is an empty Foswiki plugin. It is a fully defined plugin, but is 
    813disabled by default in a Foswiki installation. Use it as a template 
    9 for your own plugins; see %SYSTEMWEB%.Plugins for details. 
    10  
    11 This version of the !EmptyPlugin documents the handlers supported 
    12 by revision 1.2 of the Plugins API. See the documentation of =Foswiki::Func= 
    13 for more information about what this revision number means, and how a 
    14 plugin can check it. 
    15  
    16 *NOTE:* To interact with Foswiki use ONLY the official API functions 
    17 in the Foswiki::Func module. Do not reference any functions or 
    18 variables elsewhere in Foswiki, as these are subject to change 
    19 without prior warning, and your plugin may suddenly stop 
     14for your own plugins. 
     15 
     16To interact with Foswiki use ONLY the official APIs 
     17documented in %SYSTEMWEB%.DevelopingPlugins. <strong>Do not reference any 
     18packages, functions or variables elsewhere in Foswiki</strong>, as these are 
     19subject to change without prior warning, and your plugin may suddenly stop 
    2020working. 
    2121 
    22 For increased performance, all handlers except initPlugin are 
    23 disabled below. *To enable a handler* remove the leading DISABLE_ from 
    24 the function name. For efficiency and clarity, you should comment out or 
    25 delete the whole of handlers you don't use before you release your 
    26 plugin. 
    27  
    28 *NOTE:* When developing a plugin it is important to remember that 
     22Error messages can be output using the =Foswiki::Func= =writeWarning= and 
     23=writeDebug= functions. You can also =print STDERR=; the output will appear 
     24in the webserver error log. Most handlers can also throw exceptions (e.g. 
     25[[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::OopsException][Foswiki::OopsException]]) 
     26 
     27For increased performance, all handler functions except =initPlugin= are 
     28commented out below. *To enable a handler* remove the leading =#= from 
     29each line of the function. For efficiency and clarity, you should 
     30only uncomment handlers you actually use. 
     31 
     32__NOTE:__ When developing a plugin it is important to remember that 
     33 
    2934Foswiki is tolerant of plugins that do not compile. In this case, 
    3035the failure will be silent but the plugin will not be available. 
    31 See [[%SYSTEMWEB%.Plugins#FAILEDPLUGINS]] for error messages. 
    32  
    33 *NOTE:* Defining deprecated handlers will cause the handlers to be  
    34 listed in [[%SYSTEMWEB%.Plugins#FAILEDPLUGINS]]. See 
    35 [[%SYSTEMWEB%.Plugins#Handlig_deprecated_functions]] 
    36 for information on regarding deprecated handlers that are defined for 
    37 compatibility with older Foswiki versions. 
    38  
    39 *NOTE:* All but the initPlugin are disabled. To enable a callback, remove =DISABLE_= from the function name. 
    40  
    41 %STARTINCLUDE% 
    42  
    43 *NOTE:* When writing handlers, keep in mind that these may be invoked 
     36See %SYSTEMWEB%.InstalledPlugins for error messages. 
     37 
     38__NOTE:__ Foswiki:Development.StepByStepRenderingOrder helps you decide which 
     39rendering handler to use. When writing handlers, keep in mind that these may 
     40be invoked 
     41 
    4442on included topics. For example, if a plugin generates links to the current 
    45 topic, these need to be generated before the afterCommonTagsHandler is run, 
    46 as at that point in the rendering loop we have lost the information that we 
     43topic, these need to be generated before the =afterCommonTagsHandler= is run. 
     44After that point in the rendering loop we have lost the information that 
    4745the text had been included from another topic. 
    4846 
    4947=cut 
    5048 
    51 # change the package name and $pluginName!!! 
     49# change the package name!!! 
    5250package Foswiki::Plugins::EmptyPlugin; 
    5351 
     
    6058# $VERSION is referred to by Foswiki, and is the only global variable that 
    6159# *must* exist in this package. 
    62 use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC ); 
    63  
    6460# This should always be $Rev$ so that Foswiki can determine the checked-in 
    6561# status of the plugin. It is used by the build automation tools, so 
    6662# you should leave it alone. 
    67 $VERSION = '$Rev$'; 
     63our $VERSION = '$Rev$'; 
    6864 
    6965# This is a free-form string you can use to "name" your own plugin version. 
    7066# It is *not* used by the build automation tools, but is reported as part 
    7167# of the version number in PLUGINDESCRIPTIONS. 
    72 $RELEASE = 'Foswiki-4.2'; 
     68our $RELEASE = '$Date$'; 
    7369 
    7470# Short description of this plugin 
    7571# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: 
    76 $SHORTDESCRIPTION = 'Empty Plugin used as a template for new Plugins'; 
    77  
    78 # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use preferences 
    79 # stored in the plugin topic. This default is required for compatibility with 
    80 # older plugins, but imposes a significant performance penalty, and 
    81 # is not recommended. Instead, use $Foswiki::cfg entries set in LocalSite.cfg, or 
    82 # if you want the users to be able to change settings, then use standard Foswiki 
    83 # preferences that can be defined in your %USERSWEB%.SitePreferences and overridden 
    84 # at the web and topic level. 
    85 $NO_PREFS_IN_TOPIC = 1; 
    86  
    87 # Name of this Plugin, only used in this module 
    88 $pluginName = 'EmptyPlugin'; 
    89  
    90 =begin TML 
    91  
    92 ---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean 
     72our $SHORTDESCRIPTION = 'Empty Plugin used as a template for new Plugins'; 
     73 
     74# You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use 
     75# preferences set in the plugin topic. This is required for compatibility 
     76# with older plugins, but imposes a significant performance penalty, and 
     77# is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use 
     78# =$Foswiki::cfg= entries set in =LocalSite.cfg=, or if you want the users 
     79# to be able to change settings, then use standard Foswiki preferences that 
     80# can be defined in your %USERSWEB%.SitePreferences and overridden at the web 
     81# and topic level. 
     82our $NO_PREFS_IN_TOPIC = 1; 
     83 
     84=begin TML 
     85 
     86---++ initPlugin($topic, $web, $user) -> $boolean 
    9387   * =$topic= - the name of the topic in the current CGI query 
    9488   * =$web= - the name of the web in the current CGI query 
    9589   * =$user= - the login name of the user 
    96    * =$installWeb= - the name of the web the plugin is installed in 
    97  
    98 REQUIRED 
     90   * =$installWeb= - the name of the web the plugin topic is in 
     91     (usually the same as =$Foswiki::cfg{SystemWebName}=) 
     92 
     93*REQUIRED* 
    9994 
    10095Called to initialise the plugin. If everything is OK, should return 
    10196a non-zero value. On non-fatal failure, should write a message 
    102 using Foswiki::Func::writeWarning and return 0. In this case 
     97using =Foswiki::Func::writeWarning= and return 0. In this case 
    10398%<nop>FAILEDPLUGINS% will indicate which plugins failed. 
    10499 
     
    107102will be trapped and reported in the browser. 
    108103 
    109 You may also call =Foswiki::Func::registerTagHandler= here to register 
    110 a function to handle variables that have standard Foswiki syntax - for example, 
    111 =%<nop>MYTAG{"my param" myarg="My Arg"}%. You can also override internal 
    112 Foswiki variable handling functions this way, though this practice is unsupported 
    113 and highly dangerous! 
    114  
    115 *Note:* Please align variables names with the Plugin name, e.g. if  
    116 your Plugin is called FooBarPlugin, name variables FOOBAR and/or  
     104__Note:__ Please align macro names with the Plugin name, e.g. if 
     105your Plugin is called !FooBarPlugin, name macros FOOBAR and/or 
    117106FOOBARSOMETHING. This avoids namespace issues. 
    118  
    119107 
    120108=cut 
     
    124112 
    125113    # check for Plugins.pm versions 
    126     if( $Foswiki::Plugins::VERSION < 1.026 ) { 
    127         Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); 
     114    if( $Foswiki::Plugins::VERSION < 2.0 ) { 
     115        Foswiki::Func::writeWarning( 'Version mismatch between ', 
     116                                     __PACKAGE__, ' and Plugins.pm' ); 
    128117        return 0; 
    129118    } 
    130119 
    131     # Example code of how to get a preference value, register a variable handler 
    132     # and register a RESTHandler. (remove code you do not need) 
    133  
    134     # Set plugin preferences in LocalSite.cfg, like this: 
     120    # Example code of how to get a preference value, register a macro 
     121    # handler and register a RESTHandler (remove code you do not need) 
     122 
     123    # Set your per-installation plugin configuration in LocalSite.cfg, 
     124    # like this: 
    135125    # $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} = 1; 
     126    # Optional: See %SYSTEMWEB%.DevelopingPlugins#ConfigSpec for information 
     127    # on integrating your plugin configuration with =configure=. 
     128 
    136129    # Always provide a default in case the setting is not defined in 
    137130    # LocalSite.cfg. See %SYSTEMWEB%.Plugins for help in adding your plugin 
    138131    # configuration to the =configure= interface. 
    139     my $setting = $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0; 
    140     $debug = $Foswiki::cfg{Plugins}{EmptyPlugin}{Debug} || 0; 
    141  
    142     # register the _EXAMPLETAG function to handle %EXAMPLETAG{...}% 
     132    # my $setting = $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0; 
     133 
     134    # Register the _EXAMPLETAG function to handle %EXAMPLETAG{...}% 
    143135    # This will be called whenever %EXAMPLETAG% or %EXAMPLETAG{...}% is 
    144136    # seen in the topic text. 
     
    153145} 
    154146 
    155 # The function used to handle the %EXAMPLETAG{...}% variable 
    156 # You would have one of these for each variable you want to process. 
    157 sub _EXAMPLETAG { 
    158     my($session, $params, $theTopic, $theWeb) = @_; 
    159     # $session  - a reference to the Foswiki session object (if you don't know 
    160     #             what this is, just ignore it) 
    161     # $params=  - a reference to a Foswiki::Attrs object containing parameters. 
    162     #             This can be used as a simple hash that maps parameter names 
    163     #             to values, with _DEFAULT being the name for the default 
    164     #             parameter. 
    165     # $theTopic - name of the topic in the query 
    166     # $theWeb   - name of the web in the query 
    167     # Return: the result of processing the variable 
    168  
    169     # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}% 
    170     # $params->{_DEFAULT} will be 'hamburger' 
    171     # $params->{sideorder} will be 'onions' 
    172 } 
     147# The function used to handle the %EXAMPLETAG{...}% macro 
     148# You would have one of these for each macro you want to process. 
     149#sub _EXAMPLETAG { 
     150#    my($session, $params, $theTopic, $theWeb) = @_; 
     151#    # $session  - a reference to the Foswiki session object (if you don't know 
     152#    #             what this is, just ignore it) 
     153#    # $params=  - a reference to a Foswiki::Attrs object containing 
     154#    #             parameters. 
     155#    #             This can be used as a simple hash that maps parameter names 
     156#    #             to values, with _DEFAULT being the name for the default 
     157#    #             (unnamed) parameter. 
     158#    # $theTopic - name of the topic in the query 
     159#    # $theWeb   - name of the web in the query 
     160#    # Return: the result of processing the macro. This will replace the 
     161#    # macro call in the final text. 
     162# 
     163#    # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}% 
     164#    # $params->{_DEFAULT} will be 'hamburger' 
     165#    # $params->{sideorder} will be 'onions' 
     166#} 
    173167 
    174168=begin TML 
     
    183177=cut 
    184178 
    185 sub DISABLE_earlyInitPlugin { 
    186     return undef; 
    187 } 
     179#sub earlyInitPlugin { 
     180#    return undef; 
     181#} 
    188182 
    189183=begin TML 
     
    201195This handler is called very early, immediately after =earlyInitPlugin=. 
    202196 
    203 *Since:* Foswiki::Plugins::VERSION = '1.010' 
    204  
    205 =cut 
    206  
    207 sub DISABLE_initializeUserHandler { 
    208     # do not uncomment, use $_[0], $_[1]... instead 
    209     ### my ( $loginName, $url, $pathInfo ) = @_; 
    210  
    211     Foswiki::Func::writeDebug( "- ${pluginName}::initializeUserHandler( $_[0], $_[1] )" ) if $debug; 
    212 } 
     197*Since:* Foswiki::Plugins::VERSION = '2.0' 
     198 
     199=cut 
     200 
     201#sub initializeUserHandler { 
     202#    my ( $loginName, $url, $pathInfo ) = @_; 
     203#} 
    213204 
    214205=begin TML 
     
    221212Called when a new user registers with this Foswiki. 
    222213 
    223 *Since:* Foswiki::Plugins::VERSION = '1.010' 
    224  
    225 =cut 
    226  
    227 sub DISABLE_registrationHandler { 
    228     # do not uncomment, use $_[0], $_[1]... instead 
    229     ### my ( $web, $wikiName, $loginName ) = @_; 
    230  
    231     Foswiki::Func::writeDebug( "- ${pluginName}::registrationHandler( $_[0], $_[1] )" ) if $debug; 
    232 } 
     214*Since:* Foswiki::Plugins::VERSION = '2.0' 
     215 
     216=cut 
     217 
     218#sub registrationHandler { 
     219#    my ( $web, $wikiName, $loginName ) = @_; 
     220#} 
    233221 
    234222=begin TML 
     
    238226   * =$topic= - the name of the topic in the current CGI query 
    239227   * =$web= - the name of the web in the current CGI query 
    240    * =$included= - Boolean flag indicating whether the handler is invoked on an included topic 
     228   * =$included= - Boolean flag indicating whether the handler is 
     229     invoked on an included topic 
    241230   * =$meta= - meta-data object for the topic MAY BE =undef= 
    242 This handler is called by the code that expands %<nop>TAGS% syntax in 
     231This handler is called by the code that expands %<nop>MACROS% syntax in 
    243232the topic body and in form fields. It may be called many times while 
    244233a topic is being rendered. 
    245234 
    246 For variables with trivial syntax it is far more efficient to use 
    247 =Foswiki::Func::registerTagHandler= (see =initPlugin=). 
    248  
    249 Plugins that have to parse the entire topic content should implement 
    250 this function. Internal Foswiki 
    251 variables (and any variables declared using =Foswiki::Func::registerTagHandler=) 
    252 are expanded _before_, and then again _after_, this function is called 
    253 to ensure all %<nop>TAGS% are expanded. 
     235Only plugins that have to parse the entire topic content should implement 
     236this function. For expanding macros with trivial syntax it is *far* more 
     237efficient to use =Foswiki::Func::registerTagHandler= (see =initPlugin=). 
     238 
     239Internal Foswiki macros, (and any macros declared using 
     240=Foswiki::Func::registerTagHandler=) are expanded _before_, and then again 
     241_after_, this function is called to ensure all %<nop>MACROS% are expanded. 
    254242 
    255243*NOTE:* when this handler is called, &lt;verbatim> blocks have been 
     
    260248handler. Use the =$meta= object. 
    261249 
    262 *Since:* $Foswiki::Plugins::VERSION 1.000 
    263  
    264 =cut 
    265  
    266 sub DISABLE_commonTagsHandler { 
    267     # do not uncomment, use $_[0], $_[1]... instead 
    268     ### my ( $text, $topic, $web, $included, $meta ) = @_; 
    269      
    270     # If you don't want to be called from nested includes... 
    271     #   if( $_[3] ) { 
    272     #   # bail out, handler called from an %INCLUDE{}% 
    273     #         return; 
    274     #   } 
    275  
    276     Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    277  
    278     # do custom extension rule, like for example: 
    279     # $_[0] =~ s/%XYZ%/&handleXyz()/ge; 
    280     # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/ge; 
    281 } 
     250*Since:* $Foswiki::Plugins::VERSION 2.0 
     251 
     252=cut 
     253 
     254#sub commonTagsHandler { 
     255#    my ( $text, $topic, $web, $included, $meta ) = @_; 
     256# 
     257#    # If you don't want to be called from nested includes... 
     258#    #   if( $included ) { 
     259#    #         # bail out, handler called from an %INCLUDE{}% 
     260#    #         return; 
     261#    #   } 
     262# 
     263#    # You can work on $text in place by using the special perl 
     264#    # variable $_[0]. These allow you to operate on $text 
     265#    # as if it was passed by reference; for example: 
     266#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     267#} 
    282268 
    283269=begin TML 
     
    288274   * =$web= - the name of the web in the current CGI query 
    289275   * =$meta= - meta-data object for the topic MAY BE =undef= 
    290 This handler is called before Foswiki does any expansion of it's own 
     276This handler is called before Foswiki does any expansion of its own 
    291277internal variables. It is designed for use by cache plugins. Note that 
    292278when this handler is called, &lt;verbatim> blocks are still present 
     
    304290=cut 
    305291 
    306 sub DISABLE_beforeCommonTagsHandler { 
    307     # do not uncomment, use $_[0], $_[1]... instead 
    308     ### my ( $text, $topic, $web, $meta ) = @_; 
    309  
    310     Foswiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    311 } 
     292#sub beforeCommonTagsHandler { 
     293#    my ( $text, $topic, $web, $meta ) = @_; 
     294# 
     295#    # You can work on $text in place by using the special perl 
     296#    # variable $_[0]. These allow you to operate on $text 
     297#    # as if it was passed by reference; for example: 
     298#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     299#} 
    312300 
    313301=begin TML 
     
    318306   * =$web= - the name of the web in the current CGI query 
    319307   * =$meta= - meta-data object for the topic MAY BE =undef= 
    320 This handler is after Foswiki has completed expansion of %TAGS%. 
     308This handler is called after Foswiki has completed expansion of %MACROS%. 
    321309It is designed for use by cache plugins. Note that when this handler 
    322310is called, &lt;verbatim> blocks are present in the text. 
     
    331319=cut 
    332320 
    333 sub DISABLE_afterCommonTagsHandler { 
    334     # do not uncomment, use $_[0], $_[1]... instead 
    335     ### my ( $text, $topic, $web, $meta ) = @_; 
    336  
    337     Foswiki::Func::writeDebug( "- ${pluginName}::afterCommonTagsHandler( $_[2].$_[1] )" ) if $debug; 
    338 } 
     321#sub afterCommonTagsHandler { 
     322#    my ( $text, $topic, $web, $meta ) = @_; 
     323# 
     324#    # You can work on $text in place by using the special perl 
     325#    # variable $_[0]. These allow you to operate on $text 
     326#    # as if it was passed by reference; for example: 
     327#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     328#} 
    339329 
    340330=begin TML 
    341331 
    342332---++ preRenderingHandler( $text, \%map ) 
    343    * =$text= - text, with the head, verbatim and pre blocks replaced with placeholders 
    344    * =\%removed= - reference to a hash that maps the placeholders to the removed blocks. 
     333   * =$text= - text, with the head, verbatim and pre blocks replaced 
     334     with placeholders 
     335   * =\%removed= - reference to a hash that maps the placeholders to 
     336     the removed blocks. 
    345337 
    346338Handler called immediately before Foswiki syntax structures (such as lists) are 
    347 processed, but after all variables have been expanded. Use this handler to  
     339processed, but after all variables have been expanded. Use this handler to 
    348340process special syntax only recognised by your plugin. 
    349341 
    350 Placeholders are text strings constructed using the tag name and a  
    351 sequence number e.g. 'pre1', "verbatim6", "head1" etc. Placeholders are  
    352 inserted into the text inside &lt;!--!marker!--&gt; characters so the  
     342Placeholders are text strings constructed using the tag name and a 
     343sequence number e.g. 'pre1', "verbatim6", "head1" etc. Placeholders are 
     344inserted into the text inside &lt;!--!marker!--&gt; characters so the 
    353345text will contain &lt;!--!pre1!--&gt; for placeholder pre1. 
    354346 
    355 Each removed block is represented by the block text and the parameters  
     347Each removed block is represented by the block text and the parameters 
    356348passed to the tag (usually empty) e.g. for 
    357349<verbatim> 
     
    365357$removed->{'pre1'}{params}: class="slobadob" 
    366358</pre> 
    367 Iterating over blocks for a single tag is easy. For example, to prepend a  
     359Iterating over blocks for a single tag is easy. For example, to prepend a 
    368360line number to every line of every pre block you might use this code: 
    369361<verbatim> 
    370362foreach my $placeholder ( keys %$map ) { 
    371363    if( $placeholder =~ /^pre/i ) { 
    372        my $n = 1; 
    373        $map->{$placeholder}{text} =~ s/^/$n++/gem; 
     364        my $n = 1; 
     365        $map->{$placeholder}{text} =~ s/^/$n++/gem; 
    374366    } 
    375367} 
    376368</verbatim> 
    377369 
     370__NOTE__: This handler is called once for each rendered block of text i.e. 
     371it may be called several times during the rendering of a topic. 
     372 
     373*NOTE:* meta-data is _not_ embedded in the text passed to this 
     374handler. 
     375 
     376Since Foswiki::Plugins::VERSION = '2.0' 
     377 
     378=cut 
     379 
     380#sub preRenderingHandler { 
     381#    my( $text, $pMap ) = @_; 
     382# 
     383#    # You can work on $text in place by using the special perl 
     384#    # variable $_[0]. These allow you to operate on $text 
     385#    # as if it was passed by reference; for example: 
     386#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     387#} 
     388 
     389=begin TML 
     390 
     391---++ postRenderingHandler( $text ) 
     392   * =$text= - the text that has just been rendered. May be modified in place. 
     393 
    378394*NOTE*: This handler is called once for each rendered block of text i.e.  
    379395it may be called several times during the rendering of a topic. 
     
    382398handler. 
    383399 
    384 Since Foswiki::Plugins::VERSION = '1.026' 
    385  
    386 =cut 
    387  
    388 sub DISABLE_preRenderingHandler { 
    389     # do not uncomment, use $_[0], $_[1]... instead 
    390     #my( $text, $pMap ) = @_; 
    391 } 
    392  
    393 =begin TML 
    394  
    395 ---++ postRenderingHandler( $text ) 
    396    * =$text= - the text that has just been rendered. May be modified in place. 
    397  
    398 *NOTE*: This handler is called once for each rendered block of text i.e.  
    399 it may be called several times during the rendering of a topic. 
    400  
    401 *NOTE:* meta-data is _not_ embedded in the text passed to this 
    402 handler. 
    403  
    404 Since Foswiki::Plugins::VERSION = '1.026' 
    405  
    406 =cut 
    407  
    408 sub DISABLE_postRenderingHandler { 
    409     # do not uncomment, use $_[0], $_[1]... instead 
    410     #my $text = shift; 
    411 } 
     400Since Foswiki::Plugins::VERSION = '2.0' 
     401 
     402=cut 
     403 
     404#sub postRenderingHandler { 
     405#    my $text = shift; 
     406#    # You can work on $text in place by using the special perl 
     407#    # variable $_[0]. These allow you to operate on $text 
     408#    # as if it was passed by reference; for example: 
     409#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     410#} 
    412411 
    413412=begin TML 
     
    423422(using %META: tags) 
    424423 
    425 *Since:* Foswiki::Plugins::VERSION = '1.010' 
    426  
    427 =cut 
    428  
    429 sub DISABLE_beforeEditHandler { 
    430     # do not uncomment, use $_[0], $_[1]... instead 
    431     ### my ( $text, $topic, $web ) = @_; 
    432  
    433     Foswiki::Func::writeDebug( "- ${pluginName}::beforeEditHandler( $_[2].$_[1] )" ) if $debug; 
    434 } 
     424*Since:* Foswiki::Plugins::VERSION = '2.0' 
     425 
     426=cut 
     427 
     428#sub beforeEditHandler { 
     429#    my ( $text, $topic, $web ) = @_; 
     430# 
     431#    # You can work on $text in place by using the special perl 
     432#    # variable $_[0]. These allow you to operate on $text 
     433#    # as if it was passed by reference; for example: 
     434#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     435#} 
    435436 
    436437=begin TML 
     
    449450handler. Use the =$meta= object. 
    450451 
    451 *Since:* $Foswiki::Plugins::VERSION 1.010 
    452  
    453 =cut 
    454  
    455 sub DISABLE_afterEditHandler { 
    456     # do not uncomment, use $_[0], $_[1]... instead 
    457     ### my ( $text, $topic, $web ) = @_; 
    458  
    459     Foswiki::Func::writeDebug( "- ${pluginName}::afterEditHandler( $_[2].$_[1] )" ) if $debug; 
    460 } 
     452*Since:* $Foswiki::Plugins::VERSION 2.0 
     453 
     454=cut 
     455 
     456#sub afterEditHandler { 
     457#    my ( $text, $topic, $web ) = @_; 
     458# 
     459#    # You can work on $text in place by using the special perl 
     460#    # variable $_[0]. These allow you to operate on $text 
     461#    # as if it was passed by reference; for example: 
     462#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     463#} 
    461464 
    462465=begin TML 
     
    477480text format. 
    478481 
    479 *Since:* Foswiki::Plugins::VERSION = '1.010' 
    480  
    481 =cut 
    482  
    483 sub DISABLE_beforeSaveHandler { 
    484     # do not uncomment, use $_[0], $_[1]... instead 
    485     ### my ( $text, $topic, $web ) = @_; 
    486  
    487     Foswiki::Func::writeDebug( "- ${pluginName}::beforeSaveHandler( $_[2].$_[1] )" ) if $debug; 
    488 } 
     482*Since:* Foswiki::Plugins::VERSION = 2.0 
     483 
     484=cut 
     485 
     486#sub beforeSaveHandler { 
     487#    my ( $text, $topic, $web ) = @_; 
     488# 
     489#    # You can work on $text in place by using the special perl 
     490#    # variable $_[0]. These allow you to operate on $text 
     491#    # as if it was passed by reference; for example: 
     492#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     493#} 
    489494 
    490495=begin TML 
     
    502507*NOTE:* meta-data is embedded in $text (using %META: tags) 
    503508 
    504 *Since:* Foswiki::Plugins::VERSION 1.025 
    505  
    506 =cut 
    507  
    508 sub DISABLE_afterSaveHandler { 
    509     # do not uncomment, use $_[0], $_[1]... instead 
    510     ### my ( $text, $topic, $web, $error, $meta ) = @_; 
    511  
    512     Foswiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( $_[2].$_[1] )" ) if $debug; 
    513 } 
     509*Since:* Foswiki::Plugins::VERSION 2.0 
     510 
     511=cut 
     512 
     513#sub afterSaveHandler { 
     514#    my ( $text, $topic, $web, $error, $meta ) = @_; 
     515# 
     516#    # You can work on $text in place by using the special perl 
     517#    # variable $_[0]. These allow you to operate on $text 
     518#    # as if it was passed by reference; for example: 
     519#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     520#} 
    514521 
    515522=begin TML 
     
    526533This handler is called just after the rename/move/delete action of a web, topic or attachment. 
    527534 
    528 *Since:* Foswiki::Plugins::VERSION = '1.11' 
    529  
    530 =cut 
    531  
    532 sub DISABLE_afterRenameHandler { 
    533     # do not uncomment, use $_[0], $_[1]... instead 
    534     ### my ( $oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment ) = @_; 
    535  
    536     Foswiki::Func::writeDebug( "- ${pluginName}::afterRenameHandler( " . 
    537                              "$_[0].$_[1] $_[2] -> $_[3].$_[4] $_[5] )" ) if $debug; 
    538 } 
     535*Since:* Foswiki::Plugins::VERSION = '2.0' 
     536 
     537=cut 
     538 
     539#sub afterRenameHandler { 
     540#    my ( $oldWeb, $oldTopic, $oldAttachment, 
     541#         $newWeb, $newTopic, $newAttachment ) = @_; 
     542#} 
    539543 
    540544=begin TML 
     
    553557   * =tmpFilename= - name of a temporary file containing the attachment data 
    554558 
    555 *Since:* Foswiki::Plugins::VERSION = 1.025 
    556  
    557 =cut 
    558  
    559 sub DISABLE_beforeAttachmentSaveHandler { 
    560     # do not uncomment, use $_[0], $_[1]... instead 
    561     ###   my( $attrHashRef, $topic, $web ) = @_; 
    562     Foswiki::Func::writeDebug( "- ${pluginName}::beforeAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
    563 } 
     559*Since:* Foswiki::Plugins::VERSION = 2.0 
     560 
     561=cut 
     562 
     563#sub beforeAttachmentSaveHandler { 
     564#    my( $attrHashRef, $topic, $web ) = @_; 
     565#} 
    564566 
    565567=begin TML 
     
    576578   * =user= - the user id 
    577579 
    578 *Since:* Foswiki::Plugins::VERSION = 1.025 
    579  
    580 =cut 
    581  
    582 sub DISABLE_afterAttachmentSaveHandler { 
    583     # do not uncomment, use $_[0], $_[1]... instead 
    584     ###   my( $attrHashRef, $topic, $web ) = @_; 
    585     Foswiki::Func::writeDebug( "- ${pluginName}::afterAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug; 
    586 } 
     580*Since:* Foswiki::Plugins::VERSION = 2.0 
     581 
     582=cut 
     583 
     584#sub afterAttachmentSaveHandler { 
     585#    my( $attrHashRef, $topic, $web ) = @_; 
     586#} 
    587587 
    588588=begin TML 
     
    628628required to resolve concurrent edits on a topic. 
    629629 
    630 *Since:* Foswiki::Plugins::VERSION = 1.1 
    631  
    632 =cut 
    633  
    634 sub DISABLE_mergeHandler { 
    635 } 
     630*Since:* Foswiki::Plugins::VERSION = 2.0 
     631 
     632=cut 
     633 
     634#sub mergeHandler { 
     635#    my ( $diff, $old, $new, $info ) = @_; 
     636#} 
    636637 
    637638=begin TML 
     
    652653using the =Foswiki::Func::addToHEAD= method. 
    653654 
    654 *Since:* Foswiki::Plugins::VERSION 1.1 
    655  
    656 =cut 
    657  
    658 sub DISABLE_modifyHeaderHandler { 
    659     my ( $headers, $query ) = @_; 
    660  
    661     Foswiki::Func::writeDebug( "- ${pluginName}::modifyHeaderHandler()" ) if $debug; 
    662 } 
     655*Since:* Foswiki::Plugins::VERSION 2.0 
     656 
     657=cut 
     658 
     659#sub modifyHeaderHandler { 
     660#    my ( $headers, $query ) = @_; 
     661#} 
    663662 
    664663=begin TML 
     
    674673the others will be ignored. 
    675674 
    676 *Since:* Foswiki::Plugins::VERSION 1.010 
    677  
    678 =cut 
    679  
    680 sub DISABLE_redirectCgiQueryHandler { 
    681     # do not uncomment, use $_[0], $_[1] instead 
    682     ### my ( $query, $url ) = @_; 
    683  
    684     Foswiki::Func::writeDebug( "- ${pluginName}::redirectCgiQueryHandler( query, $_[1] )" ) if $debug; 
    685 } 
     675*Since:* Foswiki::Plugins::VERSION 2.0 
     676 
     677=cut 
     678 
     679#sub redirectCgiQueryHandler { 
     680#    my ( $query, $url ) = @_; 
     681#} 
    686682 
    687683=begin TML 
     
    704700continues by considering the built-in types. 
    705701 
    706 *Since:* Foswiki::Plugins::VERSION 1.1 
     702*Since:* Foswiki::Plugins::VERSION 2.0 
    707703 
    708704Note that you can also extend the range of available 
     
    714710=cut 
    715711 
    716 sub DISABLE_renderFormFieldForEditHandler { 
    717 } 
     712#sub renderFormFieldForEditHandler { 
     713#    my ( $name, $type, $size, $value, $attributes, $possibleValues) = @_; 
     714#} 
    718715 
    719716=begin TML 
     
    730727Return the new link text. 
    731728 
    732 *Since:* Foswiki::Plugins::VERSION 1.1 
    733  
    734 =cut 
    735  
    736 sub DISABLE_renderWikiWordHandler { 
    737     my( $linkText, $hasExplicitLinkLabel, $web, $topic ) = @_; 
    738     return $linkText; 
    739 } 
     729*Since:* Foswiki::Plugins::VERSION 2.0 
     730 
     731=cut 
     732 
     733#sub renderWikiWordHandler { 
     734#    my( $linkText, $hasExplicitLinkLabel, $web, $topic ) = @_; 
     735#    return $linkText; 
     736#} 
    740737 
    741738=begin TML 
     
    751748     the page is actually written. This is a string, which must end in \n\n. 
    752749 
    753 *Since:* Foswiki::Plugins::VERSION 1.2 
    754  
    755 =cut 
    756  
    757 sub DISABLE_completePageHandler { 
    758     #my($html, $httpHeaders) = @_; 
    759     # modify $_[0] or $_[1] if you must change the HTML or headers 
    760 } 
     750*Since:* Foswiki::Plugins::VERSION 2.0 
     751 
     752=cut 
     753 
     754#sub completePageHandler { 
     755#    my( $html, $httpHeaders ) = @_; 
     756#    # modify $_[0] or $_[1] if you must change the HTML or headers 
     757#    # You can work on $html and $httpHeaders in place by using the 
     758#    # special perl variables $_[0] and $_[1]. These allow you to operate 
     759#    # on parameters as if they were passed by reference; for example: 
     760#    # $_[0] =~ s/SpecialString/my alternative/ge; 
     761#} 
    761762 
    762763=begin TML 
     
    774775Foswiki::Support.Faq1 
    775776 
    776 *Since:* Foswiki::Plugins::VERSION 1.1 
    777  
    778 =cut 
    779  
    780 sub restExample { 
    781    #my ($session) = @_; 
    782    return "This is an example of a REST invocation\n\n"; 
    783 } 
     777*Since:* Foswiki::Plugins::VERSION 2.0 
     778 
     779=cut 
     780 
     781#sub restExample { 
     782#   my ($session) = @_; 
     783#   return "This is an example of a REST invocation\n\n"; 
     784#} 
    784785 
    7857861; 
    786 __DATA__ 
     787__END__ 
    787788This copyright information applies to the EmptyPlugin: 
    788789 
     
    797798# and TWiki Contributors. All Rights Reserved. Foswiki Contributors 
    798799# are listed in the AUTHORS file in the root of this distribution. 
    799  
    800 This license applies to EmptyPlugin *and also to any derivatives* 
     800# 
     801# This license applies to EmptyPlugin *and also to any derivatives* 
    801802# 
    802803# This program is free software; you can redistribute it and/or 
  • trunk/core/data/System/DevelopingPlugins.txt

    r1314 r1318  
    11---+ Developing Plugins 
    22%TOC% 
    3 The usual way Foswiki is extended is by writing a _Plugin_. Plugins extend Foswiki by providing functions that 'listen' to events in the Foswiki core, and handling these events. These functions are called "Plugin Handlers" and they are described in depth in %SYSTEMWEB%.EmptyPlugin ( =lib/Foswiki/Plugins/EmptyPlugin.pm= ). 
     3The usual way Foswiki is extended is by writing a _Plugin_. Plugins extend Foswiki by providing functions that 'listen' to events in the Foswiki core, and handling these events. These functions are called "Plugin Handlers" and they are described in depth in [[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Plugins::EmptyPlugin][EmptyPlugin]] ( =lib/Foswiki/Plugins/EmptyPlugin.pm= ). 
    44 
    55---++ APIs available to Extensions 
Note: See TracChangeset for help on using the changeset viewer.