TWiki Plugins
Plug-in enhanced feature add-ons, with a Plugin API for developers
Overview
You can add Plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you:
- add virtually unlimited features while keeping the main TWiki code compact and efficient;
- heavily customize an installation and still do clean updates to new versions of TWiki;
- rapidly develop new TWiki functions in Perl using the Plugin API.
Everything to do with TWiki Plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the
TWiki:Plugins web.
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.
Installing Plugins
Each TWikiPlugin 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.
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. You should be able to find detailed instructions are in the Plugin documentation.
Each Plugin has a standard release page, located in the
TWiki:Plugins web at TWiki.org. There's usually a number of other related pages, such as a developers page, and an appraisal page.
On-Site Pretesting
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 satisifed that it won't compromise your main installation, you can install it there as well.
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 %FAILEDPLUGINS%
TWikiVariable? can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.
Some Notes on Plugin Performance
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. You can only really tell by installing the plugin and running experiments yourself. The Apache
ab utility is very useful for doing this.

If 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.)
Listing Active Plugins
Plugin status variables let you list all active Plugins wherever needed.
%ACTIVATEDPLUGINS%
On this TWiki site, the enabled Plugins are:
CommentPlugin,
EditTablePlugin,
HeadlinesPlugin,
ImageGalleryPlugin,
InterwikiPlugin,
PreferencesPlugin,
RenderListPlugin,
SlideShowPlugin,
SmiliesPlugin,
SpreadSheetPlugin,
TablePlugin.
%PLUGINDESCRIPTIONS%
- CalendarPlugin: (disabled)
- CommentPlugin (Dakar, 6827): Allows users to quickly post comments to a page without an edit/preview/save cycle.
- EditTablePlugin (Dakar, 6827): Edit TWiki tables using edit fields, date pickers and drop down boxes
- HeadlinesPlugin (Dakar, 6827): Build news portals that show headline news based on RSS news feeds from news sites.
- ImageGalleryPlugin (3.1): Displays image gallery with auto-generated thumbnails from attachments.
- InterwikiPlugin (Dakar, $Rev: 7338$): Link
ExternalSite:Page text to external sites based on aliases defined in the %RULESTOPIC% topic - PreferencesPlugin (Dakar, 6827): Allows editing of preferences using fields predefined in a form
- RenderListPlugin (Dakar, $Rev: 7338$): Render bullet lists in a variety of formats
- SlideShowPlugin (Dakar, $Rev: 7338$): Create web based presentations based on topics with headings.
- SmiliesPlugin (Dakar, 6827): Render smilies as icons, like
:-) for
or :cool: for :cool: - SpreadSheetPlugin (Dakar, 6827): Add spreadsheet calculation like
"$SUM( $ABOVE() )" to tables located in APS Sahaja Yoga topics. - TablePlugin (Dakar, 6850): Control attributes of tables and sorting of table columns
%FAILEDPLUGINS%
| Plugin | Errors |
|---|
| CalendarPlugin |
TWiki::Plugins::CalendarPlugin could not be loaded. Errors were:
Can't locate Date/Calc.pm in @INC (@INC contains: /var/www/sahajayogaverona.it/public/wiki/lib/CPAN/lib//arch/ /var/www/sahajayogaverona.it/public/wiki/lib/CPAN/lib//5.10.1/i486-linux-gnu-thread-multi/ /var/www/sahajayogaverona.it/public/wiki/lib/CPAN/lib//5.10.1/ /var/www/sahajayogaverona.it/public/wiki/lib/CPAN/lib// /var/www/sahajayogaverona.it/public/wiki/lib . /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl) at /var/www/sahajayogaverona.it/public/wiki/lib/TWiki/Plugins/CalendarPlugin.pm line 203.
BEGIN failed--compilation aborted at /var/www/sahajayogaverona.it/public/wiki/lib/TWiki/Plugins/CalendarPlugin.pm line 203.
Compilation failed in require at (eval 40) line 1.
BEGIN failed--compilation aborted at (eval 40) line 1.
----
|
| CommentPlugin | none |
| EditTablePlugin | none |
| HeadlinesPlugin | none |
| ImageGalleryPlugin | none |
| InterwikiPlugin | none |
| PreferencesPlugin | none |
| RenderListPlugin | none |
| SlideShowPlugin | none |
| SmiliesPlugin | none |
| SpreadSheetPlugin | none |
| TablePlugin | none |
| Handler | Plugins |
|---|
| afterAttachmentSaveHandler | |
| afterCommonTagsHandler | |
| afterEditHandler | |
| afterSaveHandler | |
| beforeAttachmentSaveHandler | |
| beforeCommonTagsHandler | |
| beforeEditHandler | |
| beforeSaveHandler | CommentPlugin |
| commonTagsHandler | CommentPlugin EditTablePlugin HeadlinesPlugin ImageGalleryPlugin SlideShowPlugin SmiliesPlugin SpreadSheetPlugin |
| earlyInitPlugin | |
| endRenderingHandler | |
| initPlugin | CommentPlugin EditTablePlugin HeadlinesPlugin ImageGalleryPlugin InterwikiPlugin PreferencesPlugin RenderListPlugin SlideShowPlugin SmiliesPlugin SpreadSheetPlugin TablePlugin |
| initializeUserHandler | |
| insidePREHandler | |
| modifyHeaderHandler | |
| mergeHandler | |
| outsidePREHandler | |
| postRenderingHandler | EditTablePlugin PreferencesPlugin |
| preRenderingHandler | InterwikiPlugin PreferencesPlugin RenderListPlugin SmiliesPlugin TablePlugin |
| redirectCgiQueryHandler | |
| registrationHandler | |
| renderFormFieldForEditHandler | |
| renderWikiWordHandler | |
| startRenderingHandler | |
| writeHeaderHandler | |
12 plugins
The TWiki Plugin API
The Application Programming Interface (API) for TWikiPlugins provides the specifications for hooking into the core TWiki code from your external Perl Plugin module.
Available Core Functions
The
TWikiFuncDotPm module (
lib/TWiki/Func.pm) describes ALL the interfaces available to Plugins. Plugins should ONLY use the interfaces described in this module.

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.
Predefined Hooks
In addition to TWiki core functions, Plugins can use
predefined hooks, or
call backs, as described in the
lib/TWiki/Plugins/EmptyPlugin.pm module.
- All but the initPlugin are disabled. To enable a call back, remove
DISABLE_ from the function name.
TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
Hints on Writing Fast Plugins
- Delay initialization as late as possible. For example, if your plugin is a simple syntax processor, you might delay loading extra Perl modules until yu actually see the syntax in the text.
- For example, use an
eval block like this:
eval { require IPC::Run }
return "<font color=\"red\">SamplePlugin: Can't load required modules ($@)</font>" if $@; - You can use a flag to avoid running the initialization twice
Security
- 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.
- 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
- Always use the TWiki::Sandbox to execute commands.
- 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.
Creating Plugins
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 Plugins by providing a programming interface for TWiki.
Anatomy of a Plugin
A basic TWiki Plugin consists of two elements:
- a Perl module, ex:
MyFirstPlugin.pm - a documentation topic, ex:
MyFirstPlugin.txt
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.
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.
The Plugin API handles the details of connecting your Perl module with main TWiki code. When you're familiar with the
Plugin API, you're ready to develop Plugins.
Creating the Perl Module
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 specs for more information.
Writing the Documentation Topic
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.) To create a documentation topic:
- Copy the Plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:
- enter the Plugin name in the "How to Create a Plugin" section
- click Create
- select all in the Edit box & copy
- Cancel the edit
- go back to your site to the TWiki web
- In the GoBox enter your Plugin name, for example
MyFirstPlugin, press enter and create the new topic - paste & save new Plugin topic on your site
- Customize your Plugin topic.
- In case you plan to publish your Plugin at TWiki.org, use Interwiki names for author names, like TWiki:Main/TWikiGuest.
- Save your topic, for use in packaging and publishing your Plugin.
OUTLINE: Doc Topic Contents
Check the Plugins web on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
Syntax Rules: <Describe any special text formatting that will be rendered.>"
Example: <Include an example of the Plugin in action. Possibly include a static HTML version of the example to compare if the installation was a success!>"
Plugin Settings: <Description and settings for custom Plugin %VARIABLES%, and those required by TWiki.>"
- Plugins Preferences <If user settings are needed, explain... Entering values works exactly like TWikiPreferences and WebPreferences: six (6) spaces and then:>"
- Set <EXAMPLE = value added>
Plugin Installation Instructions: <Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.>"
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.>"
Packaging for Distribution
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!
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).
- Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them ALL:
-
lib/TWiki/Plugins/MyFirstPlugin.pm -
data/TWiki/MyFirstPlugin.txt -
pub/TWiki/MyFirstPlugin/uparrow.gif [a required graphic]
- 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:-
lib/TWiki/Plugins/MyFirstPlugin.pm -
data/TWiki/MyFirstPlugin.txt -
pub/TWiki/MyFirstPlugin/uparrow.gif
Publishing for Public Use
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 by following these steps:
- Post the Plugin documentation topic in the TWiki:Plugins/PluginPack
age:
- enter the Plugin name in the "How to Create a Plugin" section, for example
MyFirstPlugin - paste in the topic text from Creating Pl
ugin Documentation and save
- Attach the distribution zip file to the topic, ex: =MyFirstPlugin.z
ip=
- 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 fu
ture development. (User support for Plugins is handled in
TWiki:Support.)
- Put the Plugin into the CVS repository, see TWiki:Plugins/ReadmeFir
st (optional)

Once you have done the above steps once, you can use the BuildContrib to upload updates to your plugin.
Where to store Plugin Internal Data
Plugins that need to store data should use the functions in the
FuncDotPm? interface. These functions support saving and loading of:
You can also create a plugin "work area" using the
getWorkArea function, which gives you a persistant directory where you can store data files.
Related Topics: DeveloperDocumentationCategory,
AdminDocumentationCategory