72b0a3c7fda44b63efb0b885cd41b2fcd31b9bba
[openafs-wiki.git] / TWiki / TWikiPlugins.mdwn
1 <div>
2   <ul>
3     <li><a href="#TWiki Plugins"> TWiki Plugins</a><ul>
4         <li><a href="#Installing Plugins"> Installing Plugins</a></li>
5         <li><a href="#Pre-Installed Plugins"> Pre-Installed Plugins</a></li>
6         <li><a href="#Managing Installed Plugins"> Managing Installed Plugins</a><ul>
7             <li><a href="#Set Preferences for Individual P"> Set Preferences for Individual Plugins</a></li>
8             <li><a href="#List Active Plugins Automaticall"> List Active Plugins Automatically </a></li>
9           </ul>
10         </li>
11         <li><a href="#Creating New Plugins"> Creating New Plugins</a><ul>
12             <li><a href="#Anatomy of a Plugin"> Anatomy of a Plugin</a></li>
13             <li><a href="#TWiki Plugin API"> TWiki Plugin API</a></li>
14             <li><a href="#Customize the _DefaultPlugin"> Customize the DefaultPlugin</a></li>
15             <li><a href="#Create a Plugin Module in Perl"> Create a Plugin Module in Perl</a></li>
16             <li><a href="#Create a Plugin Documentation To"> Create a Plugin Documentation Topic</a></li>
17             <li><a href="#Package a Plugin for Distributio"> Package a Plugin for Distribution</a></li>
18             <li><a href="#Publish a Plugin for General Use"> Publish a Plugin for General Use</a></li>
19           </ul>
20         </li>
21       </ul>
22     </li>
23   </ul>
24 </div>
25
26 ## <a name="TWiki Plugins"></a> TWiki Plugins
27
28 TWikiPlugins allow you to add new features to TWiki without changing the core program. Using a plug-in approach means that you can:
29
30 - add virtually unlimited features while keeping the main TWiki program compact and efficient;
31 - heavily customize an installation and still do clean updates to new versions of TWiki;
32 - rapidly develop new TWiki functions in Perl using the Plugin API.
33
34 Everything to do with TWiki Plugins - including demos, new releases, downloads, and discussion - is available at TWiki.org, in the ** [[TWiki.org Plugins web|Main/TWiki:Plugins]]**.
35
36 <a name="InstallPlugin"></a>
37
38 ### <a name="Installing Plugins"></a> Installing Plugins
39
40 Each TWikiPlugin comes with full documentation: step-by-step installation instructions, a detailed description of any special requirements, version details, and a working example for testing.
41
42 Most Plugins can be installed in three easy steps, with no programming skills required:
43
44 1. **Download** the zip file containing the Plugin, documentation, and any other required files, from TWiki:Plugins.
45 2. **Distribute** the files to their proper locations - unzip the zip archive in your TWiki installation directory - if have a standard TWiki installation, this will distribute automatically. Otherwise, place the files according to the directory paths listed on the Plugin top in TWiki:Plugins.
46 3. **Check** the demo example on the Plugin topic: if it's working, the installation was fine!
47
48 Some Plugins need certain Perl modules to be pre-installed on the host system. Plugins may also use other resources, like graphics, other modules, applications, templates. In these cases, detailed instructions are in the Plugin documentation.
49
50 TWikiPlugin documentation pages are located at TWiki.org, in TWiki:Plugins web. Each Plugin has an doc topic (ex: <code>**SomePlugin**</code>) and a separate development page.
51
52 - **Doc page:** Read all available info about the Plugin; download the attached distribution files.
53 - **Dev page:** Post feature requests, bug reports and general dev comments; topic title ends in <code>**Dev**</code> (ex: <code>**SomePluginDev**</code>).
54 - **User support:** Post installation, how to use type questions (and answers, if you have them) in the TWiki:Support web.
55
56 ### <a name="Pre-Installed Plugins"></a> Pre-Installed Plugins
57
58 TWiki comes with three Plugins as part of the standard installation.
59
60 - **DefaultPlugin** handles some legacy TWiki variables that may be present in long-established sites. This option can be controlled from [[TWikiPreferences]]. (Perl programmers can also [[add rules|Main/WebHome#Customize_the_DefaultPlugin]] for simple custom processing.)
61
62 - **EmptyPlug** is a fully functional Plugin module, minus any active code; it does nothing but serve as a template on demand.
63
64 - **InterwikiPlugin** is included but can be disabled or removed. Use it for quick linking to frequently linked to remote sites. Ex: <code>**TWiki:Plugins**</code> expands to TWiki:Plugins - on TWiki.org. You can add your own shortcuts and URLs to the existing directory of Wiki-related sites.
65
66 ### <a name="Managing Installed Plugins"></a> Managing Installed Plugins
67
68 Ideally, after you've [[installed a Plugin|Main/WebHome#InstallPlugin]], just read the instructions and you're set. In fact, some Plugins require additional settings or offer extra options that you can modify on Preferences pages. You may want to make a Plugin available only in certain webs, or temporarily disable it. And having to list all available Plugins will probably come up. You can handle all of these with simple procedures.
69
70 #### <a name="Set Preferences for Individual P"></a> Set Preferences for Individual Plugins
71
72 Installed Plugins can be **toggled on or off**, site-wide or by web, through TWikiPreferences and individual WebPreferences:
73
74 - All Plugin modules present in the <code>**lib/TWiki/Plugins**</code> directory are activated automatically unless disabled by the <code>**DISABLEDPLUGINS**</code> Preferences variable in TWikiPreferences. You can optionally list the installed Plugins in the <code>**INSTALLEDPLUGINS**</code> Preferences variable. This is useful to define the sequence of Plugin execution, or to specify other webs than the %WIKITOOLNAME% web for the Plugin topics. Settings in [[TWikiPreferences]] are:
75   - <code>**Set INSTALLEDPLUGINS = DefaultPlugin, ...**</code>
76   - <code>**Set DISABLEDPLUGINS = EmptyPlugin, ...**</code>
77
78 **Plugin execution order** in TWiki is determined by searching Plugin topics in a specific sequence: First, full <code>**web.topicname**</code> name, if specified in <code>**INSTALLEDPLUGINS**</code>; next, the TWiki web is searched; and finally, the current web.
79
80 **Plugin-specific settings** are done in individual Plugin topics. Two settings are standard for each Plugin:
81
82 1. One line description, used to form the bullets describing the Plugins in the [[TextFormattingRules]] topic:
83   - <code>**Set SHORTDESCRIPTION = Blah blah woof woof.**</code>
84 2. Debug Plugin, output can be seen in <code>**data/debug.txt**</code>. Set to 0=off or 1=on:
85   - <code>**Set DEBUG = 0**</code>
86
87 - The settings can be retrieved as Preferences variables like <code>**%&lt;pluginname&gt;\_&lt;var&gt;%**</code>, ex: <code>**%DEFAULTPLUGIN\_SHORTDESCRIPTION%**</code> shows the description of the DefaultPlugin.
88
89 #### <a name="List Active Plugins Automaticall"></a> List Active Plugins Automatically
90
91 Plugin status variables let you list all active Plugins wherever needed. There are two list formats:
92
93 - The <code>**%ACTIVATEDPLUGINS%**</code> variable lists activated Plugins by name. (This variable is displayed in [[TWikiPreferences]] for debugging use.)
94 - The <code>**%PLUGINDESCRIPTIONS%**</code> variable displays a bullet list with a one-line description of each active Plugins. This variable is based on the <code>**%&lt;plugin&gt;\_SHORTDESCRIPTION%**</code> Preferences variables of individual topics and is shown in [[TextFormattingRules]].
95
96 > <span><font> **DEMO: Active Plugin Variables** </font></span>
97 >
98 > <code>**%ACTIVATEDPLUGINS%**</code><br /> On this TWiki site, the active Plugins are: [[SpreadSheetPlugin]], [[CommentPlugin]], [[EditTablePlugin]], [[InterwikiPlugin]], [[PreferencesPlugin]], [[SlideShowPlugin]], [[SmiliesPlugin]], [[TablePlugin]], [[TwistyPlugin]].
99 >
100 > <code>**%PLUGINDESCRIPTIONS%**</code><br /> You can use any of these active TWiki Plugins:
101 >
102 > - [[SpreadSheetPlugin]] <span>(any TWiki, 10197)</span>:
103 > - [[CommentPlugin]] <span>(Dakar, 11359)</span>: Allows users to quickly post comments to a page without an edit/preview/save cycle
104 > - [[EditTablePlugin]] <span>(any TWiki, 11646)</span>:
105 > - [[InterwikiPlugin]] <span>(Dakar, $Rev: 11935$)</span>:
106 > - [[PreferencesPlugin]] <span>(Dakar, 9839)</span>:
107 > - [[SlideShowPlugin]] <span>(Any TWiki, $Rev: 12847$)</span>:
108 > - [[SmiliesPlugin]] <span>(Dakar, 8154)</span>:
109 > - [[TablePlugin]] <span>(1.020, 12339)</span>:
110 > - [[TwistyPlugin]] <span>(1.2.0, $Rev: 12154$)</span>:
111
112 **TIP! To test new Plugins** on your installation before making them public, you may want to use one of these two approaches:
113
114 - **Method 1:** Create a Production and a Test installation of TWiki. The <code>**twiki/data**</code>, <code>**twiki/templates**</code> and <code>**twiki/pub**</code> directories are shared, and the <code>**twiki/bin**</code> and <code>**twiki/lib**</code> directories are separate. Do all tests of Plugins and other new features in the Test installation. When everything works, copy the modified files over to the Production installation. This way, you can update a live TWiki installation and users won't even notice.
115
116 - **Method 2:** List the Plugin under test in the DISABLEDPLUGINS variable in [[TWikiPreferences]]. Redefine the DISABLEDPLUGINS variable in the test web and do the testing there.
117
118 <a name="CreatePlugins"></a>
119
120 ### <a name="Creating New Plugins"></a> Creating New Plugins
121
122 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.
123
124 #### <a name="Anatomy of a Plugin"></a> Anatomy of a Plugin
125
126 A basic TWiki Plugin consists of two elements:
127
128 - a Perl module, ex: <code>**YourPlugin.pm**</code>
129 - a documentation topic, ex: <code>**YourPlugin.txt**</code>
130
131 The Perl module can be a block of code that connects 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.
132
133 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.
134
135 <a name="PluginAPI"></a>
136
137 #### <a name="TWiki Plugin API"></a> TWiki Plugin API
138
139 The Application Programming Interface (API) for TWikiPlugins provides the specifications for hooking into the core TWiki code from your external Perl Plugin module. The Plugin API is new to the Production version of TWiki with the TWikiReleaseSpring2001.
140
141 The <code>**lib/TWiki/Func.pm**</code> implements ALL official Plugin functions. Plugins should ONLY use functions published in this module.
142
143 <span><font>**DevALERT:**</font></span> If you use functions not in <code>**Func.pm**</code>, 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.
144
145 In addition to TWiki core functions, Plugins can use **predefined hooks**, or **call backs**, listed in the <code>**lib/TWiki/Plugins/EmptyPlugin.pm**</code> module.
146
147 - All but the initPlugin are disabled. To enable a call back, remove <code>**DISABLE\_**</code> from the function name.
148
149 - For improve performance, enable only the functions you really need. NOTE: <code>**outsidePREHandler**</code> and <code>**insidePREHandler**</code> are particularly expensive.
150
151 #### <a name="Customize the _DefaultPlugin"></a> Customize the DefaultPlugin
152
153 - **DefaultPlugin** can handle some outdated TWiki variables, found, for example, in sites recently updated from an old version. Settings are in [[TWikiPreferences]]. You can also add your own simple custom processing rules here, though in all but very simple cases, writing a new Plugin is preferable.
154
155 #### <a name="Create a Plugin Module in Perl"></a> Create a Plugin Module in Perl
156
157 Copy file ([`EmptyPlugin.pm`](http://twiki.org/lib/TWiki/Plugins/EmptyPlugin.pm) to <code>**&lt;name&gt;Plugin.pm**</code> <code>**EmptyPlugin.pm**</code> contains no executable code, 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.
158
159 <a name="CreatePluginTopic"></a>
160
161 #### <a name="Create a Plugin Documentation To"></a> Create a Plugin Documentation Topic
162
163 The Plugin documentation topic contains usage instructions and version details. It serves the Plugin files as [[FileAttachments]] for downloading. (The doc topic is also included _in_ the [[distribution package|Main/WebHome#CreatePluginPackage]].) To create a documentation topic:
164
165 1. **Copy** the Plugin topic template from <http://TWiki.org/cgi-bin/view/TWiki/EmptyPlugin>. To copy the text, go to the page and:
166   - click Edit
167   - select all in the Edit box &amp; copy
168   - Cancel the edit
169   - paste &amp; save as a text file or new topic on your site
170 2. **Customize** the template for your Plugin; you'll probably want to post a working version on your local TWiki site.
171 3. **Save** your topic as a text file, for use in [[packaging|Main/WebHome#CreatePluginPackage]] and [[publishing|Main/WebHome#PublishPlugin]] your Plugin.
172
173 > <span><font>**OUTLINE:** Doc Topic Contents </font></span>
174 >
175 > <br />
176 >
177 > Check
178 >
179 > [[EmptyPlugin]]
180 >
181 > on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
182 >
183 > **Syntax Rules:** Describe any special text formatting that will be rendered.
184 >
185 > **YourPlugin Settings:** Description and settings for your custom Plugin %VARIABLES%, and those required by TWiki.
186 >
187 > Plugins Preferences work exactly like [[TWikiPreferences]] and [[WebPreferences]]: six (6) spaces and then:
188 >
189 > - - Set EXAMPLE = got it!
190 >
191 > **How-to Instructions:** Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.
192 >
193 > **Test Example:** Include an example of the Plugin in action: if it works, the installation was a success!
194 >
195 > **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.
196
197 <a name="CreatePluginPackage"></a>
198
199 #### <a name="Package a Plugin for Distributio"></a> Package a Plugin for Distribution
200
201 A minimum Plugin release consists of a Perl module with a [[WikiName]] that ends in <code>**Plugin**</code>, ex: <code>**YourPlugin.pm**</code>, and a documentation page with the same name(<code>**YourPlugin.txt**</code>).
202
203 1. Distribute your Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them ALL:
204   - <code>**lib/TWiki/Plugins/YourPlugin.pm**</code>
205   - <code>**data/TWiki/YourPlugin.txt**</code>
206   - <code>**pub/TWiki/YourPlugin/uparrow.gif**</code> [a required graphic]
207 2. Create a zip archive with the Plugin name (<code>**YourPlugin.zip**</code>) and add the entire directory structure from Step 1. Your archive should look like this:
208   - <code>**lib/TWiki/Plugins/YourPlugin.pm**</code>
209   - <code>**data/TWiki/YourPlugin.txt**</code>
210   - <code>**pub/TWiki/YourPlugin/uparrow.gif**</code>
211
212 <a name="PublishPlugin"></a>
213
214 #### <a name="Publish a Plugin for General Use"></a> Publish a Plugin for General Use
215
216 You can release your tested, packaged Plugin to the TWiki community through the TWiki:Plugins web, where all Plugins submitted to TWiki.org are available for download and further development discussion. Publish your Plugin in three steps:
217
218 1. **Post** the Plugin documentation topic in the TWiki:Plugins web:
219   - create a new topic using the Plugin name, ex: <code>**YourPlugin.txt**</code>;
220   - paste in the topic text from [[Creating Plugin Documentation|Main/WebHome#CreatePluginTopic]] and Save.
221 2. **Attach** the distribution zip file to the topic, ex: <code>**YourPlugin.zip**</code>.
222 3. **Link** from the doc page to a new, blank page named after the Plugin, and ending in <code>**Dev**</code>, ex: <code>**YourPluginDev**</code>. This is the discussion page for future development. (User support for Plugins is handled in TWiki:Support.)
223
224 -- [[MikeMannix]] - 26 Aug 2001