Added the framework to allow us to populate standards parts of the
[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.5 2004/09/08 15:46:53 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_ok
15 open Cocanwiki_diff
16
17 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
18   let template = get_template dbh hostid "restore_form.html" in
19
20   (* Parameters. *)
21   let page = q#param "page" in
22   let old_version = int_of_string (q#param "version") in
23
24   template#set "page" page;
25   template#set "version" (string_of_int old_version);
26
27   (* Compute the diff between the latest version of this page and the
28    * page we're wanting to restore.
29    *)
30   let sth = dbh#prepare_cached "select id from pages
31                                  where hostid = ? and url = ?" in
32   sth#execute [`Int hostid; `String page];
33
34   let version = sth#fetch1int () in
35
36   if version = old_version then (
37     error ~back_button:true ~title:"Restoring live version"
38       q "You seem to be trying to restore the live version.";
39     raise CgiExit
40   );
41
42   let diff, _ = get_diff dbh hostid page ~old_version ~version () in
43
44   (* Display the diff. *)
45   template#set "diff" diff;
46
47   q#template template
48
49 let () =
50   register_script ~restrict:[CanEdit] run