(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: recent.ml,v 1.7 2004/09/09 12:21:22 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template open Cocanwiki_date let max_age = "3 months" let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let template = get_template dbh hostid "recent.html" in let sth = dbh#prepare_cached "select id, url, url_deleted, title, last_modified_date, logged_ip from pages where hostid = ? and last_modified_date >= current_timestamp - interval ? order by last_modified_date desc" in sth#execute [`Int hostid; `String max_age]; let table = sth#map (function | [`Int version; `String url; _; `String title; `Timestamp last_modified_date; logged_ip] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; "is_live", Template.VarConditional true ] | [`Int version; `Null; `String url; `String title; `Timestamp last_modified_date; logged_ip] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; "is_live", Template.VarConditional false ] | _ -> assert false) in template#table "recent_changes" table; q#template template let () = register_script ~restrict:[CanEdit] run