Fixed (C) messages in all the files.
[cocanwiki.git] / scripts / recent.ml
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 $
5  *
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.
10  *
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.
15  *
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.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25 open Printf
26
27 open Cocanwiki
28 open Cocanwiki_template
29 open Cocanwiki_date
30
31 let max_age = "3 months"
32
33 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
34   let template = get_template dbh hostid "recent.html" in
35
36   let sth =
37     dbh#prepare_cached
38       "select id, url, url_deleted, title, last_modified_date, logged_ip
39          from pages
40         where hostid = ?
41           and last_modified_date >= current_timestamp - interval ?
42         order by last_modified_date desc" in
43   sth#execute [`Int hostid; `String max_age];
44
45   let table =
46     sth#map
47       (function
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 =
52                match logged_ip with
53                    `Null -> false, ""
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 =
67                match logged_ip with
68                    `Null -> false, ""
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
79
80   template#table "recent_changes" table;
81
82   q#template template
83
84 let () =
85   register_script ~restrict:[CanEdit] run