Admin Plugins

To fit in with current Dokuwiki structure there needs to be four separate entry points to the plugin.

  1. from act_dispatch(), any processing is done here, …
    • handle() method, no parameters
  2. from tpl_admin(), html generation is done here, …
    • html() method, no parameters
  3. from html_admin(), supply text prompt and sort order for admin menu, …
    • getMenuText() method, one parameter, current language
    • getMenuSort() method, no parameters
  4. for info plugin, provide summary information about the plugin, …
    • getInfo() method, no parameters

Discussion

Concerns

  • language handling for plugins — addressed:

Plugin Interface

getInfo()

Return hash containing summary information about the plugin (identical to method and hash used for syntax plugins.

getMenuText($lang)

Return text prompt to be displayed on the main administration menu.

getMenuSort()

return an integer used to determine order of display on main administration menu.

handle()

Do all processing not required by html generation.

html()

Output the html required.

Dokuwiki Interface

act_dispatch

inc/actions.php act_dispatch() #67, replace current if ($ACT == 'admin') { } block with below

  //handle admin tasks
  if($ACT == 'admin'){
    // retrieve admin plugin name from $_REQUEST['page']
    if ($_REQUEST['page']) {
      $pluginlist = plugin_list('admin');
      if (in_array($_REQUEST['page'], $pluginlist)) {     
        // attempt to load the plugin
        if ($plugin =& plugin_load('admin',$_REQUEST['page']) !== NULL)
            $plugin->handle();
      }
    } 
  }

tpl_admin

inc/template.php

function tpl_admin() {
    $plugin = NULL;
    if ($_REQUEST['page']) {
        $pluginlist = plugin_list('admin');
 
        if (in_array($_REQUEST['page'], $pluginlist)) {
          $plugin =& plugin_load('admin',$_REQUEST['page']);
        }
    }
 
    if ($plugin !== NULL)
        $plugin->html();
    else
        html_admin();
}

html_admin

inc/html.php html_admin()

/**
 * Print the admin overview page
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 */
function html_admin(){
  global $ID;
  global $lang;
  global $conf;
 
  print p_locale_xhtml('admin');
 
  // build menu of admin functions from the plugins that handle them
  $pluginlist = plugin_list('admin');
  $menu = array();
  foreach ($pluginlist as $p) {
    if($obj =& plugin_load('admin',$p) === NULL) continue;
    $menu[] = array('plugin' => $p, 
                    'prompt' => $obj->getMenuText($conf['lang']),
                    'sort' => $obj->getMenuSort()
                   );
  }
 
  usort($menu, p_sort_modes);
 
  // output the menu
  ptln('<ul>');
 
  foreach ($menu as $item) {
    ptln('  <li><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></li>');
  }
 
  // add in non-plugin functions
  if (!$conf['openregister']){
    ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>');
  }
 
  ptln('</ul>');
}

Base Class

Unable to display file "dokuwiki/lib/plugins/admin.php": It may not exist, or permission may be denied.

Skeleton Plugin

Admin Plugin Skeleton

<?php
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 {
 
    /**
     * 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://wiki.splitbrain.org/plugin:admin',
      );
    }
 
    /**
     * return sort order for position in admin menu
     */
    function getMenuSort() {
      return 999;
    }
 
    /**
     * handle user request
     */
    function handle() {
    }
 
    /**
     * output appropriate html
     */
    function html() {
    }
 
}

Screenshot - Admin Page

Skeleton plugin left in to show how easy it is :-)

Sample Plugin - ACL

Converted from the current inc/admin_acl.php file. Its a really simple conversion, rename two functions (admin_acl_handler()handle() & admin_acl_htmlhtml()) and prefix all internal function calls with $this-> and add in the three one liner methods, getInfo(), getMenuText() and getMenuSort().

Unable to display file "dokuwiki/lib/plugins/acl/admin.php": It may not exist, or permission may be denied.

 
tutorials/admin_plugins.txt · Last modified: 2005/10/06 10:07 by 192.168.0.100
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki