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