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: recent.ml,v 1.7 2004/09/09 12:21:22 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 max_age = "3 months"
33 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
34 let template = get_template dbh hostid "recent.html" in
38 "select id, url, url_deleted, title, last_modified_date, logged_ip
41 and last_modified_date >= current_timestamp - interval ?
42 order by last_modified_date desc" in
43 sth#execute [`Int hostid; `String max_age];
48 | [`Int version; `String url; _; `String title;
49 `Timestamp last_modified_date; logged_ip] ->
50 let date = printable_date_time last_modified_date in
51 let has_logged_ip, logged_ip =
54 | `String ip -> true, ip
55 | _ -> assert false in
56 [ "version", Template.VarString (string_of_int version);
57 "url", Template.VarString url;
58 "title", Template.VarString title;
59 "last_modified_date", Template.VarString date;
60 "has_logged_ip", Template.VarConditional has_logged_ip;
61 "logged_ip", Template.VarString logged_ip;
62 "is_live", Template.VarConditional true ]
63 | [`Int version; `Null; `String url; `String title;
64 `Timestamp last_modified_date; logged_ip] ->
65 let date = printable_date_time last_modified_date in
66 let has_logged_ip, logged_ip =
69 | `String ip -> true, ip
70 | _ -> assert false in
71 [ "version", Template.VarString (string_of_int version);
72 "url", Template.VarString url;
73 "title", Template.VarString title;
74 "last_modified_date", Template.VarString date;
75 "has_logged_ip", Template.VarConditional has_logged_ip;
76 "logged_ip", Template.VarString logged_ip;
77 "is_live", Template.VarConditional false ]
78 | _ -> assert false) in
80 template#table "recent_changes" table;
85 register_script ~restrict:[CanEdit] run