====== Admin Plugin Example ====== This Hello World example show an admin plugin. In particular it shows a bare bones form with hidden controls to generate values to return to the plugin and all displayed text is retrieved from the localized language file. Three files are needed * [[#plugin.info.txt]], contain metadata about the plugin, see [[plugin info]] for more details. * [[#admin.php]], the actual plugin code called when entering from the [[:admin window]]. * [[#lang/en/lang.php]], an English language file with [[localization|localized]] strings used for this plugin. ===== plugin.info.txt ===== ''lib/plugins/skeleton/plugin.info.txt'' base skeleton author me email me@somesite.com date 20yy-mm-dd name Hello World Plugin desc Demonstration plugin url https://www.dokuwiki.org/plugin:skeleton ===== admin.php ===== ''lib/plugins/skeleton/admin.php'' */ /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_skeleton extends AdminPlugin { private $output = 'world'; /** * handle user request */ public function handle() { global $INPUT; if (!$INPUT->has('cmd')) return; // first time - nothing to do $this->output = 'invalid'; if (!checkSecurityToken()) return; if (!is_array($INPUT->param('cmd')) return; // verify valid values $cmd = $INPUT->arr('cmd'); switch (key($cmd)) { case 'hello' : $this->output = 'again'; break; case 'goodbye': $this->output = 'goodbye'; break; } } /** * output appropriate html */ public function html() { echo '

' . htmlspecialchars($this->getLang($this->output)) . '

'; echo '
'; //set hidden values to ensure DokuWiki will return back to this plugin echo ' '; echo ' '; formSecurityToken(); echo ' '; echo ' '; echo '
'; } }
===== lang/en/lang.php ===== ''lib/plugins/skeleton/lang/en/lang.php'' */ // for admin plugins, the menu prompt to be displayed in the admin menu // if set here, the plugin doesn't need to override the getMenuText() method $lang['menu'] = 'Admin Skeleton...'; $lang['btn_hello'] = 'hello'; $lang['btn_goodbye'] = 'goodbye'; $lang['world'] = 'Hello, world!'; $lang['again'] = 'Hello again!'; $lang['goodbye'] = 'Goodbye.'; $lang['invalid'] = 'invalid input detected!';