| 1 | # See bottom of file for default license and copyright information |
|---|
| 2 | |
|---|
| 3 | =begin TML |
|---|
| 4 | |
|---|
| 5 | ---+ package Foswiki::Plugins::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. |
|---|
| 11 | |
|---|
| 12 | This is an empty Foswiki plugin. It is a fully defined plugin, but is |
|---|
| 13 | disabled by default in a Foswiki installation. Use it as a template |
|---|
| 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 | working. |
|---|
| 21 | |
|---|
| 22 | Error messages can be output using the =Foswiki::Func= =writeWarning= and |
|---|
| 23 | =writeDebug= functions. These logs can be found in the Foswiki/working/logs |
|---|
| 24 | directory. You can also =print STDERR=; the output will appear in the |
|---|
| 25 | webserver error log. The {WarningsAreErrors} configure setting makes |
|---|
| 26 | Foswiki less tolerant of errors, and it is recommended to set it during |
|---|
| 27 | development. It can be set using configure, in the 'Miscellaneous' |
|---|
| 28 | section. Most handlers can also throw exceptions (e.g. |
|---|
| 29 | [[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::OopsException][Foswiki::OopsException]]) |
|---|
| 30 | |
|---|
| 31 | For increased performance, all handler functions except =initPlugin= are |
|---|
| 32 | commented out below. *To enable a handler* remove the leading =#= from |
|---|
| 33 | each line of the function. For efficiency and clarity, you should |
|---|
| 34 | only uncomment handlers you actually use. |
|---|
| 35 | |
|---|
| 36 | __NOTE:__ When developing a plugin it is important to remember that |
|---|
| 37 | Foswiki is tolerant of plugins that do not compile. In this case, |
|---|
| 38 | the failure will be silent but the plugin will not be available. |
|---|
| 39 | See %SYSTEMWEB%.InstalledPlugins for error messages. |
|---|
| 40 | |
|---|
| 41 | __NOTE:__ Foswiki:Development.StepByStepRenderingOrder helps you decide which |
|---|
| 42 | rendering handler to use. When writing handlers, keep in mind that these may |
|---|
| 43 | be invoked on included topics. For example, if a plugin generates links to the |
|---|
| 44 | current topic, these need to be generated before the =afterCommonTagsHandler= |
|---|
| 45 | is run. After that point in the rendering loop we have lost the information |
|---|
| 46 | that the text had been included from another topic. |
|---|
| 47 | |
|---|
| 48 | __NOTE:__ Not all handlers (and not all parameters passed to handlers) are |
|---|
| 49 | available with all versions of Foswiki. Where a handler has been added |
|---|
| 50 | the POD comment will indicate this with a "Since" line |
|---|
| 51 | e.g. *Since:* Foswiki::Plugins::VERSION 1.1 |
|---|
| 52 | |
|---|
| 53 | Deprecated handlers are still available, and can continue to be used to |
|---|
| 54 | maintain compatibility with earlier releases, but will be removed at some |
|---|
| 55 | point in the future. If you do implement deprecated handlers, then you can |
|---|
| 56 | do no harm by simply keeping them in your code, but you are recommended to |
|---|
| 57 | implement the alternative as soon as possible. |
|---|
| 58 | |
|---|
| 59 | See http://foswiki.org/Download/ReleaseDates for a breakdown of release |
|---|
| 60 | versions. |
|---|
| 61 | |
|---|
| 62 | =cut |
|---|
| 63 | |
|---|
| 64 | # change the package name!!! |
|---|
| 65 | package Foswiki::Plugins::EmptyPlugin; |
|---|
| 66 | |
|---|
| 67 | # Always use strict to enforce variable scoping |
|---|
| 68 | use strict; |
|---|
| 69 | use warnings; |
|---|
| 70 | |
|---|
| 71 | use Foswiki::Func (); # The plugins API |
|---|
| 72 | use Foswiki::Plugins (); # For the API version |
|---|
| 73 | |
|---|
| 74 | # $VERSION is referred to by Foswiki, and is the only global variable that |
|---|
| 75 | # *must* exist in this package. This should always be in the format |
|---|
| 76 | # $Rev$ so that Foswiki can determine the checked-in status of the |
|---|
| 77 | # extension. |
|---|
| 78 | our $VERSION = '$Rev$'; |
|---|
| 79 | |
|---|
| 80 | # $RELEASE is used in the "Find More Extensions" automation in configure. |
|---|
| 81 | # It is a manually maintained string used to identify functionality steps. |
|---|
| 82 | # You can use any of the following formats: |
|---|
| 83 | # tuple - a sequence of integers separated by . e.g. 1.2.3. The numbers |
|---|
| 84 | # usually refer to major.minor.patch release or similar. You can |
|---|
| 85 | # use as many numbers as you like e.g. '1' or '1.2.3.4.5'. |
|---|
| 86 | # isodate - a date in ISO8601 format e.g. 2009-08-07 |
|---|
| 87 | # date - a date in 1 Jun 2009 format. Three letter English month names only. |
|---|
| 88 | # Note: it's important that this string is exactly the same in the extension |
|---|
| 89 | # topic - if you use %$RELEASE% with BuildContrib this is done automatically. |
|---|
| 90 | our $RELEASE = '1.1.2'; |
|---|
| 91 | |
|---|
| 92 | # Short description of this plugin |
|---|
| 93 | # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: |
|---|
| 94 | our $SHORTDESCRIPTION = 'Empty Plugin used as a template for new Plugins'; |
|---|
| 95 | |
|---|
| 96 | # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use |
|---|
| 97 | # preferences set in the plugin topic. This is required for compatibility |
|---|
| 98 | # with older plugins, but imposes a significant performance penalty, and |
|---|
| 99 | # is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use |
|---|
| 100 | # =$Foswiki::cfg= entries, or if you want the users |
|---|
| 101 | # to be able to change settings, then use standard Foswiki preferences that |
|---|
| 102 | # can be defined in your %USERSWEB%.SitePreferences and overridden at the web |
|---|
| 103 | # and topic level. |
|---|
| 104 | # |
|---|
| 105 | # %SYSTEMWEB%.DevelopingPlugins has details of how to define =$Foswiki::cfg= |
|---|
| 106 | # entries so they can be used with =configure=. |
|---|
| 107 | our $NO_PREFS_IN_TOPIC = 1; |
|---|
| 108 | |
|---|
| 109 | =begin TML |
|---|
| 110 | |
|---|
| 111 | ---++ initPlugin($topic, $web, $user) -> $boolean |
|---|
| 112 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 113 | * =$web= - the name of the web in the current CGI query |
|---|
| 114 | * =$user= - the login name of the user |
|---|
| 115 | * =$installWeb= - the name of the web the plugin topic is in |
|---|
| 116 | (usually the same as =$Foswiki::cfg{SystemWebName}=) |
|---|
| 117 | |
|---|
| 118 | *REQUIRED* |
|---|
| 119 | |
|---|
| 120 | Called to initialise the plugin. If everything is OK, should return |
|---|
| 121 | a non-zero value. On non-fatal failure, should write a message |
|---|
| 122 | using =Foswiki::Func::writeWarning= and return 0. In this case |
|---|
| 123 | %<nop>FAILEDPLUGINS% will indicate which plugins failed. |
|---|
| 124 | |
|---|
| 125 | In the case of a catastrophic failure that will prevent the whole |
|---|
| 126 | installation from working safely, this handler may use 'die', which |
|---|
| 127 | will be trapped and reported in the browser. |
|---|
| 128 | |
|---|
| 129 | __Note:__ Please align macro names with the Plugin name, e.g. if |
|---|
| 130 | your Plugin is called !FooBarPlugin, name macros FOOBAR and/or |
|---|
| 131 | FOOBARSOMETHING. This avoids namespace issues. |
|---|
| 132 | |
|---|
| 133 | =cut |
|---|
| 134 | |
|---|
| 135 | sub initPlugin { |
|---|
| 136 | my ( $topic, $web, $user, $installWeb ) = @_; |
|---|
| 137 | |
|---|
| 138 | # check for Plugins.pm versions |
|---|
| 139 | if ( $Foswiki::Plugins::VERSION < 2.0 ) { |
|---|
| 140 | Foswiki::Func::writeWarning( 'Version mismatch between ', |
|---|
| 141 | __PACKAGE__, ' and Plugins.pm' ); |
|---|
| 142 | return 0; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | # Example code of how to get a preference value, register a macro |
|---|
| 146 | # handler and register a RESTHandler (remove code you do not need) |
|---|
| 147 | |
|---|
| 148 | # Set your per-installation plugin configuration in LocalSite.cfg, |
|---|
| 149 | # like this: |
|---|
| 150 | # $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} = 1; |
|---|
| 151 | # See %SYSTEMWEB%.DevelopingPlugins#ConfigSpec for information |
|---|
| 152 | # on integrating your plugin configuration with =configure=. |
|---|
| 153 | |
|---|
| 154 | # Always provide a default in case the setting is not defined in |
|---|
| 155 | # LocalSite.cfg. |
|---|
| 156 | # my $setting = $Foswiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0; |
|---|
| 157 | |
|---|
| 158 | # Register the _EXAMPLETAG function to handle %EXAMPLETAG{...}% |
|---|
| 159 | # This will be called whenever %EXAMPLETAG% or %EXAMPLETAG{...}% is |
|---|
| 160 | # seen in the topic text. |
|---|
| 161 | Foswiki::Func::registerTagHandler( 'EXAMPLETAG', \&_EXAMPLETAG ); |
|---|
| 162 | |
|---|
| 163 | # Allow a sub to be called from the REST interface |
|---|
| 164 | # using the provided alias |
|---|
| 165 | Foswiki::Func::registerRESTHandler( 'example', \&restExample ); |
|---|
| 166 | |
|---|
| 167 | # Plugin correctly initialized |
|---|
| 168 | return 1; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | # The function used to handle the %EXAMPLETAG{...}% macro |
|---|
| 172 | # You would have one of these for each macro you want to process. |
|---|
| 173 | #sub _EXAMPLETAG { |
|---|
| 174 | # my($session, $params, $topic, $web, $topicObject) = @_; |
|---|
| 175 | # # $session - a reference to the Foswiki session object |
|---|
| 176 | # # (you probably won't need it, but documented in Foswiki.pm) |
|---|
| 177 | # # $params= - a reference to a Foswiki::Attrs object containing |
|---|
| 178 | # # parameters. |
|---|
| 179 | # # This can be used as a simple hash that maps parameter names |
|---|
| 180 | # # to values, with _DEFAULT being the name for the default |
|---|
| 181 | # # (unnamed) parameter. |
|---|
| 182 | # # $topic - name of the topic in the query |
|---|
| 183 | # # $web - name of the web in the query |
|---|
| 184 | # # $topicObject - a reference to a Foswiki::Meta object containing the |
|---|
| 185 | # # topic the macro is being rendered in (new for foswiki 1.1.x) |
|---|
| 186 | # # Return: the result of processing the macro. This will replace the |
|---|
| 187 | # # macro call in the final text. |
|---|
| 188 | # |
|---|
| 189 | # # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}% |
|---|
| 190 | # # $params->{_DEFAULT} will be 'hamburger' |
|---|
| 191 | # # $params->{sideorder} will be 'onions' |
|---|
| 192 | #} |
|---|
| 193 | |
|---|
| 194 | =begin TML |
|---|
| 195 | |
|---|
| 196 | ---++ earlyInitPlugin() |
|---|
| 197 | |
|---|
| 198 | This handler is called before any other handler, and before it has been |
|---|
| 199 | determined if the plugin is enabled or not. Use it with great care! |
|---|
| 200 | |
|---|
| 201 | If it returns a non-null error string, the plugin will be disabled. |
|---|
| 202 | |
|---|
| 203 | =cut |
|---|
| 204 | |
|---|
| 205 | #sub earlyInitPlugin { |
|---|
| 206 | # return undef; |
|---|
| 207 | #} |
|---|
| 208 | |
|---|
| 209 | =begin TML |
|---|
| 210 | |
|---|
| 211 | ---++ initializeUserHandler( $loginName, $url, $pathInfo ) |
|---|
| 212 | * =$loginName= - login name recovered from $ENV{REMOTE_USER} |
|---|
| 213 | * =$url= - request url |
|---|
| 214 | * =$pathInfo= - pathinfo from the CGI query |
|---|
| 215 | Allows a plugin to set the username. Normally Foswiki gets the username |
|---|
| 216 | from the login manager. This handler gives you a chance to override the |
|---|
| 217 | login manager. |
|---|
| 218 | |
|---|
| 219 | Return the *login* name. |
|---|
| 220 | |
|---|
| 221 | This handler is called very early, immediately after =earlyInitPlugin=. |
|---|
| 222 | |
|---|
| 223 | *Since:* Foswiki::Plugins::VERSION = '2.0' |
|---|
| 224 | |
|---|
| 225 | =cut |
|---|
| 226 | |
|---|
| 227 | #sub initializeUserHandler { |
|---|
| 228 | # my ( $loginName, $url, $pathInfo ) = @_; |
|---|
| 229 | #} |
|---|
| 230 | |
|---|
| 231 | =begin TML |
|---|
| 232 | |
|---|
| 233 | ---++ finishPlugin() |
|---|
| 234 | |
|---|
| 235 | Called when Foswiki is shutting down, this handler can be used by the plugin |
|---|
| 236 | to release resources - for example, shut down open database connections, |
|---|
| 237 | release allocated memory etc. |
|---|
| 238 | |
|---|
| 239 | Note that it's important to break any cycles in memory allocated by plugins, |
|---|
| 240 | or that memory will be lost when Foswiki is run in a persistent context |
|---|
| 241 | e.g. mod_perl. |
|---|
| 242 | |
|---|
| 243 | =cut |
|---|
| 244 | |
|---|
| 245 | #sub finishPlugin { |
|---|
| 246 | #} |
|---|
| 247 | |
|---|
| 248 | =begin TML |
|---|
| 249 | |
|---|
| 250 | ---++ registrationHandler($web, $wikiName, $loginName, $data ) |
|---|
| 251 | * =$web= - the name of the web in the current CGI query |
|---|
| 252 | * =$wikiName= - users wiki name |
|---|
| 253 | * =$loginName= - users login name |
|---|
| 254 | * =$data= - a hashref containing all the formfields POSTed to the registration script |
|---|
| 255 | |
|---|
| 256 | Called when a new user registers with this Foswiki. |
|---|
| 257 | |
|---|
| 258 | Note that the handler is not called when the user submits the registration |
|---|
| 259 | form if {Register}{NeedVerification} is enabled. It is then called when |
|---|
| 260 | the user submits the activation code. |
|---|
| 261 | |
|---|
| 262 | *Since:* Foswiki::Plugins::VERSION = '2.0' |
|---|
| 263 | |
|---|
| 264 | =cut |
|---|
| 265 | |
|---|
| 266 | #sub registrationHandler { |
|---|
| 267 | # my ( $web, $wikiName, $loginName, $data ) = @_; |
|---|
| 268 | #} |
|---|
| 269 | |
|---|
| 270 | =begin TML |
|---|
| 271 | |
|---|
| 272 | ---++ commonTagsHandler($text, $topic, $web, $included, $meta ) |
|---|
| 273 | * =$text= - text to be processed |
|---|
| 274 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 275 | * =$web= - the name of the web in the current CGI query |
|---|
| 276 | * =$included= - Boolean flag indicating whether the handler is |
|---|
| 277 | invoked on an included topic |
|---|
| 278 | * =$meta= - meta-data object for the topic MAY BE =undef= |
|---|
| 279 | This handler is called by the code that expands %<nop>MACROS% syntax in |
|---|
| 280 | the topic body and in form fields. It may be called many times while |
|---|
| 281 | a topic is being rendered. |
|---|
| 282 | |
|---|
| 283 | Only plugins that have to parse the entire topic content should implement |
|---|
| 284 | this function. For expanding macros with trivial syntax it is *far* more |
|---|
| 285 | efficient to use =Foswiki::Func::registerTagHandler= (see =initPlugin=). |
|---|
| 286 | |
|---|
| 287 | Internal Foswiki macros, (and any macros declared using |
|---|
| 288 | =Foswiki::Func::registerTagHandler=) are expanded _before_, and then again |
|---|
| 289 | _after_, this function is called to ensure all %<nop>MACROS% are expanded. |
|---|
| 290 | |
|---|
| 291 | *NOTE:* when this handler is called, <verbatim> blocks have been |
|---|
| 292 | removed from the text (though all other blocks such as <pre> and |
|---|
| 293 | <noautolink> are still present). |
|---|
| 294 | |
|---|
| 295 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 296 | handler. Use the =$meta= object. |
|---|
| 297 | |
|---|
| 298 | *NOTE:* Read the developer supplement at |
|---|
| 299 | Foswiki:Development.AddToZoneFromPluginHandlers if you are calling |
|---|
| 300 | =addToZone()= from this handler |
|---|
| 301 | |
|---|
| 302 | *Since:* $Foswiki::Plugins::VERSION 2.0 |
|---|
| 303 | |
|---|
| 304 | =cut |
|---|
| 305 | |
|---|
| 306 | #sub commonTagsHandler { |
|---|
| 307 | # my ( $text, $topic, $web, $included, $meta ) = @_; |
|---|
| 308 | # |
|---|
| 309 | # # If you don't want to be called from nested includes... |
|---|
| 310 | # # if( $included ) { |
|---|
| 311 | # # # bail out, handler called from an %INCLUDE{}% |
|---|
| 312 | # # return; |
|---|
| 313 | # # } |
|---|
| 314 | # |
|---|
| 315 | # # You can work on $text in place by using the special perl |
|---|
| 316 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 317 | # # as if it was passed by reference; for example: |
|---|
| 318 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 319 | #} |
|---|
| 320 | |
|---|
| 321 | =begin TML |
|---|
| 322 | |
|---|
| 323 | ---++ beforeCommonTagsHandler($text, $topic, $web, $meta ) |
|---|
| 324 | * =$text= - text to be processed |
|---|
| 325 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 326 | * =$web= - the name of the web in the current CGI query |
|---|
| 327 | * =$meta= - meta-data object for the topic MAY BE =undef= |
|---|
| 328 | This handler is called before Foswiki does any expansion of its own |
|---|
| 329 | internal variables. It is designed for use by cache plugins. Note that |
|---|
| 330 | when this handler is called, <verbatim> blocks are still present |
|---|
| 331 | in the text. |
|---|
| 332 | |
|---|
| 333 | *NOTE*: This handler is called once for each call to |
|---|
| 334 | =commonTagsHandler= i.e. it may be called many times during the |
|---|
| 335 | rendering of a topic. |
|---|
| 336 | |
|---|
| 337 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 338 | handler. |
|---|
| 339 | |
|---|
| 340 | *NOTE:* This handler is not separately called on included topics. |
|---|
| 341 | |
|---|
| 342 | *NOTE:* Read the developer supplement at |
|---|
| 343 | Foswiki:Development.AddToZoneFromPluginHandlers if you are calling |
|---|
| 344 | =addToZone()= from this handler |
|---|
| 345 | |
|---|
| 346 | =cut |
|---|
| 347 | |
|---|
| 348 | #sub beforeCommonTagsHandler { |
|---|
| 349 | # my ( $text, $topic, $web, $meta ) = @_; |
|---|
| 350 | # |
|---|
| 351 | # # You can work on $text in place by using the special perl |
|---|
| 352 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 353 | # # as if it was passed by reference; for example: |
|---|
| 354 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 355 | #} |
|---|
| 356 | |
|---|
| 357 | =begin TML |
|---|
| 358 | |
|---|
| 359 | ---++ afterCommonTagsHandler($text, $topic, $web, $meta ) |
|---|
| 360 | * =$text= - text to be processed |
|---|
| 361 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 362 | * =$web= - the name of the web in the current CGI query |
|---|
| 363 | * =$meta= - meta-data object for the topic MAY BE =undef= |
|---|
| 364 | This handler is called after Foswiki has completed expansion of %MACROS%. |
|---|
| 365 | It is designed for use by cache plugins. Note that when this handler |
|---|
| 366 | is called, <verbatim> blocks are present in the text. |
|---|
| 367 | |
|---|
| 368 | *NOTE*: This handler is called once for each call to |
|---|
| 369 | =commonTagsHandler= i.e. it may be called many times during the |
|---|
| 370 | rendering of a topic. |
|---|
| 371 | |
|---|
| 372 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 373 | handler. |
|---|
| 374 | |
|---|
| 375 | *NOTE:* Read the developer supplement at |
|---|
| 376 | Foswiki:Development.AddToZoneFromPluginHandlers if you are calling |
|---|
| 377 | =addToZone()= from this handler |
|---|
| 378 | |
|---|
| 379 | =cut |
|---|
| 380 | |
|---|
| 381 | #sub afterCommonTagsHandler { |
|---|
| 382 | # my ( $text, $topic, $web, $meta ) = @_; |
|---|
| 383 | # |
|---|
| 384 | # # You can work on $text in place by using the special perl |
|---|
| 385 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 386 | # # as if it was passed by reference; for example: |
|---|
| 387 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 388 | #} |
|---|
| 389 | |
|---|
| 390 | =begin TML |
|---|
| 391 | |
|---|
| 392 | ---++ preRenderingHandler( $text, \%map ) |
|---|
| 393 | * =$text= - text, with the head, verbatim and pre blocks replaced |
|---|
| 394 | with placeholders |
|---|
| 395 | * =\%removed= - reference to a hash that maps the placeholders to |
|---|
| 396 | the removed blocks. |
|---|
| 397 | |
|---|
| 398 | Handler called immediately before Foswiki syntax structures (such as lists) are |
|---|
| 399 | processed, but after all variables have been expanded. Use this handler to |
|---|
| 400 | process special syntax only recognised by your plugin. |
|---|
| 401 | |
|---|
| 402 | Placeholders are text strings constructed using the tag name and a |
|---|
| 403 | sequence number e.g. 'pre1', "verbatim6", "head1" etc. Placeholders are |
|---|
| 404 | inserted into the text inside <!--!marker!--> characters so the |
|---|
| 405 | text will contain <!--!pre1!--> for placeholder pre1. |
|---|
| 406 | |
|---|
| 407 | Each removed block is represented by the block text and the parameters |
|---|
| 408 | passed to the tag (usually empty) e.g. for |
|---|
| 409 | <verbatim> |
|---|
| 410 | <pre class='slobadob'> |
|---|
| 411 | XYZ |
|---|
| 412 | </pre> |
|---|
| 413 | </verbatim> |
|---|
| 414 | the map will contain: |
|---|
| 415 | <pre> |
|---|
| 416 | $removed->{'pre1'}{text}: XYZ |
|---|
| 417 | $removed->{'pre1'}{params}: class="slobadob" |
|---|
| 418 | </pre> |
|---|
| 419 | Iterating over blocks for a single tag is easy. For example, to prepend a |
|---|
| 420 | line number to every line of every pre block you might use this code: |
|---|
| 421 | <verbatim> |
|---|
| 422 | foreach my $placeholder ( keys %$map ) { |
|---|
| 423 | if( $placeholder =~ /^pre/i ) { |
|---|
| 424 | my $n = 1; |
|---|
| 425 | $map->{$placeholder}{text} =~ s/^/$n++/gem; |
|---|
| 426 | } |
|---|
| 427 | } |
|---|
| 428 | </verbatim> |
|---|
| 429 | |
|---|
| 430 | __NOTE__: This handler is called once for each rendered block of text i.e. |
|---|
| 431 | it may be called several times during the rendering of a topic. |
|---|
| 432 | |
|---|
| 433 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 434 | handler. |
|---|
| 435 | |
|---|
| 436 | *NOTE:* Read the developer supplement at |
|---|
| 437 | Foswiki:Development.AddToZoneFromPluginHandlers if you are calling |
|---|
| 438 | =addToZone()= from this handler |
|---|
| 439 | |
|---|
| 440 | Since Foswiki::Plugins::VERSION = '2.0' |
|---|
| 441 | |
|---|
| 442 | =cut |
|---|
| 443 | |
|---|
| 444 | #sub preRenderingHandler { |
|---|
| 445 | # my( $text, $pMap ) = @_; |
|---|
| 446 | # |
|---|
| 447 | # # You can work on $text in place by using the special perl |
|---|
| 448 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 449 | # # as if it was passed by reference; for example: |
|---|
| 450 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 451 | #} |
|---|
| 452 | |
|---|
| 453 | =begin TML |
|---|
| 454 | |
|---|
| 455 | ---++ postRenderingHandler( $text ) |
|---|
| 456 | * =$text= - the text that has just been rendered. May be modified in place. |
|---|
| 457 | |
|---|
| 458 | *NOTE*: This handler is called once for each rendered block of text i.e. |
|---|
| 459 | it may be called several times during the rendering of a topic. |
|---|
| 460 | |
|---|
| 461 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 462 | handler. |
|---|
| 463 | |
|---|
| 464 | *NOTE:* Read the developer supplement at |
|---|
| 465 | Foswiki:Development.AddToZoneFromPluginHandlers if you are calling |
|---|
| 466 | =addToZone()= from this handler |
|---|
| 467 | |
|---|
| 468 | Since Foswiki::Plugins::VERSION = '2.0' |
|---|
| 469 | |
|---|
| 470 | =cut |
|---|
| 471 | |
|---|
| 472 | #sub postRenderingHandler { |
|---|
| 473 | # my $text = shift; |
|---|
| 474 | # # You can work on $text in place by using the special perl |
|---|
| 475 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 476 | # # as if it was passed by reference; for example: |
|---|
| 477 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 478 | #} |
|---|
| 479 | |
|---|
| 480 | =begin TML |
|---|
| 481 | |
|---|
| 482 | ---++ beforeEditHandler($text, $topic, $web ) |
|---|
| 483 | * =$text= - text that will be edited |
|---|
| 484 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 485 | * =$web= - the name of the web in the current CGI query |
|---|
| 486 | This handler is called by the edit script just before presenting the edit text |
|---|
| 487 | in the edit box. It is called once when the =edit= script is run. |
|---|
| 488 | |
|---|
| 489 | *NOTE*: meta-data may be embedded in the text passed to this handler |
|---|
| 490 | (using %META: tags) |
|---|
| 491 | |
|---|
| 492 | *Since:* Foswiki::Plugins::VERSION = '2.0' |
|---|
| 493 | |
|---|
| 494 | =cut |
|---|
| 495 | |
|---|
| 496 | #sub beforeEditHandler { |
|---|
| 497 | # my ( $text, $topic, $web ) = @_; |
|---|
| 498 | # |
|---|
| 499 | # # You can work on $text in place by using the special perl |
|---|
| 500 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 501 | # # as if it was passed by reference; for example: |
|---|
| 502 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 503 | #} |
|---|
| 504 | |
|---|
| 505 | =begin TML |
|---|
| 506 | |
|---|
| 507 | ---++ afterEditHandler($text, $topic, $web, $meta ) |
|---|
| 508 | * =$text= - text that is being previewed |
|---|
| 509 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 510 | * =$web= - the name of the web in the current CGI query |
|---|
| 511 | * =$meta= - meta-data for the topic. |
|---|
| 512 | This handler is called by the preview script just before presenting the text. |
|---|
| 513 | It is called once when the =preview= script is run. |
|---|
| 514 | |
|---|
| 515 | *NOTE:* this handler is _not_ called unless the text is previewed. |
|---|
| 516 | |
|---|
| 517 | *NOTE:* meta-data is _not_ embedded in the text passed to this |
|---|
| 518 | handler. Use the =$meta= object. |
|---|
| 519 | |
|---|
| 520 | *Since:* $Foswiki::Plugins::VERSION 2.0 |
|---|
| 521 | |
|---|
| 522 | =cut |
|---|
| 523 | |
|---|
| 524 | #sub afterEditHandler { |
|---|
| 525 | # my ( $text, $topic, $web ) = @_; |
|---|
| 526 | # |
|---|
| 527 | # # You can work on $text in place by using the special perl |
|---|
| 528 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 529 | # # as if it was passed by reference; for example: |
|---|
| 530 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 531 | #} |
|---|
| 532 | |
|---|
| 533 | =begin TML |
|---|
| 534 | |
|---|
| 535 | ---++ beforeSaveHandler($text, $topic, $web, $meta ) |
|---|
| 536 | * =$text= - text _with embedded meta-data tags_ |
|---|
| 537 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 538 | * =$web= - the name of the web in the current CGI query |
|---|
| 539 | * =$meta= - the metadata of the topic being saved, represented by a Foswiki::Meta object. |
|---|
| 540 | |
|---|
| 541 | This handler is called each time a topic is saved. |
|---|
| 542 | |
|---|
| 543 | *NOTE:* meta-data is embedded in =$text= (using %META: tags). If you modify |
|---|
| 544 | the =$meta= object, then it will override any changes to the meta-data |
|---|
| 545 | embedded in the text. Modify *either* the META in the text *or* the =$meta= |
|---|
| 546 | object, never both. You are recommended to modify the =$meta= object rather |
|---|
| 547 | than the text, as this approach is proof against changes in the embedded |
|---|
| 548 | text format. |
|---|
| 549 | |
|---|
| 550 | *Since:* Foswiki::Plugins::VERSION = 2.0 |
|---|
| 551 | |
|---|
| 552 | =cut |
|---|
| 553 | |
|---|
| 554 | #sub beforeSaveHandler { |
|---|
| 555 | # my ( $text, $topic, $web ) = @_; |
|---|
| 556 | # |
|---|
| 557 | # # You can work on $text in place by using the special perl |
|---|
| 558 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 559 | # # as if it was passed by reference; for example: |
|---|
| 560 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 561 | #} |
|---|
| 562 | |
|---|
| 563 | =begin TML |
|---|
| 564 | |
|---|
| 565 | ---++ afterSaveHandler($text, $topic, $web, $error, $meta ) |
|---|
| 566 | * =$text= - the text of the topic _excluding meta-data tags_ |
|---|
| 567 | (see beforeSaveHandler) |
|---|
| 568 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 569 | * =$web= - the name of the web in the current CGI query |
|---|
| 570 | * =$error= - any error string returned by the save. |
|---|
| 571 | * =$meta= - the metadata of the saved topic, represented by a Foswiki::Meta object |
|---|
| 572 | |
|---|
| 573 | This handler is called each time a topic is saved. |
|---|
| 574 | |
|---|
| 575 | *NOTE:* meta-data is embedded in $text (using %META: tags) |
|---|
| 576 | |
|---|
| 577 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 578 | |
|---|
| 579 | =cut |
|---|
| 580 | |
|---|
| 581 | #sub afterSaveHandler { |
|---|
| 582 | # my ( $text, $topic, $web, $error, $meta ) = @_; |
|---|
| 583 | # |
|---|
| 584 | # # You can work on $text in place by using the special perl |
|---|
| 585 | # # variable $_[0]. These allow you to operate on $text |
|---|
| 586 | # # as if it was passed by reference; for example: |
|---|
| 587 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 588 | #} |
|---|
| 589 | |
|---|
| 590 | =begin TML |
|---|
| 591 | |
|---|
| 592 | ---++ afterRenameHandler( $oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment ) |
|---|
| 593 | |
|---|
| 594 | * =$oldWeb= - name of old web |
|---|
| 595 | * =$oldTopic= - name of old topic (empty string if web rename) |
|---|
| 596 | * =$oldAttachment= - name of old attachment (empty string if web or topic rename) |
|---|
| 597 | * =$newWeb= - name of new web |
|---|
| 598 | * =$newTopic= - name of new topic (empty string if web rename) |
|---|
| 599 | * =$newAttachment= - name of new attachment (empty string if web or topic rename) |
|---|
| 600 | |
|---|
| 601 | This handler is called just after the rename/move/delete action of a web, topic or attachment. |
|---|
| 602 | |
|---|
| 603 | *Since:* Foswiki::Plugins::VERSION = '2.0' |
|---|
| 604 | |
|---|
| 605 | =cut |
|---|
| 606 | |
|---|
| 607 | #sub afterRenameHandler { |
|---|
| 608 | # my ( $oldWeb, $oldTopic, $oldAttachment, |
|---|
| 609 | # $newWeb, $newTopic, $newAttachment ) = @_; |
|---|
| 610 | #} |
|---|
| 611 | |
|---|
| 612 | =begin TML |
|---|
| 613 | |
|---|
| 614 | ---++ beforeUploadHandler(\%attrHash, $meta ) |
|---|
| 615 | * =\%attrHash= - reference to hash of attachment attribute values |
|---|
| 616 | * =$meta= - the Foswiki::Meta object where the upload will happen |
|---|
| 617 | |
|---|
| 618 | This handler is called once when an attachment is uploaded. When this |
|---|
| 619 | handler is called, the attachment has *not* been recorded in the database. |
|---|
| 620 | |
|---|
| 621 | The attributes hash will include at least the following attributes: |
|---|
| 622 | * =attachment= => the attachment name - must not be modified |
|---|
| 623 | * =user= - the user id - must not be modified |
|---|
| 624 | * =comment= - the comment - may be modified |
|---|
| 625 | * =stream= - an input stream that will deliver the data for the |
|---|
| 626 | attachment. The stream can be assumed to be seekable, and the file |
|---|
| 627 | pointer will be positioned at the start. It is *not* necessary to |
|---|
| 628 | reset the file pointer to the start of the stream after you are |
|---|
| 629 | done, nor is it necessary to close the stream. |
|---|
| 630 | |
|---|
| 631 | The handler may wish to replace the original data served by the stream |
|---|
| 632 | with new data. In this case, the handler can set the ={stream}= to a |
|---|
| 633 | new stream. |
|---|
| 634 | |
|---|
| 635 | For example: |
|---|
| 636 | <verbatim> |
|---|
| 637 | sub beforeUploadHandler { |
|---|
| 638 | my ( $attrs, $meta ) = @_; |
|---|
| 639 | my $fh = $attrs->{stream}; |
|---|
| 640 | local $/; |
|---|
| 641 | # read the whole stream |
|---|
| 642 | my $text = <$fh>; |
|---|
| 643 | # Modify the content |
|---|
| 644 | $text =~ s/investment bank/den of thieves/gi; |
|---|
| 645 | $fh = new File::Temp(); |
|---|
| 646 | print $fh $text; |
|---|
| 647 | $attrs->{stream} = $fh; |
|---|
| 648 | |
|---|
| 649 | } |
|---|
| 650 | </verbatim> |
|---|
| 651 | |
|---|
| 652 | *Since:* Foswiki::Plugins::VERSION = 2.1 |
|---|
| 653 | |
|---|
| 654 | =cut |
|---|
| 655 | |
|---|
| 656 | #sub beforeUploadHandler { |
|---|
| 657 | # my( $attrHashRef, $topic, $web ) = @_; |
|---|
| 658 | #} |
|---|
| 659 | |
|---|
| 660 | =begin TML |
|---|
| 661 | |
|---|
| 662 | ---++ afterUploadHandler(\%attrHash, $meta ) |
|---|
| 663 | * =\%attrHash= - reference to hash of attachment attribute values |
|---|
| 664 | * =$meta= - a Foswiki::Meta object where the upload has happened |
|---|
| 665 | |
|---|
| 666 | This handler is called just after the after the attachment |
|---|
| 667 | meta-data in the topic has been saved. The attributes hash |
|---|
| 668 | will include at least the following attributes, all of which are read-only: |
|---|
| 669 | * =attachment= => the attachment name |
|---|
| 670 | * =comment= - the comment |
|---|
| 671 | * =user= - the user id |
|---|
| 672 | |
|---|
| 673 | *Since:* Foswiki::Plugins::VERSION = 2.1 |
|---|
| 674 | |
|---|
| 675 | =cut |
|---|
| 676 | |
|---|
| 677 | #sub afterUploadHandler { |
|---|
| 678 | # my( $attrHashRef, $meta ) = @_; |
|---|
| 679 | #} |
|---|
| 680 | |
|---|
| 681 | =begin TML |
|---|
| 682 | |
|---|
| 683 | ---++ mergeHandler( $diff, $old, $new, \%info ) -> $text |
|---|
| 684 | Try to resolve a difference encountered during merge. The =differences= |
|---|
| 685 | array is an array of hash references, where each hash contains the |
|---|
| 686 | following fields: |
|---|
| 687 | * =$diff= => one of the characters '+', '-', 'c' or ' '. |
|---|
| 688 | * '+' - =new= contains text inserted in the new version |
|---|
| 689 | * '-' - =old= contains text deleted from the old version |
|---|
| 690 | * 'c' - =old= contains text from the old version, and =new= text |
|---|
| 691 | from the version being saved |
|---|
| 692 | * ' ' - =new= contains text common to both versions, or the change |
|---|
| 693 | only involved whitespace |
|---|
| 694 | * =$old= => text from version currently saved |
|---|
| 695 | * =$new= => text from version being saved |
|---|
| 696 | * =\%info= is a reference to the form field description { name, title, |
|---|
| 697 | type, size, value, tooltip, attributes, referenced }. It must _not_ |
|---|
| 698 | be wrtten to. This parameter will be undef when merging the body |
|---|
| 699 | text of the topic. |
|---|
| 700 | |
|---|
| 701 | Plugins should try to resolve differences and return the merged text. |
|---|
| 702 | For example, a radio button field where we have |
|---|
| 703 | ={ diff=>'c', old=>'Leafy', new=>'Barky' }= might be resolved as |
|---|
| 704 | ='Treelike'=. If the plugin cannot resolve a difference it should return |
|---|
| 705 | undef. |
|---|
| 706 | |
|---|
| 707 | The merge handler will be called several times during a save; once for |
|---|
| 708 | each difference that needs resolution. |
|---|
| 709 | |
|---|
| 710 | If any merges are left unresolved after all plugins have been given a |
|---|
| 711 | chance to intercede, the following algorithm is used to decide how to |
|---|
| 712 | merge the data: |
|---|
| 713 | 1 =new= is taken for all =radio=, =checkbox= and =select= fields to |
|---|
| 714 | resolve 'c' conflicts |
|---|
| 715 | 1 '+' and '-' text is always included in the the body text and text |
|---|
| 716 | fields |
|---|
| 717 | 1 =<del>conflict</del> <ins>markers</ins>= are used to |
|---|
| 718 | mark 'c' merges in text fields |
|---|
| 719 | |
|---|
| 720 | The merge handler is called whenever a topic is saved, and a merge is |
|---|
| 721 | required to resolve concurrent edits on a topic. |
|---|
| 722 | |
|---|
| 723 | *Since:* Foswiki::Plugins::VERSION = 2.0 |
|---|
| 724 | |
|---|
| 725 | =cut |
|---|
| 726 | |
|---|
| 727 | #sub mergeHandler { |
|---|
| 728 | # my ( $diff, $old, $new, $info ) = @_; |
|---|
| 729 | #} |
|---|
| 730 | |
|---|
| 731 | =begin TML |
|---|
| 732 | |
|---|
| 733 | ---++ modifyHeaderHandler( \%headers, $query ) |
|---|
| 734 | * =\%headers= - reference to a hash of existing header values |
|---|
| 735 | * =$query= - reference to CGI query object |
|---|
| 736 | Lets the plugin modify the HTTP headers that will be emitted when a |
|---|
| 737 | page is written to the browser. \%headers= will contain the headers |
|---|
| 738 | proposed by the core, plus any modifications made by other plugins that also |
|---|
| 739 | implement this method that come earlier in the plugins list. |
|---|
| 740 | <verbatim> |
|---|
| 741 | $headers->{expires} = '+1h'; |
|---|
| 742 | </verbatim> |
|---|
| 743 | |
|---|
| 744 | Note that this is the HTTP header which is _not_ the same as the HTML |
|---|
| 745 | <HEAD> tag. The contents of the <HEAD> tag may be manipulated |
|---|
| 746 | using the =Foswiki::Func::addToHEAD= method. |
|---|
| 747 | |
|---|
| 748 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 749 | |
|---|
| 750 | =cut |
|---|
| 751 | |
|---|
| 752 | #sub modifyHeaderHandler { |
|---|
| 753 | # my ( $headers, $query ) = @_; |
|---|
| 754 | #} |
|---|
| 755 | |
|---|
| 756 | =begin TML |
|---|
| 757 | |
|---|
| 758 | ---++ renderFormFieldForEditHandler($name, $type, $size, $value, $attributes, $possibleValues) -> $html |
|---|
| 759 | |
|---|
| 760 | This handler is called before built-in types are considered. It generates |
|---|
| 761 | the HTML text rendering this form field, or false, if the rendering |
|---|
| 762 | should be done by the built-in type handlers. |
|---|
| 763 | * =$name= - name of form field |
|---|
| 764 | * =$type= - type of form field (checkbox, radio etc) |
|---|
| 765 | * =$size= - size of form field |
|---|
| 766 | * =$value= - value held in the form field |
|---|
| 767 | * =$attributes= - attributes of form field |
|---|
| 768 | * =$possibleValues= - the values defined as options for form field, if |
|---|
| 769 | any. May be a scalar (one legal value) or a ref to an array |
|---|
| 770 | (several legal values) |
|---|
| 771 | |
|---|
| 772 | Return HTML text that renders this field. If false, form rendering |
|---|
| 773 | continues by considering the built-in types. |
|---|
| 774 | |
|---|
| 775 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 776 | |
|---|
| 777 | Note that you can also extend the range of available |
|---|
| 778 | types by providing a subclass of =Foswiki::Form::FieldDefinition= to implement |
|---|
| 779 | the new type (see =Foswiki::Extensions.JSCalendarContrib= and |
|---|
| 780 | =Foswiki::Extensions.RatingContrib= for examples). This is the preferred way to |
|---|
| 781 | extend the form field types. |
|---|
| 782 | |
|---|
| 783 | =cut |
|---|
| 784 | |
|---|
| 785 | #sub renderFormFieldForEditHandler { |
|---|
| 786 | # my ( $name, $type, $size, $value, $attributes, $possibleValues) = @_; |
|---|
| 787 | #} |
|---|
| 788 | |
|---|
| 789 | =begin TML |
|---|
| 790 | |
|---|
| 791 | ---++ renderWikiWordHandler($linkText, $hasExplicitLinkLabel, $web, $topic) -> $linkText |
|---|
| 792 | * =$linkText= - the text for the link i.e. for =[<nop>[Link][blah blah]]= |
|---|
| 793 | it's =blah blah=, for =BlahBlah= it's =BlahBlah=, and for [[Blah Blah]] it's =Blah Blah=. |
|---|
| 794 | * =$hasExplicitLinkLabel= - true if the link is of the form =[<nop>[Link][blah blah]]= (false if it's ==<nop>[Blah]] or =BlahBlah=) |
|---|
| 795 | * =$web=, =$topic= - specify the link being rendered |
|---|
| 796 | |
|---|
| 797 | Called during rendering, this handler allows the plugin a chance to change |
|---|
| 798 | the rendering of labels used for links. |
|---|
| 799 | |
|---|
| 800 | Return the new link text. |
|---|
| 801 | |
|---|
| 802 | NOTE: this handler is to allow a plugin to change the link text for a possible link - it may never be used. |
|---|
| 803 | for example, Set ALLOWTOPICVIEW = is a possible ACRONYM link that will not be displayed unless the topic exists |
|---|
| 804 | similarly, this handler is called before the Plurals code has a chance to remove the 's' from WikiWords |
|---|
| 805 | |
|---|
| 806 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 807 | |
|---|
| 808 | =cut |
|---|
| 809 | |
|---|
| 810 | #sub renderWikiWordHandler { |
|---|
| 811 | # my( $linkText, $hasExplicitLinkLabel, $web, $topic ) = @_; |
|---|
| 812 | # return $linkText; |
|---|
| 813 | #} |
|---|
| 814 | |
|---|
| 815 | =begin TML |
|---|
| 816 | |
|---|
| 817 | ---++ completePageHandler($html, $httpHeaders) |
|---|
| 818 | |
|---|
| 819 | This handler is called on the ingredients of every page that is |
|---|
| 820 | output by the standard CGI scripts. It is designed primarily for use by |
|---|
| 821 | cache and security plugins. |
|---|
| 822 | * =$html= - the body of the page (normally <html>..$lt;/html>) |
|---|
| 823 | * =$httpHeaders= - the HTTP headers. Note that the headers do not contain |
|---|
| 824 | a =Content-length=. That will be computed and added immediately before |
|---|
| 825 | the page is actually written. This is a string, which must end in \n\n. |
|---|
| 826 | |
|---|
| 827 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 828 | |
|---|
| 829 | =cut |
|---|
| 830 | |
|---|
| 831 | #sub completePageHandler { |
|---|
| 832 | # my( $html, $httpHeaders ) = @_; |
|---|
| 833 | # # modify $_[0] or $_[1] if you must change the HTML or headers |
|---|
| 834 | # # You can work on $html and $httpHeaders in place by using the |
|---|
| 835 | # # special perl variables $_[0] and $_[1]. These allow you to operate |
|---|
| 836 | # # on parameters as if they were passed by reference; for example: |
|---|
| 837 | # # $_[0] =~ s/SpecialString/my alternative/ge; |
|---|
| 838 | #} |
|---|
| 839 | |
|---|
| 840 | =begin TML |
|---|
| 841 | |
|---|
| 842 | ---++ restExample($session) -> $text |
|---|
| 843 | |
|---|
| 844 | This is an example of a sub to be called by the =rest= script. The parameter is: |
|---|
| 845 | * =$session= - The Foswiki object associated to this session. |
|---|
| 846 | |
|---|
| 847 | Additional parameters can be recovered via the query object in the $session, for example: |
|---|
| 848 | |
|---|
| 849 | my $query = $session->{request}; |
|---|
| 850 | my $web = $query->{param}->{web}[0]; |
|---|
| 851 | |
|---|
| 852 | If your rest handler adds or replaces equivalent functionality to a standard script |
|---|
| 853 | provided with Foswiki, it should set the appropriate context in its switchboard entry. |
|---|
| 854 | A list of contexts are defined in %SYSTEMWEB%.IfStatements#Context_identifiers. |
|---|
| 855 | |
|---|
| 856 | For more information, check %SYSTEMWEB%.CommandAndCGIScripts#rest |
|---|
| 857 | |
|---|
| 858 | For information about handling error returns from REST handlers, see |
|---|
| 859 | Foswiki:Support.Faq1 |
|---|
| 860 | |
|---|
| 861 | *Since:* Foswiki::Plugins::VERSION 2.0 |
|---|
| 862 | |
|---|
| 863 | =cut |
|---|
| 864 | |
|---|
| 865 | #sub restExample { |
|---|
| 866 | # my ( $session, $subject, $verb, $response ) = @_; |
|---|
| 867 | # return "This is an example of a REST invocation\n\n"; |
|---|
| 868 | #} |
|---|
| 869 | |
|---|
| 870 | =begin TML |
|---|
| 871 | |
|---|
| 872 | ---++ Deprecated handlers |
|---|
| 873 | |
|---|
| 874 | ---+++ redirectCgiQueryHandler($query, $url ) |
|---|
| 875 | * =$query= - the CGI query |
|---|
| 876 | * =$url= - the URL to redirect to |
|---|
| 877 | |
|---|
| 878 | This handler can be used to replace Foswiki's internal redirect function. |
|---|
| 879 | |
|---|
| 880 | If this handler is defined in more than one plugin, only the handler |
|---|
| 881 | in the earliest plugin in the INSTALLEDPLUGINS list will be called. All |
|---|
| 882 | the others will be ignored. |
|---|
| 883 | |
|---|
| 884 | *Deprecated in:* Foswiki::Plugins::VERSION 2.1 |
|---|
| 885 | |
|---|
| 886 | This handler was deprecated because it cannot be guaranteed to work, and |
|---|
| 887 | caused a significant impediment to code improvements in the core. |
|---|
| 888 | |
|---|
| 889 | ---+++ beforeAttachmentSaveHandler(\%attrHash, $topic, $web ) |
|---|
| 890 | |
|---|
| 891 | * =\%attrHash= - reference to hash of attachment attribute values |
|---|
| 892 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 893 | * =$web= - the name of the web in the current CGI query |
|---|
| 894 | This handler is called once when an attachment is uploaded. When this |
|---|
| 895 | handler is called, the attachment has *not* been recorded in the database. |
|---|
| 896 | |
|---|
| 897 | The attributes hash will include at least the following attributes: |
|---|
| 898 | * =attachment= => the attachment name |
|---|
| 899 | * =comment= - the comment |
|---|
| 900 | * =user= - the user id |
|---|
| 901 | * =tmpFilename= - name of a temporary file containing the attachment data |
|---|
| 902 | |
|---|
| 903 | *Deprecated in:* Foswiki::Plugins::VERSION 2.1 |
|---|
| 904 | |
|---|
| 905 | The efficiency of this handler (and therefore it's impact on performance) |
|---|
| 906 | is very bad. Please use =beforeUploadHandler()= instead. |
|---|
| 907 | |
|---|
| 908 | =begin TML |
|---|
| 909 | |
|---|
| 910 | ---+++ afterAttachmentSaveHandler(\%attrHash, $topic, $web ) |
|---|
| 911 | |
|---|
| 912 | * =\%attrHash= - reference to hash of attachment attribute values |
|---|
| 913 | * =$topic= - the name of the topic in the current CGI query |
|---|
| 914 | * =$web= - the name of the web in the current CGI query |
|---|
| 915 | * =$error= - any error string generated during the save process (always |
|---|
| 916 | undef in 2.1) |
|---|
| 917 | |
|---|
| 918 | This handler is called just after the save action. The attributes hash |
|---|
| 919 | will include at least the following attributes: |
|---|
| 920 | * =attachment= => the attachment name |
|---|
| 921 | * =comment= - the comment |
|---|
| 922 | * =user= - the user id |
|---|
| 923 | |
|---|
| 924 | *Deprecated in:* Foswiki::Plugins::VERSION 2.1 |
|---|
| 925 | |
|---|
| 926 | This handler has a number of problems including security and performance |
|---|
| 927 | issues. Please use =afterUploadHandler()= instead. |
|---|
| 928 | |
|---|
| 929 | =cut |
|---|
| 930 | |
|---|
| 931 | 1; |
|---|
| 932 | |
|---|
| 933 | __END__ |
|---|
| 934 | Foswiki - The Free and Open Source Wiki, http://foswiki.org/ |
|---|
| 935 | |
|---|
| 936 | Author: %$AUTHOR% |
|---|
| 937 | |
|---|
| 938 | Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors |
|---|
| 939 | are listed in the AUTHORS file in the root of this distribution. |
|---|
| 940 | NOTE: Please extend that file, not this notice. |
|---|
| 941 | |
|---|
| 942 | This program is free software; you can redistribute it and/or |
|---|
| 943 | modify it under the terms of the GNU General Public License |
|---|
| 944 | as published by the Free Software Foundation; either version 2 |
|---|
| 945 | of the License, or (at your option) any later version. For |
|---|
| 946 | more details read LICENSE in the root of this distribution. |
|---|
| 947 | |
|---|
| 948 | This program is distributed in the hope that it will be useful, |
|---|
| 949 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 950 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 951 | |
|---|
| 952 | As per the GPL, removal of this notice is prohibited. |
|---|