Programs on the server performing actions such as rendering, saving and renaming topics.
These scripts are located in the bin and tools directories. This topic describes the interfaces to some of those scripts. All scripts in the bin directory can be called from the CGI (Common Gateway Interface) environment or from the command line. The scripts in the tools directory can only be called from the command line.
Details on CGI scripts located in the bin directory.
Note that a blank in the 'Default' column means that the parameter is not required, and has no default. required means the parameter is required, and has no default. text in italics describes default behaviour if no value is given.
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 user is used (usually guest).
You must be have the 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.
All parameters require a value, even if that is the empty string. Note that parameters passed on the command-line should not be URL-encoded.
When calling a tools script from the command line, you normally need to be cd'd to the =bin directory e.g.
command_line is set if there is no CGI query object available.
A comprehensive list of core context identifiers used by Foswiki is found in the IfStatements#Context_identifiers.
debugenableplugins During debugging it can be useful to selectively disable all but a subset of plugins. This parameter allows the caller to specify a comma-separated list of plugins that should be enabled.
foswikioriginalquery The original query that was being made before a redirect for user confirmation was required.
foswiki_redirect_cache Foswiki sometimes caches long lists of parameters that must survive over a sequence of browser redirects. This parameter identifies one of these caches. The parameter value is a "magic number" that uniquely idenitifies a file in the working/tmp directory. These files have a very short lifetime, and are destroyed when the cache is read.
refresh If the Foswiki page cache is in use, setting this parameter will invalidate the cache. Valid values are cache, on and all. See PageCaching for more information on the page cache.
response Used as part of the request validation process.
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.
validation_key part of cross-site scripting protection. Any request sent from browsers that might change data stored on the server must carry a key that indentifies the source of the request.
<any name> Any other parameter name passed to the script is passed through for possible use by the script. This is typically only applicable to the edit, save and view scripts.
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.
Shows all the changes in the given web.
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 of, and changes to, the site 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.
breaklock If set, any lease conflicts will be ignored, and the edit will proceed even if someone is already editing the topic.
formtemplate Name of the form to instantiate in the topic. Set to none to remove any existing form.
redirectto If the user continues from edit to save, and if the save (or cancel) 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}).
template Allows you to specify a different skin template. Overrides any setting of EDIT_TEMPLATE.
topicparent Sets the parent topic.
The EDIT_TEMPLATE preference (or the template parameter) can be used to override the default 'edit' template on a per-web or per-topic basis.
In most skins that are based on the default templates (such as Pattern skin) you can easily change the Edit and Edit WikiText buttons to append the action parameter, by setting the preference EDITACTION to the value text or form. (You can always get back to editing the whole topic by removing the action parameter from the URL browser Location window, and reloading the edit window).
The string AUTOINC followed by one or more digits anywhere in the topic name will be converted to a number such that the resulting topic name is unique in the target web. However this doesn't happen until the topic is saved.
When a new topic is created using edit, the topic isn't actually created until the edit is saved. The content of the new topic is initialised according to the parameters you pass.
templatetopic - defines the full name (web.topic) of a topic to use as a template for the new topic. The template topic is copied and, unless notemplateexpansion is set, the following macros are expanded in the topic text: URLPARAM, DATE, SERVERTIME, GMTIME, USERNAME, WIKINAME, WIKIUSERNAME, USERINFO.
text - use this as the text of the topic. Macros are not expanded in this text. Overrides any text set in the templatetopic.
formtemplate - Overrides any form set in the templatetopic.
notemplateexpansion - given by templatetopic. Use this when you want a verbatim copy of a topic.
onlynewtopic and onlywikiname are used to control validation of the new topic name.
<any name> - besides the form field value setting described above, when creating a new topic, %URLPARAM{" <any name> "}% in the templatetopic will be expanded to the parameter value.
Used for logging in with TemplateLoginManager, and for interactive validation of operations that require user confirmation.
foswikiloginaction If 'validate', the login script is being used for interactive validation of an operation. Otherwise it is being used for login.
remember If set, this will cause the user's login to be retained even after their browser is shut down.
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 must be set up to require a valid user to access this script, thus triggering the webserver login process.
Performs a range of management functions.
Note: The manage script can only be called via the HTTP POST method. Make sure you specify method="post" if you call the manage script via a form action. It is not possible to call manage from an <a href ...> link.
Alternative entry point for creation, via edit, of a new topic, used by screens that support several actions using manage.
Other parameters are the same as for edit.
newtopic Value of %TOPIC% within the web creation message. Optionally used in some skins to signify a non-default home topic.
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.
If neither action_save or action_cancel are provided, an oops error is issued. All other parameters may be interpreted as form fields, depending on the current form definition in the topic.
See BulkRegistration.
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.
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.
Alternative entry point for edit, used by screens that support several actions using manage. Parameters are as for =edit.
redirectto If the add process is successful, manage 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}). None. An Oops screen showing the results is returned.
redirectto If the remove process is successful, manage 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}). None. An Oops screen showing the results is returned.
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.
def 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.
The context parameter is only respected if the back-end store supports context diffs.
Note: The register script can only be called via the HTTP POST method except when the action is verify. Make sure you specify method="post" if you call the register script via a form action. It is not possible to call register from an <a href ...> link. The verify action is an exception as it is used to verify registration by clicking a href link from an email.
addtogroups Accepts a comma-separated list of group names to add the user to.
create If on, and a group being added to does not exist, create it.
<any name> Any other parameter passed during registration will normally be passed on into the new user's home topic, or ignored.
Used for renaming webs, topics and attachments.
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.
Rename a web.
Rename a topic or an attachment.
Note: The rename script can only be called via the HTTP POST method. Make sure you specify method="post" if you call the rename script via a form action. It is not possible to call rename from an <a href ...> link.
This script is deprecated. Its functions are covered by the manage script.
This REST (Representational State Transfer) script can be invoked via http in the same way as the other 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 Foswiki::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.
endPoint Where to redirect the response once the request is served, in the form "Web.Topic". If not given, the REST script must generate a valid response.
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.
REST scripts that require a topic context must use the standard topic parameter to pass the topic name, as the URL path is used to identify the REST funtcion. If not defined, then the topic context in REST handlers will be Main.WebHome.
The function is free to use any other query parameters for its own purposes.
The rest script should always require authentication in any site 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.
where <subject> must be the WikiWord name of one of the installed Plugins, and the <verb> is the alias for the function registered using the Foswiki::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.
Note that for Plugins to register REST handlers, they must be enabled in configure.
The save script performs a range of save-related functions.
action_addform 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_replaceform Redirect from the "change form" page.
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.
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.
newtopic If templatetopic is given, and this parameter is set to 1 and the topic does not exist, will clear the initial topic text.
originalrev Revision on which the edit started.
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.
topicparent If 'none' remove any current topic parent. If the name of a topic, set the topic parent to this.
<any name> If the topic has a form with a field called <any name>, it will set the value of that field.
Any errors will cause a redirect to another page, either an oops page to report the error, or a login if the save is not authorized.
The string AUTOINC followed by one or more digits anywhere in the topic name will be converted to a number such that the resulting topic name is unique in the target web.
otherwise no form is attached.
otherwise it defaults to the empty string.
Merging is only enabled if the topic text comes from 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.
...
It is not possible to call save from an <a href ...> link.
This cgi script has been deprecated. When called, it will redirect to the WebSearch topic, and the parameters will be passed on.
Refresh the WebStatistics topics in range of webs.
see SiteTools#WebStatistics for more details on WebStatistics and how to update statistics using cron.
Uploads an attachment to a topic. The HTTP request is expected to be in multipart/form-data format.
changeproperties if non=0, this is a property change operation only - no file will be uploaded.
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.
noredirect Normally the script will redirect to 'view' when the upload is complete, but also designed to be useable for REST-style calling using the 'noredirect' parameter. If this parameter is set it will return an appropriate HTTP status code and print a message to STDOUT, starting with 'OK' on success and 'ERROR' on failure.
redirectto URL to redirect to after upload. The parameter value can be a TopicName, a Web.TopicName, or a URL. Redirect to a URL only works if it is enabled in configure, and is ignored if noredirect is specified.
You can use a tool like curl to upload files from the command line using this script.
You can call upload easily from XmlHttpRequest in Javascript.
Note: The upload script can only be called via HTTP POST method. Make sure you specify method="post" if you call the upload script via a form action. It is not possible to call upload from an <a href ...> link.
Used for viewing topics.
on - show the text of the topic in a scrollable textarea.
debug - as on, but also shows the metadata (forms etc) associated with the topic.
text - show 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.
all - show 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.
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 /bin/view.pl/System/CommandAndCGIScripts?template=edit. This is mainly useful when you have specialised templates for a Wiki Application.
For historical reasons, the view script has a special interpretation of the text skin. This skin cannot be redefined.
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 AccessControls. In this case, you can use the viewfile script to give access to attachments while still checking access controls.
Details on command line scripts located in the tools directory.
This is a very simple script to get the content of a web site, either using GET or POST. It is marked as deprecated and might be removed in a future release. Its functions are covered by the standard wget and curl commands, which have the added advantage of performing authentication..
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 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').
This script executes a number of non-essential regular administration tasks that will help keep your site healthy and happy, such as removing expired sessions and lease files.
Note: The script has to be run by a user who can write files created by the webserver user.
Extensions, such as the MailerContrib, also install tool scripts. Check the documentation of the extension for details.
This script will download and install, or remove an extension.
Use the configure web interface to the Extensions Installer.
This script searches for missing Perl modules that should be available according to your Foswiki environment and offers installation via CPANPLUS or a supported package management system. It eases Perl module installation, which is part of a Foswiki installation, may be part of an extension installation or may need to follow upgrades. The script can be used to just provide an overview of Foswiki related perl modules in your installation by running it with option -v.
Copyright &© by the contributing authors. All material on this site is the property of the contributing authors.
