Translations of this page?:

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 (!checkSecurityToken()) return;
      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.txt · Last modified: 2011/03/15 21:28 by HåkanS
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate