DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:admin_plugin_skeleton

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
devel:admin_plugin_skeleton [2010-01-11 02:38] 70.131.57.199devel:admin_plugin_skeleton [2023-09-01 22:43] (current) Klap-in
Line 1: Line 1:
-====== Admin Plugin Skeleton ======+====== Admin Plugin Example ======
  
-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. +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. 
  
-Two files are shown here +Three files are needed 
-  * [[#admin.php]] +  * [[#plugin.info.txt]], contain metadata about the plugin, see [[plugin info]] for more details. 
-  * [[#lang.php]]+  * [[#admin.php]], the actual plugin code called when entering from the [[:admin window]]. 
 +  * [[#lang/en/lang.php]], an English language file with [[localization|localized]] strings used for this plugin. 
 + 
 +===== plugin.info.txt ===== 
 + 
 +''lib/plugins/skeleton/plugin.info.txt'' 
 + 
 +<code - 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 
 +</code>
  
 ===== admin.php ===== ===== admin.php =====
Line 11: Line 26:
 ''lib/plugins/skeleton/admin.php'' ''lib/plugins/skeleton/admin.php''
  
-<code php>+<code php admin.php>
 <?php <?php
 +
 +use dokuwiki\Extension\AdminPlugin;
 +
 /** /**
  * Plugin Skeleton: Displays "Hello World!"  * Plugin Skeleton: Displays "Hello World!"
Line 20: Line 38:
  */  */
  
-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'); 
    
 /** /**
Line 28: Line 43:
  * need to inherit from this class  * need to inherit from this class
  */  */
-class admin_plugin_skeleton extends DokuWiki_Admin_Plugin {+class admin_plugin_skeleton extends AdminPlugin {
  
-    var $output = 'world'; +    private $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      * handle user request
      */      */
-    function handle() { +    public function handle() { 
-     +        global $INPUT; 
-      if (!isset($_REQUEST['cmd'])) return;   // first time - nothing to do+         
 +        if (!$INPUT->has('cmd')) return; // first time - nothing to do
  
-      $this->output = 'invalid'; +        $this->output = 'invalid'; 
- +       
-      if (!is_array($_REQUEST['cmd'])) return;+        if (!checkSecurityToken()) return; 
 +        if (!is_array($INPUT->param('cmd')) return;
              
-      // verify valid values +        // verify valid values 
-      switch (key($_REQUEST['cmd'])) { +        $cmd = $INPUT->arr('cmd'); 
-        case 'hello' : $this->output = 'again'; break; +        switch (key($cmd)) { 
-        case 'goodbye' : $this->output = 'goodbye'; break; +            case 'hello' 
-      }      +                $this->output = 'again';  
 +                break; 
 +            case 'goodbye':  
 +                $this->output = 'goodbye';  
 +                break; 
 +        }      
     }     }
    
Line 83: Line 75:
      * output appropriate html      * output appropriate html
      */      */
-    function html() { +    public function html() { 
-      ptln('<p>'.htmlspecialchars($this->getLang($this->output)).'</p>');+        echo '<p>' . htmlspecialchars($this->getLang($this->output)) . '</p>';
              
-      ptln('<form action="'.wl($ID).'" method="post">');+        echo '<form action="' . wl($ID) . '" method="post">';
              
-      // output hidden values to ensure dokuwiki will return back to this plugin +        //set hidden values to ensure DokuWiki will return back to this plugin 
-      ptln( <input type="hidden" name="do"   value="admin" />')+        echo  <input type="hidden" name="do" value="admin" />'; 
-      ptln( <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); +        echo  <input type="hidden" name="page" value="'  
-       +                . $this->getPluginName() . '" />'
-      ptln( <input type="submit" name="cmd[hello]"  value="'.$this->getLang('btn_hello').'" />')+        formSecurityToken(); 
-      ptln( <input type="submit" name="cmd[goodbye]"  value="'.$this->getLang('btn_goodbye').'" />')+ 
-      ptln('</form>');+        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>';
     }     }
    
Line 100: Line 96:
 </code> </code>
  
-===== lang.php =====+===== lang/en/lang.php =====
  
-lib/plugins/skeleton/lang/en/lang.php+''lib/plugins/skeleton/lang/en/lang.php''
  
-<code php>+<code php lang.php>
 <?php <?php
 /** /**
- english language file+ English language file
  *  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     Christopher Smith <chris@jalakai.co.uk>  * @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 // for admin plugins, the menu prompt to be displayed in the admin menu
Line 129: Line 121:
 $lang['invalid'] = 'invalid input detected!'; $lang['invalid'] = 'invalid input detected!';
 </code> </code>
----- 
- 
  
devel/admin_plugin_skeleton.1263173909.txt.gz · Last modified: 2010-01-11 02:38 by 70.131.57.199

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