devel:helper_plugins
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:helper_plugins [2009-03-21 04:18] – efege | devel:helper_plugins [2022-09-18 23:12] (current) – [How to Write a Helper Plugin] Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Helper Plugins ====== | ====== Helper Plugins ====== | ||
- | Helper plugins make it simple for plugin developers to use functionality of other, existing plugins. For example to display a list of wiki pages, there' | + | Helper plugins make it simple for plugin developers to use functionality of other, existing plugins. For example to display a list of wiki pages, there' |
- | + | ===== How to Use a Helper Plugin ===== | |
- | ===== How to Use a Helper Plugin ===== | + | |
Helper plugins can be used from another plugin in a simple manner. | Helper plugins can be used from another plugin in a simple manner. | ||
<code php> | <code php> | ||
- | $tag = $this-> | + | $tag = $this-> |
if($tag) { | if($tag) { | ||
Line 13: | Line 12: | ||
</ | </ | ||
- | '' | + | The '' |
+ | * The first parameter is the name of the wanted helper plugin. | ||
+ | * The second indicates if an error message should be displayed in case loading the helper plugin fails (this message isn't localized and can't be localized currently). | ||
- | If you want to use a helper | + | As alternative, |
+ | |||
+ | You have to use the '' | ||
+ | * the first is the plugin type, | ||
+ | * and the second the name of the plugin you like to use. | ||
+ | Additionally '' | ||
<code php> | <code php> | ||
if(!plugin_isdisabled(' | if(!plugin_isdisabled(' | ||
- | $tag =& plugin_load(' | + | $tag = plugin_load(' |
$entries = $tag-> | $entries = $tag-> | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Reusing of plugin objects ==== | ||
+ | Default DokuWiki reuses instances of its plugins. This can be prevented by adding a '' | ||
+ | |||
+ | For example, the [[plugin: | ||
+ | <code php> | ||
+ | class helper_plugin_sqlite extends DokuWiki_Plugin { | ||
+ | ... | ||
+ | | ||
+ | /** | ||
+ | * Keep separate instances for every call to keep database connections | ||
+ | */ | ||
+ | public function isSingleton() { | ||
+ | return false; | ||
+ | } | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | So you can have more database instances: | ||
+ | <code php> | ||
+ | if(!plugin_isdisabled(' | ||
+ | $DBIa = plugin_load(' | ||
+ | if($DBIa) { | ||
+ | $DBIa-> | ||
+ | } | ||
+ | | ||
+ | $DBIb = plugin_load(' | ||
+ | ... | ||
} | } | ||
</ | </ | ||
Line 26: | Line 62: | ||
===== How to Write a Helper Plugin ===== | ===== How to Write a Helper Plugin ===== | ||
- | A helper plugin component is a class '' | + | A Helper Plugin //Example// needs: |
+ | * class name '' | ||
+ | * which extends [[xref>DokuWiki_Plugin]]((defined in '' | ||
+ | * to be stored | ||
+ | Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more helper components refer to [[plugin file structure]]. | ||
- | ==== getInfo() ==== | + | ===Required functions=== |
- | Like other plugin types, helper plugin's '' | + | * **'' |
- | and email, plugin | + | * **'' |
+ | * **'' | ||
+ | |||
+ | ===Inherited functions=== | ||
+ | * See [[common | ||
==== getMethods() ==== | ==== getMethods() ==== | ||
- | Helper plugins should also return info about the methods supported. '' | + | Helper plugins should also return info about the methods supported. '' |
Example: | Example: | ||
<code php> | <code php> | ||
- | | + | public |
$result = array(); | $result = array(); | ||
$result[] = array( | $result[] = array( | ||
- | | + | |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | |
+ | ' | ||
); | ); | ||
// and more supported methods... | // and more supported methods... | ||
return $result; | return $result; | ||
- | | + | } |
</ | </ | ||
==== Helper Methods ==== | ==== Helper Methods ==== | ||
- | The work is done by methods according to the methods listed in '' | + | The work is done by methods according to the methods listed in '' |
+ | |||
+ | ===== Common plugin functions ===== | ||
+ | Some function are shared between the plugins, refer to next sections for info about: | ||
+ | * [[common_plugin_functions# | ||
+ | * [[common_plugin_functions# | ||
+ | * Using [[plugin_file_structure# | ||
+ | |||
+ | ===== Further reading ===== | ||
+ | |||
+ | * [[Plugin programming tips]] | ||
+ | * [[plugins|Plugin Development]] | ||
+ | * [[plugintype> |
devel/helper_plugins.1237605499.txt.gz · Last modified: 2011-03-07 16:20 (external edit)