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 Plugins are usually configured by variables accessible though the [configure](http://www.dementia.org/twiki/configure) interface, but in some cases (usually older plugins) TWiki preferences are used. If a TWiki variable is defined in a Plugin topic e.g:
130
131 - Set SETTING = Create dynamic foo bar reports
132
133 Then these settings can be retrieved as preferences variables like `%<pluginname>_<var>%`. For example, `%RUBBERPLUGIN_SETTING%` shows the value of SETTING in the RubberPlugin topic.
134
135 ### <a name="Listing Active Plugins"></a> Listing Active Plugins
136
137 Plugin status variables let you list all active Plugins wherever needed.
138
139 This site is running TWiki version **TWiki-4.1.2, Sat, 03 Mar 2007, build 13046**, Plugin API version **1\.11**
140
141 <a name="ActivatedPlugins"></a>
142
143 #### <a name="=%ACTIVATEDPLUGINS%="></a> `%ACTIVATEDPLUGINS%`
144
145 On this TWiki site, the enabled Plugins are: [[SpreadSheetPlugin]], [[CommentPlugin]], [[EditTablePlugin]], [[InterwikiPlugin]], [[PreferencesPlugin]], [[SlideShowPlugin]], [[SmiliesPlugin]], [[TablePlugin]], [[TwistyPlugin]].
146
147 #### <a name="=%PLUGINDESCRIPTIONS%="></a> `%PLUGINDESCRIPTIONS%`
148
149 - [[SpreadSheetPlugin]] <span>(any TWiki, 10197)</span>:
150 - [[CommentPlugin]] <span>(Dakar, 11359)</span>: Allows users to quickly post comments to a page without an edit/preview/save cycle
151 - [[EditTablePlugin]] <span>(any TWiki, 11646)</span>:
152 - [[InterwikiPlugin]] <span>(Dakar, $Rev: 11935$)</span>:
153 - [[PreferencesPlugin]] <span>(Dakar, 9839)</span>:
154 - [[SlideShowPlugin]] <span>(Any TWiki, $Rev: 12847$)</span>:
155 - [[SmiliesPlugin]] <span>(Dakar, 8154)</span>:
156 - [[TablePlugin]] <span>(1.020, 12339)</span>:
157 - [[TwistyPlugin]] <span>(1.2.0, $Rev: 12154$)</span>:
158
159 <a name="FailedPlugins"></a>
160
161 #### <a name="=%FAILEDPLUGINS%="></a> `%FAILEDPLUGINS%`
162
163 <table border="1">
164   <tr>
165     <th>Plugin</th>
166     <th>Errors</th>
167   </tr>
168   <tr valign="top">
169     <td>[[TWiki/SpreadSheetPlugin]]</td>
170     <td><pre>
171 Plugins: could not fully register SpreadSheetPlugin, no plugin topic
172 </pre></td>
173   </tr>
174   <tr valign="top">
175     <td>[[TWiki/CommentPlugin]]</td>
176     <td><pre>
177 Plugins: could not fully register CommentPlugin, no plugin topic
178 </pre></td>
179   </tr>
180   <tr valign="top">
181     <td>[[TWiki/EditTablePlugin]]</td>
182     <td><pre>
183 Plugins: could not fully register EditTablePlugin, no plugin topic
184 </pre></td>
185   </tr>
186   <tr valign="top">
187     <td>[[TWiki/InterwikiPlugin]]</td>
188     <td><pre>
189 Plugins: could not fully register InterwikiPlugin, no plugin topic
190 </pre></td>
191   </tr>
192   <tr valign="top">
193     <td>[[TWiki/PreferencesPlugin]]</td>
194     <td><pre>
195 Plugins: could not fully register PreferencesPlugin, no plugin topic
196 </pre></td>
197   </tr>
198   <tr valign="top">
199     <td>[[TWiki/SlideShowPlugin]]</td>
200     <td><pre>
201 Plugins: could not fully register SlideShowPlugin, no plugin topic
202 </pre></td>
203   </tr>
204   <tr valign="top">
205     <td>[[TWiki/SmiliesPlugin]]</td>
206     <td><pre>
207 Plugins: could not fully register SmiliesPlugin, no plugin topic
208 </pre></td>
209   </tr>
210   <tr valign="top">
211     <td>[[TWiki/TablePlugin]]</td>
212     <td><pre>
213 Plugins: could not fully register TablePlugin, no plugin topic
214 </pre></td>
215   </tr>
216   <tr valign="top">
217     <td>[[TWiki/TwistyPlugin]]</td>
218     <td><pre>
219 Plugins: could not fully register TwistyPlugin, no plugin topic
220 </pre></td>
221   </tr>
222 </table>
223 <table border="1">
224   <tr>
225     <th>Handler</th>
226     <th>Plugins</th>
227   </tr>
228   <tr valign="top">
229     <td>beforeCommonTagsHandler</td>
230     <td>PreferencesPlugin<br />TwistyPlugin</td>
231   </tr>
232   <tr valign="top">
233     <td>beforeSaveHandler</td>
234     <td>CommentPlugin</td>
235   </tr>
236   <tr valign="top">
237     <td>commonTagsHandler</td>
238     <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />SlideShowPlugin<br />SmiliesPlugin</td>
239   </tr>
240   <tr valign="top">
241     <td>initPlugin</td>
242     <td>SpreadSheetPlugin<br />CommentPlugin<br />EditTablePlugin<br />InterwikiPlugin<br />PreferencesPlugin<br />SlideShowPlugin<br />SmiliesPlugin<br />TablePlugin<br />TwistyPlugin</td>
243   </tr>
244   <tr valign="top">
245     <td>postRenderingHandler</td>
246     <td>EditTablePlugin<br />PreferencesPlugin<br />TwistyPlugin</td>
247   </tr>
248   <tr valign="top">
249     <td>preRenderingHandler</td>
250     <td>InterwikiPlugin<br />SmiliesPlugin<br />TablePlugin</td>
251   </tr>
252 </table>
253
254 **9 plugins**
255
256 <a name="PluginAPI"></a>
257
258 ## <a name="The TWiki Plugin API"></a> The TWiki Plugin API
259
260 The Application Programming Interface (API) for TWiki Plugins provides the specifications for hooking into the core TWiki code from your external Perl Plugin module.
261
262 ### <a name="Available Core Functions"></a> Available Core Functions
263
264 The [[TWikiFuncDotPm]] module (`lib/TWiki/Func.pm`) describes **all** the interfaces available to Plugins. Plugins should **only** use the interfaces described in this module.
265
266 **_%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.
267
268 ### <a name="Predefined Hooks"></a> Predefined Hooks
269
270 In addition to TWiki core functions, Plugins can use **predefined hooks**, or **callbacks**, as described in the `lib/TWiki/Plugins/EmptyPlugin.pm` module.
271
272 - All but the initPlugin are disabled. To enable a callback, remove `DISABLE_` from the function name.
273
274 TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
275
276 <a name="FastPluginHints"></a>
277
278 ### <a name="Hints on Writing Fast Plugins"></a> Hints on Writing Fast Plugins
279
280 - 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.
281   - 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 $@;`
282 - 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/`.
283 - 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.
284 - Use registered tag handlers
285 - [[Measure the performance|Main/WebHome#MeasurePerformance]] to see the difference
286
287 ### <a name="Version Detection"></a> Version Detection
288
289 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.
290
291 - All plugin packages require a `$VERSION` variable. This should be an integer, or a subversion version id.
292
293 - The `initPlugin` handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong.
294   - The Plugin initialization code does not register a Plugin that returns 0 (or that has no `initPlugin` handler).
295
296 - `$TWiki::Plugins::VERSION` in the `TWiki::Plugins` module contains the TWiki Plugin API version, currently **1\.11**.
297   - You can also use the <code>[[%PLUGINVERSION{}%|Main/VarPLUGINVERSION]]</code> variable to query the Plugin API version or the version of installed Plugins.
298
299 ### <a name="Security"></a> Security
300
301 - 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.
302 - 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
303   - See TWiki:Plugins.MailInContrib for an example of this
304   - TWiki:Plugins.BuildContrib can help you with this
305 - Always use the TWiki::Sandbox to execute commands.
306 - 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.
307
308 <a name="CreatePlugins"></a>
309
310 ## <a name="Creating Plugins"></a> Creating Plugins
311
312 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]] Plugins by providing a programming interface for TWiki.
313
314 ### <a name="Anatomy of a Plugin"></a> Anatomy of a Plugin
315
316 A (very) basic TWiki Plugin consists of two files:
317
318 - a Perl module, e.g. `MyFirstPlugin.pm`
319 - a documentation topic, e.g. `MyFirstPlugin.txt`
320
321 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.
322
323 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.
324
325 _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_.
326
327 ### <a name="Creating the Perl Module"></a> Creating the Perl Module
328
329 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.
330
331 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:
332
333     use TWiki::Plugins::MyFirstPlugin::Attrs;
334     $var = MyFirstPlugin::Attrs->new();
335
336 <a name="CreatePluginTopic"></a>
337
338 ### <a name="Writing the Documentation Topic"></a> Writing the Documentation Topic
339
340 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:
341
342 1. **Copy** the Plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:
343   - enter the Plugin name in the "How to Create a Plugin" section
344   - click Create
345   - select all in the Edit box &amp; copy
346   - Cancel the edit
347   - go back to your site to the %SYSTEMWEB% web
348   - In the [[GoBox]] enter your Plugin name, for example `MyFirstPlugin`, press enter and create the new topic
349   - paste &amp; save new Plugin topic on your site
350 2. **Customize** your Plugin topic.
351   - 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.
352 3. **Document** the performance data you gathered while [[measuring the performance|Main/WebHome#MeasurePerformance]]
353 4. **Save** your topic, for use in [[packaging|Main/WebHome#CreatePluginPackage]] and [[publishing|Main/WebHome#PublishPlugin]] your Plugin.
354
355 > **OUTLINE: Doc Topic Contents**
356 >
357 > <br />
358 >
359 > Check the Plugins web on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
360 >
361 > **Syntax Rules:** &lt;_Describe any special text formatting that will be rendered._&gt;"
362 >
363 > **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;"
364 >
365 > **Plugin Settings:** &lt;_Description and settings for custom Plugin %VARIABLES%, and those required by TWiki._&gt;"
366 >
367 > - **Plugins Preferences** &lt;_If user settings are needed, explain... Entering values works exactly like %SYSTEMWEB%.TWikiPreferences and [[WebPreferences]]: six (6) spaces and then:_&gt;"
368 >   - **Set &lt;_EXAMPLE = value added_&gt;**
369 >
370 > **Plugin Installation Instructions:** &lt;_Step-by-step set-up guide, user help, whatever it takes to install and run, goes here._&gt;"
371 >
372 > **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;"
373
374 <a name="CreatePluginPackage"></a>
375
376 ### <a name="Packaging for Distribution"></a> Packaging for Distribution
377
378 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!
379
380 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`).
381
382 1. Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them all:
383   - `lib/TWiki/Plugins/MyFirstPlugin.pm`
384   - `data/TWiki/MyFirstPlugin.txt`
385   - `pub/TWiki/MyFirstPlugin/uparrow.gif` [a required graphic]
386 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:
387   - `lib/TWiki/Plugins/MyFirstPlugin.pm`
388   - `data/TWiki/MyFirstPlugin.txt`
389   - `pub/TWiki/MyFirstPlugin/uparrow.gif`
390
391 <a name="MeasurePerformance"></a>
392
393 ### <a name="Measuring and Improving the Plug"></a> Measuring and Improving the Plugin Performance
394
395 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.
396
397 See also [[Hints on Writing Fast Plugins|Main/WebHome#FastPluginHints]].
398
399 <a name="PublishPlugin"></a>
400
401 ### <a name="Publishing for Public Use"></a> Publishing for Public Use
402
403 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.
404
405 Publish your Plugin by following these steps:
406
407 1. **Post** the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
408   - enter the Plugin name in the "How to Create a Plugin" section, for example `MyFirstPlugin`
409   - paste in the topic text from [[Writing the Documentation Topic|Main/WebHome#CreatePluginTopic]] and save
410 2. **Attach** the distribution zip file to the topic, ex: `MyFirstPlugin.zip`
411 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.)
412 4. **Put** the Plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)
413
414 %N% Once you have done the above steps once, you can use the BuildContrib to upload updates to your Plugin.
415
416 Thank you very much for sharing your Plugin with the TWiki community :-)
417
418 <a name="RecommendedStorageOfPluginData"></a>
419
420 ## <a name="Recommended Storage of Plugin Sp"></a> Recommended Storage of Plugin Specific Data
421
422 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.
423
424 ### <a name="Plugin Internal Data"></a> Plugin Internal Data
425
426 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.
427
428 ### <a name="Web Accessible Data"></a> Web Accessible Data
429
430 **_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.
431
432 Recommendation for file name:
433
434 - Prefix the filename with an underscore (the leading underscore avoids a name clash with files attached to the same topic)
435 - Identify where the attachment originated from, typically by including the Plugin name in the file name
436 - Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
437 - Example: `_FooBarPlugin_img123.gif`
438
439 **_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.
440
441 Recommendation for file names in Plugin attachment area:
442
443 - Prefix the filename with an underscore
444 - Include the name of the web in the filename
445 - Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
446 - Example: `_Main_roundedge-ul.gif`
447
448 <a name="ConfigSpec"></a>
449
450 ## <a name="Integrating with configure"></a> Integrating with `configure`
451
452 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.
453
454 `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`.
455
456 ### <a name="Structure of a Config.spec file"></a> Structure of a `Config.spec` file
457
458 The `Config.spec` file for a plugin starts with the plugin announcing what it is:
459
460     # ---+ BathPlugin
461     # This plugin senses the level of water in your bath, and ensures the plug
462     # is not removed while the water is still warm.
463
464 This is followed by one or more configuration items. Each configuration item has a _type_, a _description_ and a _default_. For example:
465
466     # **SELECT Plastic,Rubber,Metal**
467     # Select the plug type
468     $TWiki::cfg{BathPlugin}{PlugType} = 'Plastic';
469
470     # **NUMBER**
471     # Enter the chain length in cm
472     $TWiki::cfg{BathPlugin}{ChainLength} = '30';
473
474     # **BOOLEAN EXPERT**
475     # Turn this option off to disable the water temperature alarm
476     $TWiki::cfg{BathPlugin}{TempSensorEnabled} = '1';
477
478 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,
479
480     if( $TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) {
481         die "The bathwater is too hot for comfort";
482     }
483
484 The config.spec file is read by configure, and `configure` then writes `LocalSite.cfg` with the values chosen by the local site admin.
485
486 A range of types are available for use in `Config.spec` files:
487
488 <table border="1" cellpadding="0" cellspacing="0">
489   <tr>
490     <td> BOOLEAN </td>
491     <td> A true/false value, represented as a checkbox </td>
492   </tr>
493   <tr>
494     <td> COMMAND <em>length</em></td>
495     <td> A shell command </td>
496   </tr>
497   <tr>
498     <td> LANGUAGE </td>
499     <td> A language (selected from <code>{LocalesDir}</code></td>
500   </tr>
501   <tr>
502     <td> NUMBER </td>
503     <td> A number </td>
504   </tr>
505   <tr>
506     <td> OCTAL </td>
507     <td> An octal number </td>
508   </tr>
509   <tr>
510     <td> PASSWORD <em>length</em></td>
511     <td> A password (input is hidden) </td>
512   </tr>
513   <tr>
514     <td> PATH <em>length</em></td>
515     <td> A file path </td>
516   </tr>
517   <tr>
518     <td> PERL </td>
519     <td> A perl structure, consisting of arrays and hashes </td>
520   </tr>
521   <tr>
522     <td> REGEX <em>length</em></td>
523     <td> A perl regular expression </td>
524   </tr>
525   <tr>
526     <td> SELECT <em>choices</em></td>
527     <td> Pick one of a range of choices </td>
528   </tr>
529   <tr>
530     <td> SELECTCLASS <em>root</em></td>
531     <td> Select a perl package (class) </td>
532   </tr>
533   <tr>
534     <td> STRING <em>length</em></td>
535     <td> A string </td>
536   </tr>
537   <tr>
538     <td> URL <em>length</em></td>
539     <td> A url </td>
540   </tr>
541   <tr>
542     <td> URLPATH <em>length</em></td>
543     <td> A relative URL path </td>
544   </tr>
545 </table>
546
547 All types can be followed by a comma-separated list of _attributes_.
548
549 <table border="1" cellpadding="0" cellspacing="0">
550   <tr>
551     <td> EXPERT </td>
552     <td> means this an expert option </td>
553   </tr>
554   <tr>
555     <td> M </td>
556     <td> means the setting is mandatory (may not be empty) </td>
557   </tr>
558   <tr>
559     <td> H </td>
560     <td> means the option is not visible in <code>configure</code></td>
561   </tr>
562 </table>
563
564 See `lib/TWiki.spec` for many more examples.
565
566 `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.
567
568 <a name="MaintainPlugins"></a>
569
570 ## <a name="Maintaining Plugins"></a> Maintaining Plugins
571
572 ### <a name="Discussions and Feedback on Plug"></a> Discussions and Feedback on Plugins
573
574 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.
575
576 ### <a name="Maintaining Compatibility with E"></a> Maintaining Compatibility with Earlier TWiki Versions
577
578 The Plugin interface ([[TWikiFuncDotPm]] functions and handlers) evolve over time. TWiki 4.0 introduced new API functions to address the needs of Plugin authors. It also deprecated some functions. Some Plugins written for earlier TWiki releases using unofficial TWiki internal functions no longer work on the TWiki 4.0 codebase. All this means that some Plugins need to be updated to work on the TWiki 4.0 codebase.
579
580 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.
581
582 **_%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. TWiki:TWiki.TWikiPluginsSupplement#MaintainPlugins has more.
583
584 ### <a name="Handling deprecated functions"></a> Handling deprecated functions
585
586 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.
587
588 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.
589
590 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%.
591
592 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:
593
594     package TWiki::Plugins::SinkPlugin;
595     use vars qw( %TWikiCompatibility );
596     $TWikiCompatibility{endRenderingHandler} = 1.1;
597
598 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.
599
600 **_Related Topics:_** [[DeveloperDocumentationCategory]], [[AdminDocumentationCategory]], TWiki:TWiki.TWikiPluginsSupplement