1 rizwank 1.1 # Module of TWiki Collaboration Platform, http://TWiki.org/
2 #
3 # Copyright (C) 2000-2001 Andrea Sterbini, a.sterbini@flashnet.it
4 # Copyright (C) 2001-2004 Peter Thoeny, peter@thoeny.com
5 #
6 # For licensing info read license.txt file in the TWiki root.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details, published at
16 # http://www.gnu.org/copyleft/gpl.html
17 # 2004-01-13 RafaelAlvarez Added a new Plugin callback handler (afterSaveHandler)
18 =begin twiki
19
20 ---+ TWiki:: Module
21
22 rizwank 1.1 This module handles Plugins loading, initialization and execution
23
24 =cut
25
26 package TWiki::Plugins;
27
28 use strict;
29 no strict 'refs';
30
31 use vars qw(
32 %activePluginWebs @activePlugins @instPlugins %disabledPlugins
33 @registrableHandlers %registeredHandlers %onlyOnceHandlers
34 $VERSION $initialisationErrors
35 );
36
37 $VERSION = '1.025'; # TWiki production release 01 Aug 2004
38
39 $initialisationErrors = "";
40
41 @registrableHandlers = ( # VERSION:
42 'earlyInitPlugin', # ( ) 1.020
43 rizwank 1.1 'initPlugin', # ( $topic, $web, $user, $installWeb ) 1.000
44 'initializeUserHandler', # ( $loginName, $url, $pathInfo ) 1.010
45 'registrationHandler', # ( $web, $wikiName, $loginName ) 1.010
46 'beforeCommonTagsHandler', # ( $text, $topic, $web ) 1.024
47 'commonTagsHandler', # ( $text, $topic, $web ) 1.000
48 'afterCommonTagsHandler', # ( $text, $topic, $web ) 1.024
49 'startRenderingHandler', # ( $text, $web ) 1.000
50 'outsidePREHandler', # ( $text ) 1.000
51 'insidePREHandler', # ( $text ) 1.000
52 'endRenderingHandler', # ( $text ) 1.000
53 'beforeEditHandler', # ( $text, $topic, $web ) 1.010
54 'afterEditHandler', # ( $text, $topic, $web ) 1.010
55 'beforeSaveHandler', # ( $text, $topic, $web ) 1.010
56 'afterSaveHandler', # ( $text, $topic, $web, $errors ) 1.020
57 'beforeAttachmentSaveHandler', # ( $attrHash, $topic, $web ) 1.022
58 'afterAttachmentSaveHandler', # ( $attrHash, $topic, $web, $error ) 1.022
59 'writeHeaderHandler', # ( $query ) 1.010
60 'redirectCgiQueryHandler', # ( $query, $url ) 1.010
61 'getSessionValueHandler', # ( $key ) 1.010
62 'setSessionValueHandler', # ( $key, $value ) 1.010
63 'renderFormFieldForEditHandler', # ( $name, $type, $size, $value, $attributes, $output )
64 rizwank 1.1 'renderWikiWordHandler', # ( text ) 1.023
65 );
66
67 %onlyOnceHandlers = ( 'initializeUserHandler' => 1,
68 'registrationHandler' => 1,
69 'writeHeaderHandler' => 1,
70 'redirectCgiQueryHandler' => 1,
71 'getSessionValueHandler' => 1,
72 'setSessionValueHandler' => 1,
73 'renderFormFieldForEditHandler' => 1,
74 'renderWikiWordHandler' => 1
75 );
76
77 %registeredHandlers = ();
78
79
80 # =========================
81 =pod
82
83 ---++ sub getPluginVersion()
84
85 rizwank 1.1 Returns the $TWiki::Plugins::VERSION number if no parameter is specified,
86 else returns the version number of a named Plugin. If the Plugin cannot
87 be found or is not active, 0 is returned.
88
89 =cut
90
91 sub getPluginVersion
92 {
93 my ( $thePlugin ) = @_;
94 $thePlugin = TWiki::extractNameValuePair( $thePlugin );
95 my $version = 0;
96 if( $thePlugin ) {
97 foreach my $plugin ( @activePlugins ) {
98 if( $plugin eq $thePlugin ) {
99 $version = ${"TWiki::Plugins::${plugin}::VERSION"};
100 }
101 }
102 } else {
103 $version = $VERSION;
104 }
105 return $version;
106 rizwank 1.1 }
107
108 # =========================
109 =pod
110
111 ---++ sub discoverPluginPerlModules ()
112
113 Not yet documented.
114
115 =cut
116
117 sub discoverPluginPerlModules
118 {
119 my $libDir = &TWiki::getTWikiLibDir();
120 my @plugins = ();
121 my @modules = ();
122 if( opendir( DIR, "$libDir/TWiki/Plugins" ) ) {
123 @modules = map{ s/\.pm$//i; $_ }
124 sort
125 grep /.+Plugin\.pm$/i, readdir DIR;
126 push( @plugins, @modules );
127 rizwank 1.1 closedir( DIR );
128 }
129 return @plugins;
130 }
131
132 # =========================
133 =pod
134
135 ---++ sub registerHandler ( $handlerName, $theHandler )
136
137 Not yet documented.
138
139 =cut
140
141 sub registerHandler
142 {
143 my ( $handlerName, $theHandler ) = @_;
144 push @{$registeredHandlers{$handlerName}}, ( $theHandler );
145 }
146
147 # =========================
148 rizwank 1.1 =pod
149
150 ---++ sub initialisationError
151
152 Internal routine called every time a plugin fails to load
153
154 =cut
155
156 sub initialisationError
157 {
158 my( $error ) = @_;
159 $initialisationErrors .= $error."\n";
160 &TWiki::writeWarning( $error );
161 }
162
163 =pod
164 ---++ sub registerPlugin ( $plugin, $topic, $web, $user, $theLoginName, $theUrl, $thePathInfo )
165
166 Not yet documented.
167
168 =cut
169 rizwank 1.1
170 sub registerPlugin
171 {
172 #FIXME make all this sub more robust
173 # parameters: ( $plugin, $topic, $web, $user )
174 # If $user is empty this is preInitPlugin call - used to establish the user
175 my ( $plugin, $topic, $web, $user, $theLoginName, $theUrl, $thePathInfo ) = @_;
176
177 # look for the plugin installation web (needed for attached files)
178 # in the order:
179 # 1 fully specified web.plugin
180 # 2 TWiki.plugin
181 # 3 Plugins.plugin
182 # 4 thisweb.plugin
183
184 # Ignore an empty plugin name (should not happen, fix the calling function!).
185 if ( ! $plugin ) {
186 initialisationError( "Plugins: undefined or empty plugin name" );
187 return;
188 }
189
190 rizwank 1.1 my $installWeb = '';
191 # first check for fully specified plugin
192 if ( $plugin =~ m/^(.+)\.([^\.]+Plugin)$/ ) {
193 $installWeb = $1;
194 $plugin = $2;
195 }
196
197 if( $activePluginWebs{$plugin} ) {
198 # Plugin is already registered
199 return;
200 }
201
202 if( ! $installWeb ) {
203 if ( &TWiki::Store::topicExists( $TWiki::twikiWebname, $plugin ) ) {
204 # found plugin in TWiki web
205 $installWeb = $TWiki::twikiWebname;
206 } elsif ( &TWiki::Store::topicExists( "Plugins", $plugin ) ) {
207 # found plugin in Plugins web
208 $installWeb = "Plugins";
209 } elsif ( &TWiki::Store::topicExists( $web, $plugin ) ) {
210 # found plugin in current web
211 rizwank 1.1 $installWeb = $web;
212 } else {
213 # not found
214 initialisationError( "Plugins: couldn't register $plugin, no plugin topic" );
215 return;
216 }
217 }
218
219 # untaint & clean up the dirty laundry ....
220 if ( $plugin =~ m/^([A-Za-z0-9_]+Plugin)$/ ) {
221 $plugin = $1;
222 } else {
223 initialisationError("$plugin - invalid topic name for plugin");
224 return;
225 }
226
227 my $p = 'TWiki::Plugins::'.$plugin;
228
229 eval "use $p;";
230
231 if ($@) {
232 rizwank 1.1 initialisationError("Plugin \"$p\" could not be loaded by Perl. Errors were:\n----\n$@----");
233 return;
234 }
235
236 my $h = "";
237 my $sub = "";
238 my $prefix = "";
239 if( ! $user ) {
240 $sub = $p . '::earlyInitPlugin';
241 if( ! defined( &$sub ) ) {
242 return;
243 }
244 $sub = $p. '::initializeUserHandler';
245 $user = &$sub( $theLoginName );
246 return $user;
247
248 }
249 $sub = $p.'::initPlugin';
250 # we register a plugin ONLY if it defines initPlugin AND it returns true
251 if( ! defined( &$sub ) ) {
252 initialisationError("Plugin $p iniPlugin did not return true");
253 rizwank 1.1 return;
254 }
255 # read plugin preferences before calling initPlugin
256 $prefix = uc( $plugin ) . "_";
257 &TWiki::Prefs::getPrefsFromTopic( $installWeb, $plugin, $prefix );
258
259 if( &$sub( $topic, $web, $user, $installWeb ) ) {
260 foreach $h ( @registrableHandlers ) {
261 $sub = $p.'::'.$h;
262 ®isterHandler( $h, $sub ) if defined( &$sub );
263 }
264 $activePluginWebs{$plugin} = $installWeb;
265 push( @activePlugins, $plugin );;
266 }
267 }
268
269 # =========================
270 =pod
271
272 ---++ sub applyHandlers ()
273
274 rizwank 1.1 Not yet documented.
275
276 =cut
277
278 sub applyHandlers
279 {
280 my $handlerName = shift;
281 my $theHandler;
282 if( $TWiki::disableAllPlugins ) {
283 return;
284 }
285 my $status;
286
287 foreach $theHandler ( @{$registeredHandlers{$handlerName}} ) {
288 # apply handler on the remaining list of args
289 $status = &$theHandler;
290 if( $onlyOnceHandlers{$handlerName} ) {
291 if( $status ) {
292 return $status;
293 }
294 }
295 rizwank 1.1 }
296
297 return undef;
298 }
299
300 # =========================
301 # Initialisation that is done is done before the user is known
302 # Can return a user e.g. if a plugin like SessionPlugin sets the user
303 # using initializeUserHandler.
304 =pod
305
306 ---++ sub initialize1 ( $theTopicName, $theWebName, $theLoginName, $theUrl, $thePathInfo )
307
308 Not yet documented.
309
310 =cut
311
312 sub initialize1
313 {
314 my( $theTopicName, $theWebName, $theLoginName, $theUrl, $thePathInfo ) = @_;
315
316 rizwank 1.1 # initialize variables, needed when TWiki::initialize called more then once
317 %registeredHandlers = ();
318 undef @activePlugins;
319 undef %activePluginWebs;
320 undef @instPlugins;
321 undef %disabledPlugins;
322
323 if( $ENV{'REDIRECT_STATUS'} && $ENV{'REDIRECT_STATUS'} eq '401' ) {
324 # bail out if authentication failed
325 return "";
326 }
327
328 # Get INSTALLEDPLUGINS and DISABLEDPLUGINS variables
329 my $plugin = &TWiki::Prefs::getPreferencesValue( "INSTALLEDPLUGINS" ) || "";
330 $plugin =~ s/[\n\t\s\r]+/ /go;
331 my @setInstPlugins = grep { /^.+Plugin$/ } split( /,?\s+/ , $plugin );
332 $plugin = &TWiki::Prefs::getPreferencesValue( "DISABLEDPLUGINS" ) || "";
333 foreach my $p (split( /,?\s+/ , $plugin)) {
334 if ( $p =~ /^.+Plugin$/ ) {
335 $p =~ s/^.*\.(.*)$/$1/;
336 $disabledPlugins{$p} = 1 if ( $p );
337 rizwank 1.1 }
338 }
339
340 my @discoveredPlugins = discoverPluginPerlModules();
341 my $p = "";
342 foreach $plugin ( @setInstPlugins ) {
343 $p = $plugin;
344 $p =~ s/^.*\.(.*)$/$1/o; # cut web
345 if( $p && !$disabledPlugins{$p} ) {
346 push( @instPlugins, $plugin );
347 }
348 }
349 # append discovered plugin modules to installed plugin list
350 push( @instPlugins, @discoveredPlugins );
351
352 # for efficiency we register all possible handlers at once
353 my $user = "";
354 my $posUser = "";
355 foreach $plugin ( @instPlugins ) {
356 $p = $plugin;
357 $p =~ s/^.*\.(.*)$/$1/o; # cut web
358 rizwank 1.1 unless( $disabledPlugins{$p} ) {
359 $posUser = registerPlugin( $plugin, $theTopicName, $theWebName, "", $theLoginName, $theUrl, $thePathInfo );
360 if( $posUser ) {
361 $user = $posUser;
362 }
363 }
364 }
365 unless( $user ) {
366 $user = &TWiki::initializeRemoteUser( $theLoginName );
367 }
368 return $user;
369 }
370
371
372 # =========================
373 # Initialisation that is done is done after the user is known
374 =pod
375
376 ---++ sub initialize2 ( $theTopicName, $theWebName, $theUser )
377
378 Not yet documented.
379 rizwank 1.1
380 =cut
381
382 sub initialize2
383 {
384 my( $theTopicName, $theWebName, $theUser ) = @_;
385
386 # for efficiency we register all possible handlers at once
387 my $p = "";
388 my $plugin = "";
389 foreach $plugin ( @instPlugins ) {
390 $p = $plugin;
391 $p =~ s/^.*\.(.*)$/$1/o; # cut web
392 unless( $disabledPlugins{$p} ) {
393 registerPlugin( $plugin, @_, $theWebName, $theUser );
394 }
395 }
396 }
397
398 # =========================
399 =pod
400 rizwank 1.1
401
402 --++ sub handleFailedPlugins ()
403
404 %FAILEDPLUGINS reports reasons why plugins failed to load
405
406 =cut
407
408 sub handleFailedPlugins
409 {
410 my $text;
411
412 $text .= "---++ Plugins defined\n";
413
414 foreach my $plugin (@instPlugins) {
415 $text .= "\t* $plugin\n";
416 }
417
418 $text.="\n\n";
419
420 foreach my $handler (@registrableHandlers) {
421 rizwank 1.1 $text .= "| $handler |";
422 $text .= "| $handler | ";
423 if ( defined( $registeredHandlers{$handler} ) ) {
424 $text .= join "<br />", @{$registeredHandlers{$handler}};
425 }
426 $text .= " |\n";
427 }
428
429 my $err = $initialisationErrors;
430 $err = "None" unless $err;
431 $text .= "<br />\n---++ Errors\n<verbatim>\n$err\n</verbatim>\n";
432
433 return $text;
434 }
435
436 =pod
437 ---++ sub handlePluginDescription ()
438
439 Not yet documented.
440
441 =cut
442 rizwank 1.1
443 sub handlePluginDescription
444 {
445 my $text = "";
446 my $line = "";
447 my $pref = "";
448 foreach my $plugin ( @activePlugins ) {
449 $pref = uc( $plugin ) . "_SHORTDESCRIPTION";
450 $line = &TWiki::Prefs::getPreferencesValue( $pref );
451 if( $line ) {
452 $text .= "\t\* $activePluginWebs{$plugin}.$plugin: $line\n"
453 }
454 }
455
456 return $text;
457 }
458
459 # =========================
460 =pod
461
462 ---++ sub handleActivatedPlugins ()
463 rizwank 1.1
464 Not yet documented.
465
466 =cut
467
468 sub handleActivatedPlugins
469 {
470 my $text = "";
471 foreach my $plugin ( @activePlugins ) {
472 $text .= "$activePluginWebs{$plugin}.$plugin, ";
473 }
474 $text =~ s/\,\s*$//o;
475 return $text;
476 }
477
478 # =========================
479 # FIXME: This function no longer used: superseded by initialize1.
480 # remove on non documentation-only commit.
481 =pod
482
483 ---++ sub initializeUserHandler ()
484 rizwank 1.1
485 Not yet documented.
486
487 =cut
488
489 sub initializeUserHandler
490 {
491 # Called by TWiki::initialize
492 # my( $theLoginName, $theUrl, $thePathInfo ) = @_;
493
494 unshift @_, ( 'initializeUserHandler' );
495 my $user = &applyHandlers;
496
497 if( ! defined( $user ) ) {
498 $user = &TWiki::initializeRemoteUser( $_[0] );
499 }
500
501 return $user;
502 }
503
504 # =========================
505 rizwank 1.1 =pod
506
507 ---++ sub registrationHandler ()
508
509 Not yet documented.
510
511 =cut
512
513 sub registrationHandler
514 {
515 # Called by the register script
516 # my( $web, $wikiName, $loginName ) = @_;
517 unshift @_, ( 'registrationHandler' );
518 &applyHandlers;
519 }
520
521 # =========================
522 =pod
523
524 ---++ sub beforeCommonTagsHandler ()
525
526 rizwank 1.1 Not yet documented.
527
528 =cut
529
530 sub beforeCommonTagsHandler
531 {
532 # Called by sub handleCommonTags at the beginning (for cache Plugins only)
533 # my( $text, $topic, $theWeb ) = @_;
534 unshift @_, ( 'beforeCommonTagsHandler' );
535 &applyHandlers;
536 }
537
538 # =========================
539 =pod
540
541 ---++ sub commonTagsHandler ()
542
543 Not yet documented.
544
545 =cut
546
547 rizwank 1.1 sub commonTagsHandler
548 {
549 # Called by sub handleCommonTags, after %INCLUDE:"..."%
550 # my( $text, $topic, $theWeb ) = @_;
551 unshift @_, ( 'commonTagsHandler' );
552 &applyHandlers;
553 $_[0] =~ s/%PLUGINDESCRIPTIONS%/&handlePluginDescription()/geo;
554 $_[0] =~ s/%ACTIVATEDPLUGINS%/&handleActivatedPlugins()/geo;
555 $_[0] =~ s/%FAILEDPLUGINS%/&handleFailedPlugins()/geo;
556 }
557
558 # =========================
559 =pod
560
561 ---++ sub afterCommonTagsHandler ()
562
563 Not yet documented.
564
565 =cut
566
567 sub afterCommonTagsHandler
568 rizwank 1.1 {
569 # Called by sub handleCommonTags at the end (for cache Plugins only)
570 # my( $text, $topic, $theWeb ) = @_;
571 unshift @_, ( 'afterCommonTagsHandler' );
572 &applyHandlers;
573 }
574
575 # =========================
576 =pod
577
578 ---++ sub startRenderingHandler ()
579
580 Not yet documented.
581
582 =cut
583
584 sub startRenderingHandler
585 {
586 # Called by getRenderedVersion just before the line loop
587 # my ( $text, $web ) = @_;
588 unshift @_, ( 'startRenderingHandler' );
589 rizwank 1.1 &applyHandlers;
590 }
591
592 # =========================
593 =pod
594
595 ---++ sub outsidePREHandler ()
596
597 Not yet documented.
598
599 =cut
600
601 sub outsidePREHandler
602 {
603 # Called by sub getRenderedVersion, in loop outside of <PRE> tag
604 # my( $text ) = @_;
605 unshift @_, ( 'outsidePREHandler' );
606 &applyHandlers;
607 }
608
609 # =========================
610 rizwank 1.1 =pod
611
612 ---++ sub insidePREHandler ()
613
614 Not yet documented.
615
616 =cut
617
618 sub insidePREHandler
619 {
620 # Called by sub getRenderedVersion, in loop inside of <PRE> tag
621 # my( $text ) = @_;
622 unshift @_, ( 'insidePREHandler' );
623 &applyHandlers;
624 }
625
626 # =========================
627 =pod
628
629 ---++ sub endRenderingHandler ()
630
631 rizwank 1.1 Not yet documented.
632
633 =cut
634
635 sub endRenderingHandler
636 {
637 # Called by getRenderedVersion just after the line loop
638 # my ( $text ) = @_;
639 unshift @_, ( 'endRenderingHandler' );
640 &applyHandlers;
641 }
642
643 # =========================
644 =pod
645
646 ---++ sub beforeEditHandler ()
647
648 Not yet documented.
649
650 =cut
651
652 rizwank 1.1 sub beforeEditHandler
653 {
654 # Called by edit
655 # my( $text, $topic, $web ) = @_;
656 unshift @_, ( 'beforeEditHandler' );
657 &applyHandlers;
658 }
659
660 # =========================
661 =pod
662
663 ---++ sub afterEditHandler ()
664
665 Not yet documented.
666
667 =cut
668
669 sub afterEditHandler
670 {
671 # Called by edit
672 # my( $text, $topic, $web ) = @_;
673 rizwank 1.1 unshift @_, ( 'afterEditHandler' );
674 &applyHandlers;
675 }
676
677 # =========================
678 =pod
679
680 ---++ sub beforeSaveHandler ()
681
682 Not yet documented.
683
684 =cut
685
686 sub beforeSaveHandler
687 {
688 # Called by TWiki::Store::saveTopic before the save action
689 # my ( $theText, $theTopic, $theWeb ) = @_;
690 unshift @_, ( 'beforeSaveHandler' );
691 &applyHandlers;
692 }
693
694 rizwank 1.1 =pod
695 ---++ sub afterSaveHandler ()
696
697 Not yet documented.
698
699 =cut
700
701 sub afterSaveHandler
702 {
703 # Called by TWiki::Store::saveTopic after the save action
704 # my ( $theText, $theTopic, $theWeb ) = @_;
705 unshift @_, ( 'afterSaveHandler' );
706 &applyHandlers;
707 }
708
709 =pod
710
711 ---++ sub beforeAttachmentSaveHandler ( $attrHashRef, $topic, $web )
712
713 | Description: | This code provides Plugins with the opportunity to alter an uploaded attachment between the upload and save-to-store processes. It is invoked as per other Plugins. |
714 | Parameter: =$attrHashRef= | Hash reference of attachment attributes (keys are indicated below) |
715 rizwank 1.1 | Parameter: =$topic= | Topic name |
716 | Parameter: =$web= | Web name |
717 | Return: | There is no defined return value for this call |
718
719 Keys in $attrHashRef:
720 | *Key* | *Value* |
721 | attachment | Name of the attachment |
722 | tmpFilename | Name of the local file that stores the upload |
723 | comment | Comment to be associated with the upload |
724 | user | Login name of the person submitting the attachment, e.g. "jsmith" |
725
726 Note: All keys should be used read-only, except for comment which can be modified.
727
728 Example usage:
729
730 <pre>
731 my( $attrHashRef, $topic, $web ) = @_;
732 $$attrHashRef{"comment"} .= " (NOTE: Extracted from blah.tar.gz)";
733 </pre>
734
735 =cut
736 rizwank 1.1
737 sub beforeAttachmentSaveHandler
738 {
739 # Called by TWiki::Store::saveAttachment before the save action
740 # my ( $theAttrHash, $theTopic, $theWeb ) = @_;
741 unshift @_, ( 'beforeAttachmentSaveHandler' );
742 &applyHandlers;
743 }
744
745 =pod
746
747 ---++ sub afterAttachmentSaveHandler( $attachmentAttrHash, $topic, $web, $error )
748
749 | Description: | This code provides plugins with the opportunity to alter an uploaded attachment between the upload and save-to-store processes. It is invoked as per other plugins. |
750
751 | Parameter: =$attrHashRef= | Hash reference of attachment attributes (keys are indicated below) |
752 | Parameter: =$topic= | Topic name |
753 | Parameter: =$web= | Web name |
754 | Parameter: =$error= | Error string of save action, empty if OK |
755 | Return: | There is no defined return value for this call |
756
757 rizwank 1.1 Keys in $attrHashRef:
758 | *Key* | *Value* |
759 | attachment | Name of the attachment |
760 | tmpFilename | Name of the local file that stores the upload |
761 | comment | Comment to be associated with the upload |
762 | user | Login name of the person submitting the attachment, e.g. "jsmith" |
763
764 Note: All keys should be used read-only.
765
766 =cut
767
768 sub afterAttachmentSaveHandler
769 {
770 # Called by TWiki::Store::saveAttachment after the save action
771 # my ( $theText, $theTopic, $theWeb ) = @_;
772 unshift @_, ( 'afterAttachmentSaveHandler' );
773 &applyHandlers;
774 }
775
776
777 # =========================
778 rizwank 1.1 =pod
779
780 ---++ sub writeHeaderHandler ()
781
782 Not yet documented.
783
784 =cut
785
786 sub writeHeaderHandler
787 {
788 # Called by TWiki::writeHeader
789 unshift @_, ( 'writeHeaderHandler' );
790 return &applyHandlers;
791 }
792
793 # =========================
794 =pod
795
796 ---++ sub redirectCgiQueryHandler ()
797
798 Not yet documented.
799 rizwank 1.1
800 =cut
801
802 sub redirectCgiQueryHandler
803 {
804 # Called by TWiki::redirect
805 unshift @_, ( 'redirectCgiQueryHandler' );
806 return &applyHandlers;
807 }
808
809 # =========================
810 =pod
811
812 ---++ sub getSessionValueHandler ()
813
814 Not yet documented.
815
816 =cut
817
818 sub getSessionValueHandler
819 {
820 rizwank 1.1 # Called by TWiki::getSessionValue
821 unshift @_, ( 'getSessionValueHandler' );
822 return &applyHandlers;
823 }
824
825 # =========================
826 =pod
827
828 ---++ sub setSessionValueHandler ()
829
830 Not yet documented.
831
832 =cut
833
834 sub setSessionValueHandler
835 {
836 # Called by TWiki::setSessionValue
837 unshift @_, ( 'setSessionValueHandler' );
838 return &applyHandlers;
839 }
840
841 rizwank 1.1 # ========================
842 =pod
843
844 ---++ sub renderFormFieldForEditHandler ( $name, $type, $size, $value, $attributes, $possibleValues )
845
846 | Description: | This handler is called by Form.renderForEdit, before built-in types are considered. It generates the HTML text rendering this form field, or false, if the rendering should be done by the built-in type handlers. |
847 | Parameter: =$name= | name of form field |
848 | Parameter: =$type= | type of form field |
849 | Parameter: =$size= | size of form field |
850 | Parameter: =$value= | value held in the form field |
851 | Parameter: =$attributes= | attributes of form field |
852 | Parameter: =$possibleValues= | the values defined as options for form field, if any |
853 | Return: =$text= | HTML text that renders this field. If false, form rendering continues by considering the built-in types. |
854
855 Typical usage is in the style of Form.renderForEdit:
856
857 <pre>
858 if ( is_type1($type) ) {
859 $ret = compute_formating_for_type1();
860 } elsif ( is_type2($type) ) {
861 $ret = compute_formating_for_type2();
862 rizwank 1.1 } ...
863 clean_up_if_necessary($ret);
864 return $ret;
865 </pre>
866
867 Note that a common application would be to generate formatting of the
868 field involving generation of javascript. Such usually also requires
869 the insertion of some common javascript into the page header. Unfortunately,
870 there is currently no mechanism to pass that script to where the header of
871 the page is visible. Consequentially, the common javascript will have to
872 be emitted as part of the field formatting and might be duplicated many
873 times throughout the page.
874
875 =cut
876
877 sub renderFormFieldForEditHandler
878 {
879 # Called by Form.TODO
880 unshift @_, ( 'renderFormFieldForEditHandler' );
881 return &applyHandlers;
882 }
883 rizwank 1.1
884 =pod
885
886 ---++ sub renderWikiWordHandler ()
887
888 Called by TWiki::internalLink to change how a WikiWord is rendered
889
890 Originated from the TWiki:Plugins.SpacedWikiWordPlugin hack
891
892 =cut
893
894 sub renderWikiWordHandler
895 {
896 unshift @_, ( 'renderWikiWordHandler' );
897 return &applyHandlers;
898 }
899
900
901 1;
|