At the bottom of this page are two Python scripts, ''history.cgi'' and ''diff.cgi''. These are CGI scripts that pull data from the C2 wiki and generate a somewhat friendly history listing and version diff, respectively. To use them, 1 Copy the scripts to files in your web space named ''history.cgi'' and ''diff.cgi''. 1 Configure your web server to treat these files as CGI scripts. 1 Invoke the history script as htt''''''p://url/history.cgi?Pag''''''eName. 1 Display the difference between individual page versions by selecting the versions and clicking the "Compare" button. The default is to compare the most recent version with the prior version. '''Observations''' 1 The scripts have been used on Python 2.2.2. They may run on Python 2.1, but will not run on 1.x versions. 1 Some pages (such as WikiWikiSandbox at the moment) were deleted but reinstated before the older versions had vanished from HistoryPages. So some older versions are mixed with newer versions. Because history.cgi sorts by the version number, this can cause an inversion where older instances precede the current instance. With a little bit of effort the script could be changed to sort by timestamp instead. This is left as an exercise for the reader. 1 Not all versions are present. The C2 wiki collapses together versions by a single author. 1 It is recommended to create your own copies of the scripts and use them only for yourself. A public script would be unadvisable because Ward has mechanisms in place to limit flurries of requests from the same IP. In the case of public scripts the requests all come from the single IP hosting the script. 1 It is possible to correlate the output of RecentPosts with the HistoryPages and display even more information about [most] versions. This is not as trivial as it seems, because the timestamps on RecentPosts are the times the edits were saved, while the timestamps on HistoryPages are the times the respective versions were ''superseded''. This feature is left as an exercise for the reader. 1 Not much error checking, nor is it UnitTest''''''ed. 1 You can create a WikiBookmarklet to take whatever wiki page you're viewing and show the history for that page. '''Samples''' You can see a sample snapshot of ''history.cgi'' at http://andstuff.org/wiki/history.html?WardCunningham. The "Compare" button for the snapshot is hard-wired to a comparison of revisions 688 and 689, which shows some of the capabilities of the color-coded diff (borrowed from JotEngine and MoinMoin). ---- '''history.cgi''' #!/usr/bin/python # This script is public domain import urllib import os import re try : page = os.environ['QUERY_STRING'] except : page = "" if page == "" : print "Content-type: text/plain" print print "Please indicate a page name" exit() stream = urllib.urlopen('htt''''''p://c2.com/wiki/history/' + page) history = stream.read() stream.close() stream = urllib.urlopen('htt''''''p://c2.com/cgi/quickDiff?' + page) diff = stream.read() stream.close() versions = [] re.sub(r'(HREF="(\d+)">\d+ +([-0-9A-Za-z]+ [0-9:]+))', lambda match: versions.insert(0, [int(match.group(2)), match.group(3), "htt''''''p://c2.com/wiki/history/" + page + '/' + match.group(2)]), history) re.sub(r'(Revision (\d+) made ([0-9]+ [a-z]+ ago))', lambda match: versions.insert(0, [int(match.group(2)), match.group(3), "htt''''''p://c2.com/cgi/wiki?" + page]), diff) versions.sort() versions.reverse() print "Content-type: text/html" print print "
" + "Line " + str(lastmatch[0] + 1) + ", removed:" + " | " + "Line " + str(lastmatch[1] + 1) + ", added:" + " | ||
" + leftpane + " | " + rightpane + " |