1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: history.ml,v 1.8 2004/09/21 13:01:16 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
28 open Cocanwiki_template
31 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
32 let template = get_template dbh hostid "history.html" in
34 let page = q#param "page" in
35 let page = if page = "" then "index" else page in
39 "select p.id, p.url, p.url_deleted, p.title, p.last_modified_date,
41 from pages p left outer join users u on p.logged_user = u.id
42 where p.hostid = ? and (p.url = ? or p.url_deleted = ?)
43 order by p.last_modified_date desc" in
44 sth#execute [`Int hostid; `String page; `String page];
49 | [`Int version; `String url; _; `String title;
50 `Timestamp last_modified_date; logged_ip; logged_user ] ->
51 let date = printable_date_time last_modified_date in
52 let has_logged_ip, logged_ip =
55 | `String ip -> true, ip
56 | _ -> assert false in
57 let has_logged_user, logged_user =
58 match logged_user with
60 | `String name -> true, name
61 | _ -> assert false in
62 [ "version", Template.VarString (string_of_int version);
63 "url", Template.VarString url;
64 "title", Template.VarString title;
65 "last_modified_date", Template.VarString date;
66 "has_logged_ip", Template.VarConditional has_logged_ip;
67 "logged_ip", Template.VarString logged_ip;
68 "has_logged_user", Template.VarConditional has_logged_user;
69 "logged_user", Template.VarString logged_user;
70 "is_live", Template.VarConditional true ]
71 | [`Int version; `Null; `String url; `String title;
72 `Timestamp last_modified_date; logged_ip; logged_user ] ->
73 let date = printable_date_time last_modified_date in
74 let has_logged_ip, logged_ip =
77 | `String ip -> true, ip
78 | _ -> assert false in
79 let has_logged_user, logged_user =
80 match logged_user with
82 | `String name -> true, name
83 | _ -> assert false in
84 [ "version", Template.VarString (string_of_int version);
85 "url", Template.VarString url;
86 "title", Template.VarString title;
87 "last_modified_date", Template.VarString date;
88 "has_logged_ip", Template.VarConditional has_logged_ip;
89 "logged_ip", Template.VarString logged_ip;
90 "has_logged_user", Template.VarConditional has_logged_user;
91 "logged_user", Template.VarString logged_user;
92 "is_live", Template.VarConditional false ]
93 | _ -> assert false) in
95 template#table "history" table;
100 register_script ~restrict:[CanEdit] run