Changeset 812 for trunk/core/data/System/Plugins.txt
- Timestamp:
- 11/19/08 16:05:12 (4 years ago)
- File:
-
- 1 edited
-
trunk/core/data/System/Plugins.txt (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/data/System/Plugins.txt
r700 r812 3 3 ---+ Plugins 4 4 5 _Add functionality to TWiki with readily available plugins; create plugins based on APIs_5 _Add functionality to Foswiki with readily available plugins; create plugins based on APIs_ 6 6 7 7 %TOC% … … 9 9 ---++ Overview 10 10 11 You can add plugins to extend TWiki functionality, without altering the core code. A plug-in approach lets you: 12 13 * add virtually unlimited features while keeping the main TWiki code compact and efficient; 14 * heavily customize an installation and still do clean updates to new versions of TWiki; 15 * rapidly develop new TWiki functions in Perl using the plugin API. 16 17 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. 18 19 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. 20 21 __Relevant links on TWiki.org:__ 22 * TWiki:Support.PluginsSupplement - __%T% tip:__ supplemental documentation on plugins 23 * TWiki:Plugins.PluginPackage - list of all contributed plugin packages 24 * TWiki:Plugins.PluginDevelopment - discussion and feedback on contributed plugins 25 * TWiki:Plugins.PluginBrainstorming - open forum for new plugin ideas 26 * TWiki:Plugins.PluginPackageHowTo - template to create a new plugin package 11 You can add plugins to extend Foswiki functionality, without altering the core code. A plug-in approach lets you: 12 13 * add virtually unlimited features while keeping the main Foswiki code compact and efficient; 14 * heavily customize an installation and still do clean updates to new versions of Foswiki; 15 * rapidly develop new Foswiki functions in Perl using the plugin API. 16 17 Everything to do with Foswiki plugins - demos, new releases, downloads, development, general discussion - is available at Foswiki.org, in the <b> Foswiki:Extensions </b> web. 18 19 Foswiki 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 Foswiki, but are independently developed and maintained. 20 21 Most TWiki™ plugins can also be used with Foswiki if the TWikiCompatibilityPlugin is installed. 27 22 28 23 __See other types of extensions:__ ContributedAddOns, [[Contribs]], [[Skins]] … … 31 26 ---++ Installing Plugins 32 27 33 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.28 Each Foswiki 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. 34 29 35 30 *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. 36 31 37 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.32 Each plugin has a standard release topic, located in the Foswiki:Extensions web at Foswiki.org. There's usually a number of other related topics, such as a developers page, and an appraisal page. 38 33 39 34 #PreTesting 40 35 ---+++ On-Site Pretesting 41 36 42 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.43 44 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%]]= macro can be used to debug failures. You may also want to check your webserver error log and the various TWiki log files.37 The recommended approach to testing new plugins before making them public is to create a second local Foswiki 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. 38 39 InstalledPlugins shows which plugins are: 1) installed, 2) loading properly, and 3) what plugin handlers they invoke. Any failures are shown in the Errors section. The =[[VarFAILEDPLUGINS][%<nop>FAILEDPLUGINS%]]= macro can be used to debug failures. You may also want to check your webserver error log and the various Foswiki log files. 45 40 46 41 ---+++ Some Notes on Plugin Performance 47 42 48 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=43 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, on real data. 49 44 50 45 %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% setting. … … 78 73 * =Set SHORTDESCRIPTION = Control attributes of tables and sorting of table columns= 79 74 80 [[Preference settings]] of active plugins can be retrieved anywhere in TWiki with =%<pluginname>_<var>%=, such as =%<nop>TABLEPLUGIN_SHORTDESCRIPTION%=. They can also be redefined with the =%<pluginname>_<var>%= setting at a lower level in the [[%LOCALSITEPREFS%]] or at the web level. For an easier upgrade it is recommended to customize plugin preference settings in <nop>%LOCALSITEPREFS% only.75 [[Preference settings]] of active plugins can be retrieved anywhere in Foswiki with =%<pluginname>_<var>%=, such as =%<nop>TABLEPLUGIN_SHORTDESCRIPTION%=. They can also be redefined with the =%<pluginname>_<var>%= setting at a lower level in the [[%LOCALSITEPREFS%]] or at the web level. For an easier upgrade it is recommended to customize plugin preference settings in <nop>%LOCALSITEPREFS% only. 81 76 82 77 ---+++ Listing Active Plugins … … 84 79 Plugin status macros let you list all active plugins wherever needed. 85 80 86 This site is running TWiki version *%WIKIVERSION%*, plugin API version81 This site is running Foswiki version *%WIKIVERSION%*, plugin API version 87 82 *%PLUGINVERSION{}%* 88 83 89 84 #ActivatedPlugins 90 85 ---++++ =%<nop>ACTIVATEDPLUGINS%= 91 On this TWiki site, the enabled plugins are: %ACTIVATEDPLUGINS%.86 On this Foswiki site, the enabled plugins are: %ACTIVATEDPLUGINS%. 92 87 93 88 ---++++ =%<nop>PLUGINDESCRIPTIONS%= … … 99 94 100 95 #PluginAPI 101 ---++ The TWiki Plugin API102 103 The Application Programming Interface (API) for TWiki plugins provides the specifications for hooking into the core TWiki code from your external Perl plugin module.96 ---++ The Foswiki Plugin API 97 98 The Application Programming Interface (API) for Foswiki plugins provides the specifications for hooking into the core Foswiki code from your external Perl plugin module. 104 99 105 100 ---+++ Available Core Functions 106 101 107 The TWikiFuncDotPm module (=lib/TWiki/Func.pm=) describes *all* the interfaces available to plugins. Plugins should *only* use the interfaces described in this module.108 109 __%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.102 The FoswikiFuncDotPm module (=lib/Foswiki/Func.pm=) describes *all* the interfaces available to plugins. Plugins should *only* use the interfaces described in this module. 103 104 __%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 Foswiki. 110 105 111 106 ---+++ Predefined Hooks 112 107 113 In addition to TWiki core functions, plugins can use *predefined hooks*, or *callbacks*, as described in the =lib/TWiki/Plugins/EmptyPlugin.pm= module.108 In addition to Foswiki core functions, plugins can use *predefined hooks*, or *callbacks*, as described in the =lib/Foswiki/Plugins/EmptyPlugin.pm= module. 114 109 115 110 * All but the initPlugin are disabled. To enable a callback, remove =DISABLE_= from the function name. 116 111 117 TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use.112 Foswiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use. 118 113 119 114 #FastPluginHints … … 124 119 =eval { require IPC::Run }= %BR% 125 120 =return "<font color=\"red\">SamplePlugin: Can't load required modules ($@)</font>" if $@;= 126 * 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/=.127 * 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.121 * 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/Foswiki/Plugins/BathPlugin/=. 122 * Avoid using preferences in the plugin topic; set =$NO_PREFS_IN_TOPIC= if you possibly can, as that will stop Foswiki from reading the plugin topic for every page. Use [[#ConfigSpec][Config.spec]] instead. 128 123 * Use registered tag handlers 129 124 * [[#MeasurePerformance][Measure the performance]] to see the difference … … 138 133 * The plugin initialization code does not register a plugin that returns 0 (or that has no =initPlugin= handler). 139 134 140 * =$ TWiki::Plugins::VERSION= in the =TWiki::Plugins= module contains the TWiki plugin API version, currently *%PLUGINVERSION{}%*.135 * =$Foswiki::Plugins::VERSION= in the =Foswiki::Plugins= module contains the Foswiki plugin API version, currently *%PLUGINVERSION{}%*. 141 136 * You can also use the =[[VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= macro to query the plugin API version or the version of installed plugins. 142 137 143 138 ---+++ Security 144 139 145 * 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.146 * 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.140 * Badly written plugins can open huge security holes in Foswiki. This is especially true if care isn't taken to prevent execution of arbitrary commands on the server. 141 * Don't allow sensitive configuration data to be edited by users. it is better to add sensitive configuration options to the =%Foswiki::cfg= hash than adding it as preferences in the plugin topic. 147 142 * [[#ConfigSpec][Integrating with <code>configure</code>]] describes the steps 148 * TWiki:Plugins.MailInContrib has an example149 * TWiki:Plugins.BuildContrib can help you with this150 * Always use the TWiki::Sandbox to execute commands.143 * Foswiki:Plugins.MailInContrib has an example 144 * Foswiki:Plugins.BuildContrib can help you with this 145 * Always use the Foswiki::Sandbox to execute commands. 151 146 * 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. 152 147 … … 154 149 ---++ Creating Plugins 155 150 156 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.151 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][Foswiki Plugin API]] provides the programming interface for Foswiki. 157 152 158 153 ---+++ Anatomy of a Plugin 159 154 160 A (very) basic TWiki plugin consists of two files:155 A (very) basic Foswiki plugin consists of two files: 161 156 162 157 * a Perl module, e.g. =MyFirstPlugin.pm= 163 158 * a documentation topic, e.g. =MyFirstPlugin.txt= 164 159 165 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.166 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.167 168 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.169 170 _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_.160 The Perl module can be a block of code that talks to with Foswiki alone, or it can include other elements, like other Perl modules (including other plugins), graphics, Foswiki templates, external applications (ex: a Java applet), or just about anything else it can call. 161 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/Foswiki/Plugins/MyFirstPlugin/= directory. 162 163 The plugin API handles the details of connecting your Perl module with main Foswiki code. When you're familiar with the [[#PluginAPI][Plugin API]], you're ready to develop plugins. 164 165 _The Foswiki: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_. 171 166 172 167 ---+++ Creating the Perl Module 173 168 174 Copy file =lib/ TWiki/Plugins/EmptyPlugin.pm= to =<name>Plugin.pm=. The =EmptyPlugin.pm= module contains mostly empty functions, so it does nothing, but it's ready to be used. Customize it. Refer to the [[#PluginAPI][Plugin API]] specs for more information.169 Copy file =lib/Foswiki/Plugins/EmptyPlugin.pm= to =<name>Plugin.pm=. The =EmptyPlugin.pm= module contains mostly empty functions, so it does nothing, but it's ready to be used. Customize it. Refer to the [[#PluginAPI][Plugin API]] specs for more information. 175 170 176 171 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: 177 172 <pre> 178 use TWiki::Plugins::MyFirstPlugin::Attrs;173 use Foswiki::Plugins::MyFirstPlugin::Attrs; 179 174 $var = MyFirstPlugin::Attrs->new(); 180 175 </pre> … … 185 180 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: 186 181 187 1. *Copy* the plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:182 1. *Copy* the plugin topic template from Foswiki.org. To copy the text, go to Foswiki:Plugins/PluginPackage and: 188 183 * enter the plugin name in the "How to Create a Plugin" section 189 184 * click Create … … 194 189 * paste & save new plugin topic on your site 195 190 1. *Customize* your plugin topic. 196 * 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.191 * Important: In case you plan to publish your plugin on Foswiki.org, use Interwiki names for author names and links to Foswiki.org topics, such as Foswiki:Main/%WIKINAME%. This is important because links should work properly in a plugin topic installed on any Foswiki, not just on Foswiki.org. 197 192 1. *Document* the performance data you gathered while [[#MeasurePerformance][measuring the performance]] 198 193 1. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your plugin. … … 200 195 <blockquote style="background-color:#f5f5f5"> 201 196 *OUTLINE: Doc Topic Contents* <br /> 202 Check the plugins web on TWiki.org for the latest plugin doc topic template. Here's a quick overview of what's covered:197 Check the plugins web on Foswiki.org for the latest plugin doc topic template. Here's a quick overview of what's covered: 203 198 204 199 *Syntax Rules:* <<i>Describe any special text formatting that will be rendered.</i>>" … … 206 201 *Example:* <<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>>" 207 202 208 *Plugin Settings:* <<i>Description and settings for custom plugin settings, and those required by TWiki.</i>>"209 210 * *Plugins Preferences* <<i>If user settings are needed, link to [[%SYSTEMWEB%.PreferenceSettings][preference settings]] and explain the role of the plugin name prefix 203 *Plugin Settings:* <<i>Description and settings for custom plugin settings, and those required by Foswiki.</i>>" 204 205 * *Plugins Preferences* <<i>If user settings are needed, link to [[%SYSTEMWEB%.PreferenceSettings][preference settings]] and explain the role of the plugin name prefix</i> 211 206 212 207 *Plugin Installation Instructions:* <<i>Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.</i>>" 213 208 214 *Plugin Info:* <<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>>"209 *Plugin Info:* <<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 Foswiki:Plugins web.</i>> 215 210 </blockquote> 216 211 … … 218 213 ---+++ Packaging for Distribution 219 214 220 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!215 The Foswiki:Plugins.BuildContrib is a powerful build environment that is used by the Foswiki project to build Foswiki itself, as well as many of the plugins. You don't *have* to use it, but it is highly recommended! 221 216 222 217 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=). 223 218 224 1. Distribute the plugin files in a directory structure that mirrors TWiki. If your plugin uses additional files, include them all:225 * =lib/ TWiki/Plugins/MyFirstPlugin.pm=226 * =data/ TWiki/MyFirstPlugin.txt=227 * =pub/ TWiki/MyFirstPlugin/uparrow.gif= [a required graphic]219 1. Distribute the plugin files in a directory structure that mirrors Foswiki. If your plugin uses additional files, include them all: 220 * =lib/Foswiki/Plugins/MyFirstPlugin.pm= 221 * =data/Foswiki/MyFirstPlugin.txt= 222 * =pub/Foswiki/MyFirstPlugin/uparrow.gif= [a required graphic] 228 223 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: 229 * =lib/ TWiki/Plugins/MyFirstPlugin.pm=230 * =data/ TWiki/MyFirstPlugin.txt=231 * =pub/ TWiki/MyFirstPlugin/uparrow.gif=224 * =lib/Foswiki/Plugins/MyFirstPlugin.pm= 225 * =data/Foswiki/MyFirstPlugin.txt= 226 * =pub/Foswiki/MyFirstPlugin/uparrow.gif= 232 227 233 228 #MeasurePerformance 234 229 ---+++ Measuring and Improving the Plugin Performance 235 230 236 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.231 A high quality plugin performs well. You can use the Foswiki:Plugins.PluginBenchmarkAddOn to measure your Foswiki:Plugins.PluginBenchmarks. The data is needed as part of the Documentation Topic. 237 232 238 233 See also [[#FastPluginHints][Hints on Writing Fast Plugins]]. … … 241 236 ---+++ Publishing for Public Use 242 237 243 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.238 You can release your tested, packaged plugin to the Foswiki community through the Foswiki:Plugins web. All plugins submitted to Foswiki.org are available for download and further development in Foswiki:Plugins/PluginPackage. 244 239 245 240 Publish your plugin by following these steps: 246 1. *Post* the plugin documentation topic in the TWiki:Plugins/PluginPackage:241 1. *Post* the plugin documentation topic in the Foswiki:Plugins/PluginPackage: 247 242 * enter the plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin= 248 243 * paste in the topic text from [[#CreatePluginTopic][Writing the Documentation Topic]] and save 249 244 1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip= 250 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.)251 1. *Put* the plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)245 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 Foswiki:Support.) 246 1. *Put* the plugin into the SVN repository, see Foswiki:Plugins/ReadmeFirst (optional) 252 247 253 248 %N% Once you have done the above steps once, you can use the !BuildContrib to upload updates to your plugin. 254 249 255 Thank you very much for sharing your plugin with the TWiki community :-)250 Thank you very much for sharing your plugin with the Foswiki community :-) 256 251 257 252 #RecommendedStorageOfPluginData 258 253 ---++ Recommended Storage of Plugin Specific Data 259 254 260 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.255 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 FoswikiFuncDotPm functions that support saving and loading of topics and attachments. 261 256 262 257 ---+++ Plugin Internal Data 263 258 264 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.259 You can create a plugin "work area" using the =Foswiki::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, =Foswiki::Func::storeFile()= and =Foswiki::Func::readFile()= are provided to persistently store and retrieve simple data in this area. 265 260 266 261 ---+++ Web Accessible Data 267 262 268 __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.263 __Topic-specific data__ such as generated images can be stored in the topic's attachment area, which is web accessible. Use the =Foswiki::Func::saveAttachment()= function to store the data. 269 264 270 265 Recommendation for file name: … … 274 269 * Example: =_GaugePlugin_img123.gif= 275 270 276 __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.271 __Web specific data__ can be stored in the plugin's attachment area, which is web accessible. Use the =Foswiki::Func::saveAttachment()= function to store the data. 277 272 278 273 Recommendation for file names in plugin attachment area: … … 286 281 Some extensions have setup requirements that are best integrated into =configure= rather than trying to use [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. These extensions use =Config.spec= files to publish their configuration requirements. 287 282 288 =Config.spec= files are read during 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=.283 =Config.spec= files are read during 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/Foswiki/Plugins/BathPlugin/Config.spec=. 289 284 290 285 ---+++ Structure of a <code>Config.spec</code> file … … 299 294 # **SELECT Plastic,Rubber,Metal** 300 295 # Select the plug type 301 $ TWiki::cfg{BathPlugin}{PlugType} = 'Plastic';296 $Foswiki::cfg{BathPlugin}{PlugType} = 'Plastic'; 302 297 303 298 # **NUMBER** 304 299 # Enter the chain length in cm 305 $ TWiki::cfg{BathPlugin}{ChainLength} = '30';300 $Foswiki::cfg{BathPlugin}{ChainLength} = '30'; 306 301 307 302 # **BOOLEAN EXPERT** 308 303 # Turn this option off to disable the water temperature alarm 309 $ TWiki::cfg{BathPlugin}{TempSensorEnabled} = '1';304 $Foswiki::cfg{BathPlugin}{TempSensorEnabled} = '1'; 310 305 </verbatim> 311 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,312 <verbatim> 313 if( $ TWiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) {306 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 =$Foswiki::cfg{BathPlugin}{PlugType}=, =$Foswiki::cfg{BathPlugin}{ChainLength}=, and =$Foswiki::cfg{BathPlugin}{TempSensorEnabled}= for use in your plugin. For example, 307 <verbatim> 308 if( $Foswiki::cfg{BathPlugin}{TempSensorEnabled} && $curTemperature > 50 ) { 314 309 die "The bathwater is too hot for comfort"; 315 310 } … … 340 335 | H | means the option is not visible in =configure= | 341 336 342 See =lib/ TWiki.spec= for many more examples.337 See =lib/Foswiki.spec= for many more examples. 343 338 344 339 =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. 345 340 346 TWiki:TWiki/SpecifyingConfigurationItemsForExtensions has supplemental documentation on configure settings.341 Foswiki:Foswiki/SpecifyingConfigurationItemsForExtensions has supplemental documentation on configure settings. 347 342 348 343 #MaintainPlugins … … 351 346 ---+++ Discussions and Feedback on Plugins 352 347 353 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.354 355 ---+++ Maintaining Compatibility with Earlier TWiki Versions356 357 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.358 359 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.360 361 __%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.362 Here is an example; the TWiki:Support.PluginsSupplement has more details.363 364 <verbatim> 365 if( $ TWiki::Plugins::VERSION >= 1.1 ) {366 @webs = TWiki::Func::getListOfWebs( 'user,public' );348 Each published plugin has a plugin development topic on Foswiki.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 Foswiki community. 349 350 ---+++ Maintaining Compatibility with Earlier Foswiki Versions 351 352 The plugin interface (FoswikiFuncDotPm functions and plugin handlers) evolve over time. Foswiki introduces new API functions to address the needs of plugin authors. Plugins using unofficial Foswiki internal functions may no longer work on a Foswiki upgrade. 353 354 Organizations typically do not upgrade to the latest Foswiki for many months. However, many administrators still would like to install the latest versions of a plugin on their older Foswiki installation. This need is fulfilled if plugins are maintained in a compatible manner. 355 356 __%T% Tip:__ Plugins can be written to be compatible with older and newer Foswiki releases. This can be done also for plugins using unofficial Foswiki internal functions of an earlier release that no longer work on the latest Foswiki codebase. 357 Here is an example; the Foswiki:Support.PluginsSupplement has more details. 358 359 <verbatim> 360 if( $Foswiki::Plugins::VERSION >= 1.1 ) { 361 @webs = Foswiki::Func::getListOfWebs( 'user,public' ); 367 362 } else { 368 @webs = TWiki::Func::getPublicWebList( );363 @webs = Foswiki::Func::getPublicWebList( ); 369 364 } 370 365 </verbatim> … … 372 367 ---+++ Handling deprecated functions 373 368 374 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.375 376 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.377 378 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%.379 380 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:381 382 <verbatim> 383 package TWiki::Plugins::SinkPlugin;384 use vars qw( % TWikiCompatibility );385 $ TWikiCompatibility{endRenderingHandler} = 1.1;369 From time-to-time, the Foswiki developers will add new functions to the interface (either to FoswikiFuncDotPm, 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 Foswiki release, and probably longer, though this cannot be guaranteed. 370 371 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 Foswiki.org and if necessary, contact the plugin author, for an updated version of the plugin. 372 373 Updated plugins may still need to define deprecated handlers for compatibility with old Foswiki versions. In this case, the plugin package that defines old handlers can suppress the warnings in %<nop>FAILEDPLUGINS%. 374 375 This is done by defining a map from the handler name to the =Foswiki::Plugins= version _in which the handler was first deprecated_. For example, if we need to define the =endRenderingHandler= for compatibility with =Foswiki::Plugins= versions before 1.1, we would add this to the plugin: 376 377 <verbatim> 378 package Foswiki::Plugins::SinkPlugin; 379 use vars qw( %FoswikiCompatibility ); 380 $FoswikiCompatibility{endRenderingHandler} = 1.1; 386 381 </verbatim> 387 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.382 If the currently-running Foswiki version is 1.1 _or later_, then the _handler will not be called_ and _the warning will not be issued_. Foswiki with versions of =Foswiki::Plugins= before 1.1 will still call the handler as required. 388 383 389 384 %STOPINCLUDE% 390 __Related Topics:__ DeveloperDocumentationCategory, AdminDocumentationCategory, TWiki:Support.PluginsSupplement391 385 __Related Topics:__ DeveloperDocumentationCategory, AdminDocumentationCategory, Foswiki:Support.PluginsSupplement 386
Note: See TracChangeset
for help on using the changeset viewer.
