head	1.37;
access;
symbols;
locks; strict;
comment	@# @;


1.37
date	2012.11.24.20.01.07;	author TWikiContributor;	state Exp;
branches;
next	1.36;

1.36
date	2011.06.06.21.59.34;	author TWikiContributor;	state Exp;
branches;
next	1.35;

1.35
date	2010.05.29.14.44.53;	author TWikiContributor;	state Exp;
branches;
next	1.34;

1.34
date	2008.08.03.22.17.45;	author TWikiContributor;	state Exp;
branches;
next	1.33;

1.33
date	2008.01.22.03.21.28;	author TWikiContributor;	state Exp;
branches;
next	1.32;

1.32
date	2007.01.16.04.12.00;	author TWikiContributor;	state Exp;
branches;
next	1.31;

1.31
date	2006.04.01.05.55.14;	author TWikiContributor;	state Exp;
branches;
next	1.30;

1.30
date	2006.02.01.12.01.19;	author TWikiContributor;	state Exp;
branches;
next	1.29;

1.29
date	2004.08.14.08.58.25;	author PeterThoeny;	state Exp;
branches;
next	1.28;

1.28
date	2004.08.08.04.48.59;	author PeterThoeny;	state Exp;
branches;
next	1.27;

1.27
date	2004.05.18.06.49.22;	author PeterThoeny;	state Exp;
branches;
next	1.26;

1.26
date	2003.12.15.07.23.36;	author PeterThoeny;	state Exp;
branches;
next	1.25;

1.25
date	2003.12.12.07.57.00;	author PeterThoeny;	state Exp;
branches;
next	1.24;

1.24
date	2003.08.01.07.53.49;	author PeterThoeny;	state Exp;
branches;
next	1.23;

1.23
date	2003.08.01.05.37.04;	author PeterThoeny;	state Exp;
branches;
next	1.22;

1.22
date	2003.02.28.04.32.00;	author PeterThoeny;	state Exp;
branches;
next	1.21;

1.21
date	2003.01.29.07.21.00;	author PeterThoeny;	state Exp;
branches;
next	1.20;

1.20
date	2002.12.08.06.36.28;	author PeterThoeny;	state Exp;
branches;
next	1.19;

1.19
date	2002.07.18.07.14.42;	author PeterThoeny;	state Exp;
branches;
next	1.18;

1.18
date	2001.12.03.10.17.00;	author MikeMannix;	state Exp;
branches;
next	1.17;

1.17
date	2001.09.28.00.35.05;	author MikeMannix;	state Exp;
branches;
next	1.16;

1.16
date	2001.09.18.03.55.18;	author MikeMannix;	state Exp;
branches;
next	1.15;

1.15
date	2001.09.16.06.01.21;	author MikeMannix;	state Exp;
branches;
next	1.14;

1.14
date	2001.09.15.10.07.56;	author MikeMannix;	state Exp;
branches;
next	1.13;

1.13
date	2001.09.14.09.55.51;	author PeterThoeny;	state Exp;
branches;
next	1.12;

1.12
date	2001.09.07.10.11.02;	author MikeMannix;	state Exp;
branches;
next	1.11;

1.11
date	2001.09.02.08.34.34;	author AndreaSterbini;	state Exp;
branches;
next	1.10;

1.10
date	2001.09.02.00.19.24;	author MikeMannix;	state Exp;
branches;
next	1.9;

1.9
date	2001.09.01.03.52.16;	author MikeMannix;	state Exp;
branches;
next	1.8;

1.8
date	2001.08.31.06.05.43;	author MikeMannix;	state Exp;
branches;
next	1.7;

1.7
date	2001.08.27.09.19.48;	author MikeMannix;	state Exp;
branches;
next	1.6;

1.6
date	2001.08.27.04.30.18;	author MikeMannix;	state Exp;
branches;
next	1.5;

1.5
date	2001.08.26.19.28.03;	author MikeMannix;	state Exp;
branches;
next	1.4;

1.4
date	2001.07.14.11.08.20;	author PeterThoeny;	state Exp;
branches;
next	1.3;

1.3
date	2001.03.14.02.26.38;	author PeterThoeny;	state Exp;
branches;
next	1.2;

1.2
date	2001.03.04.09.00.17;	author PeterThoeny;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.17.08.35.53;	author PeterThoeny;	state Exp;
branches;
next	;


desc
@none
@


1.37
log
@buildrelease
@
text
@%META:TOPICINFO{author="TWikiContributor" date="1353787267" format="1.1" version="37"}%
%STARTINCLUDE%
---+ TWiki Plugins

_Add functionality to TWiki with readily available plugins; create plugins based on APIs_

%TOC%

---++ 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 <b> TWiki:Plugins </b> 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.

__Relevant links on TWiki.org:__
   * TWiki:TWiki.TWikiPluginsSupplement - __%T% tip:__ supplemental documentation on TWiki plugins
   * TWiki:Plugins.PluginPackage - list of all contributed plugin packages
   * TWiki:Plugins.PluginDevelopment - discussion and feedback on contributed plugins
   * TWiki:Plugins.PluginBrainstorming - open forum for new plugin ideas
   * TWiki:Plugins.PluginPackageHowTo - template to create a new plugin package

__See other types of extensions:__ TWikiAddOns, TWikiContribs, TWikiSkins

#InstallPlugin
---++ Installing Plugins

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.

*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.

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.

#PreTesting
---+++ 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 satisfied 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 =[[VarFAILEDPLUGINS][%<nop>FAILEDPLUGINS%]]= variable 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. 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 <nop>%SCRIPTURLPATH{"view"}%/%SYSTEMWEB%/AbcPlugin=

%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 %<nop>DISABLEDPLUGINS% TWiki variable.

Define =DISABLEDPLUGINS= to be a comma-separated list of names of plugins to disable. Define it in %USERSWEB%.<nop>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,
<pre>
   * <nop>Set DISABLEDPLUGINS = SpreadSheetPlugin, EditTablePlugin
</pre>

#ManagingPlugins
---++ Managing Installed Plugins

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:

---+++ Enabling/Disabling Plugins

Plugins can be enabled and disabled with the [[%SCRIPTURLPATH{configure}%][configure]] script in the *Plugins* section. An installed plugin needs to be enabled before it can be used.

---+++ Plugin Evaluation Order

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 [[%SCRIPTURLPATH{configure}%][configure]].

#PluginSpecificSettings
---+++ Plugin-Specific Settings

Plugins can be configured with 1. preferences settings and/or 2. with configure settings. Older plugins use plugin preferences settings defined in the plugin topic, which is no longer recommended.

__1. Use preferences settings:__

Adinistrators can set plugin-specific settings in the local site preferences at <nop>%LOCALSITEPREFS% and users can overload them at the web level and page level. This approach is recommended if users should be able to overload settings. For security this is __not recommended for system settings__, such as a path to an executable. By convention, preferences setting names start with the plugin name in all caps, and an underscore. For example, to set the cache refresh period of the TWiki:Plugins.VarCachePlugin, add this bullet in <nop>%LOCALSITEPREFS%

   * =Set VARCACHEPLUGIN_REFRESH = 24=

Preferences settings that have been defined in <nop>%LOCALSITEPREFS% can be retrieved anywhere in TWiki with =%&lt;pluginname&gt;_&lt;setting&gt;%=, such as =%<nop>VARCACHEPLUGIN_REFRESH%=.

To learn how this is done, use the TWiki:Plugins.VarCachePlugin documentation and Perl plugin code as a reference.

__2. Use configure settings:__

The administrator can set plugin settings in the [[%SCRIPTURL{configure}%][configure]] interface. Recommended if only site administrators should be able to change settings. Chose this option to set sensitive or dangerous system settings, such as passwords or path to executables. To define plugin-specific configure settings,

   * [[#ConfigSpec][Create a Config.spec file]] in =lib/TWiki/Plugins/YourPlugin/= with variables, such as%BR%
     =$TWiki::cfg{Plugins}{RecentVisitorPlugin}{ShowIP} = 0;=
   * In the plugin, use those those variables, such as%BR%
     =$showIP = $TWiki::cfg{Plugins}{RecentVisitorPlugin}{ShowIP} || 0;=

To learn how this is done, use the TWiki:Plugins.RecentVisitorPlugin documentation and Perl plugin code as a reference.

In either case, define a SHORTDESCRIPTION setting in two places:

   * As a setting in the plugin documentation, which is needed for the extension reports on twiki.org. Example:%BR%
      * =Set SHORTDESCRIPTION = Show recent visitors to a TWiki site=
   * As a global Perl package variable in the plugin package, which is needed by TWiki to show info on installed plugins. Example:%BR%
     =our $SHORTDESCRIPTION = 'Show recent visitors to a TWiki site';=

For better performance, make sure you define this in the plugin package:%BR%
=our $NO_PREFS_IN_TOPIC = 1;=

---+++ Listing Active Plugins

Plugin status variables let you list all active plugins wherever needed.

This site is running TWiki version *%WIKIVERSION%*, plugin API version
*%PLUGINVERSION{}%*

#ActivatedPlugins
---++++ =%<nop>ACTIVATEDPLUGINS%=
On this TWiki site, the enabled plugins are: %ACTIVATEDPLUGINS%.

---++++ =%<nop>PLUGINDESCRIPTIONS%=
%PLUGINDESCRIPTIONS%

#FailedPlugins
---++++ =%<nop>FAILEDPLUGINS%=
%FAILEDPLUGINS%

#PluginAPI
---++ The TWiki Plugin API

The Application Programming Interface (API) for TWiki plugins 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.

__%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.

---+++ Predefined Hooks

In addition to TWiki core functions, plugins can use *predefined hooks*, or *callbacks*, as described in the =lib/TWiki/Plugins/EmptyPlugin.pm= module.

   * All but the initPlugin are commented out. To enable a callback, remove the leading  =#= from all lines of the callback.

TWiki:Codev.StepByStepRenderingOrder helps you decide which rendering handler to use.

#FastPluginHints
---+++ 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 you actually see the syntax in the text.
      * For example, use an =eval= block like this:%BR%
        =eval { require IPC::Run }= %BR%
        =return "&lt;font color=\"red\"&gt;SamplePlugin: Can't load required modules ($@@)&lt;/font&gt;" if $@@;=
   * 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/=.
   * Avoid using preferences in the plugin topic; Define =$NO_PREFS_IN_TOPIC= in your plugin package as that will stop TWiki from reading the plugin topic for every page. Use [[#ConfigSpec][Config.spec]] or preferences settings instead. ([[#PluginSpecificSettings][See details]]). 
   * Use registered tag handlers.
   * [[#MeasurePerformance][Measure the performance]] to see the difference.

---+++ Version Detection

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.

   * All plugin packages require a =$VERSION= variable. This should be an integer, or a subversion version id.

   * The =initPlugin= handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong.
      * The plugin initialization code does not register a plugin that returns 0 (or that has no =initPlugin= handler).

   * =$TWiki::Plugins::VERSION= in the =TWiki::Plugins= module contains the TWiki plugin API version, currently *%PLUGINVERSION{}%*.
      * You can also use the =[[VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= variable to query the plugin API version or the version of installed plugins.

---+++ 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.
      * [[#ConfigSpec][Integrating with <code>configure</code>]] describes the steps
      * TWiki:Plugins.MailInContrib has an example
      * TWiki:Plugins.BuildContrib can help you with this
   * 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.

#CreatePlugins
---++ 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 [[#PluginAPI][TWiki Plugin API]] provides the programming interface for TWiki.

---+++ Anatomy of a Plugin

A (very) basic TWiki plugin consists of two files:

   * a Perl module, e.g. =MyFirstPlugin.pm=
   * a documentation topic, e.g. =MyFirstPlugin.txt=

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.

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.

_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_.

---+++ Creating the Perl Module 

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.

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:
<pre>
use TWiki::Plugins::MyFirstPlugin::Attrs;
$var = MyFirstPlugin::Attrs->new();
</pre>

#CreatePluginTopic
---+++ Writing the Documentation Topic

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 [[#CreatePluginPackage][distribution package]].) To create a documentation topic:

   1. *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 &amp; copy 
      * Cancel the edit
      * go back to your site to the %SYSTEMWEB% web
      * In the JumpBox enter your plugin name, for example =MyFirstPlugin=, press enter and create the new topic
      * paste &amp; save new plugin topic on your site
   1. *Customize* your plugin topic.
      * 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/%WIKINAME%. This is important because links should work properly in a plugin topic installed on any TWiki, not just on TWiki.org.
   1. *Document* the performance data you gathered while [[#MeasurePerformance][measuring the performance]]
   1. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your plugin.

<blockquote style="background-color:#f5f5f5">
*OUTLINE: Doc Topic Contents* <br />
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:* &lt;<i>Describe any special text formatting that will be rendered.</i>&gt;" 

*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;"

*Plugin Settings:* &lt;<i>Description and settings for custom plugin %<nop>VARIABLES%, and those required by TWiki.</i>&gt;"

*Plugin Installation Instructions:* &lt;<i>Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.</i>&gt;"

*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;"
</blockquote>

#CreatePluginPackage
---+++ 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=).

   1. 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]
   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:
      * =lib/TWiki/Plugins/MyFirstPlugin.pm=
      * =data/TWiki/MyFirstPlugin.txt=
      * =pub/TWiki/MyFirstPlugin/uparrow.gif=

#MeasurePerformance
---+++ Measuring and Improving the Plugin Performance

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.

See also [[#FastPluginHints][Hints on Writing Fast Plugins]].

#PublishPlugin
---+++ 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:
   1. *Post* the plugin documentation topic in the TWiki:Plugins/PluginPackage:
      * enter the plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
      * paste in the topic text from [[#CreatePluginTopic][Writing the Documentation Topic]] and save
   1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip=
   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.)
   1. *Put* the plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)

%N% Once you have done the above steps once, you can use the !BuildContrib to upload updates to your plugin.

Thank you very much for sharing your plugin with the TWiki community :-)

#RecommendedStorageOfPluginData
---++ Recommended Storage of Plugin Specific Data

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.

---+++ Plugin Internal Data

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.

---+++ Web Accessible Data

__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.

Recommendation for file name:
   * Prefix the filename with an underscore (the leading underscore avoids a name clash with files attached to the same topic)
   * Identify where the attachment originated from, typically by including the plugin name in the file name
   * Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
   * Example: =_GaugePlugin_img123.gif=

__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.

Recommendation for file names in plugin attachment area:
   * Prefix the filename with an underscore
   * Include the name of the web in the filename
   * Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
   * Example: =_Main_roundedge-ul.gif=

#ConfigSpec
---++ Integrating with <code>configure</code>
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.

=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=.

---+++ Structure of a <code>Config.spec</code> file
The =Config.spec= file for an extension starts with the extension announcing what it is:
<verbatim>
# ---+ Extensions
# ---++ BathPlugin
# This plugin senses the level of water in your bath, and ensures the plug
# is not removed while the water is still warm.
</verbatim> 
This is followed by one or more configuration items. Each configuration item has a _type_, a _description_ and a _default_. For example:
<verbatim>
# **SELECT Plastic,Rubber,Metal**
# Select the plug type
$TWiki::cfg{BathPlugin}{PlugType} = 'Plastic';

# **NUMBER**
# Enter the chain length in cm
$TWiki::cfg{BathPlugin}{ChainLength} = 30;

# **BOOLEAN EXPERT**
# Set this option to 0 to disable the water temperature alarm
$TWiki::cfg{BathPlugin}{TempSensorEnabled} = 1;
</verbatim>
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,
<verbatim>
if( $TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) {
    die "The bathwater is too hot for comfort";
}
</verbatim>

The Config.spec file is read by =configure=, which then writes =LocalSite.cfg= with the values chosen by the local site admin.

A range of types are available for use in =Config.spec= files:

| BOOLEAN | A true/false value, represented as a checkbox |
| COMMAND _length_ | A shell command |
| LANGUAGE | A language (selected from ={LocalesDir}= |
| NUMBER | A number |
| OCTAL | An octal number |
| PASSWORD _length_ | A password (input is hidden) |
| PATH _length_ | A file path |
| PERL | A perl structure, consisting of arrays and hashes |
| REGEX _length_ | A perl regular expression |
| SELECT _choices_ | Pick one of a range of choices |
| SELECTCLASS _root_ | Select a perl package (class) |
| STRING _length_ | A string |
| URL _length_ | A url |
| URLPATH _length_ | A relative URL path |

All types can be followed by a comma-separated list of _attributes_.
| EXPERT | means this an expert option |
| M | means the setting is mandatory (may not be empty) |
| H | means the option is not visible in =configure= |

See =lib/TWiki.spec= for many more examples.

=Config.spec= files for non-plugin extensions are stored under the =Contrib= directory instead of the =Plugins= directory.

Note that from TWiki 5.0 onwards, CGI scripts (in the TWiki =bin= directory) provided by extensions must also have an entry in the =Config.spec= file. This entry looks like this (example taken from Publish<nop>Contrib)

<verbatim>
# **PERL H**
# Bin script registration - do not modify
$TWiki::cfg{SwitchBoard}{publish} = [ "TWiki::Contrib::Publish", "publish", { publishing => 1 } ];
</verbatim>
=PERL= specifies a perl data structure, and =H= a hidden setting (it won't appear in =configure=). The first field of the data value specifies the class where the function that implements the script can be found. The second field specifies the name of the function, which must be the same as the name of the script. The third parameter is a hash of initial context settings for the script.

TWiki:TWiki/SpecifyingConfigurationItemsForExtensions has supplemental documentation on configure settings.

#MaintainPlugins
---++ Maintaining Plugins

---+++ Discussions and Feedback on Plugins

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.

---+++ Maintaining Compatibility with Earlier TWiki Versions

The plugin interface (TWikiFuncDotPm functions and plugin handlers) evolve over time. TWiki introduces new API functions to address the needs of plugin authors. Plugins using unofficial TWiki internal functions may no longer work on a TWiki upgrade.

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. 

__%T% Tip:__ Plugins can be written to be compatible with older and newer TWiki releases. This can be done also for plugins using unofficial TWiki internal functions of an earlier release that no longer work on the latest TWiki codebase. 
Here is an example; the TWiki:TWiki.TWikiPluginsSupplement#MaintainPlugins has more details.

<verbatim>
    if( $TWiki::Plugins::VERSION >= 1.1 ) {
        @@webs = TWiki::Func::getListOfWebs( 'user,public' );
    } else {
        @@webs = TWiki::Func::getPublicWebList( );
    }
</verbatim>

---+++ Handling deprecated functions

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.

When a plugin defines deprecated handlers, a warning will be shown in the list generated by %<nop>FAILEDPLUGINS%. Admins who see these warnings should check TWiki.org and if necessary, contact the plugin author, for an updated version of the plugin.

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 %<nop>FAILEDPLUGINS%.

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:

<verbatim>
package TWiki::Plugins::SinkPlugin;
use vars qw( %TWikiCompatibility );
$TWikiCompatibility{endRenderingHandler} = 1.1;
</verbatim>
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.

%STOPINCLUDE%
__Related Topics:__ DeveloperDocumentationCategory, AdminDocumentationCategory, TWiki:TWiki.TWikiPluginsSupplement

-- __Contributors:__ TWiki:Main.PeterThoeny, TWiki:Main.AndreaSterbini, TWiki:Main.MikeMannix, TWiki:Main.CrawfordCurrie, TWiki:Main.ArthurClemens, TWiki:Main.WillNorris
@


1.36
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1307397574" format="1.1" version="36"}%
d62 1
a62 1
---+++ Enabling Plugins
d64 1
a64 1
Plugins can be enabled and disabled with the [[%SCRIPTURLPATH{configure}%][configure]] script. An installed plugin needs to be enabled before it can be used.
@


1.35
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1273873714" format="1.1" version="35"}%
d70 1
d73 1
a73 1
Some plugins are configured with plugin preferences variables, newer plugins with configure variables.
d75 1
a75 1
Configure variables are accessible though the [[%SCRIPTURLPATH{"configure"}%][configure]] interface. 
d77 1
a77 1
Plugin preferences variables are defined in the plugin topic and can be overloaded. The SHORTDESCRIPTION preferences variable is always present, it is needed for the TWiki:Plugins repository on twiki.org. Example preferences variable defined in the TablePlugin topic:
d79 26
a104 3
   * =Set SHORTDESCRIPTION = Control attributes of tables and sorting of table columns=
 
Preferences variables of active plugins can be retrieved anywhere in TWiki with =%&lt;pluginname&gt;_&lt;var&gt;%=, such as =%<nop>TABLEPLUGIN_SHORTDESCRIPTION%=. They can also be redefined with the =%&lt;pluginname&gt;_&lt;var&gt;%= setting at a lower level in the [[%LOCALSITEPREFS%]] or at the web level. For an easier upgrade it is recommended to customize plugin preferences variables in <nop>%LOCALSITEPREFS% only.
d139 1
a139 1
   * All but the initPlugin are disabled. To enable a callback, remove =DISABLE_= from the function name.
d141 1
a141 1
TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.
d151 3
a153 3
   * 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 [[#ConfigSpec][Config.spec]] instead. 
   * Use registered tag handlers
   * [[#MeasurePerformance][Measure the performance]] to see the difference
a233 3
   * *Plugins Preferences* &lt;<i>If user settings are needed, explain... Entering values works exactly like %SYSTEMWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:</i>&gt;"
      * *Set &lt;<i>EXAMPLE = value added</i>&gt;*

d315 2
a316 1
# ---+ BathPlugin
d341 1
a341 1
The config.spec file is read by =configure=, which then writes =LocalSite.cfg= with the values chosen by the local site admin.
@


1.34
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1208648630" format="1.1" version="34"}%
d193 1
a193 1
      * In the GoBox enter your plugin name, for example =MyFirstPlugin=, press enter and create the new topic
d292 1
a292 1
The =Config.spec= file for a plugin starts with the plugin announcing what it is:
d306 1
a306 1
$TWiki::cfg{BathPlugin}{ChainLength} = '30';
d309 2
a310 2
# Turn this option off to disable the water temperature alarm
$TWiki::cfg{BathPlugin}{TempSensorEnabled} = '1';
d312 1
a312 1
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,
d319 1
a319 1
The config.spec file is read by configure, and =configure= then writes =LocalSite.cfg= with the values chosen by the local site admin.
d345 10
a354 1
=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.
a402 1

@


1.33
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1179343828" format="1.1" version="33"}%
d5 1
a5 1
_Add functionality to TWiki with readily available Plugins; create Plugins based on APIs_
d11 1
a11 1
You can add Plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you:
d15 1
a15 1
   * rapidly develop new TWiki functions in Perl using the Plugin API.
d17 1
a17 1
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.
d19 1
a19 1
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.
d33 1
a33 1
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.
d35 1
a35 1
*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.
d37 1
a37 1
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.
d42 1
a42 1
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.
d44 1
a44 1
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 =[[VarFAILEDPLUGINS][%<nop>FAILEDPLUGINS%]]= variable can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.
d48 1
a48 1
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 <nop>%SCRIPTURLPATH{"view"}%/%SYSTEMWEB%/AbcPlugin=
d50 1
a50 1
%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 %<nop>DISABLEDPLUGINS% TWiki variable.
d60 1
a60 1
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:
d64 1
a64 1
Plugins can be enabled and disabled with the [[%SCRIPTURLPATH{configure}%][configure]] script. An installed Plugin needs to be enabled before it can be used.
d68 1
a68 1
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 [[%SCRIPTURLPATH{configure}%][configure]].
d72 9
a80 3
Plugins are usually configured by variables accessible though the [[%SCRIPTURLPATH{"configure"}%][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:
   * Set SETTING = Create dynamic foo bar reports
Then these settings can be retrieved as preferences variables like =%&lt;pluginname&gt;_&lt;var&gt;%=. For example, =%<nop>RUBBERPLUGIN_SETTING%= shows the value of SETTING in the !RubberPlugin topic.
d84 1
a84 1
Plugin status variables let you list all active Plugins wherever needed.
d86 1
a86 1
This site is running TWiki version *%WIKIVERSION%*, Plugin API version
d91 1
a91 1
On this TWiki site, the enabled Plugins are: %ACTIVATEDPLUGINS%.
d103 1
a103 1
The Application Programming Interface (API) for TWiki Plugins provides the specifications for hooking into the core TWiki code from your external Perl Plugin module.
d107 1
a107 1
The TWikiFuncDotPm module (=lib/TWiki/Func.pm=) describes *all* the interfaces available to Plugins. Plugins should *only* use the interfaces described in this module.
d109 1
a109 1
__%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.
d113 1
a113 1
In addition to TWiki core functions, Plugins can use *predefined hooks*, or *callbacks*, as described in the =lib/TWiki/Plugins/EmptyPlugin.pm= module.
d122 1
a122 1
   * 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.
d133 1
a133 1
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.
d138 1
a138 1
      * The Plugin initialization code does not register a Plugin that returns 0 (or that has no =initPlugin= handler).
d140 2
a141 2
   * =$TWiki::Plugins::VERSION= in the =TWiki::Plugins= module contains the TWiki Plugin API version, currently *%PLUGINVERSION{}%*.
      * You can also use the =[[VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= variable to query the Plugin API version or the version of installed Plugins.
d145 4
a148 3
   * 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
      * See TWiki:Plugins.MailInContrib for an example of this
d151 1
a151 1
   * 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.
d156 1
a156 1
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.
d160 1
a160 1
A (very) basic TWiki Plugin consists of two files:
d165 1
a165 1
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.
d168 1
a168 1
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.
d170 1
a170 1
_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_.
d176 1
a176 1
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:
d185 1
a185 1
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 [[#CreatePluginPackage][distribution package]].) To create a documentation topic:
d187 2
a188 2
   1. *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
d193 4
a196 4
      * In the GoBox enter your Plugin name, for example =MyFirstPlugin=, press enter and create the new topic
      * paste &amp; save new Plugin topic on your site
   1. *Customize* your Plugin topic.
      * 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/%WIKINAME%. This is important because links should work properly in a Plugin topic installed on any TWiki, not just on TWiki.org.
d198 1
a198 1
   1. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
d202 1
a202 1
Check the Plugins web on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
d206 1
a206 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;"
d208 1
a208 1
*Plugin Settings:* &lt;<i>Description and settings for custom Plugin %<nop>VARIABLES%, and those required by TWiki.</i>&gt;"
d221 1
a221 1
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!
d223 1
a223 1
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=).
d225 1
a225 1
   1. Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them all:
d229 1
a229 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:
d237 1
a237 1
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.
d244 1
a244 1
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.
d246 3
a248 3
Publish your Plugin by following these steps:
   1. *Post* the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
      * enter the Plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
d251 2
a252 2
   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.)
   1. *Put* the Plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)
d254 1
a254 1
%N% Once you have done the above steps once, you can use the !BuildContrib to upload updates to your Plugin.
d256 1
a256 1
Thank you very much for sharing your Plugin with the TWiki community :-)
d261 1
a261 1
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.
d265 1
a265 1
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.
d273 1
a273 1
   * Identify where the attachment originated from, typically by including the Plugin name in the file name
d275 1
a275 1
   * Example: =_FooBarPlugin_img123.gif=
d277 1
a277 1
__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.
d279 1
a279 1
Recommendation for file names in Plugin attachment area:
d347 2
d354 1
a354 1
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.
d358 1
a358 1
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.
d360 1
a360 1
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. 
d362 10
a371 1
__%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.
d393 2
@


1.32
log
@buildrelease
@
text
@d1 1
a1 2
%META:TOPICINFO{author="TWikiContributor" date="1168076964" format="1.1" version="32"}%
%TOC%
d3 1
a3 1
---# TWiki Plugins
d7 2
d42 1
a42 1
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.
d48 1
a48 1
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 <nop>%SCRIPTURLPATH{"view"}%/%TWIKIWEB%/AbcPlugin=
d52 1
a52 1
Define =DISABLEDPLUGINS= to be a comma-separated list of names of plugins to disable. Define it in %MAINWEB%.<nop>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,
d68 1
a68 1
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 speadsheet CALCs. This can be done with ={PluginsOrder}= in the Plugins section of [[%SCRIPTURLPATH{configure}%][configure]].
d80 4
d90 1
d117 7
a123 5
   * For example, use an =eval= block like this:%BR%
     =eval { require IPC::Run }= %BR%
     =return "&lt;font color=\"red\"&gt;SamplePlugin: Can't load required modules ($@@)&lt;/font&gt;" if $@@;=
   * You can use a flag to avoid running the initialization twice
   * The TWiki:Plugins.PluginBenchmarkAddOn comes in handy to measure and fine-tune the performance of your Plugin
d125 1
a125 1
---+++ Plugin Version Detection
d127 1
a127 1
To eliminate the incompatibility problems bound to arise from active open Plugin development, a Plugin versioning system is provided for automatic compatibility checking.
d129 1
a129 1
   * All modules require a =$VERSION='0.000'= variable, beginning at =1.000=.
d131 2
a132 2
   * The =initPlugin= handler should check all dependencies and return TRUE if the initialization is OK or FALSE if something went wrong.
      * The Plugin initialization code does not register a Plugin that returns FALSE (or that has no =initPlugin= handler).
d153 1
a153 1
A basic TWiki Plugin consists of two elements:
d155 2
a156 2
   * a Perl module, ex: =MyFirstPlugin.pm=
   * a documentation topic, ex: =MyFirstPlugin.txt=
d158 1
a158 1
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.
d163 2
a174 7
#MeasurePerformance
---+++ Measuring and Improving the Plugin Performance

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.

See also [[#FastPluginHints][Hints on Writing Fast Plugins]].

d178 1
a178 1
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:
d185 1
a185 1
      * go back to your site to the %TWIKIWEB% web
d203 1
a203 1
   * *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;"
d227 7
d258 1
a258 1
You can create a Plugin "work area" using the =TWiki::Func::getWorkArea()= function, which gives you a persistant 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.
d265 1
a265 1
   * Prefix the filename with an underscore (the leading underscore avoids a nameclash with files attached to the same topic)
d278 62
d351 1
a351 1
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 fullfilled if Plugins are maintained in a compatible manner. 
a374 1
-- __Contributors:__ TWiki:Main.PeterThoeny, TWiki:Main.AndreaSterbini, TWiki:MainMikeMannix, TWiki:CrawfordCurrie
@


1.31
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1111929255" format="1.0" version="31"}%
d20 8
a27 1
__%T% Tip:__ TWiki:TWiki.TWikiPluginsSupplement on TWiki.org has supplemental documentation on TWiki Plugins.
d49 6
a54 1
%T% 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.)
d71 3
a73 6
Plugin-specific settings are done in individual Plugin topics. Two settings are standard for each Plugin:
   1 One line description, used to form the bullets describing the Plugins in the %TWIKIWEB%.TextFormattingRules topic:
      * =Set SHORTDESCRIPTION = Create dynamic foo bar reports=
   1 Debug Plugin, output can be seen in =data/debug.txt=. Set to 0=off or 1=on:
      * =Set DEBUG = 0=
   * The settings can be retrieved as Preferences variables like =%&lt;pluginname&gt;_&lt;var&gt;%=. For example, =%<nop>DEFAULTPLUGIN_SHORTDESCRIPTION%= shows the description of the <nop>DefaultPlugin.
d252 1
a252 1
__Topic-specific data__ such as generated images can be stored in the topics attachment area, which is web accessible. Use the =TWiki::Func::saveAttachment()= function to store the data.
@


1.30
log
@buildrelease
@
text
@d1 1
a1 1
%META:TOPICINFO{author="TWikiContributor" date="1111929255" format="1.0" version="30"}%
d12 3
a14 3
	* 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.
d36 1
a36 1
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 =[[TWikiVariables#VarFAILEDPLUGINS][%<nop>FAILEDPLUGINS%]]= variable can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.
d60 5
a64 5
	1 One line description, used to form the bullets describing the Plugins in the %TWIKIWEB%.TextFormattingRules topic:
		* =Set SHORTDESCRIPTION = Create dynamic foo bar reports=
	1 Debug Plugin, output can be seen in =data/debug.txt=. Set to 0=off or 1=on:
		* =Set DEBUG = 0=
	* The settings can be retrieved as Preferences variables like =%&lt;pluginname&gt;_&lt;var&gt;%=. For example, =%<nop>DEFAULTPLUGIN_SHORTDESCRIPTION%= shows the description of the <nop>DefaultPlugin.
d94 1
a94 1
	* All but the initPlugin are disabled. To enable a callback, remove =DISABLE_= from the function name.
d101 6
a106 6
	* 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.
	* For example, use an =eval= block like this:%BR%
	  =eval { require IPC::Run }= %BR%
	  =return "&lt;font color=\"red\"&gt;SamplePlugin: Can't load required modules ($@@)&lt;/font&gt;" if $@@;=
	* You can use a flag to avoid running the initialization twice
	* The TWiki:Plugins.PluginBenchmarkAddOn comes in handy to measure and fine-tune the performance of your Plugin
d112 1
a112 1
	* All modules require a =$VERSION='0.000'= variable, beginning at =1.000=.
d114 2
a115 2
	* The =initPlugin= handler should check all dependencies and return TRUE if the initialization is OK or FALSE if something went wrong.
		* The Plugin initialization code does not register a Plugin that returns FALSE (or that has no =initPlugin= handler).
d117 2
a118 2
	* =$TWiki::Plugins::VERSION= in the =TWiki::Plugins= module contains the TWiki Plugin API version, currently *%PLUGINVERSION{}%*.
		* You can also use the =[[TWikiVariables#VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= variable to query the Plugin API version or the version of installed Plugins.
d122 6
a127 6
	* 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
		* See TWiki:Plugins.MailInContrib for an example of this
		* TWiki:Plugins.BuildContrib can help you with this
	* 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.
d138 2
a139 2
	* a Perl module, ex: =MyFirstPlugin.pm=
	* a documentation topic, ex: =MyFirstPlugin.txt=
d168 12
a179 12
	1. *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 &amp; copy 
		* Cancel the edit
		* go back to your site to the %TWIKIWEB% web
		* In the GoBox enter your Plugin name, for example =MyFirstPlugin=, press enter and create the new topic
		* paste &amp; save new Plugin topic on your site
	1. *Customize* your Plugin topic.
		* 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/%WIKINAME%. This is important because links should work properly in a Plugin topic installed on any TWiki, not just on TWiki.org.
	1. *Document* the performance data you gathered while [[#MeasurePerformance][measuring the performance]]
	1. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
d191 2
a192 2
	* *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;"
		* *Set &lt;<i>EXAMPLE = value added</i>&gt;*
d206 8
a213 8
	1. 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]
	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:
		* =lib/TWiki/Plugins/MyFirstPlugin.pm=
		* =data/TWiki/MyFirstPlugin.txt=
		* =pub/TWiki/MyFirstPlugin/uparrow.gif=
d221 6
a226 6
	1. *Post* the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
		* enter the Plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
		* paste in the topic text from [[#CreatePluginTopic][Writing the Documentation Topic]] and save
	1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip=
	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.)
	1. *Put* the Plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)
d246 4
a249 4
	* Prefix the filename with an underscore (the leading underscore avoids a nameclash with files attached to the same topic)
	* Identify where the attachment originated from, typically by including the Plugin name in the file name
	* Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
	* Example: =_FooBarPlugin_img123.gif=
d254 4
a257 4
	* Prefix the filename with an underscore
	* Include the name of the web in the filename
	* Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
	* Example: =_Main_roundedge-ul.gif=
@


1.29
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1092473905" format="1.0" version="1.29"}%
d6 1
a6 1
_Plug-in enhanced feature add-ons, with a Plugin API for developers_
d10 1
a10 1
You can add Plugins to extend TWiki's functionality, without altering the core program code. A plug-in approach lets you:
d18 1
a18 1
---++ Preinstalled Plugins
d20 1
a20 12
TWiki comes with a set of Plugins as part of the standard installation.

	* 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.)
	* EmptyPlugin: Is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development
	* CommentPlugin: %COMMENTPLUGIN_SHORTDESCRIPTION%
	* 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
	* EditTablePlugin: %EDITTABLEPLUGIN_SHORTDESCRIPTION%
	* RenderListPlugin: %RENDERLISTPLUGIN_SHORTDESCRIPTION%
	* SlideShowPlugin: %SLIDESHOWPLUGIN_SHORTDESCRIPTION%
	* SmiliesPlugin: %SMILIESPLUGIN_SHORTDESCRIPTION%
	* SpreadSheetPlugin: %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
	* TablePlugin: %TABLEPLUGIN_SHORTDESCRIPTION%
d25 3
a27 1
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. 
d29 1
a29 11
Most Plugins can be installed in three easy steps, with no programming skills required:
	1 *Download* the zip file containing the Plugin, documentation, and any other required files, from TWiki:Plugins. 
	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.
	1 *Check* the demo example on the Plugin topic: if it's working, the installation was fine!

*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.

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.
	* *Doc page:* Read all available info about the Plugin; download the attached distribution files.
	* *Dev page:* Post feature requests, bug reports and general dev comments; topic title ends in =Dev= (=SomePluginDev=).
	* *User support:* Post installation, how to use type questions (and answers, if you have them) in the TWiki:Support web.
d34 1
a34 7
To test new Plugins on your installation before making them public, you may want to use one of these two approaches:

	* *Method 1:* Safely test on-the-fly by creating separate Production and Test branches in your live TWiki installation. 
		* *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=.
		* *Test* Plugins and other new features in the Test installation until you're satisfied.
			* %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.
		* *Copy* the modified files to the Production installation. You can update a TWiki installation live and users won't even notice.
d36 1
a36 1
	* *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.
d38 1
a38 1
---+++ Checking that Plugins are Working on a Live Server
d40 1
a40 1
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.
d42 1
a42 1
---+++ A Note on Plugin Performance
d44 2
a45 1
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=
d47 1
a47 1
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.)
d49 1
a49 1
---++ Managing Plugins
d51 1
a51 1
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.
d53 1
a53 1
---+++ Setting Preferences
d55 1
a55 1
Installed Plugins can be *toggled on or off*, site-wide or by web, through <nop>TWikiPreferences and individual <nop>WebPreferences:
d57 1
a57 3
	* 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:
		* =Set INSTALLEDPLUGINS = <nop>DefaultPlugin, ...= 
		* =Set DISABLEDPLUGINS = <nop>EmptyPlugin, ...=
d59 1
a59 3
*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.

*Plugin-specific settings* are done in individual Plugin topics. Two settings are standard for each Plugin:
d61 1
a61 1
		* =Set SHORTDESCRIPTION = Blah blah woof woof.=
d64 1
a64 1
	* 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.
d68 1
a68 3
Plugin status variables let you list all active Plugins wherever needed. There are two list formats:
	* The =%<nop>ACTIVATEDPLUGINS%= variable lists activated Plugins by name. (This variable is displayed in %TWIKIWEB%.TWikiPreferences for debugging use.)
	* 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.
d70 2
a71 2
<blockquote style="background-color:#f5f5f5">
*DEMO: Automatically List Active Plugins Using Variables*
d73 2
a74 2
Using =%<nop>ACTIVATEDPLUGINS%=:<br />
On this TWiki site, the active Plugins are: %ACTIVATEDPLUGINS%.
d76 2
a77 4
Using =%<no>PLUGINDESCRIPTIONS%=:<br />
You can use any of these active TWiki Plugins:
%PLUGINDESCRIPTIONS%
</blockquote>
d82 1
a82 1
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.
d86 1
a86 1
The TWikiFuncModule (=lib/TWiki/Func.pm=) implements ALL official Plugin functions. Plugins should ONLY use functions published in this module.
d88 1
a88 1
%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.
d92 1
a92 4
In addition to TWiki core functions, Plugins can use *predefined hooks*, or *call backs*, listed 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.
	* For best performance, enable only the functions you really need. NOTE: =outsidePREHandler= and =insidePREHandler= are particularly expensive. 
d94 1
a94 3
Most Plugins use either the =commonTagsHandler= or =startRenderingHandler= for rendering tasks:
	* =commonTagsHandler:= Use it to expand =%<nop>XYZPLUGIN%= and =%<nop>XYZPLUGIN{...}%= variables
	* =startRenderingHandler:= Use it for your own rendering rules or to overload TWiki's internal rendering like =[<nop>[links]]=
d98 1
d101 2
a102 2
	* Delay the Plugin initialization to the actual function which is handling the tag. This way all the expensive initialization is done only when needed.
	* For example, use an =eval= block like:%BR%
a104 1
	* You could return errors as strings to show what happened
d106 1
d118 10
a127 1
		* You can also use the [[TWikiVariables#VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]] variable to query the Plugin API version or the version of installed Plugins.
a133 5
#DefaultPluginAlt
---+++ The <nop>DefaultPlugin Alternative

	* *<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.

d152 2
a153 2
  use TWiki::Plugins::MyFirstPlugin::Attrs;
  $var = MyFirstPlugin::Attrs->new();
d156 7
d176 4
a179 3
	2. *Customize* your Plugin topic.
		* In case you plan to publish your Plugin at TWiki.org, use Interwiki names for author names, like TWiki:Main/%WIKINAME%. 
	3. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
d202 3
a204 1
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=).
d206 1
a206 1
	1. Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them ALL:
d218 1
a218 1
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:
d220 1
d223 1
a223 1
		* paste in the topic text from [[#CreatePluginTopic][Creating Plugin Documentation]] and save
d226 3
a228 1
	1. *Put* the Plugin into the CVS repository, see TWiki:Plugins/ReadmeFirst (optional)
d233 42
a274 1
---++ Recommended Storage of Plugin Data
d276 1
a276 1
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.
d278 1
a278 1
---+++ Where to store Plugin Internal Data
d280 1
a280 1
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.
d282 1
a282 27
	* The Plugin's attachment directory is =pubdir/Installweb/FooBarPlugin=
		* =Installweb= refers to the name of the web where the Plugin is installed
	* The Plugin's attachment URL is =%<nop>PUBURL%/Installweb/FooBarPlugin=
	* The filename should start with an underscore, followed by an identifier, e.g. =_any_name.ext=
		* The leading underscore avoids a nameclash with files attached to the Plugin topic
		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
		* Do not use subdirectories (rename and delete would fail)
	* Use Plugin API functions documented in TWikiFuncModule to ensure portability:
		* Use =getPubDir()= to get the attachment root directory
		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser
		* Use =$installWeb= to get the name of the web where the Plugin is installed
		* Create the web directory and topic attachment directory if needed
	* Hint: Package the Plugin at least with one file attachment. This ensures that the attachment directory already exists

---+++ Where to Store Data for Topics using the Plugin

In case the Plugin generates data which is specific to a topic, store it in the topic's attachment directory.

	* The topic's attachment directory is =pubdir/Webname/TopicName=
	* The topic's attachment URL is =%<nop>PUBURL%/Webname/TopicName=
	* The filename should start with an underscore, followed by the Plugin name, an underscore and an identifier, e.g. =_FooBarPlugin_any_name.ext=
		* The leading underscore avoids a nameclash with files attached to the same topic
		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
		* Do not use subdirectories (rename and delete would fail)
	* Use Plugin API functions documented in TWiki.TWikiFuncModule to ensure portability:
		* Use =getPubDir()= to get the attachment root directory
		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser
a283 1
Example code to build the file name:
d285 3
a287 18
sub _make_filename
{
	 my ( $web, $topic, $name ) = @@_;

	 # Create web directory "pub/$web" if needed
	 my $dir = TWiki::Func::getPubDir() . "/$web";
	 unless( -e "$dir" ) {
		  umask( 002 );
		  mkdir( $dir, 0775 );
	 }
	 # Create topic directory "pub/$web/$topic" if needed
	 $dir .= "/$topic";
	 unless( -e "$dir" ) {
		  umask( 002 );
		  mkdir( $dir, 0775 );
	 }
	 return "$dir/_FooBarPlugin_$name";
}
d289 1
d291 2
a292 3
-- TWiki:Main/PeterThoeny - 14 Aug 2004 %BR%
-- TWiki:Main/AndreaSterbini - 29 May 2001 %BR%
-- TWiki:Main/MikeMannix - 03 Dec 2001	
d294 1
@


1.28
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1091940539" format="1.0" version="1.28"}%
d146 1
a146 1
To eliminate the incompatibility problems bound to arise from active open Plugin development, a Plugin versioning system and an API =GetVersion= detection routine are provided for automatic compatibility checking.
d153 2
a154 1
	* =$VERSION='1.000'= is the current setting in =TWiki::Plugins.pm= and in the preinstalled system Plugins (DefaultPlugin, EmptyPlugin, InterwikiPlugin).
d310 1
a310 1
-- TWiki:Main/PeterThoeny - 18 May 2004 %BR%
@


1.27
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1084862962" format="1.0" version="1.27"}%
d23 3
a25 2
	* EmptyPlugin: Is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development. 
	* 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.
@


1.26
log
@none
@
text
@d1 311
a311 306
%META:TOPICINFO{author="PeterThoeny" date="1071473016" format="1.0" version="1.26"}%
%TOC%
%STARTINCLUDE%
---# TWiki Plugins

_Plug-in enhanced feature add-ons, with a Plugin API for developers_

---++ Overview

You can add Plugins to extend TWiki's functionality, without altering the core program 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 <b> TWiki:Plugins </b> web.

---++ Preinstalled Plugins

TWiki comes with a set of Plugins as part of the standard installation.

	* 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.)
	* EmptyPlugin: Is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development. 
	* 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.
	* EditTablePlugin: %EDITTABLEPLUGIN_SHORTDESCRIPTION%
	* RenderListPlugin: %RENDERLISTPLUGIN_SHORTDESCRIPTION%
	* SlideShowPlugin: %SLIDESHOWPLUGIN_SHORTDESCRIPTION%
	* SmiliesPlugin: %SMILIESPLUGIN_SHORTDESCRIPTION%
	* SpreadSheetPlugin: %SPREADSHEETPLUGIN_SHORTDESCRIPTION%
	* TablePlugin: %TABLEPLUGIN_SHORTDESCRIPTION%

#InstallPlugin
---++ Installing Plugins

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. 

Most Plugins can be installed in three easy steps, with no programming skills required:
	1 *Download* the zip file containing the Plugin, documentation, and any other required files, from TWiki:Plugins. 
	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.
	1 *Check* the demo example on the Plugin topic: if it's working, the installation was fine!

*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.

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.
	* *Doc page:* Read all available info about the Plugin; download the attached distribution files.
	* *Dev page:* Post feature requests, bug reports and general dev comments; topic title ends in =Dev= (=SomePluginDev=).
	* *User support:* Post installation, how to use type questions (and answers, if you have them) in the TWiki:Support web.

#PreTesting
---+++ On-Site Pretesting

To test new Plugins on your installation before making them public, you may want to use one of these two approaches:

	* *Method 1:* Safely test on-the-fly by creating separate Production and Test branches in your live TWiki installation. 
		* *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=.
		* *Test* Plugins and other new features in the Test installation until you're satisfied.
			* %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.
		* *Copy* the modified files to the Production installation. You can update a TWiki installation live and users won't even notice.

	* *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.

---+++ A Note on Plugin Performance

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=

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.)

---++ Managing Plugins

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.

---+++ Setting Preferences

Installed Plugins can be *toggled on or off*, site-wide or by web, through <nop>TWikiPreferences and individual <nop>WebPreferences:

	* 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:
		* =Set INSTALLEDPLUGINS = <nop>DefaultPlugin, ...= 
		* =Set DISABLEDPLUGINS = <nop>EmptyPlugin, ...=

*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.

*Plugin-specific settings* are done in individual Plugin topics. Two settings are standard for each Plugin:
	1 One line description, used to form the bullets describing the Plugins in the %TWIKIWEB%.TextFormattingRules topic:
		* =Set SHORTDESCRIPTION = Blah blah woof woof.=
	1 Debug Plugin, output can be seen in =data/debug.txt=. Set to 0=off or 1=on:
		* =Set DEBUG = 0=
	* 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.

---+++ Listing Active Plugins

Plugin status variables let you list all active Plugins wherever needed. There are two list formats:
	* The =%<nop>ACTIVATEDPLUGINS%= variable lists activated Plugins by name. (This variable is displayed in %TWIKIWEB%.TWikiPreferences for debugging use.)
	* 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.

<blockquote style="background-color:#f5f5f5">
*DEMO: Automatically List Active Plugins Using Variables*

Using =%<nop>ACTIVATEDPLUGINS%=:<br />
On this TWiki site, the active Plugins are: %ACTIVATEDPLUGINS%.

Using =%<no>PLUGINDESCRIPTIONS%=:<br />
You can use any of these active TWiki Plugins:
%PLUGINDESCRIPTIONS%
</blockquote>

#PluginAPI
---++ The TWiki Plugin API

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.

---+++ Available Core Functions

The TWikiFuncModule (=lib/TWiki/Func.pm=) implements ALL official Plugin functions. Plugins should ONLY use functions published in this module.

%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.

---+++ Predefined Hooks

In addition to TWiki core functions, Plugins can use *predefined hooks*, or *call backs*, listed 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.
	* For best performance, enable only the functions you really need. NOTE: =outsidePREHandler= and =insidePREHandler= are particularly expensive. 

Most Plugins use either the =commonTagsHandler= or =startRenderingHandler= for rendering tasks:
	* =commonTagsHandler:= Use it to expand =%<nop>XYZPLUGIN%= and =%<nop>XYZPLUGIN{...}%= variables
	* =startRenderingHandler:= Use it for your own rendering rules or to overload TWiki's internal rendering like =[<nop>[links]]=

TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.

---+++ Hints on Writing Fast Plugins

	* Delay the Plugin initialization to the actual function which is handling the tag. This way all the expensive initialization is done only when needed.
	* For example, use an =eval= block like:%BR%
	  =eval { require IPC::Run }= %BR%
	  =return "&lt;font color=\"red\"&gt;SamplePlugin: Can't load required modules ($@@)&lt;/font&gt;" if $@@;=
	* You could return errors as strings to show what happened
	* You can use a flag to avoid running the initialization twice

---+++ Plugin Version Detection

To eliminate the incompatibility problems bound to arise from active open Plugin development, a Plugin versioning system and an API =GetVersion= detection routine are provided for automatic compatibility checking.

	* All modules require a =$VERSION='0.000'= variable, beginning at =1.000=.

	* The =initPlugin= handler should check all dependencies and return TRUE if the initialization is OK or FALSE if something went wrong.
		* The Plugin initialization code does not register a Plugin that returns FALSE (or that has no =initPlugin= handler).

	* =$VERSION='1.000'= is the current setting in =TWiki::Plugins.pm= and in the preinstalled system Plugins (DefaultPlugin, EmptyPlugin, InterwikiPlugin).

#CreatePlugins
---++ 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 [[#PluginAPI][TWiki Plugin API]] Plugins by providing a programming interface for TWiki.

#DefaultPluginAlt
---+++ The <nop>DefaultPlugin Alternative

	* *<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.

---+++ 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 [[#PluginAPI][Plugin API]], you're ready to develop Plugins.

---+++ Creating the Perl Module 

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.

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:
<pre>
  use TWiki::Plugins::MyFirstPlugin::Attrs;
  $var = MyFirstPlugin::Attrs->new();
</pre>

#CreatePluginTopic
---+++ Writing the Documentation Topic

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:

	1. *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 &amp; copy 
		* Cancel the edit
		* go back to your site to the %TWIKIWEB% web
		* In the GoBox enter your Plugin name, for example =MyFirstPlugin=, press enter and create the new topic
		* paste &amp; save new Plugin topic on your site
	2. *Customize* your Plugin topic.
		* In case you plan to publish your Plugin at TWiki.org, use Interwiki names for author names, like TWiki:Main/%WIKINAME%. 
	3. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.

<blockquote style="background-color:#f5f5f5">
*OUTLINE: Doc Topic Contents* <br />
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:* &lt;<i>Describe any special text formatting that will be rendered.</i>&gt;" 

*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;"

*Plugin Settings:* &lt;<i>Description and settings for custom Plugin %<nop>VARIABLES%, and those required by TWiki.</i>&gt;"

	* *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;"
		* *Set &lt;<i>EXAMPLE = value added</i>&gt;*

*Plugin Installation Instructions:* &lt;<i>Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.</i>&gt;"

*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;"
</blockquote>

#CreatePluginPackage
---+++ Packaging for Distribution

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=).

	1. 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]
	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:
		* =lib/TWiki/Plugins/MyFirstPlugin.pm=
		* =data/TWiki/MyFirstPlugin.txt=
		* =pub/TWiki/MyFirstPlugin/uparrow.gif=

#PublishPlugin
---+++ 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 in these steps:

	1. *Post* the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
		* enter the Plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
		* paste in the topic text from [[#CreatePluginTopic][Creating Plugin Documentation]] and save
	1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip=
	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.)
	1. *Put* the Plugin into the CVS repository, see TWiki:Plugins/ReadmeFirst (optional)

Thank you very much for sharing your Plugin with the TWiki community :-)

#RecommendedStorageOfPluginData
---++ Recommended Storage of Plugin Data

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.

---+++ Where to store Plugin Internal Data

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.

	* The Plugin's attachment directory is =pubdir/Installweb/FooBarPlugin=
		* =Installweb= refers to the name of the web where the Plugin is installed
	* The Plugin's attachment URL is =%<nop>PUBURL%/Installweb/FooBarPlugin=
	* The filename should start with an underscore, followed by an identifier, e.g. =_any_name.ext=
		* The leading underscore avoids a nameclash with files attached to the Plugin topic
		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
		* Do not use subdirectories (rename and delete would fail)
	* Use Plugin API functions documented in TWikiFuncModule to ensure portability:
		* Use =getPubDir()= to get the attachment root directory
		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser
		* Use =$installWeb= to get the name of the web where the Plugin is installed
		* Create the web directory and topic attachment directory if needed
	* Hint: Package the Plugin at least with one file attachment. This ensures that the attachment directory already exists

---+++ Where to Store Data for Topics using the Plugin

In case the Plugin generates data which is specific to a topic, store it in the topic's attachment directory.

	* The topic's attachment directory is =pubdir/Webname/TopicName=
	* The topic's attachment URL is =%<nop>PUBURL%/Webname/TopicName=
	* The filename should start with an underscore, followed by the Plugin name, an underscore and an identifier, e.g. =_FooBarPlugin_any_name.ext=
		* The leading underscore avoids a nameclash with files attached to the same topic
		* Use only alphanumeric characters, underscores and periods to avoid platform dependency issues and URL issues
		* Do not use subdirectories (rename and delete would fail)
	* Use Plugin API functions documented in TWiki.TWikiFuncModule to ensure portability:
		* Use =getPubDir()= to get the attachment root directory
		* Use =getUrlHost()= and =getPubUrlPath()= to build the URL in case you create content for the browser

Example code to build the file name:
<verbatim>
sub _make_filename
{
	 my ( $web, $topic, $name ) = @@_;

	 # Create web directory "pub/$web" if needed
	 my $dir = TWiki::Func::getPubDir() . "/$web";
	 unless( -e "$dir" ) {
		  umask( 002 );
		  mkdir( $dir, 0775 );
	 }
	 # Create topic directory "pub/$web/$topic" if needed
	 $dir .= "/$topic";
	 unless( -e "$dir" ) {
		  umask( 002 );
		  mkdir( $dir, 0775 );
	 }
	 return "$dir/_FooBarPlugin_$name";
}
</verbatim>

-- TWiki:Main/PeterThoeny - 11 Dec 2003 <br />
-- TWiki:Main/AndreaSterbini - 29 May 2001 <br />
-- TWiki:Main/MikeMannix - 03 Dec 2001	
@


1.25
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1071215820" format="1.0" version="1.25"}%
d207 1
a207 1
*Plugin Global Settings:* &lt;<i>Description and settings for custom Plugin %<nop>VARIABLES%, and those required by TWiki.</i>&gt;"
d234 1
a234 1
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. Publish your Plugin in three steps:
d236 2
a237 2
	1. *Post* the Plugin documentation topic in the TWiki:Plugins web:
		* create a new topic using the Plugin name, ex: =MyFirstPlugin.txt=
d241 1
d243 64
a306 3
-- AndreaSterbini - 29 May 2001 <br />
-- PeterThoeny - 11 Dec 2003 <br />
-- MikeMannix - 03 Dec 2001	
@


1.24
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1059724429" format="1.0" version="1.24"}%
d20 1
a20 1
TWiki comes with three Plugins as part of the standard installation.
d22 9
a30 5
	* *[[%TWIKIWEB%.DefaultPlugin][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.)

	* *[[%TWIKIWEB%.EmptyPlugin][EmptyPlugin]]* is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development. 

	* *[[%TWIKIWEB%.InterwikiPlugin][InterwikiPlugin]]* is preinstalled but can be disabled or removed. 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.
d62 1
a62 1
---+++ A Note on Performance
d64 1
a64 1
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 needs 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=
d124 15
d243 1
a243 1
-- PeterThoeny - 29 Jan 2003 <br />
@


1.23
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1059716224" format="1.0" version="1.23"}%
d60 1
a60 1
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 needs 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.
@


1.22
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1046406720" format="1.0" version="1.22"}%
d57 6
@


1.21
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1043824860" format="1.0" version="1.21"}%
d51 1
a51 1
		* *Duplicate* the =twiki/bin= and =twiki/lib= directories for the Test version, adjusting the paths in the new =lib/TWiki.cfg=, the =twiki/data=; the =twiki/templates= and =twiki/pub= directories are shared. 
@


1.20
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1039329388" format="1.0" version="1.20"}%
d111 1
a112 1
	* All but the initPlugin are disabled. To enable a call back, remove =DISABLE_= from the function name.
d149 7
a155 1
Copy file =lib/TWiki/Plugins/EmptyPlugin.pm= to =&lt;name&gt;Plugin.pm=. =EmptyPlugin.pm= contains no executable code, so it does nothing, but it's ready to be used. Customize it. Refer to the [[#PluginAPI][Plugin API]] specs for more information.
d162 4
a165 3
	1. *Copy* the Plugin topic template from EmptyPlugin. To copy the text, go to the page and:
		* click Edit
		* select all in the Edit box & copy 
d167 6
a172 3
		* paste & save as a text file or new topic on your site
	2. *Customize* the template for your Plugin; you'll probably want to post a working version on your local TWiki site.
	3. *Save* your topic as a text file, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
d176 1
a176 1
Check EmptyPlugin on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
d180 1
a180 1
*<nop>MyFirstPlugin Settings:* &lt;<i>Description and settings for custom Plugin %VARIABLES%, and those required by TWiki.</i>&gt;"
d182 3
a184 1
	* *Plugins Preferences* &lt;<i>If user settings are needed, explain... Entering valuse works exactly like %TWIKIWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:</i>&gt;"
d187 1
a187 3
*How-to Instructions:* &lt;<i>Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.</i>&gt;"

*Test Example:* &lt;<i>Include an example of the Plugin in action: if it works, the installation was a success!</i>&gt;"
d218 1
a218 1
-- PeterThoeny - 14 Sep 2001 <br />
@


1.19
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1026976482" format="1.0" version="1.19"}%
d103 1
a103 1
The =lib/TWiki/Func.pm= implements ALL official Plugin functions. Plugins should ONLY use functions published in this module. 
a106 2
	* For best performance, enable only the functions you really need. NOTE: =outsidePREHandler= and =insidePREHandler= are particularly expensive. 

d111 1
@


1.18
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="1007374620" format="1.0" version="1.18"}%
d56 1
a56 1
	* *Method 2:* List the Plugin under =Test= in the =DISABLEDPLUGINS= variable in %TWIKIWEB%.TWikiPreferences. Redefine the =DISABLEDPLUGINS= variable in the Test web and do the testing there.
d210 1
a210 1
-- MikeMannix - 03 Dec 2001	
@


1.17
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="1001637305" format="1.0" version="1.17"}%
d173 1
a173 1
<b>Plugins Preferences</b> &lt;<i>If user settings are needed, explain... Entering valuse works exactly like %TWIKIWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:</i>&gt;"
a208 1
-- MikeMannix - 01 Sep 2001 <br />
d210 1
@


1.16
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="1000787146" format="1.0" version="1.16"}%
d45 1
d50 5
a54 4
	* *Method 1:* Create Production and a Test installation of TWiki. 
		* Duplicate the =twiki/bin= and =twiki/lib= directories for the Test version, adjusting the paths in the new =lib/TWiki.cfg=, the =twiki/data=; the =twiki/templates= and =twiki/pub= directories are shared. 
		* Test Plugins and other new features in the Test installation until you're satisfied.
		* Copy the modified files to the Production installation. You can update a live TWiki installation and users won't even notice.
d105 1
a105 1
<span style="color:#ff0000"><b>DevALERT:</b></span> 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.
@


1.15
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="1000620081" format="1.0" version="1.15"}%
d10 1
a10 1
You can add Plugins to extend TWiki's functionality, without altering the core program code. With a plug-in approach, you can:
d16 1
a16 1
Everything to do with TWiki Plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the *[[TWiki:Plugins]] web*.
d22 1
a22 1
	* *<nop>DefaultPlugin* handles some legacy TWiki variables that may be present in long-established sites. This option can be controlled from %TWIKIWEB%.TWikiPreferences. (Perl programmers can also [[#Customize_the_DefaultPlugin][add rules]] for simple custom processing.)
d24 1
a24 1
	* *<nop>EmptyPlugin* is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development. 
d26 1
a26 1
	* *InterwikiPlugin* is preinstalled but can be disabled or removed. Use it for quick linking to to remote sites: =TWiki:Plugins= expands to TWiki:Plugins on TWiki.org. You can add your own shortcuts and URLs to the existing directory of Wiki-related and other probably useful sites.
d54 1
a54 1
	* *Method 2:* List the Plugin under =Test= in the DISABLEDPLUGINS variable in %TWIKIWEB%.TWikiPreferences. Redefine the DISABLEDPLUGINS variable in the Test web and do the testing there.
d58 1
a58 1
Ideally, after you've [[#InstallPlugin][installed a Plugin]], 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.
d84 1
a84 1
<span style="color:#0000ff"> *DEMO: Active Plugin Variables* </span>
d86 1
a86 1
=%<nop>ACTIVATEDPLUGINS%= <br />
d89 1
a89 1
=%<no>PLUGINDESCRIPTIONS%= <br />
d129 1
d167 1
a167 1
*Syntax Rules:* Describe any special text formatting that will be rendered. 
d169 1
a169 1
*<nop>MyFirstPlugin Settings:* Description and settings for custom Plugin %VARIABLES%, and those required by TWiki.
d171 2
a172 2
Plugins Preferences work exactly like %TWIKIWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:
		* Set EXAMPLE = got it! 
d174 1
a174 1
*How-to Instructions:* Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.
d176 1
a176 1
*Test Example:* Include an example of the Plugin in action: if it works, the installation was a success!
d178 1
a178 1
*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.
@


1.14
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="1000548476" format="1.0" version="1.14"}%
d83 1
a83 1
<blockquote style="background-color:#f0f0f0">
d162 2
a163 2
<blockquote style="background-color:#f0f0f0">
<span style="color:#0000ff"><b>OUTLINE:</b> Doc Topic Contents </span><br>
d207 1
a207 1
-- Main.PeterThoeny - 14 Sep 2001 <br />
@


1.13
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="PeterThoeny" date="1000461351" format="1.0" version="1.13"}%
d6 1
a6 1
Plugin use and development; about the Plugin API.
d10 1
a10 1
You can add Plugins to greatly extend TWiki's functionality, without alering the program core. With a plug-in approach, you can:
d26 1
a26 1
	* *InterwikiPlugin* is preinstalled but can be disabled or removed. Use it for quick linking to to remote sites: ==TWiki:Plugins== expands to TWiki:Plugins on TWiki.org. You can add your own shortcuts and URLs to the existing directory of Wiki-related and other probably useful sites.
d40 1
a40 1
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.
d42 1
a42 1
	* *Dev page:* Post feature requests, bug reports and general dev comments; topic title ends in ==Dev== (==SomePluginDev==).
d50 1
a50 1
		* Duplicate the ==twiki/bin== and ==twiki/lib== directories for the Test version, adjusting the paths in the new ==lib/TWiki.cfg==, the ==twiki/data==; the ==twiki/templates== and ==twiki/pub== directories are shared. 
d54 1
a54 1
	* *Method 2:* List the Plugin under ==Test== in the DISABLEDPLUGINS variable in %TWIKIWEB%.TWikiPreferences. Redefine the DISABLEDPLUGINS variable in the Test web and do the testing there.
d64 3
a66 3
	* 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:
		* ==Set INSTALLEDPLUGINS = <nop>DefaultPlugin, ...== 
		* ==Set DISABLEDPLUGINS = <nop>EmptyPlugin, ...==
d68 1
a68 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.
d72 4
a75 4
		* ==Set SHORTDESCRIPTION = Blah blah woof woof.==
	1 Debug Plugin, output can be seen in ==data/debug.txt==. Set to 0=off or 1=on:
		* ==Set DEBUG = 0==
	* 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.
d80 2
a81 2
	* The ==%<nop>ACTIVATEDPLUGINS%== variable lists activated Plugins by name. (This variable is displayed in %TWIKIWEB%.TWikiPreferences for debugging use.)
	* 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.
d86 1
a86 1
==%<nop>ACTIVATEDPLUGINS%== <br />
d89 1
a89 1
==%<no>PLUGINDESCRIPTIONS%== <br />
d101 1
a101 1
The ==lib/TWiki/Func.pm== implements ALL official Plugin functions. Plugins should ONLY use functions published in this module. 
d103 1
a103 1
<span style="color:#ff0000"><b>DevALERT:</b></span> 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.
d105 1
a105 1
	* For best performance, enable only the functions you really need. NOTE: ==outsidePREHandler== and ==insidePREHandler== are particularly expensive. 
d109 1
a109 1
In addition to TWiki core functions, Plugins can use *predefined hooks*, or *call backs*, listed in the ==lib/TWiki/Plugins/EmptyPlugin.pm== module.
d111 1
a111 1
	* All but the initPlugin are disabled. To enable a call back, remove ==DISABLE_== from the function name.
d115 1
a115 1
To eliminate the incompatibility problems bound to arise from active open Plugin development, a Plugin versioning system and an API ==GetVersion== detection routine are provided for automatic compatibility checking.
d117 1
a117 1
	* All modules require a ==$VERSION='0.000'== variable, beginning at ==1.000==.
d119 2
a120 2
	* The ==initPlugin== handler should check all dependencies and return TRUE if the initialization is OK or FALSE if something went wrong.
		* The Plugin initialization code does not register a Plugin that returns FALSE (or that has no ==initPlugin== handler).
d122 1
a122 1
	* ==$VERSION='1.000'== is the current setting in ==TWiki::Plugins.pm== and in the preinstalled system Plugins (DefaultPlugin, EmptyPlugin, InterwikiPlugin).
d137 2
a138 2
	* a Perl module, ex: ==MyFirstPlugin.pm==
	* a documentation topic, ex: ==MyFirstPlugin.txt==
d141 1
a141 1
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.
d147 1
a147 1
Copy file =lib/TWiki/Plugins/EmptyPlugin.pm= to ==&lt;name&gt;Plugin.pm==. ==EmptyPlugin.pm== contains no executable code, so it does nothing, but it's ready to be used. Customize it. Refer to the [[#PluginAPI][Plugin API]] specs for more information.
d183 1
a183 1
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==).
d186 7
a192 7
		* ==lib/TWiki/Plugins/MyFirstPlugin.pm==
		* ==data/TWiki/MyFirstPlugin.txt==
		* ==pub/TWiki/MyFirstPlugin/uparrow.gif== [a required graphic]
	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:
		* ==lib/TWiki/Plugins/MyFirstPlugin.pm==
		* ==data/TWiki/MyFirstPlugin.txt==
		* ==pub/TWiki/MyFirstPlugin/uparrow.gif==
d197 1
a197 1
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:
d200 4
a203 4
		* create a new topic using the Plugin name, ex: ==MyFirstPlugin.txt==;
		* paste in the topic text from [[#CreatePluginTopic][Creating Plugin Documentation]] and Save.
	1. *Attach* the distribution zip file to the topic, ex: ==MyFirstPlugin.zip==.
	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.)
@


1.12
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="999857462" format="1.0" version="1.12"}%
d16 1
a16 1
Everything to do with TWiki Plugins - demos, new releases, downloads, development, general discussion - is available at TWiki.org, in the *[[TWiki:Plugins][TWiki.org Plugins web]]*.
d24 1
a24 1
	* *<nop>EmptyPlug* is a fully functional module, minus active code; it does nothing and serves as a template for new Plugin development. 
d86 1
a86 1
==%<nop>ACTIVATEDPLUGINS%== <br>
d89 1
a89 1
==%<no>PLUGINDESCRIPTIONS%== <br>
d97 1
a97 1
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 <nop>TWikiReleaseSpring2001.
d131 1
a131 1
	* *<nop>DefaultPlugin* can handle some outdated TWiki variables, found, for example, in sites recently updated from an old version. Settings are in %TWIKIWEB%.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.
d137 2
a138 2
	* a Perl module, ex: ==YourPlugin.pm==
	* a documentation topic, ex: ==YourPlugin.txt==
d141 1
a141 1
In particular, files that should be web-accessible (graphics, Java applets ...) are best placed as attachments of the ==YourPlugin== topic. Other needed Perl code is best placed in a ==lib/TWiki/Plugins/YourPlugin/== directory.
d147 1
a147 1
Copy file ([[http://twiki.org/lib/TWiki/Plugins/EmptyPlugin.pm][<code>EmptyPlugin.pm</code>]] to ==&lt;name&gt;Plugin.pm== ==EmptyPlugin.pm== contains no executable code, so it does nothing, but it's ready to be used. Customize it. Refer to the [[#PluginAPI][Plugin API]] specs for more information.
d154 1
a154 1
	1. *Copy* the Plugin topic template from http://TWiki.org/cgi-bin/view/TWiki/EmptyPlugin. To copy the text, go to the page and:
d164 1
a164 1
Check [[%TWIKIWEB%.EmptyPlugin][EmptyPlugin]] on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
d168 1
a168 1
*<nop>YourPlugin Settings:* Description and settings for your custom Plugin %VARIABLES%, and those required by TWiki.
d183 1
a183 1
A minimum Plugin release consists of a Perl module with a TWiki.WikiName that ends in ==Plugin==, ex: ==YourPlugin.pm==, and a documentation page with the same name(==YourPlugin.txt==).
d185 8
a192 8
	1. Distribute your Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them ALL:
		* ==lib/TWiki/Plugins/YourPlugin.pm==
		* ==data/TWiki/YourPlugin.txt==
		* ==pub/TWiki/YourPlugin/uparrow.gif== [a required graphic]
	2. Create a zip archive with the Plugin name (==YourPlugin.zip==) and add the entire directory structure from Step 1. Your archive should look like this:
		* ==lib/TWiki/Plugins/YourPlugin.pm==
		* ==data/TWiki/YourPlugin.txt==
		* ==pub/TWiki/YourPlugin/uparrow.gif==
d200 1
a200 1
		* create a new topic using the Plugin name, ex: ==YourPlugin.txt==;
d202 2
a203 2
	1. *Attach* the distribution zip file to the topic, ex: ==YourPlugin.zip==.
	1. *Link* from the doc page to a new, blank page named after the Plugin, and ending in ==Dev==, ex: ==YourPluginDev==. This is the discussion page for future development. (User support for Plugins is handled in TWiki:Support.)
d205 3
a207 2
-- AndreaSterbini - 29 May 2001 <br>
-- MikeMannix - 01 Sep 2001
@


1.11
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="AndreaSterbini" date="999419674" format="1.0" version="1.11"}%
d4 1
a4 1
---## TWiki Plugins
d8 1
a8 1
---+++ Overview
d18 1
a18 1
---+++ Preinstalled Plugins
d29 1
a29 1
---+++ Installing Plugins
d45 1
a45 1
---++++ On-Site Pretesting
d56 1
a56 2

---+++ Managing Plugins
d60 1
a60 1
---++++ Setting Preferences
d77 1
a77 1
---++++ Listing Active Plugins
d95 1
a95 1
---+++ The TWiki Plugin API
d99 1
a99 1
---++++ Available Core Functions
d107 1
a107 1
---++++ Predefined Hooks
d113 1
a113 1
---++++ Plugin Version Detection
a123 1

d125 1
a125 1
---+++ Creating Plugins
d129 1
a129 1
---++++ The <nop>DefaultPlugin Alternative
d133 1
a133 1
---++++ Anatomy of a Plugin
d145 1
a145 1
---++++ Creating the Perl Module 
d150 1
a150 1
---++++ Writing the Documentation Topic
d181 1
a181 1
---++++ Packaging for Distribution
d195 1
a195 1
---++++ Publishing for Public Use
@


1.10
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="999393063" format="1.0" version="1.10"}%
d120 1
a120 1
	* The ==initPlugin== handler checks all dependencies and returns TRUE if the initialization is OK or FALSE if something went wrong.
d143 1
@


1.9
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="999317099" format="1.0" version="1.9"}%
d6 1
a6 1
<nop>TWikiPlugins allow you to add new features to TWiki without changing the core program. Using a plug-in approach means that you can:
d8 5
a12 1
	* add virtually unlimited features while keeping the main TWiki program compact and efficient;
d16 11
a26 1
Everything to do with TWiki Plugins - including demos, new releases, downloads, and discussion - is available at TWiki.org, in the <b> [[TWiki:Plugins][TWiki.org Plugins web]]</b>.
d38 1
a38 1
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.
d40 1
a40 1
<nop>TWikiPlugin documentation pages are located at TWiki.org, in TWiki:Plugins web. Each Plugin has an doc topic (ex: ==SomePlugin==) and a separate development page.
d42 1
a42 1
	* *Dev page:* Post feature requests, bug reports and general dev comments; topic title ends in ==Dev== (ex: ==SomePluginDev==).
d45 1
a45 1
---+++ Preinstalled Plugins
d47 1
a47 1
TWiki comes with three Plugins as part of the standard installation.
d49 4
a52 1
	* *<nop>DefaultPlugin* handles some legacy TWiki variables that may be present in long-established sites. This option can be controlled from %TWIKIWEB%.TWikiPreferences. (Perl programmers can also [[#Customize_the_DefaultPlugin][add rules]] for simple custom processing.)
d54 1
a54 1
	* *<nop>EmptyPlug* is a fully functional Plugin module, minus any active code; it does nothing but serve as a template on demand. 
a55 1
	* *InterwikiPlugin* is included but can be disabled or removed. Use it for quick linking to frequently linked to remote sites. Ex: ==TWiki:Plugins== expands to TWiki:Plugins - on TWiki.org. You can add your own shortcuts and URLs to the existing directory of Wiki-related sites.
d95 2
a96 1
*TIP! To test new Plugins* on your installation before making them public, you may want to use one of these two approaches:
d98 1
a98 1
	* *Method 1:* Create a Production and a Test installation of TWiki. The ==twiki/data==, ==twiki/templates== and ==twiki/pub== directories are shared, and the ==twiki/bin== and ==twiki/lib== 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.
d100 1
a100 1
	* *Method 2:* List the Plugin under test in the DISABLEDPLUGINS variable in %TWIKIWEB%.TWikiPreferences. Redefine the DISABLEDPLUGINS variable in the test web and do the testing there.
d102 1
a102 2
#CreatePlugins
---+++ Creating Plugins
d104 1
a104 1
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.
d106 1
a106 1
---++++ Anatomy of a Plugin
d108 1
a108 1
A basic TWiki Plugin consists of two elements:
d110 1
a110 2
	* a Perl module, ex: ==YourPlugin.pm==
	* a documentation topic, ex: ==YourPlugin.txt==
d112 1
a112 1
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.
d114 1
a114 1
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.
d116 1
a116 2
#PluginAPI
---++++ TWiki Plugin API
d118 1
a118 1
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 <nop>TWikiReleaseSpring2001.
d120 2
a121 1
The ==lib/TWiki/Func.pm== implements ALL official Plugin functions. Plugins should ONLY use functions published in this module. 
d123 1
a123 1
<span style="color:#ff0000"><b>DevALERT:</b></span> 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.
a124 1
In addition to TWiki core functions, Plugins can use *predefined hooks*, or *call backs*, listed in the ==lib/TWiki/Plugins/EmptyPlugin.pm== module.
d126 2
a127 1
	* All but the initPlugin are disabled. To enable a call back, remove ==DISABLE_== from the function name.
d129 1
a129 1
	* For improve performance, enable only the functions you really need. NOTE: ==outsidePREHandler== and ==insidePREHandler== are particularly expensive. 
d135 11
d206 2
a207 1
-- MikeMannix - 26 Aug 2001
@


1.8
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="999237943" format="1.0" version="1.8"}%
d31 1
a31 1
---+++ Pre-Installed Plugins
d41 1
a41 1
---+++ Managing Installed Plugins
d45 1
a45 1
---++++ Set Preferences for Individual Plugins
d62 1
a62 1
---++++ List Active Plugins Automatically  
d86 1
a86 1
---+++ Creating New Plugins
d116 1
a116 1
---++++ Customize the <nop>DefaultPlugin
d120 1
a120 1
---++++ Create a Plugin Module in Perl
d125 1
a125 1
---++++ Create a Plugin Documentation Topic
d156 1
a156 1
---++++ Package a Plugin for Distribution
d170 1
a170 1
---++++ Publish a Plugin for General Use
@


1.7
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="998903988" format="1.0" version="1.7"}%
a4 2

---+++ About Plugins
@


1.6
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="998886618" format="1.0" version="1.6"}%
d14 1
a14 1
Everything to do with TWiki Plugins - including demos, new releases, downloads, and discussion - is available at TWiki.org, in the <b> [[http://twiki.org/cgi-bin/view/Plugins][TWiki.org Plugins web]]</b>.
d49 1
a49 1
Installed Plugins can be *toggled on or off*, site-wide or by web, through TWiki.TWikiPreferences and individual WebPreferences:
d51 1
a51 1
	* 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 TWiki.TWikiPreferences are:
d67 2
a68 2
	* The ==%<nop>ACTIVATEDPLUGINS%== variable lists activated Plugins by name. (This variable is displayed in TWiki.TWikiPreferences for debugging use.)
	* 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 TWiki.TextFormattingRules.
d85 1
a85 1
	* *Method 2:* List the Plugin under test in the DISABLEDPLUGINS variable in TWiki.TWikiPreferences. Redefine the DISABLEDPLUGINS variable in the test web and do the testing there.
d141 1
a141 1
Check [[http://TWiki.org/cgi-bin/view/TWiki/EmptyPlugin][EmptyPlugin]] on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
d143 1
a143 1
*Syntax Rules:* __explanation coming up__
d178 1
a178 1
		* paste in the topic text from [[#CreatePluginTopic][How to Create the Plugin Documentation Topic]] and Save.
@


1.5
log
@none
@
text
@d1 1
a1 1
%META:TOPICINFO{author="MikeMannix" date="998854083" format="1.0" version="1.5"}%
d182 1
a182 1
-- Main.MikeMannix - 26 Aug 2001
@


1.4
log
@none
@
text
@d1 4
a4 2
%META:TOPICINFO{author="PeterThoeny" date="995108962" format="1.0beta2" version="1.4"}%
---++ TWiki Plugins
d6 1
a6 1
Plugins allow you to extend the syntax or functionality of TWiki. ...
d8 1
a8 1
TWikiPreferences has the list of installed plugins and activated plugins.
d10 3
a12 1
---+++ How to Create a Plugin
d14 1
a14 1
under construction... ( check back at http://TWiki.org/cgi-bin/view/TWiki/TWikiPlugins )
d16 2
a17 1
---+++ How to Install a Plugin
d19 1
a19 1
under construction... ( check back at http://TWiki.org/cgi-bin/view/TWiki/TWikiPlugins )
d21 4
a24 1
---+++ Plugins under the hood
d26 1
a26 3
	* All plugin modules that exist in the =lib/TWiki/Plugins= directory are activated automatically unless disabled by the =DISABLEDPLUGINS= preferences variable in 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 then the %WIKITOOLNAME% web for the plugin topics. Settings in TWiki.TWikiPreferences:
		* =Set INSTALLEDPLUGINS = <nop>DefaultPlugin, ...= 
		* =Set DISABLEDPLUGINS = <nop>EmptyPlugin, ...=
d28 4
a31 1
	* The =%<nop>ACTIVATEDPLUGINS%= variable shows all currently activated plugins. This variable is shown in TWiki.TWikiPreferences for debug reasons.
d33 1
a33 1
	* Search order for plugin topics: Full =web.topicname= name is used if specified in =INSTALLEDPLUGINS=, then the %TWIKIWEB% web is searched, then the current web.
d35 1
a35 6
	* Plugin specific settings are done in individual plugin topics. Two settings are standard for each plugin:
		* One line description, used to form the bullets describing the plugins in the TWiki.TextFormattingRules topic:
			* =Set SHORTDESCRIPTION = Blah blah.=
		* Debug plugin, output can be seen in =data/debug.txt=: (Se to 0 or 1)
			* =Set DEBUG = 0=
		* The settings can be retrieved as preferences variables like =%&lt;pluginname&gt;_&lt;var&gt;%=, i.e. =%<nop>DEFAULTPLUGIN_SHORTDESCRIPTION%= shows the description of the <nop>DefaultPlugin.
d37 1
a37 1
	* The =%<nop>PLUGINDESCRIPTIONS%= variable shows a bullet list with descriptions of all currently activated plugins. This variable is based on =%&lt;plugin&gt;_SHORTDESCRIPTION%= preferences variables of individual topics and is shown in TWiki.TextFormattingRules.
d39 144
a182 1
-- Main.PeterThoeny - 14 Jul 2001 <br>
@


1.3
log
@none
@
text
@d1 1
d16 20
a35 1
-- Main.PeterThoeny - 17 Feb 2001 <br>
@


1.2
log
@none
@
text
@d5 2
@


1.1
log
@none
@
text
@d1 2
d5 1
a5 1
__How to Create a Plugin__
d9 1
a9 1
__How to Install a Plugin__
@
