Moved to merjis/tools/wiki.
[cocanwiki.git] / scripts / diff.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: diff.ml,v 1.1 2004/09/07 10:14:09 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_diff
14
15 open Merjisforwiki
16
17 let template = get_template "diff.html"
18
19 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ =
20   let page = q#param "page" in
21   let page = if page = "" then "index" else page in
22
23   (* "version" parameter, required, is the newest version.  If the
24    * "old_version" parameter is given then we compare against that.
25    * Otherwise we look in the database to find the version of this
26    * page previous to "version", and use that as "old_version".  If
27    * there is no older version in the database, then we compare against
28    * version '0' which means a blank page.
29    *
30    * NB. In case you hadn't worked it out yet, version numbers are
31    * page.ids.
32    *)
33   let version = int_of_string (q#param "version") in
34
35   let diff, old_version =
36     try
37       let old_version = int_of_string (q#param "old_version") in
38       get_diff dbh hostid page ~old_version ~version ()
39     with
40         Not_found ->
41           get_diff dbh hostid page ~version () in
42
43   template#set "version" (string_of_int version);
44   template#set "old_version" (string_of_int old_version);
45   template#set "page" page;
46   template#set "diff" diff;
47
48   q#template template
49
50 let () =
51   register_script run