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's no need to reinvent the wheel. - Instead use the Pagelist Plugin. Take a look at the list of existing helper plugins.
Helper plugins already work in the current stable release of DokuWiki, but plugin developers need to check themselves whether the helper plugin to use is enabled. The following code snipplet loads the tag helper plugin and performs a filtering task with the method tagRefine() provided by the Tag Plugin:
if (plugin_isdisabled('tag') || (!$tag =& plugin_load('helper', 'tag'))){ msg('The Tag Plugin must be installed to use tag refinements.', -1); } else { $entries = $tag->tagRefine($entries, $refine); }
In newer versions of DokuWiki the same can be done a bit simpler:
$tag = $this->loadHelper('tag', 'The Tag Plugin must be installed to use tag refinements.'); $entries = $tag->tagRefine($entries, $refine);
loadHelper() is a method of the base DokuWiki_Plugin class inherited by all plugins. It takes two parameters, while the second is optional. The first parameter is the name of the wanted helper plugin. The second is an error message in case loading the helper plugin fails.
A helper plugin component is a class helper_plugin_<plugin name> to extend DokuWiki_Plugin in a file called helper.php in the plugin's main directory. It should support the following standard methods:
Like other plugin types, helper plugin's getInfo() method should return an array with info about author name
and email, plugin date, name, description and URL.
Helper plugins should also return info about the methods supported. getMethods() should return an array of methods, each of them with an array of method name, description, parameters and return value. Parameters and return values are arrays with parameter description as key and PHP object type as value.
Example:
function getMethods(){ $result = array(); $result[] = array( 'name' => 'getThreads', 'desc' => 'returns pages with discussion sections, sorted by recent comments', 'params' => array( 'namespace' => 'string', 'number (optional)' => 'integer'), 'return' => array('pages' => 'array'), ); // and more supported methods... return $result; }
The work is done by methods according to the methods listed in getMethods(). Of course, the helper plugin class can contain more, private methods. It's good practice that names of private methods (not listed in getMethods()) begin with an underscore.