none
[openafs-wiki.git] / TWiki / TWikiPlugins.mdwn
1 # <a name="TWiki Plugins"></a> TWiki Plugins
2
3 _Add functionality to TWiki with readily available plugins; create plugins based on APIs_
4
5 <div>
6   <ul>
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>
12           </ul>
13         </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>
22               </ul>
23             </li>
24           </ul>
25         </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>
32           </ul>
33         </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>
41           </ul>
42         </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>
46           </ul>
47         </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>
50           </ul>
51         </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>
56           </ul>
57         </li>
58       </ul>
59     </li>
60   </ul>
61 </div>
62
63 ## <a name="Overview"></a> Overview
64
65 You can add plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you:
66
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.
70
71 Everything to do with TWiki plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the ** TWiki:Plugins ** web.
72
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.
74
75 **_Relevant links on TWiki.org:_**
76
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
82
83 **_See other types of extensions:_** [[TWikiAddOns]], [[TWikiContribs]], [[TWikiSkins]]
84
85 <a name="InstallPlugin"></a>
86
87 ## <a name="Installing Plugins"></a> Installing Plugins
88
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.
90
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.
92
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.
94
95 <a name="PreTesting"></a>
96
97 ### <a name="On-Site Pretesting"></a> On-Site Pretesting
98
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.
100
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.
102
103 ### <a name="Some Notes on Plugin Performance"></a> Some Notes on Plugin Performance
104
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`
106
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.
108
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,
110
111        * Set DISABLEDPLUGINS = SpreadSheetPlugin, EditTablePlugin
112
113 <a name="ManagingPlugins"></a>
114
115 ## <a name="Managing Installed Plugins"></a> Managing Installed Plugins
116
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:
118
119 ### <a name="Enabling Plugins"></a> Enabling Plugins
120
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.
122
123 ### <a name="Plugin Evaluation Order"></a> Plugin Evaluation Order
124
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).
126
127 ### <a name="Plugin-Specific Settings"></a> Plugin-Specific Settings
128
129 Some plugins are configured with plugin preferences variables, newer plugins with configure variables.
130
131 Configure variables are accessible though the [configure](http://www.dementia.org/twiki/configure) interface.
132
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:
134
135 - `Set SHORTDESCRIPTION = Control attributes of tables and sorting of table columns`
136
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.
138
139 ### <a name="Listing Active Plugins"></a> Listing Active Plugins
140
141 Plugin status variables let you list all active plugins wherever needed.
142
143 This site is running TWiki version **TWiki-4.1.2, Sat, 03 Mar 2007, build 13046**, plugin API version **1\.11**
144
145 <a name="ActivatedPlugins"></a>
146
147 #### <a name="=%ACTIVATEDPLUGINS%="></a> `%ACTIVATEDPLUGINS%`
148
149 On this TWiki site, the enabled plugins are: [[SpreadSheetPlugin]], [[CommentPlugin]], [[EditTablePlugin]], [[InterwikiPlugin]], [[PreferencesPlugin]], [[SlideShowPlugin]], [[SmiliesPlugin]], [[TablePlugin]], [[TwistyPlugin]].
150
151 #### <a name="=%PLUGINDESCRIPTIONS%="></a> `%PLUGINDESCRIPTIONS%`
152
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>:
162
163 <a name="FailedPlugins"></a>
164
165 #### <a name="=%FAILEDPLUGINS%="></a> `%FAILEDPLUGINS%`
166
167 <table border="1">
168   <tr>
169     <th>Plugin</th>
170     <th>Errors</th>
171   </tr>
172   <tr valign="top">
173     <td>[[TWiki/SpreadSheetPlugin]]</td>
174     <td><pre>
175 Plugins: could not fully register SpreadSheetPlugin, no plugin topic
176 </pre></td>
177   </tr>
178   <tr valign="top">
179     <td>[[TWiki/CommentPlugin]]</td>
180     <td><pre>
181 Plugins: could not fully register CommentPlugin, no plugin topic
182 </pre></td>
183   </tr>
184   <tr valign="top">
185     <td>[[TWiki/EditTablePlugin]]</td>
186     <td><pre>
187 Plugins: could not fully register EditTablePlugin, no plugin topic
188 </pre></td>
189   </tr>
190   <tr valign="top">
191     <td>[[TWiki/InterwikiPlugin]]</td>
192     <td><pre>
193 Plugins: could not fully register InterwikiPlugin, no plugin topic
194 </pre></td>
195   </tr>
196   <tr valign="top">
197     <td>[[TWiki/PreferencesPlugin]]</td>
198     <td><pre>
199 Plugins: could not fully register PreferencesPlugin, no plugin topic
200 </pre></td>
201   </tr>
202   <tr valign="top">
203     <td>[[TWiki/SlideShowPlugin]]</td>
204     <td><pre>
205 Plugins: could not fully register SlideShowPlugin, no plugin topic
206 </pre></td>
207   </tr>
208   <tr valign="top">
209     <td>[[TWiki/SmiliesPlugin]]</td>
210     <td><pre>
211 Plugins: could not fully register SmiliesPlugin, no plugin topic
212 </pre></td>
213   </tr>
214   <tr valign="top">
215     <td>[[TWiki/TablePlugin]]</td>
216     <td><pre>
217 Plugins: could not fully register TablePlugin, no plugin topic
218 </pre></td>
219   </tr>
220   <tr valign="top">
221     <td>[[TWiki/TwistyPlugin]]</td>
222     <td><pre>
223 Plugins: could not fully register TwistyPlugin, no plugin topic
224 </pre></td>
225   </tr>
226 </table>
227 <table border="1">
228   <tr>
229     <th>Handler</th>
230     <th>Plugins</th>
231   </tr>
232   <tr valign="top">
233     <td>beforeCommonTagsHandler</td>
234     <td>PreferencesPlugin<br />TwistyPlugin</td>
235   </tr>
236   <tr valign="top">
237     <td>beforeSaveHandler</td>
238     <td>CommentPlugin</td>
239   </tr>
240   <tr valign="top">
241     <td>commonTagsHandler</td>
242     <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />SlideShowPlugin<br />SmiliesPlugin</td>
243   </tr>
244   <tr valign="top">
245     <td>initPlugin</td>
246     <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />InterwikiPlugin<br />PreferencesPlugin<br />SlideShowPlugin<br />SmiliesPlugin<br />TablePlugin<br />TwistyPlugin</td>
247   </tr>
248   <tr valign="top">
249     <td>postRenderingHandler</td>
250     <td>EditTablePlugin<br />PreferencesPlugin<br />TwistyPlugin</td>
251   </tr>
252   <tr valign="top">
253     <td>preRenderingHandler</td>
254     <td>InterwikiPlugin<br />SmiliesPlugin<br />TablePlugin</td>
255   </tr>
256 </table>
257
258 **9 plugins**
259
260 <a name="PluginAPI"></a>
261
262 ## <a name="The TWiki Plugin API"></a> The TWiki Plugin API
263
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.
265
266 ### <a name="Available Core Functions"></a> Available Core Functions
267
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.
269
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.
271
272 ### <a name="Predefined Hooks"></a> Predefined Hooks
273
274 In addition to TWiki core functions, plugins can use **predefined hooks**, or **callbacks**, as described in the `lib/TWiki/Plugins/EmptyPlugin.pm` module.
275
276 - All but the initPlugin are disabled. To enable a callback, remove `DISABLE_` from the function name.
277
278 TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
279
280 <a name="FastPluginHints"></a>
281
282 ### <a name="Hints on Writing Fast Plugins"></a> Hints on Writing Fast Plugins
283
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
290
291 ### <a name="Version Detection"></a> Version Detection
292
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.
294
295 - All plugin packages require a `$VERSION` variable. This should be an integer, or a subversion version id.
296
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).
299
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.
302
303 ### <a name="Security"></a> Security
304
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.
312
313 <a name="CreatePlugins"></a>
314
315 ## <a name="Creating Plugins"></a> Creating Plugins
316
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.
318
319 ### <a name="Anatomy of a Plugin"></a> Anatomy of a Plugin
320
321 A (very) basic TWiki plugin consists of two files:
322
323 - a Perl module, e.g. `MyFirstPlugin.pm`
324 - a documentation topic, e.g. `MyFirstPlugin.txt`
325
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.
327
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.
329
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_.
331
332 ### <a name="Creating the Perl Module"></a> Creating the Perl Module
333
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.
335
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:
337
338     use TWiki::Plugins::MyFirstPlugin::Attrs;
339     $var = MyFirstPlugin::Attrs->new();
340
341 <a name="CreatePluginTopic"></a>
342
343 ### <a name="Writing the Documentation Topic"></a> Writing the Documentation Topic
344
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:
346
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
349   - click Create
350   - select all in the Edit box &amp; copy
351   - Cancel the edit
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 &amp; 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.
359
360 > **OUTLINE: Doc Topic Contents**
361 >
362 > <br />
363 >
364 > Check the plugins web on TWiki.org for the latest plugin doc topic template. Here's a quick overview of what's covered:
365 >
366 > **Syntax Rules:** &lt;_Describe any special text formatting that will be rendered._&gt;"
367 >
368 > **Example:** &lt;_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!_&gt;"
369 >
370 > **Plugin Settings:** &lt;_Description and settings for custom plugin %VARIABLES%, and those required by TWiki._&gt;"
371 >
372 > - **Plugins Preferences** &lt;_If user settings are needed, explain... Entering values works exactly like %SYSTEMWEB%.TWikiPreferences and [[WebPreferences]]: six (6) spaces and then:_&gt;"
373 >   - **Set &lt;_EXAMPLE = value added_&gt;**
374 >
375 > **Plugin Installation Instructions:** &lt;_Step-by-step set-up guide, user help, whatever it takes to install and run, goes here._&gt;"
376 >
377 > **Plugin Info:** &lt;_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._&gt;"
378
379 <a name="CreatePluginPackage"></a>
380
381 ### <a name="Packaging for Distribution"></a> Packaging for Distribution
382
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!
384
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`).
386
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`
395
396 <a name="MeasurePerformance"></a>
397
398 ### <a name="Measuring and Improving the Plug"></a> Measuring and Improving the Plugin Performance
399
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.
401
402 See also [[Hints on Writing Fast Plugins|Main/WebHome#FastPluginHints]].
403
404 <a name="PublishPlugin"></a>
405
406 ### <a name="Publishing for Public Use"></a> Publishing for Public Use
407
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.
409
410 Publish your plugin by following these steps:
411
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)
418
419 %N% Once you have done the above steps once, you can use the BuildContrib to upload updates to your plugin.
420
421 Thank you very much for sharing your plugin with the TWiki community :-)
422
423 <a name="RecommendedStorageOfPluginData"></a>
424
425 ## <a name="Recommended Storage of Plugin Sp"></a> Recommended Storage of Plugin Specific Data
426
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.
428
429 ### <a name="Plugin Internal Data"></a> Plugin Internal Data
430
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.
432
433 ### <a name="Web Accessible Data"></a> Web Accessible Data
434
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.
436
437 Recommendation for file name:
438
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`
443
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.
445
446 Recommendation for file names in plugin attachment area:
447
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`
452
453 <a name="ConfigSpec"></a>
454
455 ## <a name="Integrating with configure"></a> Integrating with `configure`
456
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.
458
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`.
460
461 ### <a name="Structure of a Config.spec file"></a> Structure of a `Config.spec` file
462
463 The `Config.spec` file for a plugin starts with the plugin announcing what it is:
464
465     # ---+ BathPlugin
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.
468
469 This is followed by one or more configuration items. Each configuration item has a _type_, a _description_ and a _default_. For example:
470
471     # **SELECT Plastic,Rubber,Metal**
472     # Select the plug type
473     $TWiki::cfg{BathPlugin}{PlugType} = 'Plastic';
474
475     # **NUMBER**
476     # Enter the chain length in cm
477     $TWiki::cfg{BathPlugin}{ChainLength} = '30';
478
479     # **BOOLEAN EXPERT**
480     # Turn this option off to disable the water temperature alarm
481     $TWiki::cfg{BathPlugin}{TempSensorEnabled} = '1';
482
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,
484
485     if( $TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) {
486         die "The bathwater is too hot for comfort";
487     }
488
489 The config.spec file is read by configure, and `configure` then writes `LocalSite.cfg` with the values chosen by the local site admin.
490
491 A range of types are available for use in `Config.spec` files:
492
493 <table border="1" cellpadding="0" cellspacing="0">
494   <tr>
495     <td> BOOLEAN </td>
496     <td> A true/false value, represented as a checkbox </td>
497   </tr>
498   <tr>
499     <td> COMMAND <em>length</em></td>
500     <td> A shell command </td>
501   </tr>
502   <tr>
503     <td> LANGUAGE </td>
504     <td> A language (selected from <code>{LocalesDir}</code></td>
505   </tr>
506   <tr>
507     <td> NUMBER </td>
508     <td> A number </td>
509   </tr>
510   <tr>
511     <td> OCTAL </td>
512     <td> An octal number </td>
513   </tr>
514   <tr>
515     <td> PASSWORD <em>length</em></td>
516     <td> A password (input is hidden) </td>
517   </tr>
518   <tr>
519     <td> PATH <em>length</em></td>
520     <td> A file path </td>
521   </tr>
522   <tr>
523     <td> PERL </td>
524     <td> A perl structure, consisting of arrays and hashes </td>
525   </tr>
526   <tr>
527     <td> REGEX <em>length</em></td>
528     <td> A perl regular expression </td>
529   </tr>
530   <tr>
531     <td> SELECT <em>choices</em></td>
532     <td> Pick one of a range of choices </td>
533   </tr>
534   <tr>
535     <td> SELECTCLASS <em>root</em></td>
536     <td> Select a perl package (class) </td>
537   </tr>
538   <tr>
539     <td> STRING <em>length</em></td>
540     <td> A string </td>
541   </tr>
542   <tr>
543     <td> URL <em>length</em></td>
544     <td> A url </td>
545   </tr>
546   <tr>
547     <td> URLPATH <em>length</em></td>
548     <td> A relative URL path </td>
549   </tr>
550 </table>
551
552 All types can be followed by a comma-separated list of _attributes_.
553
554 <table border="1" cellpadding="0" cellspacing="0">
555   <tr>
556     <td> EXPERT </td>
557     <td> means this an expert option </td>
558   </tr>
559   <tr>
560     <td> M </td>
561     <td> means the setting is mandatory (may not be empty) </td>
562   </tr>
563   <tr>
564     <td> H </td>
565     <td> means the option is not visible in <code>configure</code></td>
566   </tr>
567 </table>
568
569 See `lib/TWiki.spec` for many more examples.
570
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.
572
573 TWiki:TWiki/SpecifyingConfigurationItemsForExtensions has supplemental documentation on configure settings.
574
575 <a name="MaintainPlugins"></a>
576
577 ## <a name="Maintaining Plugins"></a> Maintaining Plugins
578
579 ### <a name="Discussions and Feedback on Plug"></a> Discussions and Feedback on Plugins
580
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.
582
583 ### <a name="Maintaining Compatibility with E"></a> Maintaining Compatibility with Earlier TWiki Versions
584
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.
586
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.
588
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.
590
591         if( $TWiki::Plugins::VERSION >= 1.1 ) {
592             @webs = TWiki::Func::getListOfWebs( 'user,public' );
593         } else {
594             @webs = TWiki::Func::getPublicWebList( );
595         }
596
597 ### <a name="Handling deprecated functions"></a> Handling deprecated functions
598
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.
600
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.
602
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%.
604
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:
606
607     package TWiki::Plugins::SinkPlugin;
608     use vars qw( %TWikiCompatibility );
609     $TWikiCompatibility{endRenderingHandler} = 1.1;
610
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.
612
613 **_Related Topics:_** [[DeveloperDocumentationCategory]], [[AdminDocumentationCategory]], TWiki:TWiki.TWikiPluginsSupplement
614
615 -- **_Contributors:_** TWiki:Main.PeterThoeny, TWiki:Main.AndreaSterbini, TWiki:Main.MikeMannix, TWiki:Main.CrawfordCurrie, TWiki:Main.ArthurClemens, TWiki:Main.WillNorris