source: trunk/EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm @ 14575

Revision 14575, 33.6 KB checked in by GeorgeClark, 6 weeks ago (diff)

Item11383: Sync up release doc changes from 1.1.5

  • Property svn:keywords set to Revision Date
Line 
1# See bottom of file for default license and copyright information
2
3=begin TML
4
5---+ package Foswiki::Plugins::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.
11
12This is an empty Foswiki plugin. It is a fully defined plugin, but is
13disabled by default in a Foswiki installation. Use it as a template
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
20working.
21
22Error messages can be output using the =Foswiki::Func= =writeWarning= and
23=writeDebug= functions. These logs can be found in the Foswiki/working/logs
24directory.  You can also =print STDERR=; the output will appear in the
25webserver error log.  The {WarningsAreErrors} configure setting makes
26Foswiki less tolerant of errors, and it is recommended to set it during
27development.  It can be set using configure, in the 'Miscellaneous'
28section.  Most handlers can also throw exceptions (e.g.
29[[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::OopsException][Foswiki::OopsException]])
30
31For increased performance, all handler functions except =initPlugin= are
32commented out below. *To enable a handler* remove the leading =#= from
33each line of the function. For efficiency and clarity, you should
34only uncomment handlers you actually use.
35
36__NOTE:__ When developing a plugin it is important to remember that
37Foswiki is tolerant of plugins that do not compile. In this case,
38the failure will be silent but the plugin will not be available.
39See %SYSTEMWEB%.InstalledPlugins for error messages.
40
41__NOTE:__ Foswiki:Development.StepByStepRenderingOrder helps you decide which
42rendering handler to use. When writing handlers, keep in mind that these may
43be invoked on included topics. For example, if a plugin generates links to the
44current topic, these need to be generated before the =afterCommonTagsHandler=
45is run. After that point in the rendering loop we have lost the information
46that the text had been included from another topic.
47
48__NOTE:__ Not all handlers (and not all parameters passed to handlers) are
49available with all versions of Foswiki. Where a handler has been added
50the POD comment will indicate this with a "Since" line
51e.g. *Since:* Foswiki::Plugins::VERSION 1.1
52
53Deprecated handlers are still available, and can continue to be used to
54maintain compatibility with earlier releases, but will be removed at some
55point in the future. If you do implement deprecated handlers, then you can
56do no harm by simply keeping them in your code, but you are recommended to
57implement the alternative as soon as possible.
58
59See http://foswiki.org/Download/ReleaseDates for a breakdown of release
60versions.
61
62=cut
63
64# change the package name!!!
65package Foswiki::Plugins::EmptyPlugin;
66
67# Always use strict to enforce variable scoping
68use strict;
69use warnings;
70
71use Foswiki::Func    ();    # The plugins API
72use 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.
78our $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.
90our $RELEASE = '1.1.2';
91
92# Short description of this plugin
93# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
94our $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=.
107our $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
120Called to initialise the plugin. If everything is OK, should return
121a non-zero value. On non-fatal failure, should write a message
122using =Foswiki::Func::writeWarning= and return 0. In this case
123%<nop>FAILEDPLUGINS% will indicate which plugins failed.
124
125In the case of a catastrophic failure that will prevent the whole
126installation from working safely, this handler may use 'die', which
127will be trapped and reported in the browser.
128
129__Note:__ Please align macro names with the Plugin name, e.g. if
130your Plugin is called !FooBarPlugin, name macros FOOBAR and/or
131FOOBARSOMETHING. This avoids namespace issues.
132
133=cut
134
135sub 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
198This handler is called before any other handler, and before it has been
199determined if the plugin is enabled or not. Use it with great care!
200
201If 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
215Allows a plugin to set the username. Normally Foswiki gets the username
216from the login manager. This handler gives you a chance to override the
217login manager.
218
219Return the *login* name.
220
221This 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
235Called when Foswiki is shutting down, this handler can be used by the plugin
236to release resources - for example, shut down open database connections,
237release allocated memory etc.
238
239Note that it's important to break any cycles in memory allocated by plugins,
240or that memory will be lost when Foswiki is run in a persistent context
241e.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
256Called when a new user registers with this Foswiki.
257
258Note that the handler is not called when the user submits the registration
259form if {Register}{NeedVerification} is enabled. It is then called when
260the 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=
279This handler is called by the code that expands %<nop>MACROS% syntax in
280the topic body and in form fields. It may be called many times while
281a topic is being rendered.
282
283Only plugins that have to parse the entire topic content should implement
284this function. For expanding macros with trivial syntax it is *far* more
285efficient to use =Foswiki::Func::registerTagHandler= (see =initPlugin=).
286
287Internal 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, &lt;verbatim> blocks have been
292removed from the text (though all other blocks such as &lt;pre> and
293&lt;noautolink> are still present).
294
295*NOTE:* meta-data is _not_ embedded in the text passed to this
296handler. Use the =$meta= object.
297
298*NOTE:* Read the developer supplement at
299Foswiki: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=
328This handler is called before Foswiki does any expansion of its own
329internal variables. It is designed for use by cache plugins. Note that
330when this handler is called, &lt;verbatim> blocks are still present
331in 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
335rendering of a topic.
336
337*NOTE:* meta-data is _not_ embedded in the text passed to this
338handler.
339
340*NOTE:* This handler is not separately called on included topics.
341
342*NOTE:* Read the developer supplement at
343Foswiki: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=
364This handler is called after Foswiki has completed expansion of %MACROS%.
365It is designed for use by cache plugins. Note that when this handler
366is called, &lt;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
370rendering of a topic.
371
372*NOTE:* meta-data is _not_ embedded in the text passed to this
373handler.
374
375*NOTE:* Read the developer supplement at
376Foswiki: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
398Handler called immediately before Foswiki syntax structures (such as lists) are
399processed, but after all variables have been expanded. Use this handler to
400process special syntax only recognised by your plugin.
401
402Placeholders are text strings constructed using the tag name and a
403sequence number e.g. 'pre1', "verbatim6", "head1" etc. Placeholders are
404inserted into the text inside &lt;!--!marker!--&gt; characters so the
405text will contain &lt;!--!pre1!--&gt; for placeholder pre1.
406
407Each removed block is represented by the block text and the parameters
408passed to the tag (usually empty) e.g. for
409<verbatim>
410<pre class='slobadob'>
411XYZ
412</pre>
413</verbatim>
414the map will contain:
415<pre>
416$removed->{'pre1'}{text}:   XYZ
417$removed->{'pre1'}{params}: class="slobadob"
418</pre>
419Iterating over blocks for a single tag is easy. For example, to prepend a
420line number to every line of every pre block you might use this code:
421<verbatim>
422foreach 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.
431it 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
434handler.
435
436*NOTE:* Read the developer supplement at
437Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
438=addToZone()= from this handler
439
440Since 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.
459it 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
462handler.
463
464*NOTE:* Read the developer supplement at
465Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
466=addToZone()= from this handler
467
468Since 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
486This handler is called by the edit script just before presenting the edit text
487in 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.
512This handler is called by the preview script just before presenting the text.
513It 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
518handler. 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
541This handler is called each time a topic is saved.
542
543*NOTE:* meta-data is embedded in =$text= (using %META: tags). If you modify
544the =$meta= object, then it will override any changes to the meta-data
545embedded in the text. Modify *either* the META in the text *or* the =$meta=
546object, never both. You are recommended to modify the =$meta= object rather
547than the text, as this approach is proof against changes in the embedded
548text 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
573This 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
601This 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
618This handler is called once when an attachment is uploaded. When this
619handler is called, the attachment has *not* been recorded in the database.
620
621The 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
631The handler may wish to replace the original data served by the stream
632with new data. In this case, the handler can set the ={stream}= to a
633new stream.
634
635For example:
636<verbatim>
637sub 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
666This handler is called just after the after the attachment
667meta-data in the topic has been saved. The attributes hash
668will 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
684Try to resolve a difference encountered during merge. The =differences=
685array is an array of hash references, where each hash contains the
686following 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
701Plugins should try to resolve differences and return the merged text.
702For 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
705undef.
706
707The merge handler will be called several times during a save; once for
708each difference that needs resolution.
709
710If any merges are left unresolved after all plugins have been given a
711chance to intercede, the following algorithm is used to decide how to
712merge 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 =&lt;del>conflict&lt;/del> &lt;ins>markers&lt;/ins>= are used to
718     mark 'c' merges in text fields
719
720The merge handler is called whenever a topic is saved, and a merge is
721required 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
736Lets the plugin modify the HTTP headers that will be emitted when a
737page is written to the browser. \%headers= will contain the headers
738proposed by the core, plus any modifications made by other plugins that also
739implement this method that come earlier in the plugins list.
740<verbatim>
741$headers->{expires} = '+1h';
742</verbatim>
743
744Note that this is the HTTP header which is _not_ the same as the HTML
745&lt;HEAD&gt; tag. The contents of the &lt;HEAD&gt; tag may be manipulated
746using 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
760This handler is called before built-in types are considered. It generates
761the HTML text rendering this form field, or false, if the rendering
762should 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
772Return HTML text that renders this field. If false, form rendering
773continues by considering the built-in types.
774
775*Since:* Foswiki::Plugins::VERSION 2.0
776
777Note that you can also extend the range of available
778types by providing a subclass of =Foswiki::Form::FieldDefinition= to implement
779the new type (see =Foswiki::Extensions.JSCalendarContrib= and
780=Foswiki::Extensions.RatingContrib= for examples). This is the preferred way to
781extend 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
797Called during rendering, this handler allows the plugin a chance to change
798the rendering of labels used for links.
799
800Return the new link text.
801
802NOTE: this handler is to allow a plugin to change the link text for a possible link - it may never be used.
803for example, Set ALLOWTOPICVIEW = is a possible ACRONYM link that will not be displayed unless the topic exists
804similarly, 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
819This handler is called on the ingredients of every page that is
820output by the standard CGI scripts. It is designed primarily for use by
821cache and security plugins.
822   * =$html= - the body of the page (normally &lt;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
844This 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
847Additional parameters can be recovered via the query object in the $session, for example:
848
849my $query = $session->{request};
850my $web = $query->{param}->{web}[0];
851
852If your rest handler adds or replaces equivalent functionality to a standard script
853provided with Foswiki, it should set the appropriate context in its switchboard entry.
854A list of contexts are defined in %SYSTEMWEB%.IfStatements#Context_identifiers.
855
856For more information, check %SYSTEMWEB%.CommandAndCGIScripts#rest
857
858For information about handling error returns from REST handlers, see
859Foswiki: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
878This handler can be used to replace Foswiki's internal redirect function.
879
880If this handler is defined in more than one plugin, only the handler
881in the earliest plugin in the INSTALLEDPLUGINS list will be called. All
882the others will be ignored.
883
884*Deprecated in:* Foswiki::Plugins::VERSION 2.1
885
886This handler was deprecated because it cannot be guaranteed to work, and
887caused 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
894This handler is called once when an attachment is uploaded. When this
895handler is called, the attachment has *not* been recorded in the database.
896
897The 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
905The efficiency of this handler (and therefore it's impact on performance)
906is 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
918This handler is called just after the save action. The attributes hash
919will 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
926This handler has a number of problems including security and performance
927issues. Please use =afterUploadHandler()= instead.
928
929=cut
930
9311;
932
933__END__
934Foswiki - The Free and Open Source Wiki, http://foswiki.org/
935
936Author: %$AUTHOR%
937
938Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors
939are listed in the AUTHORS file in the root of this distribution.
940NOTE: Please extend that file, not this notice.
941
942This program is free software; you can redistribute it and/or
943modify it under the terms of the GNU General Public License
944as published by the Free Software Foundation; either version 2
945of the License, or (at your option) any later version. For
946more details read LICENSE in the root of this distribution.
947
948This program is distributed in the hope that it will be useful,
949but WITHOUT ANY WARRANTY; without even the implied warranty of
950MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
951
952As per the GPL, removal of this notice is prohibited.
Note: See TracBrowser for help on using the repository browser.