DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:admin_plugin_skeleton

This is an old revision of the document!


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

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    http://www.dokuwiki.org/plugin:skeleton',

admin.php

lib/plugins/skeleton/admin.php

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>
 */
 
 
/**
 * 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';
 
    /**
     * 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().'" />');
      formsecuritytoken();
 
      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/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.1300220478.txt.gz · Last modified: 2011-03-15 21:21 by HåkanS

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki