(file) Return to TWikiPlugins.txt CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / data / TWiki

  1 rizwank 1.1 %META:TOPICINFO{author="PeterThoeny" date="1092473905" format="1.0" version="1.29"}%
  2             %TOC%
  3             %STARTINCLUDE%
  4             ---# TWiki Plugins
  5             
  6             _Plug-in enhanced feature add-ons, with a Plugin API for developers_
  7             
  8             ---++ Overview
  9             
 10             You can add Plugins to extend TWiki's functionality, without altering the core program code. A plug-in approach lets you:
 11             
 12             	* add virtually unlimited features while keeping the main TWiki code compact and efficient;
 13             	* heavily customize an installation and still do clean updates to new versions of TWiki;
 14             	* rapidly develop new TWiki functions in Perl using the Plugin API.
 15             
 16             Everything to do with TWiki Plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the <b> TWiki:Plugins </b> web.
 17             
 18             ---++ Preinstalled Plugins
 19             
 20             TWiki comes with a set of Plugins as part of the standard installation.
 21             
 22 rizwank 1.1 	* DefaultPlugin: Optionally handles some legacy variables from older versions of TWiki. You can control this option from %TWIKIWEB%.TWikiPreferences. (Perl programmers can also [[#DefaultPluginAlt][add rules]] for simple custom processing.)
 23             	* EmptyPlugin: Is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development
 24             	* CommentPlugin: %COMMENTPLUGIN_SHORTDESCRIPTION%
 25             	* InterwikiPlugin: Use it for shorthand linking to remote sites, ex: =TWiki:Plugins= expands to TWiki:Plugins on TWiki.org. You can edit the predefined set of of Wiki-related sites, and add your own
 26             	* EditTablePlugin: %EDITTABLEPLUGIN_SHORTDESCRIPTION%
 27             	* RenderListPlugin: %RENDERLISTPLUGIN_SHORTDESCRIPTION%
 28             	* SlideShowPlugin: %SLIDESHOWPLUGIN_SHORTDESCRIPTION%
 29             	* SmiliesPlugin: %SMILIESPLUGIN_SHORTDESCRIPTION%
 30             	* SpreadSheetPlugin: %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
 31             	* TablePlugin: %TABLEPLUGIN_SHORTDESCRIPTION%
 32             
 33             #InstallPlugin
 34             ---++ Installing Plugins
 35             
 36             Each <nop>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. 
 37             
 38             Most Plugins can be installed in three easy steps, with no programming skills required:
 39             	1 *Download* the zip file containing the Plugin, documentation, and any other required files, from TWiki:Plugins. 
 40             	1 *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.
 41             	1 *Check* the demo example on the Plugin topic: if it's working, the installation was fine!
 42             
 43 rizwank 1.1 *Special Requests:* Some Plugins need certain Perl modules to be preinstalled 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.
 44             
 45             Each Plugin has a standard release page, located in the TWiki:Plugins web at TWiki.org. In addition to the documentation topic (=SomePlugin=), there's a separate development page.
 46             	* *Doc page:* Read all available info about the Plugin; download the attached distribution files.
 47             	* *Dev page:* Post feature requests, bug reports and general dev comments; topic title ends in =Dev= (=SomePluginDev=).
 48             	* *User support:* Post installation, how to use type questions (and answers, if you have them) in the TWiki:Support web.
 49             
 50             #PreTesting
 51             ---+++ On-Site Pretesting
 52             
 53             To test new Plugins on your installation before making them public, you may want to use one of these two approaches:
 54             
 55             	* *Method 1:* Safely test on-the-fly by creating separate Production and Test branches in your live TWiki installation. 
 56             		* *Duplicate* the =twiki/bin= and =twiki/lib= directories for the Test version, and adjust the paths in the new =lib/TWiki.cfg=.  The following directories are shared: =twiki/data=, =twiki/templates= and =twiki/pub=.
 57             		* *Test* Plugins and other new features in the Test installation until you're satisfied.
 58             			* %X% If you modify topics using the new features, live users will likely see unfamiliar new META tags showing up on their pages - to avoid this, create and edit test-only topics to try out new features.
 59             		* *Copy* the modified files to the Production installation. You can update a TWiki installation live and users won't even notice.
 60             
 61             	* *Method 2:* List the Plugin being tested in the =DISABLEDPLUGINS= variable in %TWIKIWEB%.TWikiPreferences. Redefine the =DISABLEDPLUGINS= variable in the =Sandbox= web and do the testing there.
 62             
 63             ---+++ Checking that Plugins are Working on a Live Server
 64 rizwank 1.1 
 65             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.
 66             
 67             ---+++ A Note on Plugin Performance
 68             
 69             The performance of the system depends on the number of Plugins installed and on the Plugin implementation. Some Plugins impose no measurable performance decrease, some do. For example, =outsidePREHandler= is an expensive callback function, or a Plugin might use many Perl libraries that need to be initialized with each page view (unless you run mod_perl). It is recommended to measure the performance with and without a new Plugin. Example for Unix:%BR% =time wget -qO /dev/null <nop>%SCRIPTURL%/view%SCRIPTSUFFIX%/%TWIKIWEB%/AbcPlugin=
 70             
 71             In case you need to install an "expensive" Plugin and you need its functionality only in one web you can place the Plugin topic into that web. TWiki will initialize the Plugin only if the Plugin topic is found (which won't be the case for other webs.)
 72             
 73             ---++ Managing Plugins
 74             
 75             When you finish [[#InstallPlugin][installing a Plugin]], you should be able to read the user instructions and go. In fact, 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.
 76             
 77             ---+++ Setting Preferences
 78             
 79             Installed Plugins can be *toggled on or off*, site-wide or by web, through <nop>TWikiPreferences and individual <nop>WebPreferences:
 80             
 81             	* All Plugin modules present in the =lib/TWiki/Plugins= directory are activated automatically unless disabled by the =DISABLEDPLUGINS= Preferences variable in <nop>TWikiPreferences. You can optionally list the installed Plugins in the =INSTALLEDPLUGINS= 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 %TWIKIWEB%.TWikiPreferences are:
 82             		* =Set INSTALLEDPLUGINS = <nop>DefaultPlugin, ...= 
 83             		* =Set DISABLEDPLUGINS = <nop>EmptyPlugin, ...=
 84             
 85 rizwank 1.1 *Plugin execution order* in TWiki is determined by searching Plugin topics in a specific sequence: First, full =web.topicname= name, if specified in =INSTALLEDPLUGINS=; next, the %TWIKIWEB% web is searched; and finally, the current web.
 86             
 87             *Plugin-specific settings* are done in individual Plugin topics. Two settings are standard for each Plugin:
 88             	1 One line description, used to form the bullets describing the Plugins in the %TWIKIWEB%.TextFormattingRules topic:
 89             		* =Set SHORTDESCRIPTION = Blah blah woof woof.=
 90             	1 Debug Plugin, output can be seen in =data/debug.txt=. Set to 0=off or 1=on:
 91             		* =Set DEBUG = 0=
 92             	* The settings can be retrieved as Preferences variables like =%&lt;pluginname&gt;_&lt;var&gt;%=, ex: =%<nop>DEFAULTPLUGIN_SHORTDESCRIPTION%= shows the description of the <nop>DefaultPlugin.
 93             
 94             ---+++ Listing Active Plugins
 95             
 96             Plugin status variables let you list all active Plugins wherever needed. There are two list formats:
 97             	* The =%<nop>ACTIVATEDPLUGINS%= variable lists activated Plugins by name. (This variable is displayed in %TWIKIWEB%.TWikiPreferences for debugging use.)
 98             	* The =%<nop>PLUGINDESCRIPTIONS%= variable displays a bullet list with a one-line description of each active Plugins. This variable is based on the =%&lt;plugin&gt;_SHORTDESCRIPTION%= Preferences variables of individual topics and is shown in %TWIKIWEB%.TextFormattingRules.
 99             
100             <blockquote style="background-color:#f5f5f5">
101             *DEMO: Automatically List Active Plugins Using Variables*
102             
103             Using =%<nop>ACTIVATEDPLUGINS%=:<br />
104             On this TWiki site, the active Plugins are: %ACTIVATEDPLUGINS%.
105             
106 rizwank 1.1 Using =%<no>PLUGINDESCRIPTIONS%=:<br />
107             You can use any of these active TWiki Plugins:
108             %PLUGINDESCRIPTIONS%
109             </blockquote>
110             
111             #PluginAPI
112             ---++ The TWiki Plugin API
113             
114             The Application Programming Interface (API) for <nop>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 01-Sep-2001 release.
115             
116             ---+++ Available Core Functions
117             
118             The TWikiFuncModule (=lib/TWiki/Func.pm=) implements ALL official Plugin functions. Plugins should ONLY use functions published in this module.
119             
120             %X% If you use functions not 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.
121             
122             ---+++ Predefined Hooks
123             
124             In addition to TWiki core functions, Plugins can use *predefined hooks*, or *call backs*, listed in the =lib/TWiki/Plugins/EmptyPlugin.pm= module.
125             
126             	* All but the initPlugin are disabled. To enable a call back, remove =DISABLE_= from the function name.
127 rizwank 1.1 	* For best performance, enable only the functions you really need. NOTE: =outsidePREHandler= and =insidePREHandler= are particularly expensive. 
128             
129             Most Plugins use either the =commonTagsHandler= or =startRenderingHandler= for rendering tasks:
130             	* =commonTagsHandler:= Use it to expand =%<nop>XYZPLUGIN%= and =%<nop>XYZPLUGIN{...}%= variables
131             	* =startRenderingHandler:= Use it for your own rendering rules or to overload TWiki's internal rendering like =[<nop>[links]]=
132             
133             TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
134             
135             ---+++ Hints on Writing Fast Plugins
136             
137             	* Delay the Plugin initialization to the actual function which is handling the tag. This way all the expensive initialization is done only when needed.
138             	* For example, use an =eval= block like:%BR%
139             	  =eval { require IPC::Run }= %BR%
140             	  =return "&lt;font color=\"red\"&gt;SamplePlugin: Can't load required modules ($@)&lt;/font&gt;" if $@;=
141             	* You could return errors as strings to show what happened
142             	* You can use a flag to avoid running the initialization twice
143             
144             ---+++ Plugin Version Detection
145             
146             To eliminate the incompatibility problems bound to arise from active open Plugin development, a Plugin versioning system is provided for automatic compatibility checking.
147             
148 rizwank 1.1 	* All modules require a =$VERSION='0.000'= variable, beginning at =1.000=.
149             
150             	* The =initPlugin= handler should check all dependencies and return TRUE if the initialization is OK or FALSE if something went wrong.
151             		* The Plugin initialization code does not register a Plugin that returns FALSE (or that has no =initPlugin= handler).
152             
153             	* =$TWiki::Plugins::VERSION= in the =TWiki::Plugins= module contains the TWiki Plugin API version, currently *%PLUGINVERSION{}%*.
154             		* You can also use the [[TWikiVariables#VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]] variable to query the Plugin API version or the version of installed Plugins.
155             
156             #CreatePlugins
157             ---++ Creating Plugins
158             
159             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 [[#PluginAPI][TWiki Plugin API]] Plugins by providing a programming interface for TWiki.
160             
161             #DefaultPluginAlt
162             ---+++ The <nop>DefaultPlugin Alternative
163             
164             	* *<nop>DefaultPlugin* can handle some outdated TWiki variables, found, for example, in sites recently updated from an old version. Settings are in DefaultPlugin topic. You can also add your own simple custom processing rules here, though in all but very simple cases, writing a new Plugin is preferable.
165             
166             ---+++ Anatomy of a Plugin
167             
168             A basic TWiki Plugin consists of two elements:
169 rizwank 1.1 
170             	* a Perl module, ex: =MyFirstPlugin.pm=
171             	* a documentation topic, ex: =MyFirstPlugin.txt=
172             
173             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.
174             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.
175             
176             The Plugin API handles the details of connecting your Perl module with main TWiki code. When you're familiar with the [[#PluginAPI][Plugin API]], you're ready to develop Plugins.
177             
178             ---+++ Creating the Perl Module 
179             
180             Copy file =lib/TWiki/Plugins/EmptyPlugin.pm= to =&lt;name&gt;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 [[#PluginAPI][Plugin API]] specs for more information.
181             
182             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 <nop>MyFirstPlugin::Attrs;= instead of just =Package Attrs;=. Then call it using:
183             <pre>
184               use TWiki::Plugins::MyFirstPlugin::Attrs;
185               $var = MyFirstPlugin::Attrs->new();
186             </pre>
187             
188             #CreatePluginTopic
189             ---+++ Writing the Documentation Topic
190 rizwank 1.1 
191             The Plugin documentation topic contains usage instructions and version details. It serves the Plugin files as %TWIKIWEB%.FileAttachments for downloading. (The doc topic is also included _in_ the [[#CreatePluginPackage][distribution package]].) To create a documentation topic:
192             
193             	1. *Copy* the Plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:
194             		* enter the Plugin name in the "How to Create a Plugin" section
195             		* click Create
196             		* select all in the Edit box &amp; copy 
197             		* Cancel the edit
198             		* go back to your site to the %TWIKIWEB% web
199             		* In the GoBox enter your Plugin name, for example =MyFirstPlugin=, press enter and create the new topic
200             		* paste &amp; save new Plugin topic on your site
201             	2. *Customize* your Plugin topic.
202             		* In case you plan to publish your Plugin at TWiki.org, use Interwiki names for author names, like TWiki:Main/%WIKINAME%. 
203             	3. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
204             
205             <blockquote style="background-color:#f5f5f5">
206             *OUTLINE: Doc Topic Contents* <br />
207             Check the Plugins web on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
208             
209             *Syntax Rules:* &lt;<i>Describe any special text formatting that will be rendered.</i>&gt;" 
210             
211 rizwank 1.1 *Example:* &lt;<i>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!</i>&gt;"
212             
213             *Plugin Settings:* &lt;<i>Description and settings for custom Plugin %<nop>VARIABLES%, and those required by TWiki.</i>&gt;"
214             
215             	* *Plugins Preferences* &lt;<i>If user settings are needed, explain... Entering values works exactly like %TWIKIWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:</i>&gt;"
216             		* *Set &lt;<i>EXAMPLE = value added</i>&gt;*
217             
218             *Plugin Installation Instructions:* &lt;<i>Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.</i>&gt;"
219             
220             *Plugin Info:* &lt;<i>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.</i>&gt;"
221             </blockquote>
222             
223             #CreatePluginPackage
224             ---+++ Packaging for Distribution
225             
226             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=).
227             
228             	1. Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them ALL:
229             		* =lib/TWiki/Plugins/MyFirstPlugin.pm=
230             		* =data/TWiki/MyFirstPlugin.txt=
231             		* =pub/TWiki/MyFirstPlugin/uparrow.gif= [a required graphic]
232 rizwank 1.1 	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:
233             		* =lib/TWiki/Plugins/MyFirstPlugin.pm=
234             		* =data/TWiki/MyFirstPlugin.txt=
235             		* =pub/TWiki/MyFirstPlugin/uparrow.gif=
236             
237             #PublishPlugin
238             ---+++ Publishing for Public Use
239             
240             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. Publish your Plugin in these steps:
241             
242             	1. *Post* the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
243             		* enter the Plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
244             		* paste in the topic text from [[#CreatePluginTopic][Creating Plugin Documentation]] and save
245             	1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip=
246             	1. *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.)
247             	1. *Put* the Plugin into the CVS repository, see TWiki:Plugins/ReadmeFirst (optional)
248             
249             Thank you very much for sharing your Plugin with the TWiki community :-)
250             
251             #RecommendedStorageOfPluginData
252             ---++ Recommended Storage of Plugin Data
253 rizwank 1.1 
254             Plugins sometimes need to store data. This can be Plugin internal data like cache data, or generated data for the browser like images. The following is a recommendation where to store the data.
255             
256             ---+++ Where to store Plugin Internal Data
257             
258             In case the Plugin generates data just for internal use, or data which is not specific to a topic, store it in the Plugin's attachment directory.
259             
260             	* The Plugin's attachment directory is =pubdir/Installweb/FooBarPlugin=
261             		* =Installweb= refers to the name of the web where the Plugin is installed
262             	* The Plugin's attachment URL is =%<nop>PUBURL%/Installweb/FooBarPlugin=
263             	* The filename should start with an underscore, followed by an identifier, e.g. =_any_name.ext=
264             		* The leading underscore avoids a nameclash with files attached to the Plugin topic
265             		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
266             		* Do not use subdirectories (rename and delete would fail)
267             	* Use Plugin API functions documented in TWikiFuncModule to ensure portability:
268             		* Use =getPubDir()= to get the attachment root directory
269             		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser
270             		* Use =$installWeb= to get the name of the web where the Plugin is installed
271             		* Create the web directory and topic attachment directory if needed
272             	* Hint: Package the Plugin at least with one file attachment. This ensures that the attachment directory already exists
273             
274 rizwank 1.1 ---+++ Where to Store Data for Topics using the Plugin
275             
276             In case the Plugin generates data which is specific to a topic, store it in the topic's attachment directory.
277             
278             	* The topic's attachment directory is =pubdir/Webname/TopicName=
279             	* The topic's attachment URL is =%<nop>PUBURL%/Webname/TopicName=
280             	* The filename should start with an underscore, followed by the Plugin name, an underscore and an identifier, e.g. =_FooBarPlugin_any_name.ext=
281             		* The leading underscore avoids a nameclash with files attached to the same topic
282             		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
283             		* Do not use subdirectories (rename and delete would fail)
284             	* Use Plugin API functions documented in TWiki.TWikiFuncModule to ensure portability:
285             		* Use =getPubDir()= to get the attachment root directory
286             		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser
287             
288             Example code to build the file name:
289             <verbatim>
290             sub _make_filename
291             {
292             	 my ( $web, $topic, $name ) = @_;
293             
294             	 # Create web directory "pub/$web" if needed
295 rizwank 1.1 	 my $dir = TWiki::Func::getPubDir() . "/$web";
296             	 unless( -e "$dir" ) {
297             		  umask( 002 );
298             		  mkdir( $dir, 0775 );
299             	 }
300             	 # Create topic directory "pub/$web/$topic" if needed
301             	 $dir .= "/$topic";
302             	 unless( -e "$dir" ) {
303             		  umask( 002 );
304             		  mkdir( $dir, 0775 );
305             	 }
306             	 return "$dir/_FooBarPlugin_$name";
307             }
308             </verbatim>
309             
310             -- TWiki:Main/PeterThoeny - 14 Aug 2004 %BR%
311             -- TWiki:Main/AndreaSterbini - 29 May 2001 %BR%
312             -- TWiki:Main/MikeMannix - 03 Dec 2001	
313             

Rizwan Kassim
Powered by
ViewCVS 0.9.2