(* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: restore_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $ *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template open Cocanwiki_ok open Cocanwiki_diff let template = get_template "restore_form.html" let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = (* Parameters. *) let page = q#param "page" in let old_version = int_of_string (q#param "version") in template#set "page" page; template#set "version" (string_of_int old_version); (* Compute the diff between the latest version of this page and the * page we're wanting to restore. *) let sth = dbh#prepare_cached "select id from pages where hostid = ? and url = ?" in sth#execute [`Int hostid; `String page]; let version = sth#fetch1int () in if version = old_version then ( error ~back_button:true ~title:"Restoring live version" q "You seem to be trying to restore the live version."; raise CgiExit ); let diff, _ = get_diff dbh hostid page ~old_version ~version () in (* Display the diff. *) template#set "diff" diff; q#template template let () = register_script run