devel:admin_plugin_skeleton
This is an old revision of the document!
Table of Contents
Admin Plugin Skeleton
This skeleton has a little more meat than the one list on the admin plugins page. 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 localised language file.
Two files are shown here
admin.php
lib/plugins/skeleton/admin.php
<?php /** * Plugin Skeleton: Displays "Hello World!" * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_skeleton extends DokuWiki_Admin_Plugin { var $output = 'world'; /** * return some info */ function getInfo(){ return array( 'author' => 'me', 'email' => 'me@somesite.com', 'date' => '20yy-mm-dd', 'name' => 'admin plugin skeleton', 'desc' => 'demonstration skeleton', 'url' => 'http://www.dokuwiki.org/plugin:adminskeleton', ); } /** * return sort order for position in admin menu */ function getMenuSort() { return 999; } /** * return a menu prompt for the admin menu * NOT REQUIRED - its better to place $lang['menu'] string in localised string file * only use this function when you need to vary the string returned */ // function getMenuText() { // return 'a menu prompt'; // } /** * handle user request */ function handle() { if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do $this->output = 'invalid'; if (!is_array($_REQUEST['cmd'])) return; // verify valid values switch (key($_REQUEST['cmd'])) { case 'hello' : $this->output = 'again'; break; case 'goodbye' : $this->output = 'goodbye'; break; } } /** * output appropriate html */ function html() { ptln('<p>'.htmlspecialchars($this->getLang($this->output)).'</p>'); ptln('<form action="'.wl($ID).'" method="post">'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' <input type="hidden" name="do" value="admin" />'); ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); ptln(' <input type="submit" name="cmd[hello]" value="'.$this->getLang('btn_hello').'" />'); ptln(' <input type="submit" name="cmd[goodbye]" value="'.$this->getLang('btn_goodbye').'" />'); ptln('</form>'); } }
lang.php
lib/plugins/skeleton/lang/en/lang.php
<?php /** * english language file * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@jalakai.co.uk> */ // settings must be present and set appropriately for the language $lang['encoding'] = 'utf-8'; $lang['direction'] = 'ltr'; // 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.1218304786.txt.gz · Last modified: 2010-01-11 02:38 (external edit)