1 rizwank 1.1 # Plugin for TWiki Collaboration Platform, http://TWiki.org/
2 #
3 # Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it
4 # Copyright (C) 2000-2004 Peter Thoeny, peter@thoeny.com
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details, published at
15 # http://www.gnu.org/copyleft/gpl.html
16 #
17 # =========================
18 #
19 # This is the default TWiki plugin. Use EmptyPlugin.pm as a template
20 # for your own plugins; see TWiki.TWikiPlugins for details.
21 #
22 rizwank 1.1 # Each plugin is a package that may contain these functions: VERSION:
23 #
24 # earlyInitPlugin ( ) 1.020
25 # initPlugin ( $topic, $web, $user, $installWeb ) 1.000
26 # initializeUserHandler ( $loginName, $url, $pathInfo ) 1.010
27 # registrationHandler ( $web, $wikiName, $loginName ) 1.010
28 # beforeCommonTagsHandler ( $text, $topic, $web ) 1.024
29 # commonTagsHandler ( $text, $topic, $web ) 1.000
30 # afterCommonTagsHandler ( $text, $topic, $web ) 1.024
31 # startRenderingHandler ( $text, $web ) 1.000
32 # outsidePREHandler ( $text ) 1.000
33 # insidePREHandler ( $text ) 1.000
34 # endRenderingHandler ( $text ) 1.000
35 # beforeEditHandler ( $text, $topic, $web ) 1.010
36 # afterEditHandler ( $text, $topic, $web ) 1.010
37 # beforeSaveHandler ( $text, $topic, $web ) 1.010
38 # afterSaveHandler ( $text, $topic, $web, $errors ) 1.020
39 # renderFormFieldForEditHandler( $name, $type, $size, $value, $attributes, $possibleValues)
40 # writeHeaderHandler ( $query ) 1.010 Use only in one Plugin
41 # redirectCgiQueryHandler ( $query, $url ) 1.010 Use only in one Plugin
42 # getSessionValueHandler ( $key ) 1.010 Use only in one Plugin
43 rizwank 1.1 # setSessionValueHandler ( $key, $value ) 1.010 Use only in one Plugin
44 #
45 # initPlugin is required, all other are optional.
46 # For increased performance, unused handlers are disabled. To
47 # enable a handler remove the leading DISABLE_ from the function
48 # name. Remove disabled handlers you do not need.
49 #
50 # NOTE: To interact with TWiki use the official TWiki functions
51 # in the TWiki::Func module. Do not reference any functions or
52 # variables elsewhere in TWiki!!
53
54
55 # =========================
56 package TWiki::Plugins::DefaultPlugin;
57
58 # =========================
59 use vars qw(
60 $web $topic $user $installWeb $VERSION $pluginName
61 $debug $doOldInclude $renderingWeb
62 );
63
64 rizwank 1.1 $VERSION = '1.021';
65 $pluginName = 'DefaultPlugin'; # Name of this Plugin
66
67 # =========================
68 sub initPlugin
69 {
70 ( $topic, $web, $user, $installWeb ) = @_;
71
72 # check for Plugins.pm versions
73 if( $TWiki::Plugins::VERSION < 1.021 ) {
74 TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
75 return 0;
76 }
77
78 # Get plugin preferences
79 $doOldInclude = TWiki::Func::getPluginPreferencesFlag( "OLDINCLUDE" ) || "";
80
81 # Get plugin debug flag
82 $debug = TWiki::Func::getPluginPreferencesFlag( "DEBUG" );
83
84 $renderingWeb = $web;
85 rizwank 1.1
86 # Plugin correctly initialized
87 TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug;
88 return 1;
89 }
90
91 # =========================
92 sub DISABLE_earlyInitPlugin
93 {
94 ### Remove DISABLE_ for a plugin that requires early initialization, that is expects to have
95 ### initializeUserHandler called before initPlugin, giving the plugin a chance to set the user
96 ### See SessionPlugin for an example of this.
97 return 1;
98 }
99
100
101 # =========================
102 sub DISABLE_initializeUserHandler
103 {
104 ### my ( $loginName, $url, $pathInfo ) = @_; # do not uncomment, use $_[0], $_[1]... instead
105
106 rizwank 1.1 TWiki::Func::writeDebug( "- ${pluginName}::initializeUserHandler( $_[0], $_[1] )" ) if $debug;
107
108 # Allows a plugin to set the username based on cookies. Called by TWiki::initialize.
109 # Return the user name, or "guest" if not logged in.
110 # New hook in TWiki::Plugins $VERSION = '1.010'
111
112 }
113
114 # =========================
115 sub DISABLE_registrationHandler
116 {
117 ### my ( $web, $wikiName, $loginName ) = @_; # do not uncomment, use $_[0], $_[1]... instead
118
119 TWiki::Func::writeDebug( "- ${pluginName}::registrationHandler( $_[0], $_[1] )" ) if $debug;
120
121 # Allows a plugin to set a cookie at time of user registration.
122 # Called by the register script.
123 # New hook in TWiki::Plugins $VERSION = '1.010'
124
125 }
126
127 rizwank 1.1 # =========================
128 sub DISABLE_beforeCommonTagsHandler
129 {
130 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
131
132 TWiki::Func::writeDebug( "- ${pluginName}::beforeCommonTagsHandler( $_[2].$_[1] )" ) if $debug;
133
134 # Called at the beginning of TWiki::handleCommonTags (for cache Plugins use only)
135 }
136
137 # =========================
138 sub commonTagsHandler
139 {
140 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
141
142 TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug;
143
144 # This is the place to define customized tags and variables
145 # Called by TWiki::handleCommonTags, after %INCLUDE:"..."%
146
147 # for compatibility for earlier TWiki versions:
148 rizwank 1.1 if( $doOldInclude ) {
149 # allow two level includes
150 $_[0] =~ s/%INCLUDE:"([^%\"]*?)"%/TWiki::handleIncludeFile( $1, $_[1], $_[2], "" )/geo;
151 $_[0] =~ s/%INCLUDE:"([^%\"]*?)"%/TWiki::handleIncludeFile( $1, $_[1], $_[2], "" )/geo;
152 }
153
154 # do custom extension rule, like for example:
155 # $_[0] =~ s/%XYZ%/&handleXyz()/ge;
156 # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/ge;
157 }
158
159 # =========================
160 sub DISABLE_afterCommonTagsHandler
161 {
162 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
163
164 TWiki::Func::writeDebug( "- ${pluginName}::afterCommonTagsHandler( $_[2].$_[1] )" ) if $debug;
165
166 # Called at the end of TWiki::handleCommonTags (for cache Plugins use only)
167 }
168
169 rizwank 1.1 # =========================
170 sub startRenderingHandler
171 {
172 ### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead
173
174 TWiki::Func::writeDebug( "- ${pluginName}::startRenderingHandler( $_[1] )" ) if $debug;
175
176 # This handler is called by getRenderedVersion just before the line loop
177
178 $renderingWeb = $_[1];
179 }
180
181 # =========================
182 sub outsidePREHandler
183 {
184 ### my ( $text ) = @_; # do not uncomment, use $_[0] instead
185
186 ##TWiki::Func::writeDebug( "- ${pluginName}::outsidePREHandler( $renderingWeb.$topic )" ) if $debug;
187
188 # This handler is called by getRenderedVersion, once per line, before any changes,
189 # for lines outside <pre> and <verbatim> tags.
190 rizwank 1.1 # Use it to define customized rendering rules
191
192 # do custom extension rule, like for example:
193 # $_[0] =~ s/old/new/go;
194
195 # render deprecated *_text_* as "bold italic" text:
196 $_[0] =~ s/(^|\s)\*_([^\s].*?[^\s])_\*(\s|$)/$1<strong><em>$2<\/em><\/strong>$3/go;
197
198 # Use alternate %Web:WikiName% syntax (versus the standard Web.WikiName).
199 # This is an old JosWiki render option. (Uncomment for JosWiki compatibility)
200 # $_[0] =~ s/(^|\s|\()\%([^\s].*?[^\s]):([^\s].*?[^\s])\%/&TWiki::Render::internalLink($2,$3,"$2:$3",$1,1)/geo;
201
202 # Use "forced" non-WikiName links (i.e. %Linkname%)
203 # This is an old JosWiki render option. (Uncomment for JosWiki compatibility)
204 # $_[0] =~ s/(^|\s|\()\%([^\s].*?[^\s])\%/&TWiki::Render::internalLink($web,$2,$2,$1,1)/geo;
205
206 # Use "forced" non-WikiName links (i.e. %Web.Linkname%)
207 # This is an old JosWiki render option combined with the new Web.LinkName notation
208 # (Uncomment for JosWiki compatibility)
209 # $_[0] =~ s/(^|\s|\()\%([a-zA-Z0-9]+)\.(.*?[^\s])\%(\s|\)|$)/&TWiki::Render::internalLink($2,$3,$3,$1,1)/geo;
210
211 rizwank 1.1 # Use <link>....</link> links
212 # This is an old JosWiki render option. (Uncomment for JosWiki compatibility)
213 # $_[0] =~ s/<link>(.*?)<\/link>/&TWiki::internalLink("",$web,$1,$1,"",1)/geo;
214 }
215
216 # =========================
217 sub DISABLE_insidePREHandler
218 {
219 ### my ( $text ) = @_; # do not uncomment, use $_[0] instead
220
221 ##TWiki::Func::writeDebug( "- ${pluginName}::insidePREHandler( $web.$topic )" ) if $debug;
222
223 # This handler is called by getRenderedVersion, once per line, before any changes,
224 # for lines inside <pre> and <verbatim> tags.
225 # Use it to define customized rendering rules
226
227 # do custom extension rule, like for example:
228 # $_[0] =~ s/old/new/go;
229 }
230
231 # =========================
232 rizwank 1.1 sub DISABLE_endRenderingHandler
233 {
234 ### my ( $text ) = @_; # do not uncomment, use $_[0] instead
235
236 TWiki::Func::writeDebug( "- ${pluginName}::endRenderingHandler( $web.$topic )" ) if $debug;
237
238 # This handler is called by getRenderedVersion just after the line loop, that is,
239 # after almost all XHTML rendering of a topic. <nop> tags are removed after this.
240
241 }
242
243 # =========================
244 sub DISABLE_beforeEditHandler
245 {
246 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
247
248 TWiki::Func::writeDebug( "- ${pluginName}::beforeEditHandler( $_[2].$_[1] )" ) if $debug;
249
250 # This handler is called by the edit script just before presenting the edit text
251 # in the edit box. Use it to process the text before editing.
252 # New hook in TWiki::Plugins $VERSION = '1.010'
253 rizwank 1.1
254 }
255
256 # =========================
257 sub DISABLE_afterEditHandler
258 {
259 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
260
261 TWiki::Func::writeDebug( "- ${pluginName}::afterEditHandler( $_[2].$_[1] )" ) if $debug;
262
263 # This handler is called by the preview script just before presenting the text.
264 # New hook in TWiki::Plugins $VERSION = '1.010'
265
266 }
267
268 # =========================
269 sub DISABLE_beforeSaveHandler
270 {
271 ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
272
273 TWiki::Func::writeDebug( "- ${pluginName}::beforeSaveHandler( $_[2].$_[1] )" ) if $debug;
274 rizwank 1.1
275 # This handler is called by TWiki::Store::saveTopic just before the save action.
276 # New hook in TWiki::Plugins $VERSION = '1.010'
277
278 }
279
280 # =========================
281 sub DISABLE_afterSaveHandler
282 {
283 ### my ( $text, $topic, $web, $error ) = @_; # do not uncomment, use $_[0], $_[1]... instead
284
285 TWiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( $_[2].$_[1] )" ) if $debug;
286
287 # This handler is called by TWiki::Store::saveTopic just after the save action.
288 # New hook in TWiki::Plugins $VERSION = '1.020'
289
290 }
291
292 # =========================
293 sub DISABLE_writeHeaderHandler
294 {
295 rizwank 1.1 ### my ( $query ) = @_; # do not uncomment, use $_[0] instead
296
297 TWiki::Func::writeDebug( "- ${pluginName}::writeHeaderHandler( query )" ) if $debug;
298
299 # This handler is called by TWiki::writeHeader, just prior to writing header.
300 # Return a single result: A string containing HTTP headers, delimited by CR/LF
301 # and with no blank lines. Plugin generated headers may be modified by core
302 # code before they are output, to fix bugs or manage caching. Plugins should no
303 # longer write headers to standard output.
304 # Use only in one Plugin.
305 # New hook in TWiki::Plugins $VERSION = '1.010'
306
307 }
308
309 # =========================
310 sub DISABLE_redirectCgiQueryHandler
311 {
312 ### my ( $query, $url ) = @_; # do not uncomment, use $_[0], $_[1] instead
313
314 TWiki::Func::writeDebug( "- ${pluginName}::redirectCgiQueryHandler( query, $_[1] )" ) if $debug;
315
316 rizwank 1.1 # This handler is called by TWiki::redirect. Use it to overload TWiki's internal redirect.
317 # Use only in one Plugin.
318 # New hook in TWiki::Plugins $VERSION = '1.010'
319
320 }
321
322 # =========================
323 sub DISABLE_getSessionValueHandler
324 {
325 ### my ( $key ) = @_; # do not uncomment, use $_[0] instead
326
327 TWiki::Func::writeDebug( "- ${pluginName}::getSessionValueHandler( $_[0] )" ) if $debug;
328
329 # This handler is called by TWiki::getSessionValue. Return the value of a key.
330 # Use only in one Plugin.
331 # New hook in TWiki::Plugins $VERSION = '1.010'
332
333 }
334
335 # =========================
336 sub DISABLE_setSessionValueHandler
337 rizwank 1.1 {
338 ### my ( $key, $value ) = @_; # do not uncomment, use $_[0], $_[1] instead
339
340 TWiki::Func::writeDebug( "- ${pluginName}::setSessionValueHandler( $_[0], $_[1] )" ) if $debug;
341
342 # This handler is called by TWiki::setSessionValue.
343 # Use only in one Plugin.
344 # New hook in TWiki::Plugins $VERSION = '1.010'
345
346 }
347
348 # =========================
349 sub DISABLE_renderFormFieldForEditHandler
350 {
351 my ( $name, $type, $size, $value, $attributes, $possibleValues ) = @_;
352
353 TWiki::Func::writeDebug( "- ${pluginName}::renderFormFieldForEditHandler( $web.$topic )" ) if $debug;
354
355 # This handler is called by Form.renderForEdit, before built in types are considered
356
357 my $ret = "";
358 rizwank 1.1 # Set ret to html, leave empty if plugin doesn't want to render this field
359 return $ret;
360 }
361
362 # =========================
363
364 1;
|