It's better when it's simple

User Tools

Site Tools


Page Annotate

Currently (2010-10-28) DokuWiki lacks possibility to give you annotated history of a page.

This is script I wrote in 30 minutes to give me idea who edited which line in page.

It extracts each page with meta from dokuwiki and commits to git with modified metadata, so you could use “git annotate” to see who edited which line and when.

# This is my version to quickly get blame to a dokuwiki page.
# it extracts each page from dokuwiki and commits to git
# and then you can use git itself to do blame.
# Author: Elan Ruusamäe <>

if ($argc < 2) {
        echo "Usage: $argv[0] PAGEID\n";
$page = $argv[1];
$dw = '/var/lib/dokuwiki';
$pages = "$dw/pages";
$meta = "$dw/meta";
$attic = "$dw/attic";
 * wrapper around exec, terminates script on error
function xsys($cmd) {
        system("set -x;$cmd", $rv);
        if ($rv != 0) {
// init
if (!is_dir(".git")) {
        xsys("git init");
// whether to track adds/removals
$track_adds = false;
if (!$track_adds) {
        xsys("echo IMPLICIT CREATE > $page");
        xsys("git add $page");
$pagefn = str_replace(":", "/", $page);
// read changes
$changesfn = "$meta/$pagefn.changes";
echo "Read $changesfn\n";
foreach (file($changesfn) as $line) {
#               1288259524   C       crs     glen    created 
#               1288262280   E       crs     glen
#               1288262444   E       crs     glen
#               1288262460   E       crs     glen
#               1288262889   D       crs     glen    removed 
        list($rev, $host, $act, $pagename, $author)= explode("\t", $line);
        echo "rev[$rev]; host[$host]; act[$act]; pagename[$pagename]; author[$author]\n";
        if ($author == '')
                $author = 'UNKNOWN';
        // hack to skip git looking up author names
        $author = "$author <$author>";
        switch ($act) {
        case 'C':
                xsys("zcat $attic/$pagefn.$rev.txt.gz > $page");
                if ($track_adds) {
                        xsys("git add $page");
                xsys("git commit --allow-empty --date $rev --author '$author' -m add $page");
        case 'E':
        case 'e':
                xsys("zcat $attic/$pagefn.$rev.txt.gz > $page");
                xsys("git commit --allow-empty --date $rev --author '$author' -m edit $page");
        case 'D':
                if ($track_adds) {
                        xsys("git rm $page");
                xsys("git commit --allow-empty --date $rev --author '$author' -m remove $page");
tips/pageannotate.txt · Last modified: 2016-02-23 12:30 by

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki