X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fhistory.ml;h=9560ba4f1b386dc5a7b185aecc0f528adeb0b191;hb=262f6a0c34949247ba6b78399b787e693da38d86;hp=a5fdf5bea4d0c7662d5c32c81f3327cca4ce93bc;hpb=3062d573a7617339324c23cdd4755f8f04956b92;p=cocanwiki.git diff --git a/scripts/history.ml b/scripts/history.ml index a5fdf5b..9560ba4 100644 --- a/scripts/history.ml +++ b/scripts/history.ml @@ -1,7 +1,22 @@ -(* COCANWIKI scripts. +(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: history.ml,v 1.1 2004/09/07 10:14:09 rich Exp $ + * $Id: history.ml,v 1.11 2006/03/27 19:10:29 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 @@ -10,61 +25,73 @@ open Cgi open Printf open Cocanwiki +open Cocanwiki_template +open Cocanwiki_date -open Merjisforwiki +let run r (q : cgi) dbh hostid _ _ = + let template = get_template dbh hostid "history.html" in -let template = get_template "history.html" - -let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ = let page = q#param "page" in let page = if page = "" then "index" else page in + template#set "page" page; - let sth = - dbh#prepare_cached - "select id, url, url_deleted, title, last_modified_date, logged_ip - from pages - where hostid = ? and (url = ? or url_deleted = ?) - order by last_modified_date desc" in - sth#execute [`Int hostid; `String page; `String page]; + let rows = + PGSQL(dbh) "nullable-results" + "select p.id, p.url, p.url_deleted, p.title, p.last_modified_date, + p.logged_ip, u.name + from pages p left outer join users u on p.logged_user = u.id + where p.hostid = $hostid and (p.url = $page or p.url_deleted = $page) + order by p.last_modified_date desc" in let table = - sth#map + List.map (function - | [`Int version; `String url; _; `String title; - `Timestamp last_modified_date; logged_ip ] -> + | (Some version, Some url, _, Some title, + Some last_modified_date, logged_ip, logged_user) -> 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); + None -> false, "" + | Some ip -> true, ip in + let has_logged_user, logged_user = + match logged_user with + None -> false, "" + | Some name -> true, name in + [ "version", Template.VarString (Int32.to_string 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; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional true ] - | [`Int version; `Null; `String url; `String title; - `Timestamp last_modified_date; logged_ip ] -> + | (Some version, None, Some url, Some title, + Some last_modified_date, logged_ip, logged_user) -> 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); + None -> false, "" + | Some ip -> true, ip in + let has_logged_user, logged_user = + match logged_user with + None -> false, "" + | Some name -> true, name in + [ "version", Template.VarString (Int32.to_string 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; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional false ] - | _ -> assert false) in + | _ -> assert false + ) rows in template#table "history" table; q#template template let () = - register_script run + register_script ~restrict:[CanEdit] run