devel:admin_plugin_skeleton
Table of Contents
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 localized strings used for this plugin.
plugin.info.txt
lib/plugins/skeleton/plugin.info.txt
- 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
- admin.php
<?php use dokuwiki\Extension\AdminPlugin; /** * Plugin Skeleton: Displays "Hello World!" * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ /** * 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 '<p>' . htmlspecialchars($this->getLang($this->output)) . '</p>'; echo '<form action="' . wl($ID) . '" method="post">'; //set hidden values to ensure DokuWiki will return back to this plugin echo ' <input type="hidden" name="do" value="admin" />'; echo ' <input type="hidden" name="page" value="' . $this->getPluginName() . '" />'; formSecurityToken(); echo ' <input type="submit" name="cmd[hello]" value="' . $this->getLang('btn_hello') . '" />'; echo ' <input type="submit" name="cmd[goodbye]" value="' . $this->getLang('btn_goodbye') . '" />'; echo '</form>'; } }
lang/en/lang.php
lib/plugins/skeleton/lang/en/lang.php
- lang.php
<?php /** * English language file * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ // 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!';
devel/admin_plugin_skeleton.txt · Last modified: by 193.184.22.170