TWiki Webmaster Reference (ver. 01 Sep 2001)This page contains all documentation topics as one long and complete reference sheet. Use the extended menu below to jump directly to sections. Doubleclick anywhere on-screen to return to the top of the page. (You can also browse the TWiki reference as individual pages from the full topics menu.)On this page:
Note: Read the most up to date version of this document at http://TWiki.org/cgi-bin/view/TWiki/TWikiDocumentation
![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
< < | Related Topics: TWikiWeb, TWikiHistory, TWikiPlannedFeatures, TWikiEnhancementRequests | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | Related Topics: TWikiSite, TWikiHistory, TWikiPlannedFeatures, TWikiEnhancementRequests | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning: Can't find topic TWiki.TWikiImplementationNotes Warning: Can't find topic TWiki.TWikiInstallationNotes Warning: Can't find topic TWiki.TWikiUpgradeNotes Warning: Can't find topic TWiki.TWikiAuthentication Warning: Can't find topic TWiki.TWikiUsernameVsLoginUsername TWiki Access ControlRestricting read and write access to topics and webs, by Users and groups TWiki Access Control allows you restrict access to single topics and entire webs, by individual user and by user Groups. Access control, combined with TWikiUserAuthentication, lets you easily create and manage an extremely flexible, fine-grained privilege system.![]() ![]() An Important Control ConsiderationYour organization will learn that, while fostering an open collaborative environment, soft security (peer review), together with version control (complete audit trail) will take care of any security concern you might have. Open, free-form editing is the essence of WikiCulture - what makes TWiki different and often more effective than other collaborative environments. For that reason, it is strongly recommended that decisions to restrict read or write access to a web or a topic are made with great care - the more restrictions, the less wiki in the mix. Experience shows that unrestricted write access works very well because:
Permissions settings of the webs on this TWiki site
Authentication vs. Access ControlAuthentication: Identifies who a user is based on a login procedure. See TWikiUserAuthentication. Access control: Restrict access to content based on users and groups once a user is identified.Users and GroupsAccess control is based on the familiar concept of Users and Groups. Users are defined by their WikiNames. They can then be organized in unlimited combinations by inclusion in one or more user Groups. For convenience, Groups can also be included in other Groups.Managing UsersA user can create an account in TWikiRegistration. The following actions are performed:
Managing GroupsThe following describes the standard TWiki support for groups. Your local TWiki may have an alternate group mapping manager installed. Check with your TWiki administrator if you are in doubt. Groups are defined by group topics located in theMain web. To create a new group, visit TWikiGroups and enter the name of the new group ending in Group into the "new group" form field. This will create a new group topic with two important settings:
![]() The Super Admin GroupA number of TWiki functions (for example, renaming webs) are only available to administrators. Administrators are simply users who belong to the SuperAdminGroup. This is a standard user group, the name of which is defined by {SuperAdminGroup} setting in configure. The default name of this group is theTWikiAdminGroup . The system administrator may have chosen a different name for this group if your local TWiki uses an alternate group mapping manager but for simplicity we will use the default name TWikiAdminGroup in the rest of this topic.
You can create new administrators simply by adding them to the TWikiAdminGroup topic. For example,
Restricting AccessYou can define who is allowed to read or write to a web or a topic. Note that some plugins may not respect access permissions.
Controlling access to a WebYou can define restrictions on who is allowed to view a TWiki web. You can restrict access to certain webs to selected Users and Groups, by:
ALLOWWEBVIEW set, this will also apply to the subweb. Also note that you will need to ensure that the parent web's FINALPREFERENCES does not include the access control settings listed above. Otherwise you will not be able override the parent web's access control settings in sub-webs.
Creation and renaming of sub-webs is controlled by the WEBCHANGE setting on the parent web (or ROOTCHANGE for root webs). Renaming is additionally restricted by the setting of WEBRENAME in the web itself.
Note: If you restrict access to the Main, make sure to add the TWikiRegistrationAgent so that users can register. Example:
Controlling access to a Topic
![]() Allowing public access to specific topics in a restricted webYou may want to completely open up access to a specific topic within a restricted web - allowing access by anybody. There is a special group for that - Main.AllUsersGroup. The following setting allows view access to the topic by anybody even if they are not authenticated.
tools/eliminate_emptydenytopic is provided.
After upgrading from pre 6.0 to post 6.0, you need to run it.
Empty values in access control variablesSetting an empty value to an access control variable is the same as not setting at all:
![]() Securing File AttachmentsBy default, TWiki does not secure file attachments. Without making the following changes to the twiki.conf file, it is possible for anyone who has access to the server to gain access to an attachment if they know the attachment's fully qualified path, even though access to the topic associated with the attachment is secured. This is because attachments are referred to directly by Apache, and are not by default delivered via TWiki scripts. This means that the above instructions for controlling to topics do not apply to attachments unless you make the changes as described below. An effective way to secure attachments is to apply the same access control settings to attachments as those applied to topics. This security enhancement can be accomplished by instructing the webserver to redirect accesses to attachments via the TWikiviewfile script, which honors the TWiki access controls settings to topics. See the notes below for implications.
The preferred method to secure attachments is by editing the twiki.conf file to include:
ScriptAlias /do /filesystem/path/to/twiki/bin Alias /pub/TWiki /filesystem/path/to/twiki/pub/TWiki Alias /pub/Sandbox /filesystem/path/to/twiki/pub/Sandbox ScriptAlias /pub /filesystem/path/to/twiki/bin/viewfileNotes:
Controlling who can manage top-level websTop level webs are a special case, because they don't have a parent web with a WebPreferences. So there has to be a special control just for the root level.
ROOTCHANGE access to rename an existing top-level web. You just need WEBCHANGE in the web itself.
How TWiki evaluates ALLOW/DENY settingsWhen deciding whether to grant access, TWiki evaluates the following rules in order (read from the top of the list; if the logic arrives at PERMITTED or DENIED that applies immediately and no more rules are applied). You need to read the rules bearing in mind that VIEW, CHANGE and RENAME access may be granted/denied separately.
Allowing web creation/deletion/rename by user mapping managerThere are cases where DENYROOTCHANGE, ALLOWROOTCHANGE, DENYWEBCHANGE, and ALLOWWEBCHANGE, and DENYWEBCHANGE are not capable enough to implement web creation and rename permissions you want. To cope with such cases, when a new web is created, thecanCreateWeb($cUID, $web) method of the user mapping manager is called if it exists.
If it returns true, TWiki goes ahead and create the web without checking access control variables.
Similarly, when a web is renamed (deletion is a form of rename), the canRenameWeb($cUID, $oldWeb, $newWeb) method of the user mapping manager is called if it exists.
Please read AllowWebCreateByUserMappingManager for more details.
Forbid certain users to do certain actions by configurationYou may have an unruly registered users (e.g. a crawler program) who don't follow the rules while you don't have control over such users. And the web application container in which TWiki is installed may be managed by somebody else and you don't have tight and quick control. To cope with such situations, certain users can be forbidden certain scripts by setting{ForbidUserAction} .
A good example is worth more than a lengthy explanation, so here it is:
$TWiki::cfg{ForbidUserAction} = ' AggresiveCrawler: edit, oops, search; ReadOnlyUser: !view, viewfile; TotallyForbidden: !nothing; ';In this example:
User masqueradingThere are cases where it's handy to access TWiki on behalf of somebody else retaining a trace of your real identity rather than completely becoming a different user. We call it user masquerading. TWiki provides a framework to implement that. Please read UserMasquerading for more information. This is an advanced feature and not many TWiki sites are using, but there is a part in the following section mentioning it, it's mentioned here.Dynamic access controlThere are pitfalls and you need to harden your web to avoid unexpected access. Before using this feature, please read this entire section through carefully. You may want to restrict access dynamically -- based on topic name, a form field value, or some combination of factors. To cope with such situations, the dynamic access control mechanism is provided. If you setDYNAMIC_ACCESS_CONTROL 'on' at WebPreferences of the web, TWiki variables in access control variables mentioned above are expanded.
Example 1 - restriction based on topic nameLet's assume you need to restrict changes only to the CroniesGroup members except with topics whose name ends with Public, which need be changed by anybody. That is achieve by the following settings on WebPrefences.* Set DYNAMIC_ACCESS_CONTROL = on * Set ALLOWWEBCHANGE = %IF{"'%CALCULATE{$SUBSTRING(%TOPIC%, -6, 6)}%' = 'Public'" then="%WIKINAME%" else="CroniesGroup"}% Example 2 - restriction based on form fieldLet's assume:
* Set DYNAMIC_ACCESS_CONTROL = on * Set ALLOWWEBVIEW = %IF{"'%CALCULATE{$SUBSTRING(%TOPIC%, 1, 6)}%' = 'ReqEnt' and '%FORMFIELD{Requestor}%' != '%WIKINAME%'" then="SupportGroup" else="%WIKINAME%"}%Specifically the following access control variables are subject to TWiki variable expansion in their values.
Dynamic access control in accessing a different web's topicLet's assume WebA has the following lines on WebPreferences.* Set DYNAMIC_ACCESS_CONTROL = on * Set MEMBERS = JaneSmith, JoeSchmoe * Set ALLOWWEBVIEW = %MEMBERS%This is not a good way to use dynamic access control but it does restrict access only to those listed in MEMBERS. However, access control doesn't work as expected when WebA.TopicB is accessed from WebC.TopicD by %INCLUDE{WebA.TopicB}% or other variables.
This is because %MEMBERS% is defined in WebA and may have a different value in other webs.
You may think the following lines cheat the access control on WebA but actually not.
* Set MEMBERS = %WIKINAME% %INCLUDE{WebA.TopicB}%This is because when a topic (e.g. WebC.TopicD) is accessed from browser and the topic refers to another topic in a different web (e.g. WebA.TopicB) and the different web employs dynamic access control, access to another topic is defined being on the safer side. Topic level dynamic access controlOn a topic, it's possible to use a variable defined on the topic for topic level access restriction. E.g.* Set MEMBERS = JaneSmith, JoeSchmoe * Set ALLOWTOPICVIEW = %MEMBERS%[This is not a good way to use dynamic access control Dynamic access control and user masqueradingYour user mapping handler may be providing the UserMasquerading feature. In that case, you expect dynamic access control to just work when user masquerading is in effect. Otherwise, you cannot test if your dynamic access control configuration is working as expected on your own. Dynamic access control does work as expected even if user masquerading is in effect. For that, the following things are happening under the hood. Let's think about Example 2 mentioned above. When you masquerading as SomebodyElse, you need to be able to see SomebodyElse's requests only. In the access control setting, a form field value is compared with %WIKINAME%. While user masquerading is in effect, your wiki name is YourNameOnBehalfOfSomebodyElse. It cannot match the form field value. To make dynamic access control work under these circumstances, variable expansion for dynamic access control is skewed as follows. Specifically, the following variables are expanded to the value of SomeboyElse's rather than YourNameOnBehalfOfSomebodyElse's.
Avoiding vulnerabilityBy default, user level preferences are read before web level preferences. This means a user can set a preferences variable at the user level and finalise it. To prevent this sort of attack, you need to harden your web or site by disabling user preferences by e.g. having the following line onlib/LocalSite.cfg
$TWiki::cfg{DemoteUserPreferences}= 1;and having the following line on your WebPreferences and then finalise DENYUSERPREFEENCES .
* Set DENYUSERPREFEENCES = allPlease read TWikiVariables#ControllingUserLevelPrefsOverride for details. Again by default, predefined variables such as %IF{...}% can be overridden by preferences variables.
If user preferences are disabled, ordinary users cannot attack using user preferences, but topic level preferences may cause unexpected consequences.
As such, all predefined variables need to be made un-overridable by having the following line on WebPreferences and then finalise OVERRIDABLEPREDEFINEDVARIABLES .
* Set OVERRIDABLEPREDEFINEDVARIABLES =Please read TWikiVariables#PredefinedVariables for details. Disabling dynamic access controlYou may not be comfortable with dynamic access control because it may slow things down. Or you may not want to be bothered by questions raised by users about it. If so, you can disable it by setting DYNAMIC_ACCESS_CONTROL 'off' and then finalizing at the local site level. (cf. TWikiVariables#Setting_Preferences_Variables)Access control and INCLUDEALLOWTOPICVIEW and ALLOWTOPICCHANGE only applies to the topic in which the settings are defined. If a topic A includes another topic B, topic A does not inherit the access rights of the included topic B. Examples: Topic A includes topic B
Customizing "access denied" messageWhen access is denied, a page as follows is displayed:![]() TOPIC_ACCESS_CONTACT varialbe on WebPreferences. e.g.
* Set TOPIC_ACCESS_CONTACT = If you need to access this site, please apply [[Main.AccessForm][here]]Please note that setting it on a topic other than WebPreferences does not take effect. This is a limitation of the current implementation. Custom user/group notationsYou can have custom user/group notations such asUSER:userid and LDAPGROUP:group-name and use them for access control. For example:
* Set ALLOWWEBCHANGE = USER:buzz, LDAPGROUP:foo-barIn a large organization, TWiki may need to depend on user and group data provided by its infrastructure. Custom user/group notations are handy in such situations though it's not trivial to implement. Please read here for details. Access Control quick recipesRestrict Access to Whole TWiki SiteIn a firewalled TWiki, e.g. an intranet wiki or extranet wiki, you want to allow only invited people to access your TWiki. There are three options: 1. Install TWiki Behind Firewall: The firewall takes care of giving access to TWiki to authorized people only. This is a typical setup for a company wiki. As for TWiki configuration, no special setup is needed. 2. Extranet TWiki Using Template Login: All TWiki content (pages and attachments) need to be access controlled. The Template Login allows users to login and logout. Only logged in users can access TWiki content. Configuration: Follow the default setup, then change these configure settings:
twiki/bin and twiki/pub directories to all but valid users. In the Apache config file for TWiki (twiki.conf or .htaccess ), replace the <FilesMatch "(attach|edit|... section with this:
<FilesMatch ".*"> require valid-user </FilesMatch>Notes:
Authenticate and Restrict Selected Webs OnlyUse the following setup to provide unrestricted viewing access to open webs, with authentication only on selected webs. Requires TWikiUserAuthentication to be enabled.
Hide Control Settings![]() Edit topic preference settings under More topic actions menu. Preferences set in this manner are not visible in the topic text, but take effect nevertheless. Access control settings added as topic preference settings are stored in the topic meta data and they override settings defined in the topic text.
Alternatively, place them in HTML comment markers, but this exposes the access setting during ordinary editing.
Obfuscating WebsAnother way of hiding webs is to keep them hidden by not publishing the URL and by preventing theall webs search option from accessing obfuscated webs. Do so by enabling the NOSEARCHALL variable in WebPreferences:
![]() Read-only Skin ModeIt is possible to turn the PatternSkin and TopMenuSkin into read-only mode by removing the edit and attach controls (links and buttons). This is mainly useful if you have TWiki application pages or dashboards where you do not want regular users to change content. The read-only skin mode is not a replacement for access control; you can use it in addition to access control. Details at PatternSkinCustomization#ReadOnlySkinMode.Configuring access control for topics of a certain name in all websYou may need to restrict access to topics of a certain name in all webs. For example, there might be an add-on refering to a certain topic of all webs. And the add-on does things only administrators are supposed to do. In that case, change to the topic needs to be restricted only to administrators and must not be overridable. Let's say there is AutomationAddOn which refers to WebAutomation of all webs. And WebAutomation needs to be modifable only by administrators. That can be achieved by the following configuration.$TWiki::cfg{Access}{Topic}{WebAutomation} = { DENYCHANGE => 'Main.AllUsersGroup', };In addition to ALLOWCHANGE , you can sepcify DENYCHANGE , ALLOWVIEW , DENYVIEW , ALLOWRENAME , and DENYRENAME as follows.
$TWiki::cfg{Access}{Topic}{SpecialTopic} = { DENYVIEW => 'JoeSchmoe', ALLOWVIEW => 'FooGroup', }; $TWiki::cfg{Access}{Topic}{TOPICNAME} has precedence over DENYTOPIC* and ALLOWTOPIC* .
For example, if the configuration for WebAutomation is there as above, there is no way to allow non-adminsitrators to change the WebAutomation topic of any web.
As a way to configure access control, this may look crude.
The reason why configured this way is that this can be part of plugin/add-on/contrib's configuration.
For example, Config.spec of AutomationAddOn would have the following lines, with which proper access control to WebAutomation topics is implemented without the administrator knowing it.
$TWiki::cfg{Access}{Topic}{WebAutomation} = { DENYCHANGE => 'Main.AllUsersGroup', }; TWiki TemplatesDefinition of the templates used to render all HTML pages displayed in TWikiOverviewTemplates are plain text with embedded template directives that tell TWiki how to compose blocks of text together, to create something new. There are two types of template:
![]() ![]() Master TemplatesTWiki uses master templates when composing the output from all actions, like topic view, edit, and preview. This allows you to change the look and feel of all pages by editing just a few template files. Master templates are also used in the definition of TWikiSkins. Master templates are stored as text files with the extension.tmpl .
They are usually HTML with embedded template directives.
The directives are expanded when TWiki wants to generate a user interface screen.
How Template Directives Work
%TMPL:DEF{"x"}% x%P%z%TMPL:END% then %TMPL:P{"x" P="y"}% will expand to xyz .
Note that parameters can simply be ignored; for example, %TMPL:P{"x"}% will expand to x%P%z.
Any alphanumeric characters can be used in parameter names.
You are highly recommended to use parameter names that cannot be confused with TWikiVariables.
Note that three parameter names, context , then and else are reserved.
They are used to support a limited form of "if" condition that you can use to select which of two templates to use, based on a context identifier:
%TMPL:DEF{"link_inactive"}%<input type="button" disabled value="Link>%TMPL:END% %TMPL:DEF{"link_active"}%<input type="button" onclick="link()" value="Link" />%TMPL:END% %TMPL:P{context="inactive" then="inactive_link" else="active_link"}% for %CONTEXT%When the "inactive" context is set, then this will expand the "link_inactive" template; otherwise it will expand the "link_active" template. See IfStatements for details of supported context identifiers. Finding TemplatesThe master templates shipped with a twiki release are stored in the twiki/templates directory. As an example,twiki/templates/view.tmpl is the default template file for the twiki/bin/view script.
You can save templates in other directories as long as they are listed in the {TemplatePath} configuration setting.
The {TemplatePath} is defined in the Miscellaneous section of the configure page.
You can also save templates in user topics (IF there is no possible template match in the templates directory).
The {TemplatePath} configuration setting defines which topics will be accepted as templates.
Templates that are included with an explicit '.tmpl' extension are looked for only in the templates/ directory.
For instance %TMPL:INCLUDE{"example.tmpl"}% will only return templates/example.tmpl , regardless of {TemplatePath} and SKIN settings.
The out-of-the-box setting of {TemplatePath} supports the following search order to determine which template file or topic to use for a particular script or %TMPL:INCLUDE{"script"}% statement.
The skin path is set as described in TWikiSkins.
example template file will be searched for in the following places, when the current web is Thisweb and the skin path is print,pattern :
view and edit scripts, for example when a topic-specific template is required. Two preference variables can be used to override the templates used:
view and edit respectively. The template search order is as specified above.
Both VIEW_TEMPLATE and EDIT_TEMPLATE may contain TWiki variables, which are expanded.
For example, the following setting causes Item* topics to be displayed with the custom view template ItemViewTmpl while the other topics are displayed normally.
* Set VIEW_TEMPLATE = %IF{"'%CALCULATE{$SUBSTRING(%TOPIC%, 1, 4)}%' = 'Item'" then="ItemViewTmpl"}%The following setting causes Item* topics to be edited with the editform template (edits only the TWiki form of the topic without editing the topic text) while the other topics are edited normally.
* Set EDIT_TEMPLATE = %IF{"'%CALCULATE{$SUBSTRING(%TOPIC%, 1, 4)}%' = 'Item'" then="editform"}% ![]() {TemplatePath} so that another directory, such as the %USERSWEB% appears at the front. You can then put your own templates into that directory or web and these will override the standard templates. (Note that such will increase the lookup time for templates by searching your directory first.)
TMPL:INCLUDE recursion for piecewise customization, or mixing in new featuresIf there is recursion in the TMPL:INCLUDE chain (eg twiki.classic.tmpl contains%TMPL:INCLUDE{"twiki"}% , the templating system will include the next twiki.SKIN in the skin path.
For example, to create a customization of pattern skin, where you only want to over-ride the breadcrumbs for the view script, you can create only a view.yourlocal.tmpl:
%TMPL:INCLUDE{"view"}% %TMPL:DEF{"breadcrumb"}% We don't want any crumbs %TMPL:END%and then set SKIN=yourlocal,pattern The default {TemplatePath} will not give you the desired result if you put these statements in the topic Thisweb.YourlocalSkinViewTemplate . The default {TemplatePath} will resolve the request to the template/view.pattern.tmpl , before it gets to the Thisweb.YourlocalSkinViewTemplate resolution. You can make it work by prefixing the {TemplatePath} with: $web.YourlocalSkin$nameTemplate .
Default master templatetwiki.tmpl is the default master template. It defines the following sections.
Template TopicsThe second type of template in TWiki are template topics. Template topics define the default text for new topics. There are four types of template topic:
edit script, TWiki locates a topic to use as a content template according to the following search order:
Variable ExpansionTWikiVariables located in template topics get expanded as follows when a new topic is created.1. Default variable expansionThe following variables used in a template topic automatically get expanded when new topic is created based on it:
2. Preventing variable expansionIn a template topic, embed text that you do not want expanded inside a%STARTSECTION{type="templateonly"}% ... %ENDSECTION{type="templateonly"}% section. For example, you might want to write this in the template topic:
%STARTSECTION{type="templateonly"}% This template can only be changed by: * Set ALLOWTOPICCHANGE = Main.TWikiAdminGroup %ENDSECTION{type="templateonly"}%This will restrict who can edit the template topic, but will be removed when a new topic based on that template topic is created. %NOP% can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation. For example, escape %SERVERTIME% with %SER%NOP%VERTIME% .
3. Causing variable expansion in a sectionYou can forcefully expand TWikiVariables by placing them inside atype="expandvariables" section in the template topic, such as:
...Example: If you have the following content in a template topic: * %SYSTEMWEB%.ATasteOfTWiki - view a short introductory presentation on TWiki for beginners * %SYSTEMWEB%.WelcomeGuest - starting points on TWiki * %SYSTEMWEB%.TWikiUsersGuide - complete TWiki documentation * Sandbox.%HOMETOPIC% - try out TWiki on your own * Sandbox.%TOPIC%Sandbox - just for meyou will get this raw text in new topics based on that template topic: * TWiki.ATasteOfTWiki - view a short introductory presentation on TWiki for beginners * TWiki.WelcomeGuest - starting points on TWiki * TWiki.TWikiUsersGuide - complete TWiki documentation * Sandbox.WebHome - try out TWiki on your own * Sandbox.JimmyNeutronSandbox - just for me 4. Specifying variables to be expanded individuallyYou may want to mix variables to be expanded and variables not to be. By prepending a variable name withEOTC__ (EOTC followed by two underscores; EOTC stands for Expand On Topic Creation), you can have the variable expanded.
Here's an example.
%EOTC__SEARCH{"." topic="%URLPARAM{prefix}%*" nonoise="on" format="$percntINCLUDE{$topic}$percnt" separator="$n" }%This yields a series of %INCLUDE{...}% s, which are not expanded.
This is not achievable by an expandvariables section.
Specifying a FormWhen you create a new topic based on a template, you often want the new topic to have a form attached to it. You can attach a form to the template topic, in which case it will be copied into the new topic. Sometimes this isn't quite what you want, as it copies all the existing data from the template topic into the new topic. To avoid this and use the default values specified in the form definition instead, you can use theformtemplate CGI parameter to the edit script to specify the name of a form to attach.
See TWikiScripts for information about all the other parameters to edit .
Automatically Generated Unique Topic NamesFor TWiki applications it is useful to be able to automatically generate unique topic names, such as BugID0001, BugID0002, etc. You can addAUTOINC<n> to the topic name in the edit and save scripts, and it will be replaced with an auto-incremented number on topic save. <n> is a number starting from 0, and may include leading zeros. Leading zeros are used to zero-pad numbers so that auto-incremented topic names can sort properly. Deleted topics are not re-used to ensure uniqueness of topic names. That is, the auto-incremented number is always higher than the existing ones, even if there are gaps in the number sequence.
Examples:
AUTOINC<n> are preserved, but are not taken into account when calculating the next increment. Use this to create topic names that have a unique identifier (serial number) and a descriptive text.
Example:
[[%SCRIPTURLPATH{edit}%/%WEB%/BugIDAUTOINC00001?templatetopic=BugTemplate;topicparent=%TOPIC%;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]Note: After the save operation, the web client is redirected to the newly created topic by default. If the specified topic name contains AUTOINC<n> and you want to redirect to a different URL containing the newly created topic's name, you can use AUTOINC in the redirectto parameter. Let's say the specified topic name is ItemAUTOINC0001 , and redirectto is set to %SCRIPTURL{view}%/%WEB%/ViewerTopic?id=ItemAUTOINC . If the latest existing topic is Item0123 , a new topic named Item0124 is created, and the web client is redirected to ViewerTopic?id=Item0124 in the current web.
Template Topics in ActionHere is an example for creating new topics (in the Sandbox web) based on a specific template topic and form: The above form asks for a topic name. A hidden input tag namedtemplatetopic specifies ExampleTopicTemplate as the template topic to use. Here is the raw text of the form:
%EDITFORMFIELD{ "new" type="start" action="edit" topic="Sandbox.%TOPIC%" }% * New example topic: %EDITFORMFIELD{ "topic" type="text" value="ExampleTopicAUTOINC0001" size="30" }% %EDITFORMFIELD{ "templatetopic" type="hidden" value="%SYSTEMWEB%.ExampleTopicTemplate" }% %EDITFORMFIELD{ "topicparent" type="hidden" value="%HOMETOPIC%" }% %EDITFORMFIELD{ "onlywikiname" type="hidden" value="on" }% %EDITFORMFIELD{ "onlynewtopic" type="hidden" value="on" }% %EDITFORMFIELD{ "form" type="submit" value="Create" }% %EDITFORMFIELD{ "form" type="end" }%Here is the equivalent form using a hand-crafted HTML form: <form name="new" action="%SCRIPTURLPATH{edit}%/Sandbox/%HOMETOPIC%"> * New example topic: <input type="text" name="topic" value="ExampleTopicAUTOINC0001" size="30" /> <input type="hidden" name="templatetopic" value="%SYSTEMWEB%.ExampleTopicTemplate" /> <input type="hidden" name="topicparent" value="%HOMETOPIC%" /> <input type="hidden" name="onlywikiname" value="on" /> <input type="hidden" name="onlynewtopic" value="on" /> <input type="submit" class="twikiSubmit" value="Create" /> </form> ![]() save script instead of the edit script in the form action. When you specify the save script in an HTML form tag you have to use the "post" method. This is done automatically when using the EDITFORMFIELD variable. Example when using the HTML form tag:
<form name="new" action="%SCRIPTURLPATH{save}%/Sandbox/" method="post"> ... </form> ![]() edit and save scripts understand many more parameters, see TWikiScripts#edit and TWikiScripts#save for details.
![]() %WIKIUSERNAME% and %DATE% variables in your topic templates to include the signature of the person creating a new topic. The variables are expanded into fixed text when a new topic is created. The standard signature is: -- %WIKIUSERNAME% - %DATE%
Using Absolute vs Relative URLs in TemplatesWhen you use TWikiVariables such as %PUBURL% and %PUBURLPATH% in templates you should be aware that using %PUBURL% instead of %PUBURLPATH% puts absolute URLs in the produced HTML. This means that when a user saves a TWiki page in HTML and emails the file to someone outside a company firewall, the receiver has a severe problem viewing it. It is therefore recommended always to use the %PUBURLPATH% to refer to images, CSS, Javascript files etc so links become relative. This way browsers just give up right away and show a usable html file. Related Topics: TWikiSkins, TWikiForms, TWikiScripts, DeveloperDocumentationCategory, AdminDocumentationCategoryTWiki SkinsA skin overlays regular templates to provide specific look and feel to TWiki screens.OverviewTWiki uses TWikiTemplates files as the basis of all the screens it uses to interact with users. Each screen has an associated template file that contains the basic layout of the screen. This is then filled in by the code to generate what you see in the browser. TWiki ships with a default set of template files that give a very basic, CSS-themable, look-and-feel. TWiki also includes support for skins that can be selected to give different, more sophisticated, look and feel. A default TWiki installation will usually start up with the PatternSkin already selected. Skins may also be defined by third parties and loaded into a TWiki installation to give more options. To see how TWiki looks when no skin is selected, view the current page with a non-existing skin. TWiki topic content is not affected by the choice of skin, however a skin can be defined to use a CSS (Cascading Style Sheet) which can provide a radically different appearance to the text layout. Relevant links on TWiki.org:
Changing the default TWiki skinTWiki ships with the TopMenuSkin activated by default. You can set a skin for the whole site, a single web, a single topic, or for each user individually. This is done by setting the SKIN preferences setting to the name of a skin. If the skin you select doesn't exist, then TWiki will pick up the default templates. For example, to make the SKIN setting work across all topics and webs, put it in TWikiPreferences. Skins can cascade using a skin path explained below. One skin can be based on another one, and extensions can introduce additional screen elements. For example, the TagMePlugin adds tag elements to the TopMenuSkin, and the TopMenuSkin is based on the PatternSkin, resulting in this skin path:* Set SKIN = tagme, topmenu, pattern Defining SkinsYou may want to define your own skin, for example to comply with corporate web guidelines, or because you have a aesthetic vision that you want to share. There are a couple of places you can start doing this. The TWikiTemplates files used for skins are located in thetwiki/templates directory and are named according to the skin: <scriptname>.<skin>.tmpl . Skin files may also be defined in TWiki topics - see TWikiTemplates for details.
To start creating a new skin, copy the default TWikiTemplates (like view.tmpl ), or copy an existing skin to use as a base for your own skin. You should only need to copy the files you intend to customize, as TWiki can be configured to fall back to another skin if a template is not defined in your skin. Name the files as described above (for example view.myskin.tmpl ).
If you use PatternSkin as your starting point, and you want to modify the layout, colors or even the templates to suit your own needs, have a look first at the topics PatternSkinCustomization and PatternSkinCssCookbook.
For your own TWiki skin we encourage you to show a small TWiki logo at the bottom of your skin:
![]() %WEBCOPYRIGHT% variable.
![]() text skin, and skin names starting with rss have hard-coded meanings.
The following template files are used for TWiki screens, and are referenced in the TWiki core code. If a skin doesn't define its own version of a template file, then TWiki will fall back to the next skin in the skin path, or finally, to the default version of the template file.
(Certain template files are expected to provide certain TMPL:DEFs - these are listed in sub-bullets)
twiki.tmpl is a master template conventionally used by other templates, but not used directly by code.
![]() <p /> in the generated html. It will produce invalid html, and may break the page layout.
Partial customization, or adding in new features to an existing skinYou can use recursion in the TMPL:INCLUDE chain (e.g.twiki.pattern.tmpl contains %TMPL:INCLUDE{"twiki"}% , the templating system will include the next twiki.SKIN in the skin path (which is explained below). For example, to create a customization of pattern skin, where you only want to remove the edit & WYSIWYG buttons from view page, you create only a view.yourlocal.tmpl :
%TMPL:INCLUDE{"view"}% %TMPL:DEF{"edit_topic_link"}%%TMPL:END% %TMPL:DEF{"edit_wysiwyg_link"}%%TMPL:END%and then set SKIN=yourlocal,pattern .
Variables in SkinsYou can use template variables, TWikiVariables, and other predefined variables to compose your skins. Some commonly used variables in skins:
The Jump Box and Navigation BoxThe default skins include a Jump Box, to jump to a topic. The box also understands URLs, e.g. you can typehttp://www.google.com/ to jump to an external web site. The feature is handy if you build a skin that has a select box of frequently used links, like Intranet home, employee database, sales database and such. A little JavaScript gets into action on the onchange method of the select tag to fill the selected URL into the "Go" box field, then submits the form.
Here is an example form that has a select box and the Jump Box for illustration purposes. You need to have JavaScript enabled for this to work:
Note: Redirect to a URL only works if it is enabled in configure (Miscellaneous, {AllowRedirectUrl} ).
Using Cascading Style SheetsCSS files are gererally attachments to the skin topic that are included in the the skin templates - in the case of PatternSkin in the templatestyles.pattern.tmpl .
<style type='text/css' media='all'>@import url('%PUBURLPATH%/%SYSTEMWEB%/MySkin/mystyle.css');</style> Attachment TablesControlling the look and feel of attachment tables is a little bit more complex than for the rest of a skin. By default, the attachment table is a standard TWiki table, and the look is controlled in the same way as other tables. In a very few cases you may want to change the content of the table as well. The format of standard attachment tables is defined through the use of special TWiki template macros which by default, are defined in theattachtables.tmpl template using the %TMPL:DEF macro syntax described in TWikiTemplates. These macros are:
ATTACH:row macros are expanded for each file in the attachment table, using the following special tags:
Packaging and Publishing SkinsSee TWiki:Plugins/SkinPackagingHowTo![]() ![]() Browsing Installed SkinsYou can try out all installed skins in the TWikiSkinBrowser.Activating SkinsTWiki uses a skin search path, which lets you combine skins additively. The skin path is defined using a combination of TWikiVariables and URL parameters. TWiki works by asking for a template for a particular function - for example, 'view'. The detail of how templates are searched for is described in TWikiTemplates, but in summary, the templates directory is searched for a file calledview. skin.tmpl , where skin is the name of the skin e.g. pattern . If no template is found, then the fallback is to use view.tmpl . Each skin on the path is searched for in turn. For example, if you have set the skin path to local,pattern then view.local.tmpl will be searched for first, then view.pattern.tmpl and finally view.tmpl .
The basic skin is defined by a SKIN setting:
?skin=catskin,bearskin :
Setting SKIN (or the ?skin parameter in the URL) replaces the existing skin path setting, for the current page only. You can also extend the existing skin path as well, using covers.
ruskin, catskin, bearskin ). There is also an equivalent cover URL parameter. The difference between setting SKIN vs. COVER is that if the chosen template is not found (e.g., for included templates), SKIN will fall back onto the next skin in line, or the default skin, if only one skin was present, while COVER will always fall back onto the current skin.
An example would be invoking the printable mode, which is achieved by applying ?cover=print . The view.print.tmpl simply invokes the viewprint template for the current skin which then can appropriately include all other used templates for the current skin. Where the printable mode be applied by using SKIN , all skins would have the same printable appearance.
The full skin path is built up as follows: SKIN setting (or ?skin if it is set), then COVER setting is added, then ?cover .
Conditional Skin ActivationTWiki skins can be activated conditionally using IfStatements. For example, you might want to use a mobile skin for iPhone and Android user agents, and the default skin otherwise. This example uses the print skin on iPhone and Android:* Set SKIN = %IF{ "'%HTTP{"User-Agent"}%'~'*iPhone*' OR '%HTTP{"User-Agent"}%'~'*Android*'" then="print, pattern" else="topmenu, pattern" }% Hard-Coded SkinsThetext skin is reserved for TWiki internal use.
Skin names starting with rss also have a special meaning; if one or more of the skins in the skin path starts with 'rss' then 8-bit characters will be encoded as XML entities in the output, and the content-type header will be forced to text/xml .
Related Topics: TWikiSkinBrowser, AdminDocumentationCategory, DeveloperDocumentationCategory, TWiki:TWiki.TWikiSkinsSupplement![]() ![]() ![]() ![]() TWiki VariablesSpecial text strings expand on the fly to display dynamic content, such as user data or system info TWikiVariables are text strings -%VARIABLE% or %VARIABLE{ parameter="value" }% - that expand into content whenever a topic is rendered for viewing. There are two types of variables:
TWiki Variables Wizard — to Find and Compose Variables
Select a category and a variable
![]()
Build Your Variable:
<----><----> Using VariablesTo use a variable type its name. For example,
Variable NamesVariable names must start with a letter, optionally followed by letters, numbers and underscore '_' characters. Both upper-case and lower-case characters can be used,%MYVAR% , %MyVar% , %My2ndVar% , and %My_Var% are valid names. Variables are case sensitive, e.g. %MyVAR% and %MYVAR% are not the same.
By convention all settings, predefined variables and variables handled by extensions are always UPPER-CASE.
Preferences VariablesUnlike predefined variables, preferences variables can be defined by the user in various places.Setting Preferences VariablesYou can set variables in all the following places:
preview will show the wrong thing, and you must save the topic to see it correctly.
The syntax for setting variables is the same anywhere in TWiki (on its own TWiki bullet line, including nested bullets): [multiple of 3 spaces] * [space] Set [space] VARIABLENAME [space] = [space] value
Examples:
* Set VARIABLENAME1 = value * Set VARIABLENAME2 = valueSpaces between the = sign and the value will be ignored. You can split a value over several lines by indenting following lines with spaces - as long as you don't try to use * as the first character on the following line. Example: * Set VARIABLENAME = value starts here and continues hereWhatever you include in your variable will be expanded on display, exactly as if it had been entered directly. Example: Create a custom logo variable
* Set MYLOGO = %PUBURL%/%WEB%/LogoTopic/mylogo.gifYou can also set preferences variables on a topic by clicking the link Edit topic preference settings under More topic actions . Use the same * Set VARIABLENAME = value syntax. Preferences set in this manner are not visible in the topic text, but take effect nevertheless.
Controlling User Level Preferences OverrideBy default, user level variables are set at the step 4 as stated in the previous section. That means a user can finalise some preferences variables so that web level or topic level setting cannot override it. This may result in a situation the web or page owner doesn't expect.$TWiki::cfg{DemoteUserPreferences} has been introduced to avoid it.
If it's set to true, user level variables are set at the last step instead of the step 4.
But this is not enough.
To guarantee a certain result, you need to finalise critical preferences variables set at the web or topic level, which is cumbersome.
So preferences variables DENYUSERPREFEENCES and ALLOWUSERPREFERENCES have been introduced.
* Set DENYUSERPREFERENCES = allIf you allow INYMCEPLUGIN_DISABLE and SKIN to be set at the user level:
* Set ALLOWUSERPREFERENCES = TINYMCEPLUGIN_DISABLE, SKINIf you allow user preferences to set anything other than TINYMCEPLUGIN_DISABLE or SKIN :
* Set DENYUSERPREFERENCES = TINYMCEPLUGIN_DISABLE, SKINPlease note DENYUSERPREFEENCES and ALLOWUSERPREFERENCES affect user preferences regardless of $TWiki::cfg{DemoteUserPreferences} .
You can set those variables at the site level while $TWiki::cfg{DemoteUserPreferences} setting to false.
If you do so, you should finalise DENYUSERPREFEENCES and ALLOWUSERPREFERENCES .
Otherwise, they might be overridden by user preferences.
You will get the most benefit of DENYUSERPREFEENCES and ALLOWUSERPREFERENCES by setting $TWiki::cfg{DemoteUserPreferences} to true.
That way, each web can specify how much user level preferences overriding is allowed.
Parameterized Variables (Macros)It is possible to pass parameters to TWiki variables. This is called a macro in a programming language. To define a parameterized variable, set a variable that contains other variables, such as:* Set EXAMPLE = Example variable using %DEFAULT%, %PARAM1% and %PARAM2% * Set DEMO = Demo using %DEFAULT{ default="(undefined)" }%, %PARAM1{ default="(undefined)" }% and %PARAM2{ default="(undefined)" }%A special %DEFAULT% variable denotes the default (nameless) parameter of the calling variable. Variables optionally may list a default="..." parameter that gets used in case the calling variable does not specify that parameter.
To use a parameterized variable (or call a macro), add parameters within the curly brackets, such as:
* %EXAMPLE{ "foo" PARAM1="bar" PARAM2="baz" }% * %DEMO{ "demo" PARAM2="parameter 2" }% -- note that PARAM1 is missingwhich resolves to:
ExampleDefine variables:* Set DRINK = red wine * Set FAVORITE = My %DEFAULT{default="favorite"}% dish is %DISH{default="steak"}%, my %DEFAULT{default="favorite"}% drink is %DRINK%. ![]() %DISH{default="steak"}% ), or as a preferences setting (Set DRINK = ... ).
Use Variables:
%FAVORITE{ DISH="Sushi" DRINK="Sake" }%Returns: %FAVORITE{ DISH="Sushi" DRINK="Sake" }% %FAVORITE{}%Returns: %FAVORITE{}% %FAVORITE{ "preferred" }%Returns: %FAVORITE{ "preferred" }% <-- Redefine what is defined in INCLUDE:
Access Control VariablesThese are special types of preferences variables to control access to content. TWikiAccessControl explains these security settings in detail.Local values for variablesCertain topics (a users home topic, web site and default preferences topics) have a problem; variables defined in those topics can have two meanings. For example, consider a user topic. A user may want to use a double-height edit box when they are editing their home topic - but only when editing their home topic. The rest of the time, they want to have a normal edit box. This separation is achieved usingLocal in place of Set in the variable definition. For example, if the user sets the following in their home topic:
* Set EDITBOXHEIGHT = 10 * Local EDITBOXHEIGHT = 20Then when they are editing any other topic, they will get a 10 high edit box. However when they are editing their home topic, they will get a 20 high edit box. Local can be used wherever a preference needs to take a different value depending on where the current operation is being performed.
Use this powerful feature with great care! %ALLVARIABLES% can be used to get a listing of the values of all variables in their evaluation order, so you can see variable scope if you get confused.
Frequently Used Preferences VariablesThe following preferences variables are frequently used. They are defined in TWikiPreferences#Miscellaneous_Settings:
Predefined VariablesMost predefined variables return values that were either set in the configuration when TWiki was installed, or taken from server info (such as current username, or date and time). Some, like%SEARCH% , are powerful and general tools.
Search or List Variables by CategoryDocumenting TWiki VariablesThis section is for people documenting TWiki variables of the TWiki core and TWiki extensions. Each variable is documented in a topic namedVar<name> in the TWiki web. For example, a %LIGHTSABER% variable has a documentation topic called VarLIGHTSABER. The topic is expected to have a specific format so that reports in this TWikiVariables topic, in TWikiVariablesSearch and in category topics work as expected.
Basic structure of a variable documentation topic:
VarLIGHTSABER topic:
#VarLIGHTSABER ---+++ LIGHTSABER -- laser sword to fend of unethical competition * The =%<nop>LIGHTSABER{}%= variable is handled by the LightsaberPlugin. * Syntax: =%<nop>LIGHTSABER{ _parameters_ }%= * Parameters: | *Parameter* | *Description* | *Default* | | =color="..."= | Color: =red=, =glue=, =green= | =white= | | =sound="..."= | Sound: =none=, =standard=, =loud= | =none= | * Example: =%<nop>LIGHTSABER{ color="red" }%= shows a red Lightsaber * Expands to: =%LIGHTSABER{ color="red" }%= * Note: The Lightsaber is a fictional weapon in the Star Wars universe, a "laser sword." * Category: FormattingAndRenderingVariables, UIAndVisualizationVariables * Related: [[%IF{"'%INCLUDINGTOPIC%'='TWikiVariables'" then="#"}%VarPLASMA][PLASMA]], LightsaberPlugin Warning: Can't find topic TWiki.TWikiNotificationOfChanges Warning: Can't find topic TWiki.TWikiFormTemplate Warning: Can't find topic TWiki.MetaDataDefinition Warning: Can't find topic TWiki.MetaDataRendering TWiki PluginsAdd functionality to TWiki with readily available plugins; create plugins based on APIsOverviewYou can add plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you:
![]()
Installing PluginsThe TWiki:Plugins![]() ![]() yum , apt-get , rpm , etc) to install dependent libraries.
If available, install CPAN (Comprehensive Perl Archive Network) libraries with the OS package manager. For example, to install IO::Socket::SSL on Fedora/RedHat/CentOS, run yum install perl-IO-Socket-SSL . CPAN modules can also be installed natively, see TWiki:TWiki.HowToInstallCpanModules![]() On-Site PretestingIf you have a mission critical TWiki installation and you are concerned about installing new plugins, you can test new plugins before making them available by creating a second test TWiki installation, and test the plugin there. It is also possible to configure this test TWiki to use the live data. You can allow selected users access to the test area. Once you are satisfied that it won't compromise your primary installation, you can install it there as well. InstalledPlugins shows which plugins are: 1) installed, 2) loading properly, and 3) what TWiki:Codev.PluginHandlers![]() %FAILEDPLUGINS% variable can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.
Some Notes on Plugin PerformanceThe performance of the system depends to some extent on the number of plugins installed and on the plugin implementation. Some plugins impose no measurable performance decrease, some do. For example, a Plugin might use many Perl libraries that need to be initialized with each page view (unless you run mod_perl). You can only really tell the performance impact by installing the plugin and by measuring the performance with and without the new plugin. Use the TWiki:Plugins.PluginBenchmarkAddOn![]() ab utility. Example on Unix:time wget -qO /dev/null /twiki/bin/view/TWiki/AbcPlugin
![]() DISABLEDPLUGINS to be a comma-separated list of names of plugins to disable. Define it in Main.TWikiPreferences to disable those plugins everywhere, in the WebPreferences topic to disable them in an individual web, or in a topic to disable them in that topic. For example,
* Set DISABLEDPLUGINS = SpreadSheetPlugin, EditTablePlugin Managing Installed PluginsSome plugins require additional settings or offer extra options that you have to select. Also, you may want to make a plugin available only in certain webs, or temporarily disable it. And may want to list all available plugins in certain topics. You can handle all of these management tasks with simple procedures:Enabling/Disabling PluginsPlugins can be enabled and disabled with the configure script in the Plugins section. An installed plugin needs to be enabled before it can be used.Plugin Evaluation OrderBy default, TWiki executes plugins in alphabetical order on plugin name. It is possible to change the order, for example to evaluate database variables before the spreadsheet CALCs. This can be done with{PluginsOrder} in the plugins section of configure.
Plugin-Specific SettingsPlugins can be configured with 1. preferences settings and/or 2. with configure settings. Older plugins use plugin preferences settings defined in the plugin topic, which is no longer recommended. 1. Use preferences settings: Adinistrators can set plugin-specific settings in the local site preferences at Main.TWikiPreferences and users can overload them at the web level and page level. This approach is recommended if users should be able to overload settings. For security this is not recommended for system settings, such as a path to an executable. By convention, preferences setting names start with the plugin name in all caps, and an underscore. For example, to set the cache refresh period of the TWiki:Plugins.VarCachePlugin![]()
%<pluginname>_<setting>% , such as %VARCACHEPLUGIN_REFRESH% .
To learn how this is done, use the TWiki:Plugins.VarCachePlugin![]()
![]()
our $NO_PREFS_IN_TOPIC = 1;
Listing Active PluginsPlugin status variables let you list all active plugins wherever needed. This site is running TWiki version TWiki-6.1.0, Mon, 16 Jul 2018, build 30610, plugin API version 6.10
On this TWiki site, the enabled plugins are: SpreadSheetPlugin, BackupRestorePlugin, ColorPickerPlugin, CommentPlugin, DBIQueryPlugin, DatePickerPlugin, EditTablePlugin, HeadlinesPlugin, InterwikiPlugin, JQueryPlugin, PreferencesPlugin, SetGetPlugin, SlideShowPlugin, SmiliesPlugin, TWikiSheetPlugin, TablePlugin, TagMePlugin, TinyMCEPlugin, TwistyPlugin, WatchlistPlugin, WysiwygPlugin.
|
Plugin | Errors |
---|---|
SpreadSheetPlugin | none |
BackupRestorePlugin | none |
ColorPickerPlugin | none |
CommentPlugin | none |
DBIQueryPlugin | none |
DatePickerPlugin | none |
EditTablePlugin | none |
HeadlinesPlugin | none |
InterwikiPlugin | none |
JQueryPlugin | none |
PreferencesPlugin | none |
SetGetPlugin | none |
SlideShowPlugin | none |
SmiliesPlugin | none |
TWikiSheetPlugin | none |
TablePlugin | none |
TagMePlugin | none |
TinyMCEPlugin | none |
TwistyPlugin | none |
WatchlistPlugin | none |
WysiwygPlugin | none |
Handler | Plugins |
---|---|
afterEditHandler | WysiwygPlugin |
afterRenameHandler | TagMePlugin WatchlistPlugin |
afterSaveHandler | TagMePlugin WatchlistPlugin |
beforeCommonTagsHandler | DBIQueryPlugin EditTablePlugin PreferencesPlugin TWikiSheetPlugin TwistyPlugin WysiwygPlugin |
beforeEditHandler | TinyMCEPlugin WysiwygPlugin |
beforeMergeHandler | WysiwygPlugin |
beforeSaveHandler | CommentPlugin WatchlistPlugin WysiwygPlugin |
commonTagsHandler | SpreadSheetPlugin BackupRestorePlugin CommentPlugin DBIQueryPlugin EditTablePlugin JQueryPlugin SlideShowPlugin SmiliesPlugin TWikiSheetPlugin |
initPlugin | SpreadSheetPlugin BackupRestorePlugin ColorPickerPlugin CommentPlugin DBIQueryPlugin DatePickerPlugin EditTablePlugin HeadlinesPlugin InterwikiPlugin JQueryPlugin PreferencesPlugin SetGetPlugin SlideShowPlugin SmiliesPlugin TWikiSheetPlugin TablePlugin TagMePlugin TinyMCEPlugin TwistyPlugin WatchlistPlugin WysiwygPlugin |
modifyHeaderHandler | WysiwygPlugin |
postRenderingHandler | DBIQueryPlugin PreferencesPlugin WysiwygPlugin |
preRenderingHandler | InterwikiPlugin SmiliesPlugin TablePlugin |
lib/TWiki/Func.pm
) describes all the interfaces available to plugins. Plugins should only use the interfaces described in this module.
Func.pm
, you run the risk of creating security holes. Also, your plugin will likely break and require updating when you upgrade to a new version of TWiki.
lib/TWiki/Plugins/EmptyPlugin.pm
module.
#
from all lines of the callback.
eval
block like this:eval { require IPC::Run }
return "<font color=\"red\">SamplePlugin: Can't load required modules ($@)</font>" if $@;
lib/TWiki/Plugins/BathPlugin/
.
$NO_PREFS_IN_TOPIC
in your plugin package as that will stop TWiki from reading the plugin topic for every page. Use Config.spec or preferences settings instead. (See details).
$VERSION
variable. This should be an integer, or a subversion version id.
initPlugin
handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong. initPlugin
handler).
$TWiki::Plugins::VERSION
in the TWiki::Plugins
module contains the TWiki plugin API version, currently 6.10. %PLUGINVERSION{}%
variable to query the plugin API version or the version of installed plugins.
%TWiki::cfg
hash than adding it as preferences in the plugin topic. configure
describes the steps
MyFirstPlugin.pm
MyFirstPlugin.txt
MyFirstPlugin
topic. Other needed Perl code is best placed in a lib/TWiki/Plugins/MyFirstPlugin/
directory.
The plugin API handles the details of connecting your Perl module with main TWiki code. When you're familiar with the Plugin API, you're ready to develop plugins.
The TWiki:Plugins.BuildContriblib/TWiki/Plugins/EmptyPlugin.pm
to <name>Plugin.pm
. The EmptyPlugin.pm
module contains mostly empty functions, so it does nothing, but it's ready to be used. Customize it. Refer to the Plugin API specs for more information.
If your plugin uses its own modules and objects, you must include the name of the plugin in the package name. For example, write Package MyFirstPlugin::Attrs;
instead of just Package Attrs;
. Then call it using:
use TWiki::Plugins::MyFirstPlugin::Attrs; $var = MyFirstPlugin::Attrs->new();
MyFirstPlugin
, press enter and create the new topic
OUTLINE: Doc Topic Contents
Check the plugins web on TWiki.org for the latest plugin doc topic template. Here's a quick overview of what's covered: Syntax Rules: <Describe any special text formatting that will be rendered.>" Example: <Include an example of the plugin in action. Possibly include a static HTML version of the example to compare if the installation was a success!>" Plugin Settings: <Description and settings for custom plugin %VARIABLES%, and those required by TWiki.>" Plugin Installation Instructions: <Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.>" Plugin Info: <Version, credits, history, requirements - entered in a form, displayed as a table. Both are automatically generated when you create or edit a page in the TWiki:Pluginsweb.>"
Plugin
, ex: MyFirstPlugin.pm
, and a documentation page with the same name(MyFirstPlugin.txt
).
lib/TWiki/Plugins/MyFirstPlugin.pm
data/TWiki/MyFirstPlugin.txt
pub/TWiki/MyFirstPlugin/uparrow.gif
[a required graphic]
MyFirstPlugin.zip
) and add the entire directory structure from Step 1. The archive should look like this: lib/TWiki/Plugins/MyFirstPlugin.pm
data/TWiki/MyFirstPlugin.txt
pub/TWiki/MyFirstPlugin/uparrow.gif
MyFirstPlugin
MyFirstPlugin.zip
Dev
, ex: MyFirstPluginDev
. This is the discussion page for future development. (User support for plugins is handled in TWiki:SupportTWiki::Func::getWorkArea()
function, which gives you a persistent directory where you can store data files. By default they will not be web accessible. The directory is guaranteed to exist, and to be writable by the webserver user. For convenience, TWiki::Func::storeFile()
and TWiki::Func::readFile()
are provided to persistently store and retrieve simple data in this area.
TWiki::Func::saveAttachment()
function to store the data.
Recommendation for file name: _GaugePlugin_img123.gif
TWiki::Func::saveAttachment()
function to store the data.
Recommendation for file names in plugin attachment area: _Main_roundedge-ul.gif
configure
configure
rather than trying to use TWiki preferences variables. These extensions use Config.spec
files to publish their configuration requirements.
Config.spec
files are read during TWiki configuration. Once a Config.spec
has defined a configuration item, it is available for edit through the standard configure
interface. Config.spec
files are stored in the 'plugin directory' e.g. lib/TWiki/Plugins/BathPlugin/Config.spec
.
Config.spec
file Config.spec
file for an extension starts with the extension announcing what it is:
# ---+ Extensions # ---++ BathPlugin # This plugin senses the level of water in your bath, and ensures the plug # is not removed while the water is still warm.This is followed by one or more configuration items. Each configuration item has a type, a description and a default. For example:
# **SELECT Plastic,Rubber,Metal** # Select the plug type $TWiki::cfg{BathPlugin}{PlugType} = 'Plastic'; # **NUMBER** # Enter the chain length in cm $TWiki::cfg{BathPlugin}{ChainLength} = 30; # **BOOLEAN EXPERT** # Set this option to 0 to disable the water temperature alarm $TWiki::cfg{BathPlugin}{TempSensorEnabled} = 1;The type (e.g.
**SELECT**
) tells configure
to how to prompt for the value. It also tells configure
how to do some basic checking on the value you actually enter. All the comments between the type and the configuration item are taken as part of the description. The configuration item itself defines the default value for the configuration item. The above spec defines the configuration items $TWiki::cfg{BathPlugin}{PlugType}
, $TWiki::cfg{BathPlugin}{ChainLength}
, and $TWiki::cfg{BathPlugin}{TempSensorEnabled}
for use in your plugin. For example,
if( $TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) { die "The bathwater is too hot for comfort"; }The Config.spec file is read by
configure
, which then writes LocalSite.cfg
with the values chosen by the local site admin.
A range of types are available for use in Config.spec
files:
BOOLEAN | A true/false value, represented as a checkbox |
COMMAND length | A shell command |
LANGUAGE | A language (selected from {LocalesDir} |
NUMBER | A number |
OCTAL | An octal number |
PASSWORD length | A password (input is hidden) |
PATH length | A file path |
PERL | A perl structure, consisting of arrays and hashes |
REGEX length | A perl regular expression |
SELECT choices | Pick one of a range of choices |
SELECTCLASS root | Select a perl package (class) |
STRING length | A string |
URL length | A url |
URLPATH length | A relative URL path |
EXPERT | means this an expert option |
M | means the setting is mandatory (may not be empty) |
H | means the option is not visible in configure |
lib/TWiki.spec
for many more examples.
Config.spec
files for non-plugin extensions are stored under the Contrib
directory instead of the Plugins
directory.
Note that from TWiki 5.0 onwards, CGI scripts (in the TWiki bin
directory) provided by extensions must also have an entry in the Config.spec
file. This entry looks like this (example taken from PublishContrib)
# **PERL H** # Bin script registration - do not modify $TWiki::cfg{SwitchBoard}{publish} = [ "TWiki::Contrib::Publish", "publish", { publishing => 1 } ];
PERL
specifies a perl data structure, and H
a hidden setting (it won't appear in configure
). The first field of the data value specifies the class where the function that implements the script can be found. The second field specifies the name of the function, which must be the same as the name of the script. The third parameter is a hash of initial context settings for the script.
TWiki:TWiki/SpecifyingConfigurationItemsForExtensionsDev
, such as MyFirstPluginDev
. The plugin development topic is a great resource to discuss feature enhancements and to get feedback from the TWiki community.
if( $TWiki::Plugins::VERSION >= 1.1 ) { @webs = TWiki::Func::getListOfWebs( 'user,public' ); } else { @webs = TWiki::Func::getPublicWebList( ); }
TWiki::Plugins
version in which the handler was first deprecated. For example, if we need to define the endRenderingHandler
for compatibility with TWiki::Plugins
versions before 1.1, we would add this to the plugin:
package TWiki::Plugins::SinkPlugin; use vars qw( %TWikiCompatibility ); $TWikiCompatibility{endRenderingHandler} = 1.1;If the currently-running TWiki version is 1.1 or later, then the handler will not be called and the warning will not be issued. TWiki with versions of
TWiki::Plugins
before 1.1 will still call the handler as required.