Moved to merjis/tools/wiki.
[cocanwiki.git] / scripts / restore_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: restore_form.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 Merjisforwiki
13
14 open Cocanwiki
15 open Cocanwiki_ok
16 open Cocanwiki_diff
17
18 let template = get_template "restore_form.html"
19
20 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ =
21   (* Parameters. *)
22   let page = q#param "page" in
23   let old_version = int_of_string (q#param "version") in
24
25   template#set "page" page;
26   template#set "version" (string_of_int old_version);
27
28   (* Compute the diff between the latest version of this page and the
29    * page we're wanting to restore.
30    *)
31   let sth = dbh#prepare_cached "select id from pages
32                                  where hostid = ? and url = ?" in
33   sth#execute [`Int hostid; `String page];
34
35   let version = sth#fetch1int () in
36
37   if version = old_version then (
38     error ~back_button:true ~title:"Restoring live version"
39       q "You seem to be trying to restore the live version.";
40     raise CgiExit
41   );
42
43   let diff, _ = get_diff dbh hostid page ~old_version ~version () in
44
45   (* Display the diff. *)
46   template#set "diff" diff;
47
48   q#template template
49
50 let () =
51   register_script run