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 have the `twiki/bin` directory on the perl path 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 on the command line 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, even if that is the empty string.
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`. See [configure](http://www.dementia.org/twiki/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   <tr>
223     <td><code>redirectto</code></td>
224     <td> If the user continues from edit to save, and if the save process is successful, save will redirect to this topic or URL. The parameter value can be a <code>TopicName</code>, a <code>Web.TopicName</code>, or a URL.%BR% <strong><em>Note:</em></strong> Redirect to a URL only works if it is enabled in <code>configure</code> (Miscellaneous <code>{AllowRedirectUrl}</code>). </td>
225     <td>   </td>
226   </tr>
227 </table>
228
229 Form field values are passed in parameters named 'field' - for example, if I have a field `Status` the parameter name is `Status`.
230
231 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.
232
233 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.
234
235 ### <a name="=login="></a> `login`
236
237 Used for logging in when TWiki login is being used (e.g TemplateLoginManager).
238
239 <table border="1" cellpadding="0" cellspacing="0">
240   <tr>
241     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
242     <th bgcolor="#99CCCC"><strong> Description </strong></th>
243     <th bgcolor="#99CCCC"><strong> Default </strong></th>
244   </tr>
245   <tr>
246     <td><code>origurl</code></td>
247     <td> URL that was being accessed when an access violation occurred. the login process will redirect to this URL if it is successful </td>
248     <td> none </td>
249   </tr>
250   <tr>
251     <td><code>username</code></td>
252     <td> username of user logging in </td>
253     <td> none </td>
254   </tr>
255   <tr>
256     <td><code>password</code></td>
257     <td> password of user logging in </td>
258     <td> none </td>
259   </tr>
260 </table>
261
262 ### <a name="=logon="></a> `logon`
263
264 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.
265
266 ### <a name="=manage="></a> `manage`
267
268 Performs a range of management functions.
269
270 <table border="1" cellpadding="0" cellspacing="0">
271   <tr>
272     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
273     <th bgcolor="#99CCCC"><strong> Description </strong></th>
274     <th bgcolor="#99CCCC"><strong> Default </strong></th>
275   </tr>
276   <tr>
277     <td><code>action</code></td>
278     <td> One of <code>createweb</code>, <code>deleteUserAccount</code>, <code>editSettings</code> or <code>saveSettings</code></td>
279     <td> none </td>
280   </tr>
281 </table>
282
283 #### <a name="=action=createweb="></a> `action=createweb`
284
285 <table border="1" cellpadding="0" cellspacing="0">
286   <tr>
287     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
288     <th bgcolor="#99CCCC"><strong> Description </strong></th>
289     <th bgcolor="#99CCCC"><strong> Default </strong></th>
290   </tr>
291   <tr>
292     <td><code>newweb</code></td>
293     <td> Name of the new web </td>
294     <td> '' </td>
295   </tr>
296   <tr>
297     <td><code>baseweb</code></td>
298     <td> Name of the web to copy to create the new web </td>
299     <td> '' </td>
300   </tr>
301   <tr>
302     <td><code>webbgcolor</code></td>
303     <td> value for WEBBGCOLOR </td>
304     <td> '' </td>
305   </tr>
306   <tr>
307     <td><code>sitemapwhat</code></td>
308     <td> Value for SITEMAPWHAT </td>
309     <td> '' </td>
310   </tr>
311   <tr>
312     <td><code>sitemapuseto</code></td>
313     <td> Value for SITEMAPUSETO </td>
314     <td> '' </td>
315   </tr>
316   <tr>
317     <td><code>nosearchall</code></td>
318     <td> Value for NOSEARCHALL </td>
319     <td> '' </td>
320   </tr>
321 </table>
322
323 #### <a name="=action=delete_UserAccount="></a> `action=deleteUserAccount`
324
325 Unregisters (removes) the currently logged-in user.
326
327 <table border="1" cellpadding="0" cellspacing="0">
328   <tr>
329     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
330     <th bgcolor="#99CCCC"><strong> Description </strong></th>
331     <th bgcolor="#99CCCC"><strong> Default </strong></th>
332   </tr>
333   <tr>
334     <td><code>password</code></td>
335     <td> Users' password </td>
336     <td> none </td>
337   </tr>
338 </table>
339
340 #### <a name="=action=editSettings="></a> `action=editSettings`
341
342 No parameters
343
344 #### <a name="=action=bulkRegister="></a> `action=bulkRegister`
345
346 See [[BulkRegistration]].
347
348 <table border="1" cellpadding="0" cellspacing="0">
349   <tr>
350     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
351     <th bgcolor="#99CCCC"><strong> Description </strong></th>
352     <th bgcolor="#99CCCC"><strong> Default </strong></th>
353   </tr>
354   <tr>
355     <td><code>OverwriteHomeTopics</code></td>
356     <td> Whether to overwrite existing home topics or not </td>
357     <td> false </td>
358   </tr>
359   <tr>
360     <td><code>EmailUsersWithDetails</code></td>
361     <td> Whether to mail registered users or not </td>
362     <td> false </td>
363   </tr>
364   <tr>
365     <td><code>LogTopic</code></td>
366     <td> Topic to save the log in </td>
367     <td> Same as topic name, with 'Result' appended. </td>
368   </tr>
369 </table>
370
371 #### <a name="=action=saveSettings="></a> `action=saveSettings`
372
373 <table border="1" cellpadding="0" cellspacing="0">
374   <tr>
375     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
376     <th bgcolor="#99CCCC"><strong> Description </strong></th>
377     <th bgcolor="#99CCCC"><strong> Default </strong></th>
378   </tr>
379   <tr>
380     <td><code>text</code></td>
381     <td> Text of the topic </td>
382     <td> '' </td>
383   </tr>
384   <tr>
385     <td><code>originalrev</code></td>
386     <td> Revision that the edit started on </td>
387     <td> Most recent revision </td>
388   </tr>
389 </table>
390
391 All other parameters may be interpreted as form fields, depending on the current form definition in the topic.
392
393 ### <a name="=oops="></a> `oops`
394
395 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).
396
397 `oops` templates are used with the `oops` script to generate system messages. This is done to make internationalisation or other local customisations simple.
398
399 The `oops` script supports the following parameters:
400
401 <table border="1" cellpadding="0" cellspacing="0">
402   <tr>
403     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
404     <th bgcolor="#99CCCC"><strong> Description </strong></th>
405     <th bgcolor="#99CCCC"><strong> Default </strong></th>
406   </tr>
407   <tr>
408     <td><code>template</code></td>
409     <td> Name of the template file to display </td>
410     <td>   </td>
411   </tr>
412   <tr>
413     <td><code>def</code></td>
414     <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>
415     <td>   </td>
416   </tr>
417   <tr>
418     <td><code>paramN</code></td>
419     <td> Where N is an integer from 1 upwards. These values will be substituted into <code>template</code> for <code>%PARAM1%</code> etc. </td>
420     <td>   </td>
421   </tr>
422 </table>
423
424 ### <a name="=passwd="></a> `passwd`
425
426 <table border="1" cellpadding="0" cellspacing="0">
427   <tr>
428     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
429     <th bgcolor="#99CCCC"><strong> Description </strong></th>
430     <th bgcolor="#99CCCC"><strong> Default </strong></th>
431   </tr>
432   <tr>
433     <td><code>action</code></td>
434     <td> one of <code>changePassword</code> or <code>resetPassword</code></td>
435     <td> none </td>
436   </tr>
437 </table>
438
439 Other parameters as described under `manage`, `action=changePassword`.
440
441 #### <a name="=action=changePassword="></a> `action=changePassword`
442
443 <table border="1" cellpadding="0" cellspacing="0">
444   <tr>
445     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
446     <th bgcolor="#99CCCC"><strong> Description </strong></th>
447     <th bgcolor="#99CCCC"><strong> Default </strong></th>
448   </tr>
449   <tr>
450     <td><code>username</code></td>
451     <td> Username </td>
452     <td>   </td>
453   </tr>
454   <tr>
455     <td><code>oldpassword</code></td>
456     <td> Existing password (plain text) </td>
457     <td>   </td>
458   </tr>
459   <tr>
460     <td><code>password</code></td>
461     <td> New password (plain text) </td>
462     <td>   </td>
463   </tr>
464   <tr>
465     <td><code>passwordA</code></td>
466     <td> New password confirmation (plain text) </td>
467     <td>   </td>
468   </tr>
469   <tr>
470     <td><code>TopicName</code></td>
471     <td> ? </td>
472     <td>   </td>
473   </tr>
474 </table>
475
476 ### <a name="=preview="></a> `preview`
477
478 This script is _deprecated_. Its functions are covered by the `save` script.
479
480 ### <a name="=rdiff="></a> `rdiff`
481
482 Renders the differences between version of a TWiki topic
483
484 <table border="1" cellpadding="0" cellspacing="0">
485   <tr>
486     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
487     <th bgcolor="#99CCCC"><strong> Description </strong></th>
488     <th bgcolor="#99CCCC"><strong> Default </strong></th>
489   </tr>
490   <tr>
491     <td> rev1 </td>
492     <td> the higher revision </td>
493     <td>   </td>
494   </tr>
495   <tr>
496     <td> rev2 </td>
497     <td> the lower revision </td>
498     <td>   </td>
499   </tr>
500   <tr>
501     <td> render </td>
502     <td> the rendering style {sequential, sidebyside, raw, debug} </td>
503     <td> DIFFRENDERSTYLE, <code>sequential</code></td>
504   </tr>
505   <tr>
506     <td> type </td>
507     <td> {history, diff, last} history diff, version to version, last version to previous </td>
508     <td><code>diff</code></td>
509   </tr>
510   <tr>
511     <td> context </td>
512     <td> number of lines of context </td>
513     <td>   </td>
514   </tr>
515 </table>
516
517 TODO:
518
519 - add a \{word\} render style
520
521 ### <a name="=register="></a> `register`
522
523 <table border="1" cellpadding="0" cellspacing="0">
524   <tr>
525     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
526     <th bgcolor="#99CCCC"><strong> Description </strong></th>
527     <th bgcolor="#99CCCC"><strong> Default </strong></th>
528   </tr>
529   <tr>
530     <td><code>action</code></td>
531     <td><code>register</code> or <code>verify</code> or <code>resetPassword</code> or <code>approve</code></td>
532     <td>   </td>
533   </tr>
534 </table>
535
536 ### <a name="=rename="></a> `rename`
537
538 Used for renaming topics.
539
540 <table border="1" cellpadding="0" cellspacing="0">
541   <tr>
542     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
543     <th bgcolor="#99CCCC"><strong> Description </strong></th>
544     <th bgcolor="#99CCCC"><strong> Default </strong></th>
545   </tr>
546   <tr>
547     <td><code>skin</code></td>
548     <td> skin(s) to use </td>
549     <td>   </td>
550   </tr>
551   <tr>
552     <td><code>newweb</code></td>
553     <td> new web name </td>
554     <td>   </td>
555   </tr>
556   <tr>
557     <td><code>newtopic</code></td>
558     <td> new topic name </td>
559     <td>   </td>
560   </tr>
561   <tr>
562     <td><code>breaklock</code></td>
563     <td>   </td>
564     <td>   </td>
565   </tr>
566   <tr>
567     <td><code>attachment</code></td>
568     <td>   </td>
569     <td>   </td>
570   </tr>
571   <tr>
572     <td><code>confirm</code></td>
573     <td> if defined, requires a second level of confirmation </td>
574     <td>   </td>
575   </tr>
576   <tr>
577     <td><code>currentwebonly</code></td>
578     <td> if defined, searches current web only for links to this topic </td>
579     <td>   </td>
580   </tr>
581   <tr>
582     <td><code>nonwikiword</code></td>
583     <td> if defined, a non-wikiword is acceptable for the new topic name </td>
584     <td>   </td>
585   </tr>
586 </table>
587
588 ### <a name="=resetpasswd="></a> `resetpasswd`
589
590 Reset the password for a single or multiple users
591
592 <table border="1" cellpadding="0" cellspacing="0">
593   <tr>
594     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
595     <th bgcolor="#99CCCC"><strong> Description </strong></th>
596     <th bgcolor="#99CCCC"><strong> Default </strong></th>
597   </tr>
598   <tr>
599     <td><code>LoginName</code></td>
600     <td><strong>list</strong> of usernames to reset </td>
601     <td> none - error if not set </td>
602   </tr>
603   <tr>
604     <td><code>Introduction</code></td>
605     <td> message to be sent alongside the reset, most often used to announce to the user that they have been given an account. </td>
606     <td> '' </td>
607   </tr>
608 </table>
609
610 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]].
611
612 [[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.
613
614 ### <a name="=rest="></a> `rest`
615
616 This REST ([Representational State Transfer](http://en.wikipedia.org/wiki/REST)) script can be invoked via http in the same way as the other TWiki scripts (see **Invocation Examples**, below) to execute a function that is associated to a "subject" and a "verb" (see below). These functions are usually registered by plugins using the `TWiki::Func::registerRESTHandler` method. The `rest` script will print the result directly to the browser unless the `endPoint` parameter is specified, in which case it will output a redirect to the given topic.
617
618 The `rest` script supports the following parameters:
619
620 <table border="1" cellpadding="0" cellspacing="0">
621   <tr>
622     <td><code>username</code></td>
623     <td> If <code>TemplateLogin</code>, or a similar login manager not embedded in the web server, is used, then you need to pass a username and password to the server. The <code>username</code> and <code>password</code> parameters are used for this purpose. </td>
624   </tr>
625   <tr>
626     <td><code>password</code></td>
627     <td> See <code>username</code></td>
628   </tr>
629   <tr>
630     <td><code>topic</code></td>
631     <td> If defined as the full name (including web) of a topic, then when the script starts up plugins will be passed this as the "current" topic. If not defined, then %USERWEB%.WebHome will be passed to plugins. </td>
632   </tr>
633   <tr>
634     <td><code>endPoint</code></td>
635     <td> Where to redirect the response once the request is served, in the form "Web.Topic" </td>
636   </tr>
637 </table>
638
639 The function is free to use any other query parameters for its own purposes.
640
641 %X% The `rest` script should **always** require authentication in any TWiki that has logins. Otherwise there is a risk of opening up major security holes. So make sure you add it to the list of authenticated scripts if you are using `ApacheLogin`.
642
643 #### <a name="Invocation Examples"></a> Invocation Examples
644
645 The `rest` script assumes that it will be called with URL in the form:
646
647 `http://my.host/bin/rest/<subject>/<verb>`
648
649 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 `TWiki::Func::registerRESTHandler` method. The `<subject>` and `<verb>` are then used to lookup and call the registered function.
650
651 `<subject>` and `<verb>` are checked for illegal characters exactly in the same way as the web and topic names.
652
653 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]]).
654
655 [Call the Plugin](http://www.dementia.org/twiki/rest/EmptyPlugin/example?debugenableplugin=EmptyPlugin)
656
657 Note that for Plugins to register REST handlers, they must be enabled in `configure`.
658
659 ### <a name="=save="></a> `save`
660
661 The `save` script performs a range of save-related functions, as selected by the `action` parameter.
662
663 <table border="1" cellpadding="0" cellspacing="0">
664   <tr>
665     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
666     <th bgcolor="#99CCCC"><strong> Description </strong></th>
667     <th bgcolor="#99CCCC"><strong> Default </strong></th>
668   </tr>
669   <tr>
670     <td><code>action_save=1</code></td>
671     <td><strong>default</strong>; save, return to view, dontnotify is <code>off</code></td>
672     <td>   </td>
673   </tr>
674   <tr>
675     <td><code>action_quietsave=1</code></td>
676     <td> save, and return to view, <code>dontnotify</code> is <code>on</code></td>
677     <td>   </td>
678   </tr>
679   <tr>
680     <td><code>action_checkpoint</code></td>
681     <td> save and redirect to the edit script, <code>dontnotify</code> is <code>on</code></td>
682     <td>   </td>
683   </tr>
684   <tr>
685     <td><code>action_cancel</code></td>
686     <td> exit without save, return to view </td>
687     <td>   </td>
688   </tr>
689   <tr>
690     <td><code>action_preview</code></td>
691     <td> preview edited text </td>
692     <td>   </td>
693   </tr>
694   <tr>
695     <td><code>action_addform</code></td>
696     <td> Redirect to the "change form" page. </td>
697     <td>   </td>
698   </tr>
699   <tr>
700     <td><code>action_replaceform...</code></td>
701     <td> Redirect to the "change form" page. </td>
702     <td>   </td>
703   </tr>
704   <tr>
705     <td><code>action_delRev</code></td>
706     <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>
707     <td>   </td>
708   </tr>
709   <tr>
710     <td><code>action_repRev</code></td>
711     <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>
712     <td>   </td>
713   </tr>
714   <tr>
715     <td><code>onlynewtopic</code></td>
716     <td> If set, error if topic already exists </td>
717     <td>   </td>
718   </tr>
719   <tr>
720     <td><code>onlywikiname</code></td>
721     <td> If set, error if topic name is not a [[Main/WikiWord]]</td>
722     <td>   </td>
723   </tr>
724   <tr>
725     <td><code>dontnotify</code></td>
726     <td> if defined, suppress change notification </td>
727     <td>   </td>
728   </tr>
729   <tr>
730     <td><code>templatetopic</code></td>
731     <td> Name of a topic to use as a template for the text and form </td>
732     <td>   </td>
733   </tr>
734   <tr>
735     <td><code>text</code></td>
736     <td> New text of the topic </td>
737     <td>   </td>
738   </tr>
739   <tr>
740     <td><code>forcenewrevision</code></td>
741     <td> if set, forces a revision even if TWiki thinks one isn't needed </td>
742     <td>   </td>
743   </tr>
744   <tr>
745     <td><code>topicparent</code></td>
746     <td> If 'none' remove any current topic parent. If the name of a topic, set the topic parent to this. </td>
747     <td>   </td>
748   </tr>
749   <tr>
750     <td><code>formtemplate</code></td>
751     <td> if defined, use the named template for the form </td>
752     <td>   </td>
753   </tr>
754   <tr>
755     <td><code>editaction</code></td>
756     <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>
757     <td>   </td>
758   </tr>
759   <tr>
760     <td><code>originalrev</code></td>
761     <td> Revision on which the edit started. </td>
762     <td>   </td>
763   </tr>
764   <tr>
765     <td><code>edit</code></td>
766     <td> The script to use to edit the topic when action is <code>checkpoint</code></td>
767     <td><code>edit</code></td>
768   </tr>
769   <tr>
770     <td><code>editparams</code></td>
771     <td> The parameter string to use to edit the topic </td>
772     <td>   </td>
773   </tr>
774   <tr>
775     <td><code>redirectto</code></td>
776     <td> The save process will redirect to this topic or URL if it is successful. (Typically this would be the URL that was being viewed when edit was invoked). The parameter value can be a <code>TopicName</code>, a <code>Web.TopicName</code>, or a URL.%BR% <strong><em>Note:</em></strong> Redirect to a URL only works if it is enabled in <code>configure</code> (Miscellaneous <code>{AllowRedirectUrl}</code>). </td>
777     <td> view topic being edited </td>
778   </tr>
779 </table>
780
781 Any errors will cause a redirect to an `oops` page.
782
783 The parameters are interpreted in according to the following rules.
784
785 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.
786 2. When the action is `save`, `checkpoint`, `quietsave`, or `preview`:
787   1. The new text is taken from the `text` parameter, if it is defined,
788     - otherwise it is taken from the `templatetopic`, if it is defined,
789     - otherwise it is taken from the previous version of the topic, if any,
790   2. The name of the new form is taken from the `formtemplate`, if defined
791     - otherwise it is taken from the `templatetopic`, if defined,
792     - otherwise it is taken from the previous version of the topic, if any,
793     - otherwise no form is attached.
794   3. The value for each field in the form is taken from the query, if it is defined
795     - otherwise it is taken from the `templatetopic`, if defined,
796     - otherwise it is taken from the previous version of the topic, if any,
797     - otherwise it defaults to the empty string.
798
799 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.
800
801 Form field values are passed in parameters named 'field' - for example, if I have a field `Status` the parameter name is `Status`.
802
803 ### <a name="=search="></a> `search`
804
805 CGI gateway to the `%SEARCH%` functionality driven by the following CGI parameters:
806
807 <table border="1" cellpadding="0" cellspacing="0">
808   <tr>
809     <th bgcolor="#99CCCC"><strong> Parameter: </strong></th>
810     <th bgcolor="#99CCCC"><strong> Description: </strong></th>
811     <th bgcolor="#99CCCC"><strong> Default: </strong></th>
812   </tr>
813   <tr>
814     <td><code>"text"</code></td>
815     <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>
816     <td> required </td>
817   </tr>
818   <tr>
819     <td><code>search="text"</code></td>
820     <td> (Alternative to above) </td>
821     <td> N/A </td>
822   </tr>
823   <tr>
824     <td><code>web="Name"</code><br /><code>web="Main, Know"</code><br /><code>web="all"</code></td>
825     <td> Comma-separated list of webs to search. See [[Main/TWikiVariables#VarSEARCH]] for more details. </td>
826     <td> Current web </td>
827   </tr>
828   <tr>
829     <td><code>topic="WebPreferences"</code><br /><code>topic="*Bug"</code></td>
830     <td> Limit search to topics: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. </td>
831     <td> All topics in a web </td>
832   </tr>
833   <tr>
834     <td><code>excludetopic="Web*"</code><br /><code>excludetopic="WebHome, WebChanges"</code></td>
835     <td> Exclude topics from search: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. </td>
836     <td> None </td>
837   </tr>
838   <tr>
839     <td><code>type="keyword"</code><br /><code>type="literal"</code><br /><code>type="regex"</code></td>
840     <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>
841     <td><code>%SEARCHVAR- DEFAULTTYPE%</code> [[Main/TWikiPreferences]] setting (%SEARCHVARDEFAULTTYPE%) </td>
842   </tr>
843   <tr>
844     <td><code>scope="topic"</code><br /><code>scope="text"</code><br /><code>scope="all"</code></td>
845     <td> Search topic name (title); the text (body) of topic; or all (both) </td>
846     <td><code>"text"</code></td>
847   </tr>
848   <tr>
849     <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>
850     <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>
851     <td> Sort by topic name </td>
852   </tr>
853   <tr>
854     <td><code>limit="all"</code><br /><code>limit="16"</code></td>
855     <td> Limit the number of results returned. This is done after sorting if <code>order</code> is specified </td>
856     <td> All results </td>
857   </tr>
858   <tr>
859     <td><code>date="..."</code></td>
860     <td> limits the results to those pages with latest edit time in the given [[Main/TimeInterval]]. </td>
861     <td> All results </td>
862   </tr>
863   <tr>
864     <td><code>reverse="on"</code></td>
865     <td> Reverse the direction of the search </td>
866     <td> Ascending search </td>
867   </tr>
868   <tr>
869     <td><code>casesensitive="on"</code></td>
870     <td> Case sensitive search </td>
871     <td> Ignore case </td>
872   </tr>
873   <tr>
874     <td><code>bookview="on"</code></td>
875     <td>[[Main/BookView]] search, e.g. show complete topic text </td>
876     <td> Show topic summary </td>
877   </tr>
878   <tr>
879     <td><code>nonoise="on"</code></td>
880     <td> Shorthand for <code>nosummary="on" nosearch="on" nototal="on" zeroresults="off" noheader="on" noempty="on"</code></td>
881     <td> Off </td>
882   </tr>
883   <tr>
884     <td><code>nosummary="on"</code></td>
885     <td> Show topic title only </td>
886     <td> Show topic summary </td>
887   </tr>
888   <tr>
889     <td><code>nosearch="on"</code></td>
890     <td> Suppress search string </td>
891     <td> Show search string </td>
892   </tr>
893   <tr>
894     <td><code>noheader="on"</code></td>
895     <td> Suppress search header <br /><span style="background: #FFB0B0"> <strong>Topics: Changed: By:</strong> </span></td>
896     <td> Show search header </td>
897   </tr>
898   <tr>
899     <td><code>nototal="on"</code></td>
900     <td> Do not show number of topics found </td>
901     <td> Show number </td>
902   </tr>
903   <tr>
904     <td><code>zeroresults="off"</code></td>
905     <td> Suppress all output if there are no hits </td>
906     <td><code>zeroresults="on"</code>, displays: "Number of topics: 0" </td>
907   </tr>
908   <tr>
909     <td><code>noempty="on"</code></td>
910     <td> Suppress results for webs that have no hits. </td>
911     <td> Show webs with no hits </td>
912   </tr>
913   <tr>
914     <td><code>header="..."</code><br /><code>format="..."</code></td>
915     <td> Custom format results: see <strong>[[Main/FormattedSearch]]</strong> for usage, variables &amp; examples </td>
916     <td> Results in table </td>
917   </tr>
918   <tr>
919     <td><code>expandvariables="on"</code></td>
920     <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>
921     <td> Raw text </td>
922   </tr>
923   <tr>
924     <td><code>multiple="on"</code></td>
925     <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>
926     <td> Only one hit per topic </td>
927   </tr>
928   <tr>
929     <td><code>nofinalnewline="on"</code></td>
930     <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>
931     <td><code>off</code></td>
932   </tr>
933   <tr>
934     <td><code>separator=", "</code></td>
935     <td> Line separator between hits </td>
936     <td> Newline <code>"$n"</code></td>
937   </tr>
938 </table>
939
940 ### <a name="=statistics="></a> `statistics`
941
942 Refresh the [[WebStatistics]] topics in range of webs.
943
944 <table border="1" cellpadding="0" cellspacing="0">
945   <tr>
946     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
947     <th bgcolor="#99CCCC"><strong> Description </strong></th>
948     <th bgcolor="#99CCCC"><strong> Default </strong></th>
949   </tr>
950   <tr>
951     <td><code>webs</code></td>
952     <td> comma-separated list of webs to run stats on </td>
953     <td> all accessible webs </td>
954   </tr>
955   <tr>
956     <td><code>logdate</code></td>
957     <td> YYYYMM to generate statistics for </td>
958     <td> current month </td>
959   </tr>
960 </table>
961
962 for example:
963
964 1. from browser <http://www.dementia.org/twiki/statistics> updates _all user webs_
965 2. from browser <http://www.dementia.org/twiki/statistics?webs=TWiki,Main,Sandbox> updates _TWiki,Main,Sandbox_
966 3. from browser <http://www.dementia.org/twiki/statistics/%WEB%> updates %WEB%
967 4. from command line twiki/bin/statistics updates _all user webs_
968 5. from command line twiki/bin/statistics -webs=TWiki,Main,Sandbox updates _TWiki,Main,Sandbox_
969 6. from command line twiki/bin/statistics %WEB%.WebHome updates %WEB%
970
971 see [[TWikiSiteTools#WebStatistics_site_statistics]] for updating statistics using cron.
972
973 ### <a name="=twiki="></a> `twiki`
974
975 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.
976
977 ### <a name="=upload="></a> `upload`
978
979 Uploads an attachment to a topic. The HTTP request is expected to be in `multipart/form-data` format.
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>hidefile</code></td>
989     <td> if defined, will not show file in attachment table </td>
990     <td>   </td>
991   </tr>
992   <tr>
993     <td><code>filepath</code></td>
994     <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>
995     <td>   </td>
996   </tr>
997   <tr>
998     <td><code>filename</code></td>
999     <td> deprecated, do not use </td>
1000     <td>   </td>
1001   </tr>
1002   <tr>
1003     <td><code>filecomment</code></td>
1004     <td> Comment to associate with file in attachment table </td>
1005     <td>   </td>
1006   </tr>
1007   <tr>
1008     <td><code>createlink</code></td>
1009     <td> if defined, will create a link to file at end of topic </td>
1010     <td>   </td>
1011   </tr>
1012   <tr>
1013     <td><code>changeproperties</code></td>
1014     <td> if defined, this is a property change operation <strong>only</strong> - no file will be uploaded. </td>
1015     <td> null </td>
1016   </tr>
1017 </table>
1018
1019 You can use a tool like `curl` to upload files from the command line using this script.
1020
1021 ### <a name="=view="></a> `view`
1022
1023 Used for viewing topics.
1024
1025 <table border="1" cellpadding="0" cellspacing="0">
1026   <tr>
1027     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
1028     <th bgcolor="#99CCCC"><strong> Description </strong></th>
1029     <th bgcolor="#99CCCC"><strong> Default </strong></th>
1030   </tr>
1031   <tr>
1032     <td><code>raw=on</code></td>
1033     <td> Shows the text of the topic in a scrollable textarea </td>
1034     <td>   </td>
1035   </tr>
1036   <tr>
1037     <td><code>raw=debug</code></td>
1038     <td> As <code>raw=on</code>, but also shows the metadata (forms etc) associated with the topic. </td>
1039     <td>   </td>
1040   </tr>
1041   <tr>
1042     <td><code>raw=text</code></td>
1043     <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>
1044   </tr>
1045   <tr>
1046     <td><code>raw=all</code></td>
1047     <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>
1048     <td>   </td>
1049   </tr>
1050   <tr>
1051     <td><code>section</code></td>
1052     <td> Allows to view only a part of the topic delimited by a named section (see [[TWiki/VarSTARTSECTION]]). If the given section is not present, no topic content is displayed. </td>
1053     <td>   </td>
1054   </tr>
1055   <tr>
1056     <td><code>contenttype</code></td>
1057     <td> Allows you to specify a different <strong>Content-Type:</strong> (e.g. <code>contenttype=text/plain</code>) </td>
1058     <td>   </td>
1059   </tr>
1060   <tr>
1061     <td><code>rev</code></td>
1062     <td> Revision to view (e.g. <code>rev=45</code>) </td>
1063     <td>   </td>
1064   </tr>
1065   <tr>
1066     <td><code>template</code></td>
1067     <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>
1068     <td>   </td>
1069   </tr>
1070 </table>
1071
1072 %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.
1073
1074 ### <a name="=viewfile="></a> `viewfile`
1075
1076 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.
1077
1078 <table border="1" cellpadding="0" cellspacing="0">
1079   <tr>
1080     <th bgcolor="#99CCCC"><strong> Parameter </strong></th>
1081     <th bgcolor="#99CCCC"><strong> Description </strong></th>
1082     <th bgcolor="#99CCCC"><strong> Default </strong></th>
1083   </tr>
1084   <tr>
1085     <td><code>filename</code></td>
1086     <td> name of attachment </td>
1087     <td>   </td>
1088   </tr>
1089   <tr>
1090     <td><code>rev</code></td>
1091     <td> Revision to view </td>
1092     <td>   </td>
1093   </tr>
1094 </table>
1095
1096 ## <a name="Command Line Scripts"></a> Command Line Scripts
1097
1098 Details on command line scripts located in the `twiki/tools` directory.
1099
1100 ### <a name="=geturl.pl="></a> `geturl.pl`
1101
1102 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.
1103
1104 - Usage: `geturl.pl <host> <path> [<port> [<header>]]`
1105 - Example: `geturl.pl some.domain /some/dir/file.html 80`
1106 - Will get: `http://some.domain:80/some/dir/file.html`
1107
1108 ### <a name="=rewriteshebang.pl="></a> `rewriteshebang.pl`
1109
1110 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').
1111
1112 ### <a name="=tick_twiki.pl="></a> `tick_twiki.pl`
1113
1114 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.
1115
1116 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`
1117
1118 **_Note:_** The script has to be run by a user who can write files created by the webserver user.
1119
1120 **_Related Topics:_** [[AdminDocumentationCategory]], [[DeveloperDocumentationCategory]]