It's better when it's simple

User Tools

Site Tools


Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community

Follow us on Facebook, Twitter and other social networks.


Export multiple pages to HTML

Export your page(s) by:

  • Siteexport Plugin (only for open wiki)
  • or one of the scripts below

For exporting multiple pages or whole namespaces have a look at the offline-doku script by Pavel Shevaev.

Unfortunately, offline-DokuWiki does not handle plugin content correctly. Does anyone knows a solution for that?
Pavel's script requires PHP >4.3. for those who don't want to upgrade change line ~46
$tokens = $parser->parse(file_get_contents($file));
$fp = fopen($file, "rb");
$buffer = fread($fp, filesize($file));
$tokens = $parser->parse($buffer);

Here's an example command line using Pavuk for exporting all pages:

pavuk -dont_leave_site -noRobots -index_name "index.html" -httpad "+X_DOKUWIKI_DO: export_xhtml" -cookie_file cookies.txt -cookie_send -skip_rpattern "(.*\?do=(diff|revisions|backlink|index|export_.*))|feed\.php.*" -tr_chr_chr "?&*:" _ -post_update -fnrules F "*" "%h/%d/%b%E"

Simply change the URL at the end of the command. Also, this command handles ACL restrictions using a cookie file. Copy the “cookies.txt” file from your web browser's profile to allow the script to login using your credentials.

Here's a quick-and-dirty bash script to export all pages using the export_xhtmlbody option (see above)

#DokuWiki Export 0.1 - by Venator85 (venator85[at]gmail[dot]com)
#Warning: DokuWiki's URL rewrite must be turned OFF for this to work, otherwise change line 27 accordingly
# Save this script in an empty dir and run it from a shell:
# sh
FTP_DOKU_PATH="" # No trailing slashes!
HTTP_DOKU_PATH="" # No trailing slashes!
wget --ftp-user=$FTPUSER --ftp-password=$FTPPASS --recursive --no-host-directories --cut-dirs=2 "$FTP_DOKU_PATH/data/pages/"
mkdir "./exported"
for i in `find pages/ -type f`
	wget -O - "$HTTP_DOKU_PATH/doku.php?do=export_xhtmlbody&id=$PAGE" > "./exported/$PAGE.htm"

And not so dirty PHP-CLI script to do the same without problems. But you need commandline access to server (e.g. SSH) and PHP-CLI installed to do this. Copy this script to dokuwiki root, cd to that directory and launch /usr/bin/php export.php (or whatever you called the file) → it will show you help.

<?php //DokuWiki exporter - copylefted by 2o1o (copy this file to dokuwiki root)
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
function p_file_xhtml($id, $excuse=false){
    if(@file_exists($id)) return p_cached_output($id,'xhtml',$id);
    return p_wiki_xhtml($id, '', $excuse);
if($argc > 1) {
  foreach($argv as $file) echo p_file_xhtml($file, false);
} else { 
  if(!isset($argv[0])) $argv[0] = __FILE__;
  echo "<h1>This is NOT web application, this is PHP-CLI application (for commandline)</h1><pre>\n";
  echo "Note that you will probably need to install php-cgi package. Check if you have 'php' command on your system\n";
  echo "php-cgi binary is commonly placed in /usr/bin/php\n\n";
  echo "Usage examples:\n";
  echo "\tphp ".$argv[0]." start\n\t\t- export single page 'start'\n";
  echo "\tphp ".$argv[0]." start > start.html\n\t\t- export single page 'start' to file start.html\n";
  echo "\tphp ".$argv[0]." start wiki:syntax\n\t\t- export multiple pages\n";
  echo "\tphp ".$argv[0]." data/pages/start.txt\n\t\t- export single page using filename\n";
  echo "\tphp ".$argv[0]." data/pages/wiki/*\n\t\t- export whole namespace 'wiki'\n";
  echo "\tphp ".$argv[0]." $(find ./data/pages/wiki/)\n\t\t- export whole namespace 'wiki' and it's sub-namespaces\n";
  echo "\tphp ".$argv[0]." $(find ./data/pages/) > dump.html\n\t\t- dump whole wiki to file dump.html\n";
  echo "\nOnce you have HTML dump you need, you can add optional CSS styles or charset-encoding header to it,\n";
  echo "then you are ready to distribute it, or (eg.) convert it to PDF using htmldoc, or html2pdf webservice.\n\n";

BTW I've just realized that it's not secure to have this script in dokuwiki root with register globals = on, since somebody can set $argv to override ACL to read any page, so if you don't want to have all of your pages to be publicly readable then don't be stupid and disable register globals in php.ini or at least deny this file in .htaccess if you can't!

And if you want to export each page to single file instead of one big, you can use some command like this:

mkdir dump; for i in $(ls -1 data/pages/); do php export.php data/pages/$i > dump/$i.html; done

but maybe you will appreciate siteexport more to do this…

→ see also related page

tips/export_html.txt · Last modified: 2013-11-20 16:30 by Klap-in