Action plugins are a way to modify many aspects of how DokuWiki behaves in certain cases independent of a page's syntax. To be able to modify a DokuWiki internal behavior it needs to trigger an event. Your action plugin can register as a handler for such an event and then work with the given event data.
To learn more about events, read the following pages:
Insert a javascript script link in all pages.
<?php /** * Example Action Plugin: Example Component. * * @author Samuele Tognini <samuele@cli.di.unipi.it> */ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); class action_plugin_example extends DokuWiki_Action_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Me name', 'email' => 'myname@example.org', 'date' => '2006-12-17', 'name' => 'Example (action plugin component)', 'desc' => 'Example action functions.', 'url' => 'http://www.example.org', ); } /** * Register its handlers with the dokuwiki's event controller */ function register(&$controller) { $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_hookjs'); } /** * Hook js script into page headers. * * @author Samuele Tognini <samuele@cli.di.unipi.it> */ function _hookjs(&$event, $param) { $event->data["script"][] = array ("type" => "text/javascript", "charset" => "utf-8", "_data" => "", "src" => DOKU_BASE."lib/plugins/example/example.js" ); } }
Inserts a button into the editor toolbar:
data<?php /** * Example Action Plugin: Inserts a button into the toolbar * * @author Gina Haeussge <osd@foosel.net> */ if (!defined('DOKU_INC')) die(); if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); require_once (DOKU_PLUGIN . 'action.php'); class action_plugin_actionexample extends DokuWiki_Action_Plugin { /** * Return some info */ function getInfo() { return array ( 'author' => 'Some name', 'email' => 'foo@bar.org', 'date' => '2007-04-05', 'name' => 'Toolbar Action Plugin', 'desc' => 'Inserts a button into the toolbar', 'url' => 'http://www.example.com/plugin/toolbar', ); } /** * Register the eventhandlers */ function register(&$controller) { $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insert_button', array ()); } /** * Inserts the toolbar button */ function insert_button(& $event, $param) { global $lang; global $conf; include_once (dirname(__FILE__) . '/lang/en/lang.php'); @ include_once (dirname(__FILE__) . '/lang/' . $conf['lang'] . '/lang.php'); $event->data[] = array ( 'type' => 'format', 'title' => $lang['qb_abutton'], 'icon' => '../../plugins/actionexample/abutton.png', 'open' => '<abutton>', 'close' => '</abutton>', ); } }