Hitzigrath

Netzwerk-Administrator und Hobby-Fotograf

Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

docs:dokuwiki:hack_pluginbase

beispielhafte Plugin Grundgerüste

Hilfestellung zum schreiben diverser Plugins - hier ein paar Grundgerüste.

DEPRECATED - Die Templats müssen überarbeitet werden und sind ab „Hogfather“ nicht mehr einsetzbar.

Es sind am Anfang der Dateien drei mögliche Lizenzen angegeben, wovon eine auszuwählen ist und die anderen Einträge gelöscht werden können.

Ebenfalls ist natürlich der Author seinen Gegebenheiten anzupassen.

admin.php

admin.php
<?php
/**
 * DokuWiki Admin Plugin Example
 *
 * @license    GPL (http://www.gnu.org/licenses/gpl.html)
 * @license    CC0 - Public Domain Dedication (http://creativecommons.org/publicdomain/zero/1.0/)
 * @license    Public Domain Mark (http://creativecommons.org/publicdomain/mark/1.0/)
 * @author     M.K. Hitzigrath <mkh@hitzigrath.de>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
class admin_plugin_example extends DokuWiki_Admin_Plugin {
 
    /**
     * Initialisierung
     */
    var $config = array();
 
    function admin_plugin_example() {
        global $conf;
        $this->config = $conf;
    }
 
    /**
     * weitere Basis-Funktionen
     */
    function forAdminOnly(){
        if ($this->getConf('managerConfig') == 3) {
            return false;             // auch Managers dürfen Administrieren
        } else {
            return true;              // nur Admins können Administieren (default wenn diese Funktion nicht vorhanden)
        }
    }
 
    function getMenuSort() {          // Position auf der Admin-Page
        return 139;
    }
 
    function handle() {
        global $INPUT;
 
        if ($INPUT->str('act') && checkSecurityToken()) {
            if ($INPUT->str('act') == "add") {
              // ... tue was auch immer bei dieser Aktion ...
            }
        }
    }
 
    function html() {
        global $lang;
 
        echo $this->locale_xhtml('admin_plugin');       
 
        ptln('');
        ptln('<div id="'.$this->getPluginName().'_manager">');
        $form = new Doku_Form('formAdd',wl($ID));
        $form->addHidden('id',$ID);
        $form->addHidden('do','admin');
        $form->addHidden('page',$this->getPluginName());
        $form->addHidden('act','add');
 
//        $form->addElement(form_makeButton('submit','',$this->getLang('btn_submit')));
        $form->addElement(form_makeButton('submit','',$lang['btn_save']));
        $form->printForm();
        ptln('</div><!-- #'.$this->getPluginName().'_manager -->');
    }
 
    /**
     * weitere Funktion für irgend etwas falls Bedarf
     */
    function __doSomething() {
        // hier Code schreiben
    }
}
?>

Weitere Infos zu Admin Plugins.

action.php

action.php
<?php
/**
 * DokuWiki Action Plugin Example
 *
 * @license    GPL (http://www.gnu.org/licenses/gpl.html)
 * @license    CC0 - Public Domain Dedication (http://creativecommons.org/publicdomain/zero/1.0/)
 * @license    Public Domain Mark (http://creativecommons.org/publicdomain/mark/1.0/)
 * @author     M.K. Hitzigrath <mkh@hitzigrath.de>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
class action_plugin_example extends DokuWiki_Action_Plugin { 
 
    /**
     * Initialisierung (optional nur wenn Bedarf)
     */
    var $config = array();
    var $BV_Flag      = false;
    var $BP_Message   = '';
 
    function action_plugin_example(){
        global $conf;
        $this->config = $conf;
 
//        $this->setupLocale();               // enable direct access to language strings
    }
 
    /**
     * Registrierung eigener handlers mit dem DokuWiki Event Controller
     */
    function register(&$controller) {
        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'example_handle');
        $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, '_example_output');
    }
 
    function example_handle (&$event, $param) {
        global $ID;
        global $INFO;
 
        if (($event->data == 'show' || $event->data == 'edit') && (!$INFO['isadmin'] && !$INFO['ismanager'])) {
            $this->BV_Flag = true;
//            $this->BP_Message = $this->lang['msg_exampleMessage'];
            $this->BP_Message = $this->getLang('msg_exampleMessage');
        }
    }
 
    function _example_output (&$event, $param) {
        if ($this->BV_Flag && $this->BP_Message <> '') {
            ptln('<div id="'.$this->getPluginName().'_style">');
            ptln('  <b>'. hsc($this->BP_Message) .'</b>');
 
            $event->preventDefault();       // Stoppen weiterer Ausgabe
            $event->stopPropagation();
        }
    }
 
    /**
     * weitere Funktion für irgend etwas falls Bedarf
     */
    function __doSomething() {
        // hier Code schreiben
    }
}
?>

Weitere Infos zu Action Plugins.

helper.php

helper.php
<?php
/**
 * DokuWiki Helper Plugin Example
 *
 * @license    GPL (http://www.gnu.org/licenses/gpl.html)
 * @license    CC0 - Public Domain Dedication (http://creativecommons.org/publicdomain/zero/1.0/)
 * @license    Public Domain Mark (http://creativecommons.org/publicdomain/mark/1.0/)
 * @author     M.K. Hitzigrath <mkh@hitzigrath.de>
 */
 
if(!defined('DOKU_INC')) die();
 
class helper_plugin_example extends DokuWiki_Plugin {
 
    /**
     * Initialisierung (optional nur wenn Bedarf)
     */
    var $config = array();
 
    function helper_plugin_example(){
        global $conf;
        $this->config = $conf;
    }
 
    /**
     * Funktion für irgend etwas
     */
    function doSomething() {
        // hier Code schreiben
    }
}
?>

Weitere Infos zu Helper Plugins.

syntax.php

syntax.php
<?php
/**
 * DokuWiki Syntax Plugin Example
 *
 * @license    GPL (http://www.gnu.org/licenses/gpl.html)
 * @license    CC0 - Public Domain Dedication (http://creativecommons.org/publicdomain/zero/1.0/)
 * @license    Public Domain Mark (http://creativecommons.org/publicdomain/mark/1.0/)
 * @author     M.K. Hitzigrath <mkh@hitzigrath.de>
 */
 
if(!defined('DOKU_INC')) die();
 
//if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
//if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
require_once DOKU_PLUGIN.'syntax.php';
 
class syntax_plugin_example extends DokuWiki_Syntax_Plugin {
 
    /**
     * Initialisierung (optional nur wenn Bedarf)
     */
    var $config = array();
 
    function syntax_plugin_example(){
        global $conf;
        $this->config = $conf;
    }
 
    /**
     * weitere Basis-Funktionen
     */
    function getType() {
        return 'substition';
    }
 
    function getSort() {
        return 169;
    }
 
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('{{tag>.*?}}',$mode,'plugin_example');
    }
 
    function handle($match, $state, $pos, &$handler){
        global $conf;
        $this->Info = $this->getInfo();
        $this->Info['PluginPath'] = DOKU_PLUGIN.$this->Info['base'].'/';
 
        // Eingabe-Wert verarbeiten
        $returnWert = $match;
 
        // Übergabe-Wert für Renderer
        return $returnWert;
    }
 
    function render($mode, &$render, $data) {
        if($mode != 'xhtml') return false;
 
        // Übergabe-Wert vom handle()
        $returnWert = $data;
 
        // Ausgabe erzeugen
        $render->doc .= hsc('irgend eine Ausgabe');
 
        return true;
    }
 
    /**
     * weitere Funktion für irgend etwas (falls Bedarf)
     */
    function _doSomething() {
        // hier Code schreiben
    }
}
?>

Weitere Infos zu Syntax Plugins.

TODO Sort-Liste verlinken

renderer.php

renderer.php
<?php
/**
 * DokuWiki Renderer Plugin Example
 *
 * @license    GPL (http://www.gnu.org/licenses/gpl.html)
 * @license    CC0 - Public Domain Dedication (http://creativecommons.org/publicdomain/zero/1.0/)
 * @license    Public Domain Mark (http://creativecommons.org/publicdomain/mark/1.0/)
 * @author     M.K. Hitzigrath <mkh@hitzigrath.de>
 */
 
if(!defined('DOKU_INC')) die();
 
require_once DOKU_INC.'inc/parser/xhtml.php';
 
class renderer_plugin_example extends Doku_Renderer_xhtml {
 
    /**
     * Initialisierung (optional nur wenn Bedarf)
     */
    var $config = array();
 
    function renderer_plugin_example(){
        global $conf;
        $this->config = $conf;
    }
 
    /**
     * Make available as XHTML replacement renderer
     */
    function canRender($format){
        if($format == 'xhtml') return true;
    }
 
    /**
     * Beispiel einer geänderten Funktion aus
     * http://xref.dokuwiki.org/reference/dokuwiki/inc/parser/xhtml.php.html
     * 
     * Renders internal and external media
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     * @changes M.K. Hitzigrath <mkh@hitzigrath.de>
     */
    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
                      $height=NULL, $cache=NULL, $render = true) {
 
        $ret = '';
 
        // ...
        // eigentlicher Original-Code mit den Änderungen
        // ...
 
        return $ret;
    }
 
    /**
     * weitere Funktion für irgend etwas falls Bedarf
     */
    function own_doSomething() {
        // hier Code schreiben
    }
}
?>

Weitere Infos zu Renderer Plugins.

auth.php

TODO

remote.php

TODO

Dieser Artikel ist publiziert unter: CC by-nc-sa

docs/dokuwiki/hack_pluginbase.txt · Zuletzt geändert: 05.10.2023 - 09:46 von Mischa