Translations of this page?:

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's no need to reinvent the wheel. - Instead use the Pagelist Plugin. Take a look at the list of existing helper plugins.

How to Use a Helper Plugin

Helper plugins can be used from another plugin in a simple manner.

$tag = $this->loadHelper('tag', true);
 
if($tag) {
    $entries = $tag->tagRefine($entries, $refine);
}

loadHelper() is a method of the base DokuWiki_Plugin class inherited by all plugins but syntax plugins. It takes two parameters, while the second is optional. 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 plugin in a syntax plugin you have to use the plugin_load() function. It takes two parameters, the first is the plugin type, and the second the name of the plugin you like to use. Additionally plugin_isdisabled() can be used to check if a plugin is available or not.

if(!plugin_isdisabled('tag')) {
    $tag =& plugin_load('helper', 'tag');
    $entries = $tag->tagRefine($entries, $refine);
}

How to Write a Helper Plugin

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:

getInfo()

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.

getMethods()

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;
  }

Helper Methods

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.

 
devel/helper_plugins.txt · Last modified: 2008/09/16 17:54 by birke
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsDarcsXRefTranslate