Dokuwiki - Plugin Development

About

This pages are notes above the devel:unittesting page.

For a list of nice plugin, see solutions:nice

Subject

Name

https://www.dokuwiki.org/devel:plugin_file_structure#name_conventions_of_plugin_name

  • 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.

Configuration

Plugin

  • 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;
 
        parent::setUp();
        
        // Plugin conf 
        $conf ['plugin']['creole']['precedence'] = 'Creole';
        $conf ['plugin']['creole']['linebreak']  = 'Whitespace';
        
        // Dokuwiki conf (To get nice url)
        // https://www.dokuwiki.org/config:userewrite
        $conf['userewrite']= 1;
        // https://www.dokuwiki.org/config:useslash
        $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);

}

Metadata

Store derived data: Dokuwiki - Metadata Renderer

Debug / Log

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

Example:

dbglog("\nBlablabla\n");

Example:

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

Mode

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

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);
idx_addPage($pageId);
$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);

Version

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?
        $auth->retrieveUsers(0,0,$filter);
    }
  • Page ACL check
isHiddenPage($id) || auth_quickaclcheck($id) < AUTH_READ || !page_exists($id)

Security

Support

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.

Example:

@unlink($target);
@rmdir($target);

Powered by ComboStrap