TWiki CGI and Command Line ScriptsPrograms on the TWiki server performing actions such as rendering, saving and renaming topics. The TWiki scripts are located in thetwiki/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) environment or from the command line. The scripts in the twiki/tools directory can only be called from the command line.
On this page:
CGI Scripts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Details on CGI scripts located in the twiki/bin directory.
General Information | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CGI environment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 ). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Command-line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 .
Parameters are passed on the command line using '-name' - for example,
$ cd /usr/local/twiki/bin $ save -topic MyWeb.MyTopic -user admin -action save -text "New text of the topic"All parameters require a value, even if that is the empty string. Common parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Shows all the changes in the given web.
The changes script can receive one parameter:
%SEARCH% , while this script reads the changes file in each web, making it much faster.
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.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The edit script understands the following parameters, typically supplied by HTML input fields:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Form field values are passed in parameters named 'field' - for example, if I have a field Status the parameter name is Status .
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.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Used for logging in when TWiki login is being used (e.g TemplateLoginManager).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Performs a range of management functions.
manage script can only be called via http POST method for createweb renameweb , and deleteUserAccount .
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Deleted: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No parameters
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
See BulkRegistration.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Change password, email address, or both, of a user.
password, =passwordA and email are optional. If neither or password and passwordA is set, then the user password is left unchanged. If email is unset, their email is left unchanged.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reset the password for a single or multiple users
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unregisters (removes) the currently logged-in user.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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).
oops templates are used with the oops script to generate system messages. This is done to make internationalisation or other local customisations simple.
The oops script supports the following parameters:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This script is deprecated. Its functions are covered by the save script.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Renders the differences between version of a TWiki topic
|
Parameter | Description | Default |
---|---|---|
action |
register or verify or resetPassword or approve |
register
script can only be called via http POST method, not GET. Make sure to specify the "post"
method if you call the register
script via a form action.
rename
Parameter | Description | Default |
---|---|---|
skin |
skin(s) to use | |
newweb |
new web name | |
newtopic |
new topic name | |
breaklock |
||
attachment |
||
confirm |
if defined, requires a second level of confirmation | |
currentwebonly |
if defined, searches current web only for links to this topic | |
nonwikiword |
if defined, a non-wikiword is acceptable for the new topic name | |
redirectto |
If the rename process is successful, rename will redirect to this topic or URL. The parameter value can be a TopicName , a Web.TopicName , or a URL.Note: Redirect to a URL only works if it is enabled in configure (Miscellaneous {AllowRedirectUrl} ). |
rename
script can only be called via http POST method, not GET. Make sure you specify method="post"
if you call the rename
script via a form action.
rest
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.
The rest
script supports the following parameters:
username |
If TemplateLogin , 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 username and password parameters are used for this purpose. |
password |
See username |
topic |
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 Main.WebHome will be passed to plugins. |
endPoint |
Where to redirect the response once the request is served, in the form "Web.Topic" |
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
.
rest
script assumes that it will be called with URL in the form:
http://my.host/bin/rest/<subject>/<verb>
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.
<subject>
and <verb>
are checked for illegal characters exactly in the same way as the web and topic names.
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).
Call the Plugin
Note that for Plugins to register REST handlers, they must be enabled in configure
.
save
save
script performs a range of save-related functions, as selected by the action
parameter.
Parameter | Description | Default |
---|---|---|
action_save=1 |
default; save, return to view, dontnotify is off |
|
action_quietsave=1 |
save, and return to view, dontnotify is on |
|
action_checkpoint |
save and redirect to the edit script, dontnotify is on |
|
action_cancel |
exit without save, return to view | |
action_preview |
preview edited text | |
action_addform |
Redirect to the "change form" page. | |
action_replaceform... |
Redirect to the "change form" page. | |
action_delRev |
Administrators only delete the most recent revision of the topic - all other parameters are ignored. You have to be an administrator to use this, and not all store implementations will support it. | |
action_repRev |
Administrators only replace the text of the most recent revision of the topic with the text in the text parameter. text must included embedded meta-data tags. All other parameters are ignored. You have to be an administrator to use this, and not all store implementations will support it. |
|
onlynewtopic |
If set, error if topic already exists | |
onlywikiname |
If set, error if topic name is not a WikiWord | |
dontnotify |
if defined, suppress change notification | |
templatetopic |
Name of a topic to use as a template for the text and form (new topic only) | |
text |
New text of the topic | |
forcenewrevision |
if set, forces a revision even if TWiki thinks one isn't needed | |
topicparent |
If 'none' remove any current topic parent. If the name of a topic, set the topic parent to this. | |
formtemplate |
if defined, use the named template for the form (will remove the form is set to 'none') | |
editaction |
When action is checkpoint , add form or replace form... , this is used as the action parameter to the edit script that is redirected to after the save is complete. |
|
originalrev |
Revision on which the edit started. | |
edit |
The script to use to edit the topic when action is checkpoint |
edit |
editparams |
The parameter string to use to edit the topic | |
redirectto |
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 TopicName , a Web.TopicName , or a URL.Note: Redirect to a URL only works if it is enabled in configure (Miscellaneous {AllowRedirectUrl} ). |
view topic being edited |
oops
page.
The parameters are interpreted in according to the following rules.
X
characters in the topic name will be converted to a number such that the resulting topic name is unique in the target web.
save
, checkpoint
, quietsave
, or preview
: text
parameter, if it is defined, templatetopic
, if it is defined, (new topic only)
formtemplate
, if defined templatetopic
, if defined, (new topic only)
templatetopic
, if defined, (new topic only)
text
and originalrev
is > 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.
Form field values are passed in parameters named 'field' - for example, if I have a field Status
the parameter name is Status
.
save
script can only be called via http POST method, not GET. Make sure to specify the "post"
method if you call the save
script via a form action. Example:
<form name="new" action="%SCRIPTURLPATH{save}%/Sandbox/" method="post"> ... </form>It is not possible to call
save
from an <a href="">
link.
search
%SEARCH%
functionality driven by the following CGI parameters:
Parameter: | Description: | Default: |
---|---|---|
"text" |
Search term. Is a keyword search, literal search or regular expression search, depending on the type parameter. SearchHelp has more |
required |
search="text" |
(Alternative to above) | N/A |
web="Name" web="Main, Know" web="all" |
Comma-separated list of webs to search. See TWikiVariables#VarSEARCH for more details. | Current web |
topic="WebPreferences" topic="*Bug" |
Limit search to topics: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. | All topics in a web |
excludetopic="Web*" excludetopic="WebHome, WebChanges" |
Exclude topics from search: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. | None |
type="keyword" type="literal" type="regex" |
Do a keyword search like soap "web service" -shampoo ; a literal search like web service ; or RegularExpression search like soap;web service;!shampoo |
%SEARCHVAR- DEFAULTTYPE% preferences setting (literal) |
scope="topic" scope="text" scope="all" |
Search topic name (title); the text (body) of topic; or all (both) | "text" |
order="topic" order="created" order="modified" order="editby" order= |
Sort the results of search by the topic names, topic creation time, last modified time, last editor, or named field of TWikiForms. The sorting is done web by web; in case you want to sort across webs, create a formatted table and sort it with TablePlugin's initsort | Sort by topic name |
limit="all" limit="16" |
Limit the number of results returned. This is done after sorting if order is specified |
All results |
date="..." |
limits the results to those pages with latest edit time in the given time interval. | All results |
reverse="on" |
Reverse the direction of the search | Ascending search |
casesensitive="on" |
Case sensitive search | Ignore case |
bookview="on" |
BookView search, e.g. show complete topic text | Show topic summary |
nonoise="on" |
Shorthand for nosummary="on" nosearch="on" nototal="on" zeroresults="off" noheader="on" noempty="on" |
Off |
nosummary="on" |
Show topic title only | Show topic summary |
nosearch="on" |
Suppress search string | Show search string |
noheader="on" |
Suppress search header Topics: Changed: By: |
Show search header |
nototal="on" |
Do not show number of topics found | Show number |
zeroresults="off" |
Suppress all output if there are no hits | zeroresults="on" , displays: "Number of topics: 0" |
noempty="on" |
Suppress results for webs that have no hits. | Show webs with no hits |
header="..." format="..." |
Custom format results: see FormattedSearch for usage, variables & examples | Results in table |
expandvariables="on" |
Expand variables before applying a FormattedSearch on a search hit. Useful to show the expanded text, e.g. to show the result of a SpreadSheetPlugin %CALC{}% instead of the formula |
Raw text |
multiple="on" |
Multiple hits per topic. Each hit can be formatted. The last token is used in case of a regular expression ";" and search | Only one hit per topic |
nofinalnewline="on" |
If on , 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. |
off |
separator=", " |
Line separator between hits | Newline "$n" |
statistics
Parameter | Description | Default |
---|---|---|
webs |
comma-separated list of webs to run stats on | all accessible webs |
logdate |
YYYYMM to generate statistics for | current month |
upload
multipart/form-data
format.Parameter | Description | Default |
---|---|---|
hidefile |
if defined, will not show file in attachment table | |
filepath |
local (client) path name of the file being uploaded. This is used to look up the data for the file in the HTTP query. | |
filename |
deprecated, do not use | |
filecomment |
Comment to associate with file in attachment table | |
createlink |
if defined, will create a link to file at end of topic | |
changeproperties |
if defined, this is a property change operation only - no file will be uploaded. | null |
curl
to upload files from the command line using this script.
upload
script can only be called via http POST method, not GET.
view
Parameter | Description | Default |
---|---|---|
raw=on |
Shows the text of the topic in a scrollable textarea | |
raw=debug |
As raw=on , but also shows the metadata (forms etc) associated with the topic. |
|
raw=text |
Shows only the source of the topic, as plain text (Content-type: text/plain). Only shows the body text, not the form or other meta-data. | |
raw=all |
Shows only the source of the topic, as plain text (Content-type: text/plain), with embedded meta-data. This may be useful if you want to extract the source of a topic to a local file on disc. | |
section |
Allows to view only a part of the topic delimited by a named section (see VarSTARTSECTION). If the given section is not present, no topic content is displayed. | |
contenttype |
Allows you to specify a different Content-Type: (e.g. contenttype=text/plain ) |
|
rev |
Revision to view (e.g. rev=45 ) |
|
template |
Allows you to specify a different skin template, overriding the 'view' template the view script would normally use. The default template is view . For example, you could specify /twiki/bin/view/TWiki/TWikiScripts?template=edit. This is mainly useful when you have specialised templates for a TWiki Application. |
|
topic |
redirects (at the beging of the cgi script running) to show the spcified Web.Topic, or, redirects to a URL, if allowed by {AllowRedirectUrl} and {PermittedRedirectHostUrls} |
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.
viewfile
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.
Parameter | Description | Default |
---|---|---|
filename |
name of attachment | |
rev |
Revision to view |
filename
parameter, you can append the attachment name
to the end of the URL path (after the topic) e.g. https://wiki.ivoa.net/twiki/bin/viewfile/Webname/TopicName/Attachment.gif
twiki/tools
directory.
geturl.pl
wget
and curl
commands. geturl.pl <host> <path> [<port> [<header>]]
geturl.pl some.domain /some/dir/file.html 80
http://some.domain:80/some/dir/file.html
rewriteshebang.pl
#!/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').
tick_twiki.pl
0 0 * * 0 cd /usr/twiki/bin && perl ../tools/tick_twiki.pl
Note: The script has to be run by a user who can write files created by the webserver user.