Changeset 1318
- Timestamp:
- 12/13/08 15:44:10 (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
EmptyPlugin/data/System/EmptyPlugin.txt (modified) (2 diffs)
-
EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm (modified) (32 diffs)
-
core/data/System/DevelopingPlugins.txt (modified) (1 diff)
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 $"}%2 1 ---+ Empty Plugin 3 2 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.3 This Plugin does nothing. 5 4 6 To create your own Plugin: 5 This is an empty Plugin topic you can use as a template for your own Plugin 6 documentation topic. 7 7 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"}% 8 Learn how to create your own plugin in %SYSTEMWEB%.DevelopingPlugins. 16 9 17 10 ---++ Plugin Preferences 18 11 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:12 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: 20 13 * One line description, used by other tools: 21 14 * Set SHORTDESCRIPTION = Empty Plugin used as a template for new Plugins … … 25 18 * <nop>Set EMPTYPLUGIN_MYPREFERENCE = my preference 26 19 20 ---++ Installation 21 %$INSTALL_INSTRUCTIONS% 22 27 23 ---++ Plugin Info 28 24 29 | Plugin Author: | Foswiki:Main.AndreaSterbini, TWiki:Main.PeterThoeny, Foswiki:Main.CrawfordCurrie|30 | Copyright: | © 2008, Foswiki Contributors <br>© 2001-2007, TWiki Contributors|25 | Author: | Foswiki:Main.PluginAuthor| 26 | Copyright: | © 2008, Foswiki Contributors | 31 27 | 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 | 33 30 34 31 35 -
trunk/EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm
r1316 r1318 4 4 5 5 ---+ package EmptyPlugin 6 7 Foswiki plugins 'listen' to events happening in the core by registering an 8 interest in those events. They do this by declaring 'plugin handlers'. These 9 are simply functions with a particular name that, if they exist in your 10 plugin, will be called by the core. 6 11 7 12 This is an empty Foswiki plugin. It is a fully defined plugin, but is 8 13 disabled 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 14 for your own plugins. 15 16 To interact with Foswiki use ONLY the official APIs 17 documented in %SYSTEMWEB%.DevelopingPlugins. <strong>Do not reference any 18 packages, functions or variables elsewhere in Foswiki</strong>, as these are 19 subject to change without prior warning, and your plugin may suddenly stop 20 20 working. 21 21 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 22 Error messages can be output using the =Foswiki::Func= =writeWarning= and 23 =writeDebug= functions. You can also =print STDERR=; the output will appear 24 in the webserver error log. Most handlers can also throw exceptions (e.g. 25 [[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::OopsException][Foswiki::OopsException]]) 26 27 For increased performance, all handler functions except =initPlugin= are 28 commented out below. *To enable a handler* remove the leading =#= from 29 each line of the function. For efficiency and clarity, you should 30 only uncomment handlers you actually use. 31 32 __NOTE:__ When developing a plugin it is important to remember that 33 29 34 Foswiki is tolerant of plugins that do not compile. In this case, 30 35 the 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 36 See %SYSTEMWEB%.InstalledPlugins for error messages. 37 38 __NOTE:__ Foswiki:Development.StepByStepRenderingOrder helps you decide which 39 rendering handler to use. When writing handlers, keep in mind that these may 40 be invoked 41 44 42 on 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 43 topic, these need to be generated before the =afterCommonTagsHandler= is run. 44 After that point in the rendering loop we have lost the information that 47 45 the text had been included from another topic. 48 46 49 47 =cut 50 48 51 # change the package name and $pluginName!!!49 # change the package name!!! 52 50 package Foswiki::Plugins::EmptyPlugin; 53 51 … … 60 58 # $VERSION is referred to by Foswiki, and is the only global variable that 61 59 # *must* exist in this package. 62 use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC );63 64 60 # This should always be $Rev$ so that Foswiki can determine the checked-in 65 61 # status of the plugin. It is used by the build automation tools, so 66 62 # you should leave it alone. 67 $VERSION = '$Rev$';63 our $VERSION = '$Rev$'; 68 64 69 65 # This is a free-form string you can use to "name" your own plugin version. 70 66 # It is *not* used by the build automation tools, but is reported as part 71 67 # of the version number in PLUGINDESCRIPTIONS. 72 $RELEASE = 'Foswiki-4.2';68 our $RELEASE = '$Date$'; 73 69 74 70 # Short description of this plugin 75 71 # 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 72 our $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. 82 our $NO_PREFS_IN_TOPIC = 1; 83 84 =begin TML 85 86 ---++ initPlugin($topic, $web, $user) -> $boolean 93 87 * =$topic= - the name of the topic in the current CGI query 94 88 * =$web= - the name of the web in the current CGI query 95 89 * =$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* 99 94 100 95 Called to initialise the plugin. If everything is OK, should return 101 96 a non-zero value. On non-fatal failure, should write a message 102 using Foswiki::Func::writeWarningand return 0. In this case97 using =Foswiki::Func::writeWarning= and return 0. In this case 103 98 %<nop>FAILEDPLUGINS% will indicate which plugins failed. 104 99 … … 107 102 will be trapped and reported in the browser. 108 103 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 105 your Plugin is called !FooBarPlugin, name macros FOOBAR and/or 117 106 FOOBARSOMETHING. This avoids namespace issues. 118 119 107 120 108 =cut … … 124 112 125 113 # 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' ); 128 117 return 0; 129 118 } 130 119 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: 135 125 # $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} = 1; 126 # Optional: See %SYSTEMWEB%.DevelopingPlugins#ConfigSpec for information 127 # on integrating your plugin configuration with =configure=. 128 136 129 # Always provide a default in case the setting is not defined in 137 130 # LocalSite.cfg. See %SYSTEMWEB%.Plugins for help in adding your plugin 138 131 # 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{...}% 143 135 # This will be called whenever %EXAMPLETAG% or %EXAMPLETAG{...}% is 144 136 # seen in the topic text. … … 153 145 } 154 146 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 #} 173 167 174 168 =begin TML … … 183 177 =cut 184 178 185 sub DISABLE_earlyInitPlugin {186 return undef;187 }179 #sub earlyInitPlugin { 180 # return undef; 181 #} 188 182 189 183 =begin TML … … 201 195 This handler is called very early, immediately after =earlyInitPlugin=. 202 196 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 #} 213 204 214 205 =begin TML … … 221 212 Called when a new user registers with this Foswiki. 222 213 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 #} 233 221 234 222 =begin TML … … 238 226 * =$topic= - the name of the topic in the current CGI query 239 227 * =$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 241 230 * =$meta= - meta-data object for the topic MAY BE =undef= 242 This handler is called by the code that expands %<nop> TAGS% syntax in231 This handler is called by the code that expands %<nop>MACROS% syntax in 243 232 the topic body and in form fields. It may be called many times while 244 233 a topic is being rendered. 245 234 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. 235 Only plugins that have to parse the entire topic content should implement 236 this function. For expanding macros with trivial syntax it is *far* more 237 efficient to use =Foswiki::Func::registerTagHandler= (see =initPlugin=). 238 239 Internal 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. 254 242 255 243 *NOTE:* when this handler is called, <verbatim> blocks have been … … 260 248 handler. Use the =$meta= object. 261 249 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 #} 282 268 283 269 =begin TML … … 288 274 * =$web= - the name of the web in the current CGI query 289 275 * =$meta= - meta-data object for the topic MAY BE =undef= 290 This handler is called before Foswiki does any expansion of it 's own276 This handler is called before Foswiki does any expansion of its own 291 277 internal variables. It is designed for use by cache plugins. Note that 292 278 when this handler is called, <verbatim> blocks are still present … … 304 290 =cut 305 291 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 #} 312 300 313 301 =begin TML … … 318 306 * =$web= - the name of the web in the current CGI query 319 307 * =$meta= - meta-data object for the topic MAY BE =undef= 320 This handler is after Foswiki has completed expansion of %TAGS%.308 This handler is called after Foswiki has completed expansion of %MACROS%. 321 309 It is designed for use by cache plugins. Note that when this handler 322 310 is called, <verbatim> blocks are present in the text. … … 331 319 =cut 332 320 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 #} 339 329 340 330 =begin TML 341 331 342 332 ---++ 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. 345 337 346 338 Handler called immediately before Foswiki syntax structures (such as lists) are 347 processed, but after all variables have been expanded. Use this handler to 339 processed, but after all variables have been expanded. Use this handler to 348 340 process special syntax only recognised by your plugin. 349 341 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 <!--!marker!--> characters so the 342 Placeholders are text strings constructed using the tag name and a 343 sequence number e.g. 'pre1', "verbatim6", "head1" etc. Placeholders are 344 inserted into the text inside <!--!marker!--> characters so the 353 345 text will contain <!--!pre1!--> for placeholder pre1. 354 346 355 Each removed block is represented by the block text and the parameters 347 Each removed block is represented by the block text and the parameters 356 348 passed to the tag (usually empty) e.g. for 357 349 <verbatim> … … 365 357 $removed->{'pre1'}{params}: class="slobadob" 366 358 </pre> 367 Iterating over blocks for a single tag is easy. For example, to prepend a 359 Iterating over blocks for a single tag is easy. For example, to prepend a 368 360 line number to every line of every pre block you might use this code: 369 361 <verbatim> 370 362 foreach my $placeholder ( keys %$map ) { 371 363 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; 374 366 } 375 367 } 376 368 </verbatim> 377 369 370 __NOTE__: This handler is called once for each rendered block of text i.e. 371 it 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 374 handler. 375 376 Since 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 378 394 *NOTE*: This handler is called once for each rendered block of text i.e. 379 395 it may be called several times during the rendering of a topic. … … 382 398 handler. 383 399 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 } 400 Since 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 #} 412 411 413 412 =begin TML … … 423 422 (using %META: tags) 424 423 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 #} 435 436 436 437 =begin TML … … 449 450 handler. Use the =$meta= object. 450 451 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 #} 461 464 462 465 =begin TML … … 477 480 text format. 478 481 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 #} 489 494 490 495 =begin TML … … 502 507 *NOTE:* meta-data is embedded in $text (using %META: tags) 503 508 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 #} 514 521 515 522 =begin TML … … 526 533 This handler is called just after the rename/move/delete action of a web, topic or attachment. 527 534 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 #} 539 543 540 544 =begin TML … … 553 557 * =tmpFilename= - name of a temporary file containing the attachment data 554 558 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 #} 564 566 565 567 =begin TML … … 576 578 * =user= - the user id 577 579 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 #} 587 587 588 588 =begin TML … … 628 628 required to resolve concurrent edits on a topic. 629 629 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 #} 636 637 637 638 =begin TML … … 652 653 using the =Foswiki::Func::addToHEAD= method. 653 654 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 #} 663 662 664 663 =begin TML … … 674 673 the others will be ignored. 675 674 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 #} 686 682 687 683 =begin TML … … 704 700 continues by considering the built-in types. 705 701 706 *Since:* Foswiki::Plugins::VERSION 1.1702 *Since:* Foswiki::Plugins::VERSION 2.0 707 703 708 704 Note that you can also extend the range of available … … 714 710 =cut 715 711 716 sub DISABLE_renderFormFieldForEditHandler { 717 } 712 #sub renderFormFieldForEditHandler { 713 # my ( $name, $type, $size, $value, $attributes, $possibleValues) = @_; 714 #} 718 715 719 716 =begin TML … … 730 727 Return the new link text. 731 728 732 *Since:* Foswiki::Plugins::VERSION 1.1733 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 #} 740 737 741 738 =begin TML … … 751 748 the page is actually written. This is a string, which must end in \n\n. 752 749 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 #} 761 762 762 763 =begin TML … … 774 775 Foswiki::Support.Faq1 775 776 776 *Since:* Foswiki::Plugins::VERSION 1.1777 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 #} 784 785 785 786 1; 786 __ DATA__787 __END__ 787 788 This copyright information applies to the EmptyPlugin: 788 789 … … 797 798 # and TWiki Contributors. All Rights Reserved. Foswiki Contributors 798 799 # 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* 801 802 # 802 803 # This program is free software; you can redistribute it and/or -
trunk/core/data/System/DevelopingPlugins.txt
r1314 r1318 1 1 ---+ Developing Plugins 2 2 %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= ).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 [[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Plugins::EmptyPlugin][EmptyPlugin]] ( =lib/Foswiki/Plugins/EmptyPlugin.pm= ). 4 4 5 5 ---++ APIs available to Extensions
Note: See TracChangeset
for help on using the changeset viewer.
