Integrate DokuWiki to your website

What

  • from your PHP code, grab any page from DokuWiki and display it as you wish (within your template, for example).
  • no modifications to your DokuWiki installation
  • done very little code

How

How DokuWiki works: wiki markup is read by a parser which returns instructions. These instructions are processed by a renderer to produce some HTML code.

Just for reference, an instruction looks like that:

Array
(
    [0] => internallink
    [1] => Array
        (
            [0] => java:spring:hello_world
            [1] => Hello World
        )
 
    [2] => 150
)

Instead of redoing the same process at each user request, DokuWiki has a powerful multi-level caching system. By using it, we can just get the cached instructions, and process them with a custom renderer to generate our own HTML code (with links to our PHP pages, not DokuWiki urls).

The example

Download it here. File hierarchy

  • index.php
  • doc.php
  • dokuwiki
  • include
    • DokuWikiRendererXHTML.php

The index page contains several links to doc.php, which directly uses data files from the dokuwiki folder (a standard dokuwiki installation). DokuWikiRendererXHTML.php is a custom renderer (overrides some methods of DokuWiki's default HTML renderer).

How to make the example work

  • doc.php: update the three variables in the configuration section.
  • view index.php in your browser (with the same base url that you've put in doc.php). Click on 'DokuWiki standard interface'. View the two listed wiki pages.
  • go back to index.php and view the “Integrated wiki pages” links.

Details

  • We overrided DokuWiki renderer just to make internal links go to our website pages, not to the corresponding dokuwiki installation pages.
  • DokuWiki use urls for cache files, that's why you need to view the page in DokuWiki first before being able to see it through your own PHP code. You'll notice that only if you copy/move your DokuWiki installtion somewhere else and try to view its pages through your own PHP code.
  • Not secured: any page from your DokuWiki installation can be viewed
  • if you don't need the “Table of Contents” in the generated HTML, add in doc.php, under // init renderer:
$renderer->notoc();
 
php/integrate-dokuwiki-to-your-website.txt · Last modified: 2010/09/08 19:01 by maestric
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki