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();

Feedback

Another COOL stuff, something I was looking for a long time. I would suggest two more tutorials when you have free time again ;) A) Customized your Dokuwiki instance to your site theme or template (like in Kohanaphp, where you have green theme all around the site) B) How about Trac integration to your site? Just like in kohanaphp again. I know there are lot of tutorials for above around. But I do not think they will explain things as simple as do.:) Anyway, thank you very much again!
Tony
Mar 14, 2008
#1
this is great except my pages are not rendering. i am getting a return of: Warning: Missing config cascade for "smileys" in /home/content/p/l/a/planseaadmin/html/wiki/inc/confutils.php on line 170. any insight?
Justin
Jan 29, 2009
#2
The need to view the page id DokuWiki first as been a little bit anoying to me, because the wiki is used on several domains and page displaying did not work correctly in some cases. So here is short code how to solve it. Just replace lines: $cache = new cache_instructions($dokuPageId, $pagePath); $instructions = $cache->retrieveCache(); with following: $cache = new cache_instructions($dokuPageId, $pagePath); if ($cache->useCache()){ $instructions = $cache->retrieveCache(); } else{ $instructions = p_get_instructions(io_readfile($pagePath)); $cache->storeCache($instructions); } Also the line: $_REQUEST['purge'] = false; should be removed or replaced with: unset($_REQUEST['purge']); because dokuwiki does not test value of that variable. It tests just presence of it. And method $cache->useCache() always return false when the $_REQUEST['purge'] exists.
Karel Kozlík
Apr 26, 2009
#3
Wow, that's great Karel, thank you very much for the information!
Jérôme Jaglale
Apr 26, 2009
#4
Hey, I met this problem:
Warning: Missing config cascade for "smileys" in /public_html/wiki/dokuwiki/inc/confutils.php on line 198
created:
last Modified:
Do you have any suggestion to fix it?
Aladdin
Nov 11, 2010
#5
Hi,
Great utility, thanks. I got the example to work but when I try it on my site I get errors for missing function calls. It looks like the DS_STORE files contain the needed functions defined. However your DS_STORES do not appear to work with my dokuwiki installation. Is there any information that tells how to create these.
Tom
Jan 11, 2011
#6
.DS_Store files are only Mac OS X system files. You can remove them.
Jérôme Jaglale
Jan 11, 2011
#7
Thanks for the quick reply. I did remove them and your example still worked but mine still did not. I saw that I am running dokuwiki version 2010-11-07. I walked thru the missing includes and added into doc.php the following

require DOKU_PATH . '/inc/pageutils.php';
require DOKU_PATH . '/inc/io.php';
require DOKU_PATH . '/inc/confutils.php';
require DOKU_PATH . '/inc/init.php';

It then worked perfectly. Thanks again, you saved me from wasting time looking into DS_STORE files!
Tom
Jan 11, 2011
#8
Hi, thanks for this nice solution.
Your demo is working nicely in my localhost and I'm trying to implement it with the newest Dokuwiki release (2015-08-10a "Detritus"). Unfortunately, is not rendering at all, I just get a blank page. My server erro.log uotputs:

PHP Fatal error: Class 'DokuWiki_Plugin' not found in /var/www/html/admin/tutorial/dokuwiki/inc/parser/parser.php on line 202

Any hint will be appreciated!
Dan
Oct 31, 2015
#9
I am getting the same message about the class not being found as Dan is getting in the comment above. I'm on Detritus as well:

[Tue Oct 11 16:36:33 2016] [error] [client <IP ADDRESS>]
PHP Fatal error: Class 'DokuWiki_Plugin' not found in /var/www/wiki/inc/parser/parser.php on line 202,
referer: <URL OF SITE>/index.php

Any help would be much appreciated!
Andrew Mulheirn
Oct 11, 2016
#10