none
[openafs-wiki.git] / TWiki / TWikiScripts.mdwn
1 <div>
2   <ul>
3     <li><a href="#TWiki CGI and Command Line Scrip"> TWiki CGI and Command Line Scripts</a><ul>
4         <li><a href="#CGI Scripts"> CGI Scripts</a><ul>
5             <li><a href="#General Information"> General Information</a><ul>
6                 <li><a href="#CGI environment"> CGI environment</a></li>
7                 <li><a href="#Command-line"> Command-line</a></li>
8                 <li><a href="#Common parameters"> Common parameters</a></li>
9               </ul>
10             </li>
11             <li><a href="#=attach="> attach</a></li>
12             <li><a href="#=changes="> changes</a></li>
13             <li><a href="#=configure="> configure</a></li>
14             <li><a href="#=edit="> edit</a></li>
15             <li><a href="#=login="> login</a></li>
16             <li><a href="#=logon="> logon</a></li>
17             <li><a href="#=manage="> manage</a><ul>
18                 <li><a href="#=action=createweb="> action=createweb</a></li>
19                 <li><a href="#=action=delete_UserAccount="> action=deleteUserAccount</a></li>
20                 <li><a href="#=action=editSettings="> action=editSettings</a></li>
21                 <li><a href="#=action=bulkRegister="> action=bulkRegister</a></li>
22                 <li><a href="#=action=saveSettings="> action=saveSettings</a></li>
23               </ul>
24             </li>
25             <li><a href="#=oops="> oops</a></li>
26             <li><a href="#=passwd="> passwd</a><ul>
27                 <li><a href="#=action=changePassword="> action=changePassword</a></li>
28               </ul>
29             </li>
30             <li><a href="#=preview="> preview</a></li>
31             <li><a href="#=rdiff="> rdiff</a></li>
32             <li><a href="#=register="> register</a></li>
33             <li><a href="#=rename="> rename</a></li>
34             <li><a href="#=resetpasswd="> resetpasswd</a></li>
35             <li><a href="#=rest="> rest</a><ul>
36                 <li><a href="#Invocation Examples"> Invocation Examples</a></li>
37               </ul>
38             </li>
39             <li><a href="#=save="> save</a></li>
40             <li><a href="#=search="> search</a></li>
41             <li><a href="#=statistics="> statistics</a></li>
42             <li><a href="#=twiki="> twiki</a></li>
43             <li><a href="#=upload="> upload</a></li>
44             <li><a href="#=view="> view</a></li>
45             <li><a href="#=viewfile="> viewfile</a></li>
46           </ul>
47         </li>
48         <li><a href="#Command Line Scripts"> Command Line Scripts</a><ul>
49             <li><a href="#=geturl.pl="> geturl.pl</a></li>
50             <li><a href="#=rewriteshebang.pl="> rewriteshebang.pl</a></li>
51             <li><a href="#=tick_twiki.pl="> tick_twiki.pl</a></li>
52           </ul>
53         </li>
54       </ul>
55     </li>
56   </ul>
57 </div>
58
59 # <a name="TWiki CGI and Command Line Scrip"></a> TWiki CGI and Command Line Scripts
60
61 _Programs on the TWiki server performing actions such as rendering, saving and renaming topics._
62
63 The TWiki scripts are located in the `twiki/bin` and `twiki/tools` directories. This topic describes the interfaces to some of those scripts. All scripts in the `twiki/bin` directory can be called from the CGI ([Common Gateway Interface](http://en.wikipedia.org/wiki/Common_Gateway_Interface)) environment or from the command line. The scripts in the `twiki/tools` directory can only be called from the command line.
64
65 ## <a name="CGI Scripts"></a> CGI Scripts
66
67 Details on CGI scripts located in the `twiki/bin` directory.
68
69 ### <a name="General Information"></a> General Information
70
71 #### <a name="CGI environment"></a> CGI environment
72
73 In the CGI environment parameters are passed to the scripts via the URL and URL parameters. Environment variables are also used to determine the user performing the action. If the environment is not set up, the default TWiki user is used (usually `guest`).
74
75 #### <a name="Command-line"></a> Command-line
76
77 You **must** be cd'd to the `twiki/bin` directory to run the scripts from the command line. To avoid issues with file permissions, run the scripts as the web server user such as `nobody` or `www`.
78
79 Parameters are passed using '-name' - for example,
80
81     $ cd /usr/local/twiki/bin
82     $ save -topic MyWeb.MyTopic -user admin -action save -text "New text of the topic"
83
84 All parameters require a value.
85
86 #### <a name="Common parameters"></a> Common parameters
87
88 All the scripts accept a number of common parameters. The first two components of the URL after the script name are taken as the web and the topic, respectively. Standard URL parameters are:
89
90 <table border="1" cellpadding="0" cellspacing="0">
91   <tr>
92     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
93     <th bgcolor="#99CCCC"><strong> Description </strong></th>
94     <th bgcolor="#99CCCC"><strong> Default </strong></th>
95   </tr>
96   <tr>
97     <td><code>topic</code></td>
98     <td> If this is set to a URL, TWiki will immediately redirect to that URL. Otherwise it overrides the URL and is taken as the topic name (you can pass Web.TopicName) </td>
99     <td>   </td>
100   </tr>
101   <tr>
102     <td><code>user</code></td>
103     <td> Command-line only; set the name of the user performing the action. Note: this usage is inherently insecure, as it bypasses webserver login constraints. For this reason only authorised users should be allowed to execute scripts from the command line. </td>
104     <td>   </td>
105   </tr>
106   <tr>
107     <td><code>skin</code></td>
108     <td> Overrides the default skin path (see [[Main/TWikiSkins]]) </td>
109     <td>   </td>
110   </tr>
111   <tr>
112     <td><code>cover</code></td>
113     <td> Specifies temporary skin path to prepend to the skin path for this script only (see [[Main/TWikiSkins]]) </td>
114     <td>   </td>
115   </tr>
116 </table>
117
118 ### <a name="=attach="></a> `attach`
119
120 Despite the name, this script doesn't actually attach a file to a topic - for that, use `upload`. This script is part of the transactions sequence executed when a file is uploaded from the browser. it just generates the "new attachment" page for a topic.
121
122 <table border="1" cellpadding="0" cellspacing="0">
123   <tr>
124     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
125     <th bgcolor="#99CCCC"><strong> Description </strong></th>
126     <th bgcolor="#99CCCC"><strong> Default </strong></th>
127   </tr>
128   <tr>
129     <td><code>filename</code></td>
130     <td> Name of existing attachment (if provided, this is a "manage attachment" action) </td>
131     <td> none (in which case this is a "new attachment" action) </td>
132   </tr>
133 </table>
134
135 ### <a name="=changes="></a> `changes`
136
137 Shows all the changes in the given web.
138
139 The `changes` script can receive one parameter:
140
141 <table border="1" cellpadding="0" cellspacing="0">
142   <tr>
143     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
144     <th bgcolor="#99CCCC"><strong> Description </strong></th>
145     <th bgcolor="#99CCCC"><strong> Default </strong></th>
146   </tr>
147   <tr>
148     <td><code>minor</code></td>
149     <td> If 0, show only major changes. If 1, show all the changes (both minor and major) </td>
150     <td> 0 </td>
151   </tr>
152 </table>
153
154 The main difference between invoking this script and using [[WebChanges]] is that [[WebChanges]] is based on a `%SEARCH%`, while this script reads the `changes` file in each web, making it much faster.
155
156 **NOTE**: The result from `changes` script and the topic [[WebChanges]] can be different, if the `changes` file is deleted from a web. In particular, in new installations the `changes` script will return no results while the [[WebChanges]] topic will.
157
158 ### <a name="=configure="></a> `configure`
159
160 `configure` is the browser script used for inspection and configuration of the TWiki configuration. None of the parameters to this script are useable for any purpose except `configure`.
161
162 ### <a name="=edit="></a> `edit`
163
164 The `edit` scipt understands the following parameters, typically supplied by HTML input fields:
165
166 <table border="1" cellpadding="0" cellspacing="0">
167   <tr>
168     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
169     <th bgcolor="#99CCCC"><strong> Description </strong></th>
170     <th bgcolor="#99CCCC"><strong> Default </strong></th>
171   </tr>
172   <tr>
173     <td><code>action</code></td>
174     <td> Optional. Use the editaction template instead of the standard edit. If action=text, then hide the form. If action=form hide the normal text area and only edit the form. </td>
175     <td>   </td>
176   </tr>
177   <tr>
178     <td><code>onlynewtopic</code></td>
179     <td> If set, error if topic already exists </td>
180     <td>   </td>
181   </tr>
182   <tr>
183     <td><code>onlywikiname</code></td>
184     <td> If set, error if topic name is not a [[Main/WikiWord]]</td>
185     <td>   </td>
186   </tr>
187   <tr>
188     <td><code>templatetopic</code></td>
189     <td> The name of the template topic, copied to get the initial content </td>
190     <td>   </td>
191   </tr>
192   <tr>
193     <td><code>text</code></td>
194     <td> Initial text for the topic </td>
195     <td>   </td>
196   </tr>
197   <tr>
198     <td><code>topicparent</code></td>
199     <td> The parent topic </td>
200     <td>   </td>
201   </tr>
202   <tr>
203     <td><code>formtemplate</code></td>
204     <td> Name of the form to instantiate in the topic. Overrides the form set in the <code>templatetopic</code> if defined. </td>
205     <td>   </td>
206   </tr>
207   <tr>
208     <td><code>contenttype</code></td>
209     <td> Optional parameter that defines the application type to write into the CGI header. Defaults to <code>text/html</code>. May be used to invoke alternative client applications </td>
210     <td>   </td>
211   </tr>
212   <tr>
213     <td><code>anyname</code></td>
214     <td> Any parameter can passed to the new topic; if the template topic contains <code>%URLPARAM{"anyname"}%</code>, it will be replaced by its value </td>
215     <td>   </td>
216   </tr>
217   <tr>
218     <td><code>breaklock</code></td>
219     <td> If set, any lease conflicts will be ignored, and the edit will proceed even if someone is already editing the topic. </td>
220     <td>   </td>
221   </tr>
222 </table>
223
224 Form field values are passed in parameters named 'field' - for example, if I have a field `Status` the parameter name is `Status`.
225
226 1. The first sequence of ten or more `X` characters in the topic name will be converted on save to a number such that the resulting topic name is unique in the target web.
227
228 NOTE: most skins support the definition of `EDIT_SKIN`, which is used as the value of the `cover` parameter in `edit` URLs. This allows you to override the default edit skin on a web, topic or user basis.
229
230 ### <a name="=login="></a> `login`
231
232 Used for logging in when TWiki login is being used (e.g TemplateLoginManager).
233
234 <table border="1" cellpadding="0" cellspacing="0">
235   <tr>
236     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
237     <th bgcolor="#99CCCC"><strong> Description </strong></th>
238     <th bgcolor="#99CCCC"><strong> Default </strong></th>
239   </tr>
240   <tr>
241     <td><code>origurl</code></td>
242     <td> URL that was being accessed when an access violation occurred. the login process will redirect to this URL if it is successful </td>
243     <td> none </td>
244   </tr>
245   <tr>
246     <td><code>username</code></td>
247     <td> username of user logging in </td>
248     <td> none </td>
249   </tr>
250   <tr>
251     <td><code>password</code></td>
252     <td> password of user logging in </td>
253     <td> none </td>
254   </tr>
255 </table>
256
257 ### <a name="=logon="></a> `logon`
258
259 Used for logging in when Web Server authentication is being used (e.g. ApacheLoginManager). The script does nothing; it is purely a placeholder for triggering the login process. The webserver will be set up to require a valid user to access this script, thus triggering the webserver login process.
260
261 ### <a name="=manage="></a> `manage`
262
263 Performs a range of management functions.
264
265 <table border="1" cellpadding="0" cellspacing="0">
266   <tr>
267     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
268     <th bgcolor="#99CCCC"><strong> Description </strong></th>
269     <th bgcolor="#99CCCC"><strong> Default </strong></th>
270   </tr>
271   <tr>
272     <td><code>action</code></td>
273     <td> One of <code>createweb</code>, <code>deleteUserAccount</code>, <code>editSettings</code> or <code>saveSettings</code></td>
274     <td> none </td>
275   </tr>
276 </table>
277
278 #### <a name="=action=createweb="></a> `action=createweb`
279
280 <table border="1" cellpadding="0" cellspacing="0">
281   <tr>
282     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
283     <th bgcolor="#99CCCC"><strong> Description </strong></th>
284     <th bgcolor="#99CCCC"><strong> Default </strong></th>
285   </tr>
286   <tr>
287     <td><code>newweb</code></td>
288     <td> Name of the new web </td>
289     <td> '' </td>
290   </tr>
291   <tr>
292     <td><code>baseweb</code></td>
293     <td> Name of the web to copy to create the new web </td>
294     <td> '' </td>
295   </tr>
296   <tr>
297     <td><code>webbgcolor</code></td>
298     <td> value for WEBBGCOLOR </td>
299     <td> '' </td>
300   </tr>
301   <tr>
302     <td><code>sitemapwhat</code></td>
303     <td> Value for SITEMAPWHAT </td>
304     <td> '' </td>
305   </tr>
306   <tr>
307     <td><code>sitemapuseto</code></td>
308     <td> Value for SITEMAPUSETO </td>
309     <td> '' </td>
310   </tr>
311   <tr>
312     <td><code>nosearchall</code></td>
313     <td> Value for NOSEARCHALL </td>
314     <td> '' </td>
315   </tr>
316 </table>
317
318 #### <a name="=action=delete_UserAccount="></a> `action=deleteUserAccount`
319
320 Unregisters (removes) the currently logged-in user.
321
322 <table border="1" cellpadding="0" cellspacing="0">
323   <tr>
324     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
325     <th bgcolor="#99CCCC"><strong> Description </strong></th>
326     <th bgcolor="#99CCCC"><strong> Default </strong></th>
327   </tr>
328   <tr>
329     <td><code>password</code></td>
330     <td> Users' password </td>
331     <td> none </td>
332   </tr>
333 </table>
334
335 #### <a name="=action=editSettings="></a> `action=editSettings`
336
337 No parameters
338
339 #### <a name="=action=bulkRegister="></a> `action=bulkRegister`
340
341 See [[BulkRegistration]].
342
343 <table border="1" cellpadding="0" cellspacing="0">
344   <tr>
345     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
346     <th bgcolor="#99CCCC"><strong> Description </strong></th>
347     <th bgcolor="#99CCCC"><strong> Default </strong></th>
348   </tr>
349   <tr>
350     <td><code>OverwriteHomeTopics</code></td>
351     <td> Whether to overwrite existing home topics or not </td>
352     <td> false </td>
353   </tr>
354   <tr>
355     <td><code>EmailUsersWithDetails</code></td>
356     <td> Whether to mail registered users or not </td>
357     <td> false </td>
358   </tr>
359   <tr>
360     <td><code>LogTopic</code></td>
361     <td> Topic to save the log in </td>
362     <td> Same as topic name, with 'Result' appended. </td>
363   </tr>
364 </table>
365
366 #### <a name="=action=saveSettings="></a> `action=saveSettings`
367
368 <table border="1" cellpadding="0" cellspacing="0">
369   <tr>
370     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
371     <th bgcolor="#99CCCC"><strong> Description </strong></th>
372     <th bgcolor="#99CCCC"><strong> Default </strong></th>
373   </tr>
374   <tr>
375     <td><code>text</code></td>
376     <td> Text of the topic </td>
377     <td> '' </td>
378   </tr>
379   <tr>
380     <td><code>originalrev</code></td>
381     <td> Revision that the edit started on </td>
382     <td> Most recent revision </td>
383   </tr>
384 </table>
385
386 All other parameters may be interpreted as form fields, depending on the current form definition in the topic.
387
388 ### <a name="=oops="></a> `oops`
389
390 This script is mainly used for rendering pages containing error messages, though it is also used for some functional actions such as manage pages (move topic etc).
391
392 `oops` templates are used with the `oops` script to generate system messages. This is done to make internationalisation or other local customisations simple.
393
394 The `oops` script supports the following parameters:
395
396 <table border="1" cellpadding="0" cellspacing="0">
397   <tr>
398     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
399     <th bgcolor="#99CCCC"><strong> Description </strong></th>
400     <th bgcolor="#99CCCC"><strong> Default </strong></th>
401   </tr>
402   <tr>
403     <td><code>template</code></td>
404     <td> Name of the template file to display </td>
405     <td>   </td>
406   </tr>
407   <tr>
408     <td><code>def</code></td>
409     <td> Optional, can be set to the name of a single definition within <code>template</code>. This definition will be instantiated in the <code>template</code> wherever <code>%INSTANTIATE%</code> is seen. This lets you use a single template file for many messages. For an example, see <code>oopsmanagebad.tmpl</code>. </td>
410     <td>   </td>
411   </tr>
412   <tr>
413     <td><code>paramN</code></td>
414     <td> Where N is an integer from 1 upwards. These values will be substituted into <code>template</code> for <code>%PARAM1%</code> etc. </td>
415     <td>   </td>
416   </tr>
417 </table>
418
419 ### <a name="=passwd="></a> `passwd`
420
421 <table border="1" cellpadding="0" cellspacing="0">
422   <tr>
423     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
424     <th bgcolor="#99CCCC"><strong> Description </strong></th>
425     <th bgcolor="#99CCCC"><strong> Default </strong></th>
426   </tr>
427   <tr>
428     <td><code>action</code></td>
429     <td> one of <code>changePassword</code> or <code>resetPassword</code></td>
430     <td> none </td>
431   </tr>
432 </table>
433
434 Other parameters as described under `manage`, `action=changePassword`.
435
436 #### <a name="=action=changePassword="></a> `action=changePassword`
437
438 <table border="1" cellpadding="0" cellspacing="0">
439   <tr>
440     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
441     <th bgcolor="#99CCCC"><strong> Description </strong></th>
442     <th bgcolor="#99CCCC"><strong> Default </strong></th>
443   </tr>
444   <tr>
445     <td><code>username</code></td>
446     <td> Username </td>
447     <td>   </td>
448   </tr>
449   <tr>
450     <td><code>oldpassword</code></td>
451     <td> Existing password (plain text) </td>
452     <td>   </td>
453   </tr>
454   <tr>
455     <td><code>password</code></td>
456     <td> New password (plain text) </td>
457     <td>   </td>
458   </tr>
459   <tr>
460     <td><code>passwordA</code></td>
461     <td> New password confirmation (plain text) </td>
462     <td>   </td>
463   </tr>
464   <tr>
465     <td><code>TopicName</code></td>
466     <td> ? </td>
467     <td>   </td>
468   </tr>
469 </table>
470
471 ### <a name="=preview="></a> `preview`
472
473 This script is _deprecated_. Its functions are covered by the `save` script.
474
475 ### <a name="=rdiff="></a> `rdiff`
476
477 Renders the differences between version of a TWiki topic
478
479 <table border="1" cellpadding="0" cellspacing="0">
480   <tr>
481     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
482     <th bgcolor="#99CCCC"><strong> Description </strong></th>
483     <th bgcolor="#99CCCC"><strong> Default </strong></th>
484   </tr>
485   <tr>
486     <td> rev1 </td>
487     <td> the higher revision </td>
488     <td>   </td>
489   </tr>
490   <tr>
491     <td> rev2 </td>
492     <td> the lower revision </td>
493     <td>   </td>
494   </tr>
495   <tr>
496     <td> render </td>
497     <td> the rendering style {sequential, sidebyside, raw, debug} </td>
498     <td> DIFFRENDERSTYLE, <code>sequential</code></td>
499   </tr>
500   <tr>
501     <td> type </td>
502     <td> {history, diff, last} history diff, version to version, last version to previous </td>
503     <td><code>diff</code></td>
504   </tr>
505   <tr>
506     <td> context </td>
507     <td> number of lines of context </td>
508     <td>   </td>
509   </tr>
510 </table>
511
512 TODO:
513
514 - add a \{word\} render style
515
516 ### <a name="=register="></a> `register`
517
518 <table border="1" cellpadding="0" cellspacing="0">
519   <tr>
520     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
521     <th bgcolor="#99CCCC"><strong> Description </strong></th>
522     <th bgcolor="#99CCCC"><strong> Default </strong></th>
523   </tr>
524   <tr>
525     <td><code>action</code></td>
526     <td><code>register</code> or <code>verify</code> or <code>resetPassword</code> or <code>approve</code></td>
527     <td>   </td>
528   </tr>
529 </table>
530
531 ### <a name="=rename="></a> `rename`
532
533 Used for renaming topics.
534
535 <table border="1" cellpadding="0" cellspacing="0">
536   <tr>
537     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
538     <th bgcolor="#99CCCC"><strong> Description </strong></th>
539     <th bgcolor="#99CCCC"><strong> Default </strong></th>
540   </tr>
541   <tr>
542     <td><code>skin</code></td>
543     <td> skin(s) to use </td>
544     <td>   </td>
545   </tr>
546   <tr>
547     <td><code>newweb</code></td>
548     <td> new web name </td>
549     <td>   </td>
550   </tr>
551   <tr>
552     <td><code>newtopic</code></td>
553     <td> new topic name </td>
554     <td>   </td>
555   </tr>
556   <tr>
557     <td><code>breaklock</code></td>
558     <td>   </td>
559     <td>   </td>
560   </tr>
561   <tr>
562     <td><code>attachment</code></td>
563     <td>   </td>
564     <td>   </td>
565   </tr>
566   <tr>
567     <td><code>confirm</code></td>
568     <td> if defined, requires a second level of confirmation </td>
569     <td>   </td>
570   </tr>
571   <tr>
572     <td><code>currentwebonly</code></td>
573     <td> if defined, searches current web only for links to this topic </td>
574     <td>   </td>
575   </tr>
576   <tr>
577     <td><code>nonwikiword</code></td>
578     <td> if defined, a non-wikiword is acceptable for the new topic name </td>
579     <td>   </td>
580   </tr>
581 </table>
582
583 ### <a name="=resetpasswd="></a> `resetpasswd`
584
585 Reset the password for a single or multiple users
586
587 <table border="1" cellpadding="0" cellspacing="0">
588   <tr>
589     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
590     <th bgcolor="#99CCCC"><strong> Description </strong></th>
591     <th bgcolor="#99CCCC"><strong> Default </strong></th>
592   </tr>
593   <tr>
594     <td><code>LoginName</code></td>
595     <td><strong>list</strong> of usernames to reset </td>
596     <td> none - error if not set </td>
597   </tr>
598   <tr>
599     <td><code>Introduction</code></td>
600     <td> message to be sent alongside the reset, most often used to announce to the user that they have been given an account. </td>
601     <td> '' </td>
602   </tr>
603 </table>
604
605 This is used by [[BulkResetPassword]] and [[ResetPassword]]. Only users belonging to the [[TWikiAdminGroup]] can provide a list of [[LoginNames]], non-admins can only provide a single [[LoginName]].
606
607 [[BulkRegistration]] provides the means to create multiple accounts but it does not announce those accounts to the users who own them. [[BulkResetPassword]] is used to assign the passwords, the Introduction is used to explain why they are receiving the mail.
608
609 ### <a name="=rest="></a> `rest`
610
611 This REST ([Representational State Transfer](http://en.wikipedia.org/wiki/REST)) script can be invoked via http in a similar way as the view script (see **Invocation Examples**, below) to execute a function that is associated to a "subject" and a "verb" (see below). It'll print the result directly to the stream unless the `endPoint` parameter is specified, in which case the control is redirected to the given topic.
612
613 The `rest` script itself uses one parameter:
614
615 <table border="1" cellpadding="0" cellspacing="0">
616   <tr>
617     <td><code>endPoint</code></td>
618     <td> Where to redirect the response once the request is served, in the form "Web.Topic" </td>
619   </tr>
620 </table>
621
622 Any additional parameters are passed directly to the function (i.e: The function can get any other parameter using the CGI $query object)
623
624 #### <a name="Invocation Examples"></a> Invocation Examples
625
626 The `rest` script assumes that it will be called with URL in the form:
627
628 `http://my.host/bin/rest/<subject>/<verb>`
629
630 where `<subject>` must be the [[WikiWord]] name of one of the installed [[TWikiPlugins]], and the `<verb>` is the alias for the function registered using the `registerRESTHandler`. The `<subject>` and `<verb>` are then used to lookup and call the registered function.
631
632 Functions outside the Plugins also can be registered, but please consider the security implications of allowing URL access, as functions can sidestep TWiki Authentication &amp; Authorisation settings.
633
634 `<subject>` and `<verb>` are checked for illegal characters exactly in the same way as the web and topic names.
635
636 As an example, the [[EmptyPlugin]] has registered a function to be used with the `rest` script under the subject **EmptyPlugin** and the verb **example**. Click below to see the `rest` script in action (run as [[TWikiGuest]]).
637
638 [Call the Plugin](http://www.dementia.org/twiki/rest/EmptyPlugin/example?debugenableplugin=EmptyPlugin)
639
640 You can also call the function from the command line, but this will be run as the [[TWikiAdminGroup]] (as it is assumed that shell access is secure) - eg:
641
642     ./rest EmptyPlugin.example
643
644 Note that for calls to Plugins, they must be enabled in `configure`.
645
646 ### <a name="=save="></a> `save`
647
648 The `save` script performs a range of save-related functions, as selected by the `action` parameter.
649
650 <table border="1" cellpadding="0" cellspacing="0">
651   <tr>
652     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
653     <th bgcolor="#99CCCC"><strong> Description </strong></th>
654     <th bgcolor="#99CCCC"><strong> Default </strong></th>
655   </tr>
656   <tr>
657     <td><code>action_save=1</code></td>
658     <td><strong>default</strong>; save, return to view, dontnotify is OFF </td>
659     <td>   </td>
660   </tr>
661   <tr>
662     <td><code>action_quietsave=1</code></td>
663     <td> save, and return to view, <code>dontnotify</code> is ON </td>
664     <td>   </td>
665   </tr>
666   <tr>
667     <td><code>action_checkpoint</code></td>
668     <td> save and redirect to the edit script, <code>dontnotify</code> is ON </td>
669     <td>   </td>
670   </tr>
671   <tr>
672     <td><code>action_cancel</code></td>
673     <td> exit without save, return to view </td>
674     <td>   </td>
675   </tr>
676   <tr>
677     <td><code>action_preview</code></td>
678     <td> preview edited text </td>
679     <td>   </td>
680   </tr>
681   <tr>
682     <td><code>action_addform</code></td>
683     <td> Redirect to the "change form" page. </td>
684     <td>   </td>
685   </tr>
686   <tr>
687     <td><code>action_replaceform...</code></td>
688     <td> Redirect to the "change form" page. </td>
689     <td>   </td>
690   </tr>
691   <tr>
692     <td><code>action_delRev</code></td>
693     <td><strong>Administrators only</strong> delete the most recent revision of the topic - all other parameters are ignored. You have to be a member of [[Main/TWikiAdminGroup]] to use this, and not all store implementations will support it. </td>
694     <td>   </td>
695   </tr>
696   <tr>
697     <td><code>action_repRev</code></td>
698     <td><strong>Administrators only</strong> replace the text of the most recent revision of the topic with the text in the <code>text</code> parameter. <code>text</code> must included embedded meta-data tags. All other parameters are ignored. You have to be a member of [[Main/TWikiAdminGroup]] to use this, and not all store implementations will support it. </td>
699     <td>   </td>
700   </tr>
701   <tr>
702     <td><code>onlynewtopic</code></td>
703     <td> If set, error if topic already exists </td>
704     <td>   </td>
705   </tr>
706   <tr>
707     <td><code>onlywikiname</code></td>
708     <td> If set, error if topic name is not a [[Main/WikiWord]]</td>
709     <td>   </td>
710   </tr>
711   <tr>
712     <td><code>dontnotify</code></td>
713     <td> if defined, suppress change notification </td>
714     <td>   </td>
715   </tr>
716   <tr>
717     <td><code>templatetopic</code></td>
718     <td> Name of a topic to use as a template for the text and form </td>
719     <td>   </td>
720   </tr>
721   <tr>
722     <td><code>text</code></td>
723     <td> New text of the topic </td>
724     <td>   </td>
725   </tr>
726   <tr>
727     <td><code>forcenewrevision</code></td>
728     <td> if set, forces a revision even if TWiki thinks one isn't needed </td>
729     <td>   </td>
730   </tr>
731   <tr>
732     <td><code>topicparent</code></td>
733     <td> If 'none' remove any current topic parent. If the name of a topic, set the topic parent to this. </td>
734     <td>   </td>
735   </tr>
736   <tr>
737     <td><code>formtemplate</code></td>
738     <td> if defined, use the named template for the form </td>
739     <td>   </td>
740   </tr>
741   <tr>
742     <td><code>editaction</code></td>
743     <td> When action is <code>checkpoint</code>, <code>add form</code> or <code>replace form...</code>, this is used as the <code>action</code> parameter to the <code>edit</code> script that is redirected to after the save is complete. </td>
744     <td>   </td>
745   </tr>
746   <tr>
747     <td><code>originalrev</code></td>
748     <td> Revision on which the edit started. </td>
749     <td>   </td>
750   </tr>
751 </table>
752
753 Any errors will cause a redirect to an `oops` page.
754
755 The parameters are interpreted in according to the following rules.
756
757 1. The first sequence of ten or more `X` characters in the topic name will be converted to a number such that the resulting topic name is unique in the target web.
758 2. When the action is `save`, `checkpoint`, `quietsave`, or `preview`:
759   1. The new text is taken from the `text` parameter, if it is defined,
760     - otherwise it is taken from the `templatetopic`, if it is defined,
761     - otherwise it is taken from the previous version of the topic, if any,
762   2. The name of the new form is taken from the `formtemplate`, if defined
763     - otherwise it is taken from the `templatetopic`, if defined,
764     - otherwise it is taken from the previous version of the topic, if any,
765     - otherwise no form is attached.
766   3. The value for each field in the form is taken from the query, if it is defined
767     - otherwise it is taken from the `templatetopic`, if defined,
768     - otherwise it is taken from the previous version of the topic, if any,
769     - otherwise it defaults to the empty string.
770
771 Merging is only enabled if the topic text comes from `text` and `originalrev` is &gt; 0 and is not the same as the revision number of the most recent revision. If merging is enabled both the topic and the meta-data are merged.
772
773 Form field values are passed in parameters named 'field' - for example, if I have a field `Status` the parameter name is `Status`.
774
775 ### <a name="=search="></a> `search`
776
777 CGI gateway to the `%SEARCH%` functionality driven by the following CGI parameters:
778
779 <table border="1" cellpadding="0" cellspacing="0">
780   <tr>
781     <th bgcolor="#99CCCC"><strong> Parameter: </strong></th>
782     <th bgcolor="#99CCCC"><strong> Description: </strong></th>
783     <th bgcolor="#99CCCC"><strong> Default: </strong></th>
784   </tr>
785   <tr>
786     <td><code>"text"</code></td>
787     <td> Search term. Is a keyword search, literal search or regular expression search, depending on the <code>type</code> parameter. [[Main/SearchHelp]] has more </td>
788     <td> required </td>
789   </tr>
790   <tr>
791     <td><code>search="text"</code></td>
792     <td> (Alternative to above) </td>
793     <td> N/A </td>
794   </tr>
795   <tr>
796     <td><code>web="Name"</code><br /><code>web="Main, Know"</code><br /><code>web="all"</code></td>
797     <td> Comma-separated list of webs to search. See [[Main/TWikiVariables#VarSEARCH]] for more details. </td>
798     <td> Current web </td>
799   </tr>
800   <tr>
801     <td><code>topic="WebPreferences"</code><br /><code>topic="*Bug"</code></td>
802     <td> Limit search to topics: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. </td>
803     <td> All topics in a web </td>
804   </tr>
805   <tr>
806     <td><code>excludetopic="Web*"</code><br /><code>excludetopic="WebHome, WebChanges"</code></td>
807     <td> Exclude topics from search: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. </td>
808     <td> None </td>
809   </tr>
810   <tr>
811     <td><code>type="keyword"</code><br /><code>type="literal"</code><br /><code>type="regex"</code></td>
812     <td> Do a keyword search like <code>soap "web service" -shampoo</code>; a literal search like <code>web service</code>; or [[Main/RegularExpression]] search like <code>soap;web service;!shampoo</code></td>
813     <td><code>%SEARCHVAR- DEFAULTTYPE%</code> [[Main/TWikiPreferences]] setting (%SEARCHVARDEFAULTTYPE%) </td>
814   </tr>
815   <tr>
816     <td><code>scope="topic"</code><br /><code>scope="text"</code><br /><code>scope="all"</code></td>
817     <td> Search topic name (title); the text (body) of topic; or all (both) </td>
818     <td><code>"text"</code></td>
819   </tr>
820   <tr>
821     <td><code>order="topic"</code><br /><code>order="created"</code><br /><code>order="modified"</code><br /><code>order="editby"</code><br /><code>order=<br /> "formfield(name)"</code></td>
822     <td> Sort the results of search by the topic names, topic creation time, last modified time, last editor, or named field of [[Main/TWikiForms]]. The sorting is done web by web; in case you want to sort across webs, create a [[Main/FormattedSearch]] table and sort it with [[Main/TablePlugin]]'s initsort </td>
823     <td> Sort by topic name </td>
824   </tr>
825   <tr>
826     <td><code>limit="all"</code><br /><code>limit="16"</code></td>
827     <td> Limit the number of results returned. This is done after sorting if <code>order</code> is specified </td>
828     <td> All results </td>
829   </tr>
830   <tr>
831     <td><code>date="..."</code></td>
832     <td> limits the results to those pages with latest edit time in the given [[Main/TimeInterval]]. </td>
833     <td> All results </td>
834   </tr>
835   <tr>
836     <td><code>reverse="on"</code></td>
837     <td> Reverse the direction of the search </td>
838     <td> Ascending search </td>
839   </tr>
840   <tr>
841     <td><code>casesensitive="on"</code></td>
842     <td> Case sensitive search </td>
843     <td> Ignore case </td>
844   </tr>
845   <tr>
846     <td><code>bookview="on"</code></td>
847     <td>[[Main/BookView]] search, e.g. show complete topic text </td>
848     <td> Show topic summary </td>
849   </tr>
850   <tr>
851     <td><code>nonoise="on"</code></td>
852     <td> Shorthand for <code>nosummary="on" nosearch="on" nototal="on" zeroresults="off" noheader="on" noempty="on"</code></td>
853     <td> Off </td>
854   </tr>
855   <tr>
856     <td><code>nosummary="on"</code></td>
857     <td> Show topic title only </td>
858     <td> Show topic summary </td>
859   </tr>
860   <tr>
861     <td><code>nosearch="on"</code></td>
862     <td> Suppress search string </td>
863     <td> Show search string </td>
864   </tr>
865   <tr>
866     <td><code>noheader="on"</code></td>
867     <td> Suppress search header <br /><span style="background: #FFB0B0"> <strong>Topics: Changed: By:</strong> </span></td>
868     <td> Show search header </td>
869   </tr>
870   <tr>
871     <td><code>nototal="on"</code></td>
872     <td> Do not show number of topics found </td>
873     <td> Show number </td>
874   </tr>
875   <tr>
876     <td><code>zeroresults="off"</code></td>
877     <td> Suppress all output if there are no hits </td>
878     <td><code>zeroresults="on"</code>, displays: "Number of topics: 0" </td>
879   </tr>
880   <tr>
881     <td><code>noempty="on"</code></td>
882     <td> Suppress results for webs that have no hits. </td>
883     <td> Show webs with no hits </td>
884   </tr>
885   <tr>
886     <td><code>header="..."</code><br /><code>format="..."</code></td>
887     <td> Custom format results: see <strong>[[Main/FormattedSearch]]</strong> for usage, variables &amp; examples </td>
888     <td> Results in table </td>
889   </tr>
890   <tr>
891     <td><code>expandvariables="on"</code></td>
892     <td> Expand variables before applying a [[Main/FormattedSearch]] on a search hit. Useful to show the expanded text, e.g. to show the result of a [[Main/SpreadSheetPlugin]] <code>%CALC{}%</code> instead of the formula </td>
893     <td> Raw text </td>
894   </tr>
895   <tr>
896     <td><code>multiple="on"</code></td>
897     <td> Multiple hits per topic. Each hit can be [[Main/FormattedSearch]]. The last token is used in case of a regular expression ";" <em>and</em> search </td>
898     <td> Only one hit per topic </td>
899   </tr>
900   <tr>
901     <td><code>nofinalnewline="on"</code></td>
902     <td> If <code>on</code>, the search variable does not end in a line by itself. Any text continuing immediately after the search tag on the same line will be rendered as part of the table generated by the search, if appropriate. </td>
903     <td><code>off</code></td>
904   </tr>
905   <tr>
906     <td><code>separator=", "</code></td>
907     <td> Line separator between hits </td>
908     <td> Newline <code>"$n"</code></td>
909   </tr>
910 </table>
911
912 ### <a name="=statistics="></a> `statistics`
913
914 Refresh the [[WebStatistics]] topics in range of webs.
915
916 <table border="1" cellpadding="0" cellspacing="0">
917   <tr>
918     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
919     <th bgcolor="#99CCCC"><strong> Description </strong></th>
920     <th bgcolor="#99CCCC"><strong> Default </strong></th>
921   </tr>
922   <tr>
923     <td><code>webs</code></td>
924     <td><strong>list</strong> of webs to run stats on </td>
925     <td> none </td>
926   </tr>
927 </table>
928
929 ### <a name="=twiki="></a> `twiki`
930
931 Single-script interface to the functionality of all the other scripts. Experimental, not for production use. Read the code if you want to know more.
932
933 ### <a name="=upload="></a> `upload`
934
935 Uploads an attachment to a topic. The HTTP request is expected to be in `multipart/form-data` format.
936
937 <table border="1" cellpadding="0" cellspacing="0">
938   <tr>
939     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
940     <th bgcolor="#99CCCC"><strong> Description </strong></th>
941     <th bgcolor="#99CCCC"><strong> Default </strong></th>
942   </tr>
943   <tr>
944     <td><code>hidefile</code></td>
945     <td> if defined, will not show file in attachment table </td>
946     <td>   </td>
947   </tr>
948   <tr>
949     <td><code>filepath</code></td>
950     <td> local (client) path name of the file being uploaded. This is used to look up the data for the file in the HTTP query. </td>
951     <td>   </td>
952   </tr>
953   <tr>
954     <td><code>filename</code></td>
955     <td> deprecated, do not use </td>
956     <td>   </td>
957   </tr>
958   <tr>
959     <td><code>filecomment</code></td>
960     <td> Comment to associate with file in attachment table </td>
961     <td>   </td>
962   </tr>
963   <tr>
964     <td><code>createlink</code></td>
965     <td> if defined, will create a link to file at end of topic </td>
966     <td>   </td>
967   </tr>
968   <tr>
969     <td><code>changeproperties</code></td>
970     <td> if defined, this is a property change operation <strong>only</strong> - no file will be uploaded. </td>
971     <td> null </td>
972   </tr>
973 </table>
974
975 You can use a tool like `curl` to upload files from the command line using this script.
976
977 ### <a name="=view="></a> `view`
978
979 Used for viewing topics.
980
981 <table border="1" cellpadding="0" cellspacing="0">
982   <tr>
983     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
984     <th bgcolor="#99CCCC"><strong> Description </strong></th>
985     <th bgcolor="#99CCCC"><strong> Default </strong></th>
986   </tr>
987   <tr>
988     <td><code>raw=on</code></td>
989     <td> Shows the text of the topic in a scrollable textarea </td>
990     <td>   </td>
991   </tr>
992   <tr>
993     <td><code>raw=debug</code></td>
994     <td> As <code>raw=on</code>, but also shows the metadata (forms etc) associated with the topic. </td>
995     <td>   </td>
996   </tr>
997   <tr>
998     <td><code>raw=text</code></td>
999     <td> Shows only the source of the topic, as plain text (Content-type: text/plain). Only shows the body text, <strong>not</strong> the form or other meta-data. </td>
1000   </tr>
1001   <tr>
1002     <td><code>raw=all</code></td>
1003     <td> Shows only the source of the topic, as plain text (Content-type: text/plain), <strong>with embedded meta-data</strong>. This may be useful if you want to extract the source of a topic to a local file on disc. </td>
1004     <td>   </td>
1005   </tr>
1006   <tr>
1007     <td><code>contenttype</code></td>
1008     <td> Allows you to specify a different <strong>Content-Type:</strong> (e.g. <code>contenttype=text/plain</code>) </td>
1009     <td>   </td>
1010   </tr>
1011   <tr>
1012     <td><code>rev</code></td>
1013     <td> Revision to view (e.g. <code>rev=45</code>) </td>
1014     <td>   </td>
1015   </tr>
1016   <tr>
1017     <td><code>template</code></td>
1018     <td> Allows you to specify a different skin template, overriding the 'view' template the view script would normally use. The default template is <code>view</code>. For example, you could specify [[%WEB%/%TOPIC%?template=edit]]. This is mainly useful when you have specialised templates for a TWiki Application. </td>
1019     <td>   </td>
1020   </tr>
1021 </table>
1022
1023 %X% For historical reasons, the view script has a special interpretation of the `text` skin. In earlier TWiki versions the `skin=text` parameter was used like this: `http://.../view/MyWeb/MyTopic?skin=text&contenttype=text/plain&raw=on` which shows the topic as plain text; useful for those who want to download plain text for the topic. Using `skin=text` this way is **DEPRECATED**, use `raw=text` instead.
1024
1025 ### <a name="=viewfile="></a> `viewfile`
1026
1027 Used for viewing attachments. Normally, a site will publish the attachments (`pub`) directory using a URL. However if it contains sensitive information, you will want to protect attachments using [[TWikiAccessControls]]. In this case, you can use the `viewfile` script to give access to attachments while still checking access controls.
1028
1029 <table border="1" cellpadding="0" cellspacing="0">
1030   <tr>
1031     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
1032     <th bgcolor="#99CCCC"><strong> Description </strong></th>
1033     <th bgcolor="#99CCCC"><strong> Default </strong></th>
1034   </tr>
1035   <tr>
1036     <td><code>filename</code></td>
1037     <td> name of attachment </td>
1038     <td>   </td>
1039   </tr>
1040   <tr>
1041     <td><code>rev</code></td>
1042     <td> Revision to view </td>
1043     <td>   </td>
1044   </tr>
1045 </table>
1046
1047 ## <a name="Command Line Scripts"></a> Command Line Scripts
1048
1049 Details on command line scripts located in the `twiki/tools` directory.
1050
1051 ### <a name="=geturl.pl="></a> `geturl.pl`
1052
1053 This is a very simple script to get the content of a web site. It is marked as _deprecated_ and might be removed (or enhanced) in a future TWiki release. Its functions are covered by the standard `wget` and `curl` commands.
1054
1055 - Usage: `geturl <host> <path> [<port> [<header>]]`
1056 - Example: `geturl some.domain /some/dir/file.html 80`
1057 - Will get: `http://some.domain:80/some/dir/file.html`
1058
1059 ### <a name="=rewriteshebang.pl="></a> `rewriteshebang.pl`
1060
1061 Simple script to rewrite the `#!/usr/bin/perl` shebang lines specific to your local Perl installation. It will rewrite the first line of all your TWiki cgi scripts so they use a different shebang line. Use it if your perl is in a non-standard location, or you want to use a different interpreter (such as 'speedy').
1062
1063 ### <a name="=tick_twiki.pl="></a> `tick_twiki.pl`
1064
1065 This script executes a number of non-essential regular administration tasks that will help keep your TWiki healthy and happy, such as removing expired sessions and lease files.
1066
1067 It is intended to be run as a cron job or a scheduled task once a week. Example crontab entry:%BR% `0 0 * * 0 cd /usr/twiki/bin && perl ../tools/tick_twiki.pl`
1068
1069 **_Note:_** The script has to be run by a user who can write files created by the webserver user.
1070
1071 **_Related Topics:_** [[AdminDocumentationCategory]], [[DeveloperDocumentationCategory]]