DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:pageannotate

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.

#!/usr/bin/php
<?php
# 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 <glen@pld-linux.org>

if ($argc < 2) {
        echo "Usage: $argv[0] PAGEID\n";
        exit(1);
}
$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) {
                exit($rv);
        }
}
 
// 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      192.168.2.250   C       crs     glen    created 
#               1288262280      192.168.2.250   E       crs     glen
#               1288262444      192.168.2.250   E       crs     glen
#               1288262460      192.168.2.250   E       crs     glen
#               1288262889      192.168.2.250   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");
                break;
        case 'E':
        case 'e':
                xsys("zcat $attic/$pagefn.$rev.txt.gz > $page");
                xsys("git commit --allow-empty --date $rev --author '$author' -m edit $page");
                break;
        case 'D':
                if ($track_adds) {
                        xsys("git rm $page");
                }
                xsys("git commit --allow-empty --date $rev --author '$author' -m remove $page");
                break;
        }
}
tips/pageannotate.txt · Last modified: by 89.67.9.85

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