1 # <a name="TWiki Plugins"></a> TWiki Plugins
3 _Add functionality to TWiki with readily available plugins; create plugins based on APIs_
7 <li><a href="#TWiki Plugins"> TWiki Plugins</a><ul>
8 <li><a href="#Overview"> Overview</a></li>
9 <li><a href="#Installing Plugins"> Installing Plugins</a><ul>
10 <li><a href="#On-Site Pretesting"> On-Site Pretesting</a></li>
11 <li><a href="#Some Notes on Plugin Performance"> Some Notes on Plugin Performance</a></li>
14 <li><a href="#Managing Installed Plugins"> Managing Installed Plugins</a><ul>
15 <li><a href="#Enabling Plugins"> Enabling Plugins</a></li>
16 <li><a href="#Plugin Evaluation Order"> Plugin Evaluation Order</a></li>
17 <li><a href="#Plugin-Specific Settings"> Plugin-Specific Settings</a></li>
18 <li><a href="#Listing Active Plugins"> Listing Active Plugins</a><ul>
19 <li><a href="#=%ACTIVATEDPLUGINS%="> %ACTIVATEDPLUGINS%</a></li>
20 <li><a href="#=%PLUGINDESCRIPTIONS%="> %PLUGINDESCRIPTIONS%</a></li>
21 <li><a href="#=%FAILEDPLUGINS%="> %FAILEDPLUGINS%</a></li>
26 <li><a href="#The TWiki Plugin API"> The TWiki Plugin API</a><ul>
27 <li><a href="#Available Core Functions"> Available Core Functions</a></li>
28 <li><a href="#Predefined Hooks"> Predefined Hooks</a></li>
29 <li><a href="#Hints on Writing Fast Plugins"> Hints on Writing Fast Plugins</a></li>
30 <li><a href="#Version Detection"> Version Detection</a></li>
31 <li><a href="#Security"> Security</a></li>
34 <li><a href="#Creating Plugins"> Creating Plugins</a><ul>
35 <li><a href="#Anatomy of a Plugin"> Anatomy of a Plugin</a></li>
36 <li><a href="#Creating the Perl Module"> Creating the Perl Module </a></li>
37 <li><a href="#Writing the Documentation Topic"> Writing the Documentation Topic</a></li>
38 <li><a href="#Packaging for Distribution"> Packaging for Distribution</a></li>
39 <li><a href="#Measuring and Improving the Plug"> Measuring and Improving the Plugin Performance</a></li>
40 <li><a href="#Publishing for Public Use"> Publishing for Public Use</a></li>
43 <li><a href="#Recommended Storage of Plugin Sp"> Recommended Storage of Plugin Specific Data</a><ul>
44 <li><a href="#Plugin Internal Data"> Plugin Internal Data</a></li>
45 <li><a href="#Web Accessible Data"> Web Accessible Data</a></li>
48 <li><a href="#Integrating with configure"> Integrating with <code>configure</code></a><ul>
49 <li><a href="#Structure of a Config.spec file"> Structure of a <code>Config.spec</code> file</a></li>
52 <li><a href="#Maintaining Plugins"> Maintaining Plugins</a><ul>
53 <li><a href="#Discussions and Feedback on Plug"> Discussions and Feedback on Plugins</a></li>
54 <li><a href="#Maintaining Compatibility with E"> Maintaining Compatibility with Earlier TWiki Versions</a></li>
55 <li><a href="#Handling deprecated functions"> Handling deprecated functions</a></li>
63 ## <a name="Overview"></a> Overview
65 You can add plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you:
67 - add virtually unlimited features while keeping the main TWiki code compact and efficient;
68 - heavily customize an installation and still do clean updates to new versions of TWiki;
69 - rapidly develop new TWiki functions in Perl using the plugin API.
71 Everything to do with TWiki plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the ** TWiki:Plugins ** web.
73 TWiki plugins are developed and contributed by interested members of the community. Plugins are provided on an 'as is' basis; they are not a part of TWiki, but are independently developed and maintained.
75 **_Relevant links on TWiki.org:_**
77 - TWiki:TWiki.TWikiPluginsSupplement - **_%T% tip:_** supplemental documentation on TWiki plugins
78 - TWiki:Plugins.PluginPackage - list of all contributed plugin packages
79 - TWiki:Plugins.PluginDevelopment - discussion and feedback on contributed plugins
80 - TWiki:Plugins.PluginBrainstorming - open forum for new plugin ideas
81 - TWiki:Plugins.PluginPackageHowTo - template to create a new plugin package
83 **_See other types of extensions:_** [[TWikiAddOns]], [[TWikiContribs]], [[TWikiSkins]]
85 <a name="InstallPlugin"></a>
87 ## <a name="Installing Plugins"></a> Installing Plugins
89 Each TWiki plugin comes with its own documentation: step-by-step installation instructions, a detailed description of any special requirements, version details, and a working example for testing. Many plugins have an install script that automates these steps for you.
91 **Special Requirements:** Some plugins need certain Perl modules to be preinstalled on the host system. Plugins may also use other resources, like graphics, other modules, applications, and templates. You should be able to find detailed instructions in the plugin's documentation.
93 Each plugin has a standard release topic, located in the TWiki:Plugins web at TWiki.org. There's usually a number of other related topics, such as a developers page, and an appraisal page.
95 <a name="PreTesting"></a>
97 ### <a name="On-Site Pretesting"></a> On-Site Pretesting
99 The recommended approach to testing new plugins before making them public is to create a second local TWiki installation, and test the plugin there. You can allow selected users access to the test area. Once you are satisfied that it won't compromise your main installation, you can install it there as well.
101 [[InstalledPlugins]] shows which plugins are: 1) installed, 2) loading properly, and 3) what TWiki:Codev.PluginHandlers they invoke. Any failures are shown in the Errors section. The <code>[[%FAILEDPLUGINS%|Main/VarFAILEDPLUGINS]]</code> variable can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.
103 ### <a name="Some Notes on Plugin Performance"></a> Some Notes on Plugin Performance
105 The 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, or test manually with the Apache `ab` utility. Example on Unix:%BR% `time wget -qO /dev/null http://www.dementia.org/twiki/view/%SYSTEMWEB%/AbcPlugin`
107 %T% If you need to install an "expensive" plugin, but you only need its functionality only in a subset of your data, you can disable it elsewhere by defining the %DISABLEDPLUGINS% TWiki variable.
109 Define `DISABLEDPLUGINS` to be a comma-separated list of names of plugins to disable. Define it in %USERSWEB%.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,
111 * Set DISABLEDPLUGINS = SpreadSheetPlugin, EditTablePlugin
113 <a name="ManagingPlugins"></a>
115 ## <a name="Managing Installed Plugins"></a> Managing Installed Plugins
117 Some 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:
119 ### <a name="Enabling Plugins"></a> Enabling Plugins
121 Plugins can be enabled and disabled with the [configure](http://www.dementia.org/twiki/configure) script. An installed plugin needs to be enabled before it can be used.
123 ### <a name="Plugin Evaluation Order"></a> Plugin Evaluation Order
125 By 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](http://www.dementia.org/twiki/configure).
127 ### <a name="Plugin-Specific Settings"></a> Plugin-Specific Settings
129 Some plugins are configured with plugin preferences variables, newer plugins with configure variables.
131 Configure variables are accessible though the [configure](http://www.dementia.org/twiki/configure) interface.
133 Plugin preferences variables are defined in the plugin topic and can be overloaded. The SHORTDESCRIPTION preferences variable is always present, it is needed for the TWiki:Plugins repository on twiki.org. Example preferences variable defined in the [[TablePlugin]] topic:
135 - `Set SHORTDESCRIPTION = Control attributes of tables and sorting of table columns`
137 Preferences variables of active plugins can be retrieved anywhere in TWiki with `%<pluginname>_<var>%`, such as `%TABLEPLUGIN_SHORTDESCRIPTION%`. They can also be redefined with the `%<pluginname>_<var>%` setting at a lower level in the [[Main.TWikiPreferences|Main/TWikiPreferences]] or at the web level. For an easier upgrade it is recommended to customize plugin preferences variables in Main.TWikiPreferences only.
139 ### <a name="Listing Active Plugins"></a> Listing Active Plugins
141 Plugin status variables let you list all active plugins wherever needed.
143 This site is running TWiki version **TWiki-4.1.2, Sat, 03 Mar 2007, build 13046**, plugin API version **1\.11**
145 <a name="ActivatedPlugins"></a>
147 #### <a name="=%ACTIVATEDPLUGINS%="></a> `%ACTIVATEDPLUGINS%`
149 On this TWiki site, the enabled plugins are: [[SpreadSheetPlugin]], [[CommentPlugin]], [[EditTablePlugin]], [[InterwikiPlugin]], [[PreferencesPlugin]], [[SlideShowPlugin]], [[SmiliesPlugin]], [[TablePlugin]], [[TwistyPlugin]].
151 #### <a name="=%PLUGINDESCRIPTIONS%="></a> `%PLUGINDESCRIPTIONS%`
153 - [[SpreadSheetPlugin]] <span>(any TWiki, 10197)</span>:
154 - [[CommentPlugin]] <span>(Dakar, 11359)</span>: Allows users to quickly post comments to a page without an edit/preview/save cycle
155 - [[EditTablePlugin]] <span>(any TWiki, 11646)</span>:
156 - [[InterwikiPlugin]] <span>(Dakar, $Rev: 11935$)</span>:
157 - [[PreferencesPlugin]] <span>(Dakar, 9839)</span>:
158 - [[SlideShowPlugin]] <span>(Any TWiki, $Rev: 12847$)</span>:
159 - [[SmiliesPlugin]] <span>(Dakar, 8154)</span>:
160 - [[TablePlugin]] <span>(1.020, 12339)</span>:
161 - [[TwistyPlugin]] <span>(1.2.0, $Rev: 12154$)</span>:
163 <a name="FailedPlugins"></a>
165 #### <a name="=%FAILEDPLUGINS%="></a> `%FAILEDPLUGINS%`
173 <td>[[TWiki/SpreadSheetPlugin]]</td>
175 Plugins: could not fully register SpreadSheetPlugin, no plugin topic
179 <td>[[TWiki/CommentPlugin]]</td>
181 Plugins: could not fully register CommentPlugin, no plugin topic
185 <td>[[TWiki/EditTablePlugin]]</td>
187 Plugins: could not fully register EditTablePlugin, no plugin topic
191 <td>[[TWiki/InterwikiPlugin]]</td>
193 Plugins: could not fully register InterwikiPlugin, no plugin topic
197 <td>[[TWiki/PreferencesPlugin]]</td>
199 Plugins: could not fully register PreferencesPlugin, no plugin topic
203 <td>[[TWiki/SlideShowPlugin]]</td>
205 Plugins: could not fully register SlideShowPlugin, no plugin topic
209 <td>[[TWiki/SmiliesPlugin]]</td>
211 Plugins: could not fully register SmiliesPlugin, no plugin topic
215 <td>[[TWiki/TablePlugin]]</td>
217 Plugins: could not fully register TablePlugin, no plugin topic
221 <td>[[TWiki/TwistyPlugin]]</td>
223 Plugins: could not fully register TwistyPlugin, no plugin topic
233 <td>beforeCommonTagsHandler</td>
234 <td>PreferencesPlugin<br />TwistyPlugin</td>
237 <td>beforeSaveHandler</td>
238 <td>CommentPlugin</td>
241 <td>commonTagsHandler</td>
242 <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />SlideShowPlugin<br />SmiliesPlugin</td>
246 <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />InterwikiPlugin<br />PreferencesPlugin<br />SlideShowPlugin<br />SmiliesPlugin<br />TablePlugin<br />TwistyPlugin</td>
249 <td>postRenderingHandler</td>
250 <td>EditTablePlugin<br />PreferencesPlugin<br />TwistyPlugin</td>
253 <td>preRenderingHandler</td>
254 <td>InterwikiPlugin<br />SmiliesPlugin<br />TablePlugin</td>
260 <a name="PluginAPI"></a>
262 ## <a name="The TWiki Plugin API"></a> The TWiki Plugin API
264 The Application Programming Interface (API) for TWiki plugins provides the specifications for hooking into the core TWiki code from your external Perl plugin module.
266 ### <a name="Available Core Functions"></a> Available Core Functions
268 The [[TWikiFuncDotPm]] module (`lib/TWiki/Func.pm`) describes **all** the interfaces available to plugins. Plugins should **only** use the interfaces described in this module.
270 **_%X% Note:_** If you use other core functions not described in `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.
272 ### <a name="Predefined Hooks"></a> Predefined Hooks
274 In addition to TWiki core functions, plugins can use **predefined hooks**, or **callbacks**, as described in the `lib/TWiki/Plugins/EmptyPlugin.pm` module.
276 - All but the initPlugin are disabled. To enable a callback, remove `DISABLE_` from the function name.
278 TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
280 <a name="FastPluginHints"></a>
282 ### <a name="Hints on Writing Fast Plugins"></a> Hints on Writing Fast Plugins
284 - Delay initialization as late as possible. For example, if your plugin is a simple syntax processor, you might delay loading extra Perl modules until you actually see the syntax in the text.
285 - For example, use an `eval` block like this:%BR% `eval { require IPC::Run }` %BR% `return "<font color=\"red\">SamplePlugin: Can't load required modules ($@)</font>" if $@;`
286 - Keep the main plugin package as small as possible; create other packages that are loaded if and only if they are used. For example, create sub-packages of BathPlugin in `lib/TWiki/Plugins/BathPlugin/`.
287 - Avoid using preferences in the plugin topic; set `$NO_PREFS_IN_TOPIC` if you possibly can, as that will stop TWiki from reading the plugin topic for every page. Use [[Config.spec|Main/WebHome#ConfigSpec]] instead.
288 - Use registered tag handlers
289 - [[Measure the performance|Main/WebHome#MeasurePerformance]] to see the difference
291 ### <a name="Version Detection"></a> Version Detection
293 To eliminate the incompatibility problems that are bound to arise from active open plugin development, a plugin versioning system is provided for automatic compatibility checking.
295 - All plugin packages require a `$VERSION` variable. This should be an integer, or a subversion version id.
297 - The `initPlugin` handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong.
298 - The plugin initialization code does not register a plugin that returns 0 (or that has no `initPlugin` handler).
300 - `$TWiki::Plugins::VERSION` in the `TWiki::Plugins` module contains the TWiki plugin API version, currently **1\.11**.
301 - You can also use the <code>[[%PLUGINVERSION{}%|Main/VarPLUGINVERSION]]</code> variable to query the plugin API version or the version of installed plugins.
303 ### <a name="Security"></a> Security
305 - Badly written plugins can open huge security holes in TWiki. This is especially true if care isn't taken to prevent execution of arbitrary commands on the server.
306 - Don't allow sensitive configuration data to be edited by users. it is better to add sensitive configuration options to the `%TWiki::cfg` hash than adding it as preferences in the plugin topic.
307 - [[Integrating with configure|Main/WebHome#ConfigSpec]] describes the steps
308 - TWiki:Plugins.MailInContrib has an example
309 - TWiki:Plugins.BuildContrib can help you with this
310 - Always use the TWiki::Sandbox to execute commands.
311 - Always audit the plugins you install, and make sure you are happy with the level of security provided. While every effort is made to monitor plugin authors activities, at the end of the day they are uncontrolled user contributions.
313 <a name="CreatePlugins"></a>
315 ## <a name="Creating Plugins"></a> Creating Plugins
317 With a reasonable knowledge of the Perl scripting language, you can create new plugins or modify and extend existing ones. Basic plug-in architecture uses an Application Programming Interface (API), a set of software instructions that allow external code to interact with the main program. The [[TWiki Plugin API|Main/WebHome#PluginAPI]] provides the programming interface for TWiki.
319 ### <a name="Anatomy of a Plugin"></a> Anatomy of a Plugin
321 A (very) basic TWiki plugin consists of two files:
323 - a Perl module, e.g. `MyFirstPlugin.pm`
324 - a documentation topic, e.g. `MyFirstPlugin.txt`
326 The Perl module can be a block of code that talks to with TWiki alone, or it can include other elements, like other Perl modules (including other plugins), graphics, TWiki templates, external applications (ex: a Java applet), or just about anything else it can call. In particular, files that should be web-accessible (graphics, Java applets ...) are best placed as attachments of the `MyFirstPlugin` topic. Other needed Perl code is best placed in a `lib/TWiki/Plugins/MyFirstPlugin/` directory.
328 The plugin API handles the details of connecting your Perl module with main TWiki code. When you're familiar with the [[Plugin API|Main/WebHome#PluginAPI]], you're ready to develop plugins.
330 _The TWiki:Plugins.BuildContrib module provides a lot of support for plugins development, including a plugin creator, automatic publishing support, and automatic installation script writer. If you plan on writing more than one plugin, you probably need it_.
332 ### <a name="Creating the Perl Module"></a> Creating the Perl Module
334 Copy file `lib/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|Main/WebHome#PluginAPI]] specs for more information.
336 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:
338 use TWiki::Plugins::MyFirstPlugin::Attrs;
339 $var = MyFirstPlugin::Attrs->new();
341 <a name="CreatePluginTopic"></a>
343 ### <a name="Writing the Documentation Topic"></a> Writing the Documentation Topic
345 The plugin documentation topic contains usage instructions and version details. It serves the plugin files as %SYSTEMWEB%.FileAttachments for downloading. (The doc topic is also included _in_ the [[distribution package|Main/WebHome#CreatePluginPackage]].) To create a documentation topic:
347 1. **Copy** the plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:
348 - enter the plugin name in the "How to Create a Plugin" section
350 - select all in the Edit box & copy
352 - go back to your site to the %SYSTEMWEB% web
353 - In the [[GoBox]] enter your plugin name, for example `MyFirstPlugin`, press enter and create the new topic
354 - paste & save new plugin topic on your site
355 2. **Customize** your plugin topic.
356 - Important: In case you plan to publish your plugin on TWiki.org, use Interwiki names for author names and links to TWiki.org topics, such as TWiki:Main/admin. This is important because links should work properly in a plugin topic installed on any TWiki, not just on TWiki.org.
357 3. **Document** the performance data you gathered while [[measuring the performance|Main/WebHome#MeasurePerformance]]
358 4. **Save** your topic, for use in [[packaging|Main/WebHome#CreatePluginPackage]] and [[publishing|Main/WebHome#PublishPlugin]] your plugin.
360 > **OUTLINE: Doc Topic Contents**
364 > Check the plugins web on TWiki.org for the latest plugin doc topic template. Here's a quick overview of what's covered:
366 > **Syntax Rules:** <_Describe any special text formatting that will be rendered._>"
368 > **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!_>"
370 > **Plugin Settings:** <_Description and settings for custom plugin %VARIABLES%, and those required by TWiki._>"
372 > - **Plugins Preferences** <_If user settings are needed, explain... Entering values works exactly like %SYSTEMWEB%.TWikiPreferences and [[WebPreferences]]: six (6) spaces and then:_>"
373 > - **Set <_EXAMPLE = value added_>**
375 > **Plugin Installation Instructions:** <_Step-by-step set-up guide, user help, whatever it takes to install and run, goes here._>"
377 > **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:Plugins web._>"
379 <a name="CreatePluginPackage"></a>
381 ### <a name="Packaging for Distribution"></a> Packaging for Distribution
383 The TWiki:Plugins.BuildContrib is a powerful build environment that is used by the TWiki project to build TWiki itself, as well as many of the plugins. You don't **have** to use it, but it is highly recommended!
385 If you don't want (or can't) use the BuildContrib, then a minimum plugin release consists of a Perl module with a [[WikiName]] that ends in `Plugin`, ex: `MyFirstPlugin.pm`, and a documentation page with the same name(`MyFirstPlugin.txt`).
387 1. Distribute the plugin files in a directory structure that mirrors TWiki. If your plugin uses additional files, include them all:
388 - `lib/TWiki/Plugins/MyFirstPlugin.pm`
389 - `data/TWiki/MyFirstPlugin.txt`
390 - `pub/TWiki/MyFirstPlugin/uparrow.gif` [a required graphic]
391 2. Create a zip archive with the plugin name (`MyFirstPlugin.zip`) and add the entire directory structure from Step 1. The archive should look like this:
392 - `lib/TWiki/Plugins/MyFirstPlugin.pm`
393 - `data/TWiki/MyFirstPlugin.txt`
394 - `pub/TWiki/MyFirstPlugin/uparrow.gif`
396 <a name="MeasurePerformance"></a>
398 ### <a name="Measuring and Improving the Plug"></a> Measuring and Improving the Plugin Performance
400 A high quality plugin performs well. You can use the TWiki:Plugins.PluginBenchmarkAddOn to measure your TWiki:Plugins.PluginBenchmarks. The data is needed as part of the Documentation Topic.
402 See also [[Hints on Writing Fast Plugins|Main/WebHome#FastPluginHints]].
404 <a name="PublishPlugin"></a>
406 ### <a name="Publishing for Public Use"></a> Publishing for Public Use
408 You can release your tested, packaged plugin to the TWiki community through the TWiki:Plugins web. All plugins submitted to TWiki.org are available for download and further development in TWiki:Plugins/PluginPackage.
410 Publish your plugin by following these steps:
412 1. **Post** the plugin documentation topic in the TWiki:Plugins/PluginPackage:
413 - enter the plugin name in the "How to Create a Plugin" section, for example `MyFirstPlugin`
414 - paste in the topic text from [[Writing the Documentation Topic|Main/WebHome#CreatePluginTopic]] and save
415 2. **Attach** the distribution zip file to the topic, ex: `MyFirstPlugin.zip`
416 3. **Link** from the doc page to a new, blank page named after the plugin, and ending in `Dev`, ex: `MyFirstPluginDev`. This is the discussion page for future development. (User support for plugins is handled in TWiki:Support.)
417 4. **Put** the plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)
419 %N% Once you have done the above steps once, you can use the BuildContrib to upload updates to your plugin.
421 Thank you very much for sharing your plugin with the TWiki community :-)
423 <a name="RecommendedStorageOfPluginData"></a>
425 ## <a name="Recommended Storage of Plugin Sp"></a> Recommended Storage of Plugin Specific Data
427 Plugins sometimes need to store data. This can be plugin internal data such as cache data, or data generated for browser consumption such as images. Plugins should store data using [[TWikiFuncDotPm]] functions that support saving and loading of topics and attachments.
429 ### <a name="Plugin Internal Data"></a> Plugin Internal Data
431 You can create a plugin "work area" using the `TWiki::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.
433 ### <a name="Web Accessible Data"></a> Web Accessible Data
435 **_Topic-specific data_** such as generated images can be stored in the topic's attachment area, which is web accessible. Use the `TWiki::Func::saveAttachment()` function to store the data.
437 Recommendation for file name:
439 - Prefix the filename with an underscore (the leading underscore avoids a name clash with files attached to the same topic)
440 - Identify where the attachment originated from, typically by including the plugin name in the file name
441 - Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
442 - Example: `_GaugePlugin_img123.gif`
444 **_Web specific data_** can be stored in the plugin's attachment area, which is web accessible. Use the `TWiki::Func::saveAttachment()` function to store the data.
446 Recommendation for file names in plugin attachment area:
448 - Prefix the filename with an underscore
449 - Include the name of the web in the filename
450 - Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
451 - Example: `_Main_roundedge-ul.gif`
453 <a name="ConfigSpec"></a>
455 ## <a name="Integrating with configure"></a> Integrating with `configure`
457 Some TWiki extensions have setup requirements that are best integrated into `configure` rather than trying to use TWiki preferences variables. These extensions use `Config.spec` files to publish their configuration requirements.
459 `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`.
461 ### <a name="Structure of a Config.spec file"></a> Structure of a `Config.spec` file
463 The `Config.spec` file for a plugin starts with the plugin announcing what it is:
466 # This plugin senses the level of water in your bath, and ensures the plug
467 # is not removed while the water is still warm.
469 This is followed by one or more configuration items. Each configuration item has a _type_, a _description_ and a _default_. For example:
471 # **SELECT Plastic,Rubber,Metal**
472 # Select the plug type
473 $TWiki::cfg{BathPlugin}{PlugType} = 'Plastic';
476 # Enter the chain length in cm
477 $TWiki::cfg{BathPlugin}{ChainLength} = '30';
480 # Turn this option off to disable the water temperature alarm
481 $TWiki::cfg{BathPlugin}{TempSensorEnabled} = '1';
483 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,
485 if( $TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) {
486 die "The bathwater is too hot for comfort";
489 The config.spec file is read by configure, and `configure` then writes `LocalSite.cfg` with the values chosen by the local site admin.
491 A range of types are available for use in `Config.spec` files:
493 <table border="1" cellpadding="0" cellspacing="0">
496 <td> A true/false value, represented as a checkbox </td>
499 <td> COMMAND <em>length</em></td>
500 <td> A shell command </td>
504 <td> A language (selected from <code>{LocalesDir}</code></td>
512 <td> An octal number </td>
515 <td> PASSWORD <em>length</em></td>
516 <td> A password (input is hidden) </td>
519 <td> PATH <em>length</em></td>
520 <td> A file path </td>
524 <td> A perl structure, consisting of arrays and hashes </td>
527 <td> REGEX <em>length</em></td>
528 <td> A perl regular expression </td>
531 <td> SELECT <em>choices</em></td>
532 <td> Pick one of a range of choices </td>
535 <td> SELECTCLASS <em>root</em></td>
536 <td> Select a perl package (class) </td>
539 <td> STRING <em>length</em></td>
543 <td> URL <em>length</em></td>
547 <td> URLPATH <em>length</em></td>
548 <td> A relative URL path </td>
552 All types can be followed by a comma-separated list of _attributes_.
554 <table border="1" cellpadding="0" cellspacing="0">
557 <td> means this an expert option </td>
561 <td> means the setting is mandatory (may not be empty) </td>
565 <td> means the option is not visible in <code>configure</code></td>
569 See `lib/TWiki.spec` for many more examples.
571 `Config.spec` files are also used for other (non-plugin) extensions. in this case they are stored under the `Contrib` directory instead of the `Plugins` directory.
573 TWiki:TWiki/SpecifyingConfigurationItemsForExtensions has supplemental documentation on configure settings.
575 <a name="MaintainPlugins"></a>
577 ## <a name="Maintaining Plugins"></a> Maintaining Plugins
579 ### <a name="Discussions and Feedback on Plug"></a> Discussions and Feedback on Plugins
581 Each published plugin has a plugin development topic on TWiki.org. Plugin development topics are named after your plugin and end in `Dev`, such as `MyFirstPluginDev`. The plugin development topic is a great resource to discuss feature enhancements and to get feedback from the TWiki community.
583 ### <a name="Maintaining Compatibility with E"></a> Maintaining Compatibility with Earlier TWiki Versions
585 The plugin interface ([[TWikiFuncDotPm]] functions and plugin handlers) evolve over time. TWiki introduces new API functions to address the needs of plugin authors. Plugins using unofficial TWiki internal functions may no longer work on a TWiki upgrade.
587 Organizations typically do not upgrade to the latest TWiki for many months. However, many administrators still would like to install the latest versions of a plugin on their older TWiki installation. This need is fulfilled if plugins are maintained in a compatible manner.
589 **_%T% Tip:_** Plugins can be written to be compatible with older and newer TWiki releases. This can be done also for plugins using unofficial TWiki internal functions of an earlier release that no longer work on the latest TWiki codebase. Here is an example; the TWiki:TWiki.TWikiPluginsSupplement#MaintainPlugins has more details.
591 if( $TWiki::Plugins::VERSION >= 1.1 ) {
592 @webs = TWiki::Func::getListOfWebs( 'user,public' );
594 @webs = TWiki::Func::getPublicWebList( );
597 ### <a name="Handling deprecated functions"></a> Handling deprecated functions
599 From time-to-time, the TWiki developers will add new functions to the interface (either to [[TWikiFuncDotPm]], or new handlers). Sometimes these improvements mean that old functions have to be deprecated to keep the code manageable. When this happens, the deprecated functions will be supported in the interface for at least one more TWiki release, and probably longer, though this cannot be guaranteed.
601 When a plugin defines deprecated handlers, a warning will be shown in the list generated by %FAILEDPLUGINS%. Admins who see these warnings should check TWiki.org and if necessary, contact the plugin author, for an updated version of the plugin.
603 Updated plugins may still need to define deprecated handlers for compatibility with old TWiki versions. In this case, the plugin package that defines old handlers can suppress the warnings in %FAILEDPLUGINS%.
605 This is done by defining a map from the handler name to the `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:
607 package TWiki::Plugins::SinkPlugin;
608 use vars qw( %TWikiCompatibility );
609 $TWikiCompatibility{endRenderingHandler} = 1.1;
611 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.
613 **_Related Topics:_** [[DeveloperDocumentationCategory]], [[AdminDocumentationCategory]], TWiki:TWiki.TWikiPluginsSupplement
615 -- **_Contributors:_** TWiki:Main.PeterThoeny, TWiki:Main.AndreaSterbini, TWiki:Main.MikeMannix, TWiki:Main.CrawfordCurrie, TWiki:Main.ArthurClemens, TWiki:Main.WillNorris