TWiki CGI and Command Line Scripts

Programs on the TWiki server performing actions such as rendering, saving and renaming topics.

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) environment or from the command line. The scripts in the twiki/tools directory can only be called from the command line.

CGI Scripts

Details on CGI scripts located in the twiki/bin directory.

General Information

CGI environment

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).


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

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:

Parameter Description Default
topic 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)  
user 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.  
skin Overrides the default skin path (see TWikiSkins)  
cover Specifies temporary skin path to prepend to the skin path for this script only (see TWikiSkins)  


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.

Parameter Description Default
filename Name of existing attachment (if provided, this is a "manage attachment" action) none (in which case this is a "new attachment" action)


Shows all the changes in the given web.

The changes script can receive one parameter:

Parameter Description Default
minor If 0, show only major changes. If 1, show all the changes (both minor and major) 0

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.

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.


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.


The edit script understands the following parameters, typically supplied by HTML input fields:

Parameter Description Default
action 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. You can change the Edit/Edit Raw buttons to always append the action parameter in skins like Pattern and Classic by setting the topic or preference variable EDITACTION to the value text or form. To edit the topic once the EDITACTION is defined as form simply remove the action=form from the browser URL of the edit script and reload the edit window  
onlynewtopic If set, error if topic already exists  
onlywikiname If set, error if topic name is not a WikiWord  
templatetopic The name of the template topic, copied to get the initial content (new topic only)  
text Initial text for the topic  
topicparent The parent topic  
formtemplate Name of the form to instantiate in the topic. Overrides the form set in the templatetopic if defined. (will remove the form is set to 'none')  
contenttype Optional parameter that defines the application type to write into the CGI header. Defaults to text/html. May be used to invoke alternative client applications  
anyname Any parameter can passed to the new topic; if the template topic contains %URLPARAM{"anyname"}%, it will be replaced by its value  
breaklock If set, any lease conflicts will be ignored, and the edit will proceed even if someone is already editing the topic.  
redirectto If the user continues from edit to save, and if the save (or cancels the edit) process is successful, save 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}).

Form field values are passed in parameters named 'field' - for example, if I have a field Status the parameter name is Status.

  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.

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.


Used for logging in when TWiki login is being used (e.g TemplateLoginManager).
Parameter Description Default
origurl URL that was being accessed when an access violation occurred. the login process will redirect to this URL if it is successful none
username username of user logging in none
password password of user logging in none


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.


Performs a range of management functions.
Parameter Description Default
action One of createweb, renameweb, deleteUserAccount, editSettings or saveSettings none

Note: The manage script can only be called via http POST method for createweb renameweb, and deleteUserAccount.


Parameter Description Default
newweb Name of the new web ''
baseweb Name of the web to copy to create the new web ''
webbgcolor value for WEBBGCOLOR ''
sitemapwhat Value for SITEMAPWHAT ''
sitemapuseto Value for SITEMAPUSETO ''
nosearchall Value for NOSEARCHALL ''


Parameter Description Default
newsubweb Name of the web after move ''
newparentweb New parent web name ''
confirm If defined, requires a second level of confirmation. Supported values are "getlock", "continue", and "cancel" ''


No parameters


Parameter Description Default
text Text of the topic ''
originalrev Revision that the edit started on Most recent revision
redirectto If the savesettings process is successful, save 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}).
All other parameters may be interpreted as form fields, depending on the current form definition in the topic.


See BulkRegistration.
Parameter Description Default
OverwriteHomeTopics Whether to overwrite existing home topics or not false
EmailUsersWithDetails Whether to mail registered users or not false
LogTopic Topic to save the log in Same as topic name, with 'Result' appended.


Change password, email address, or both, of a user.
Parameter Description Default
username god alone knows none
oldpassword current password none
password new password none
passwordA new password confirmation none
email new email address none
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.


Reset the password for a single or multiple users
Parameter Description Default
LoginName list of usernames to reset none - error if not set
Introduction message to be sent alongside the reset, most often used to announce to the user that they have been given an account. ''

This is used by BulkResetPassword and ResetPassword. Only administrators can provide a list of LoginNames, non-admins can only provide a single LoginName.

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.


Unregisters (removes) the currently logged-in user.
Parameter Description Default
password Users' password none


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:

Parameter Description Default
template Name of the template file to display  
def Optional, can be set to the name of a single definition within template. This definition will be instantiated in the template wherever %INSTANTIATE% is seen. This lets you use a single template file for many messages. For an example, see oopsmanagebad.tmpl.  
paramN Where N is an integer from 1 upwards. These values will be substituted into template for %PARAM1% etc.  


This script is deprecated. Its functions are covered by the save script.


Renders the differences between version of a TWiki topic

Parameter Description Default
rev1 the higher revision  
rev2 the lower revision  
render the rendering style {sequential, sidebyside, raw, debug} DIFFRENDERSTYLE, sequential
type {history, diff, last} history diff, version to version, last version to previous diff
context number of lines of context  
  • add a {word} render style


Parameter Description DefaultSorted ascending
action register or verify or resetPassword or approve  

Note: The 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.


Used for renaming topics and attachments.

Parameter Description Default
skin skin(s) to use  
newweb new web name  
newtopic new topic name  
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}).

Note: The 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.


This REST (Representational State Transfer) 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.

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"

The function is free to use any other query parameters for its own purposes.

ALERT! Note: 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.

Invocation Examples

The rest script assumes that it will be called with URL in the form:<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.


The 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