Added the framework to allow us to populate standards parts of the
[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.5 2004/09/08 15:46:52 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_template
14 open Cocanwiki_diff
15
16 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
17   let template = get_template dbh hostid "diff.html" in
18
19   let page = q#param "page" in
20   let page = if page = "" then "index" else page in
21
22   (* "version" parameter, required, is the newest version.  If the
23    * "old_version" parameter is given then we compare against that.
24    * Otherwise we look in the database to find the version of this
25    * page previous to "version", and use that as "old_version".  If
26    * there is no older version in the database, then we compare against
27    * version '0' which means a blank page.
28    *
29    * NB. In case you hadn't worked it out yet, version numbers are
30    * page.ids.
31    *)
32   let version = int_of_string (q#param "version") in
33
34   let diff, old_version =
35     try
36       let old_version = int_of_string (q#param "old_version") in
37       get_diff dbh hostid page ~old_version ~version ()
38     with
39         Not_found ->
40           get_diff dbh hostid page ~version () in
41
42   template#set "version" (string_of_int version);
43   template#set "old_version" (string_of_int old_version);
44   template#set "page" page;
45   template#set "diff" diff;
46
47   q#template template
48
49 let () =
50   register_script ~restrict:[CanEdit] run