Dokuwiki - Plugin Development

Card Puncher Data Processing


This pages are notes above the devel%3Aunittesting page.



  • an _ (underscore) is a reserved character and cannot be used in the <pluginname>
  • valid <pluginname> should only contain the characters a-z and 0-9
  • two different plugins with the same name are mutually exclusive and inherently incompatible.

The same for components.



  • In a plugin Dev
$keyvalue = $this->getConf('key');

Plugin test

In a plugin test

After setup
    // Will not work in setUpClass
    function setUp(){
        // Enable your plugin !!!!!!
        $this->pluginsEnabled[] = 'myplugin';
        // Enable other plugin
        $this->pluginsEnabled[] = 'sqlite';
        global $conf;
        // Plugin conf 
        $conf ['plugin']['creole']['precedence'] = 'Creole';
        $conf ['plugin']['creole']['linebreak']  = 'Whitespace';
        // Dokuwiki conf (To get nice url)
        $conf['userewrite']= 1;
        $conf['useslash']= 1;

Before setup

The register function are called during the parent::setUp() with the configuration found in dirname(DOKU_CONF).'/conf/local.php And that fucked up every configuration in a register function. Better not using configuration in a register function or use the below utility function just before the setup

public static function setConf($configurations)
        $file = dirname(DOKU_CONF) . '/conf/local.php';
        $text = DOKU_LF;
        foreach ($configurations as $key => $value) {
            $text .= '$conf[\'plugin\'][\'' . PluginUtility::PLUGIN_BASE_NAME . '\'][\'' . $key . '\'] = \'' . $value . '\';  ' . DOKU_LF;
        file_put_contents($file, $text, FILE_APPEND);



Store derived data: Dokuwiki - Metadata Renderer

Debug / Log

Debug function (dbg*) are in the file infoutils.php




<link href="<?php echo tpl_getMediaFile(array("css/sidebar.css")); ?>" rel="stylesheet">


All dokuwiki mode can be seen in the parser.php file


Plugin are disabled:

  • via the plugin manager
  • or programmatically by adding them in the file conf/plugins.local.php.


$plugins['authad'] = 0;
$plugins['authldap'] = 0;
$plugins['fastwiki'] = 0;

In test, this is done with this code:

TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$name'] = 0;\n");

How to capture element inside a pattern

Use the addPattern in the postConnect method and get the content in the DOKU_LEXER_MATCHED state of the handle method

Example: from the webcode plugin to capture all code block

public function postConnect()

    $this->Lexer->addExitPattern('</webcode>', $this->getPluginMode());

     * Capture all code block
    $this->Lexer->addPattern('<code.*?/code>', $this->getPluginMode());


Test example

HTTP Request

$test_name = 'test_js_show_query_string';
$test_name = 'test_js_show_query_string';
$pageId = webcomponent::getNameSpace() . $test_name;
$doku_text = 'whatever';
saveWikiText($pageId, $doku_text, $test_name);
$testRequest = new TestRequest();
$testResponse = $testRequest->get(array('id' => $pageId));
$jsSrcAttribute = $testResponse->queryHTML('script[src*="js.php"]' )->attr('src');
$pos = strpos($jsSrcAttribute,action_plugin_webcomponent_js::ACCESS_PROPERTY_KEY.'=public');
$this->assertEquals(true, $pos > 0);
  • How to get the created HTML
$domElement= $queryResponse->elements[0];
$xmlText= $queryResponse->document->saveXML($domElement);

Rendering Test

$doku_text = '<' . $element . ' class="mbt-3" >' . '[[:namespace:page#section|' . $link_content . ']]' . '</' . $element . '>';
$instructions = p_get_instructions($doku_text);
$xhtml = p_render('xhtml', $instructions, $info);
$this->assertEquals($expected, $xhtml);


Authorization Check

$conf['useacl']      = 1;                 //Use Access Control Lists to restrict access?
$conf['superuser']   = 'testuser';        //password: testpass
  • Set the user
$_SERVER['REMOTE_USER'] = 'john';
global $conf;
$conf['useacl']    = 1;
$conf['superuser'] = 'john';
  • Give a group to the user
global $USERINFO;
$USERINFO['grps'] = array('admin','user');
global $auth;
    if($auth->canDo('getUsers')) {  // is this feature available?
  • Page ACL check
isHiddenPage($id) || auth_quickaclcheck($id) < AUTH_READ || !page_exists($id)



Cannot modify header information - headers already sent by (output started at _test\core\TestUtils.php:52)

There is a problem when Dokuwiki want to delete a file and php configuration (ie php.ini) is set to output all errors.

Check the line and add a @ before.



Share this page:
Follow us:
Task Runner