(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: admin.ml,v 1.6 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 template = _get_template "admin/admin.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ _ = (* Select out the alternative hostnames. *) let sth = dbh#prepare_cached "select hs.hostid, hs.name from hostnames hs where not exists (select 1 from hosts where id = hs.hostid and canonical_hostname = hs.name)" in sth#execute []; let hostnames = sth#map (function [`Int hostid; `String name] -> hostid, name | _ -> assert false) in (* Pull out the details of all the wikis on the server. *) let sth = dbh#prepare_cached "select h.id, h.canonical_hostname, (select count(*) from pages where hostid = h.id and url is not null), (select max(last_modified_date) from pages where hostid = h.id and url is not null) from hosts h order by 2" in sth#execute []; let table = sth#map (function [`Int id; `String canonical_hostname; (`Null | `Int _) as page_count; (`Null | `Timestamp _) as last_modified_date] -> let page_count = match page_count with `Null -> 0 | `Int n -> n in let last_modified_date = match last_modified_date with `Null -> "-" | `Timestamp date -> printable_date date in let hostnames = List.filter (fun (i, _) -> i = id) hostnames in let hostnames = List.map (fun (_, hostname) -> [ "hostname", Template.VarString hostname ]) hostnames in [ "id", Template.VarString (string_of_int id); "canonical_hostname", Template.VarString canonical_hostname; "page_count", Template.VarString (string_of_int page_count); "last_modified_date", Template.VarString last_modified_date; "hostnames", Template.VarTable hostnames ] | _ -> assert false) in template#table "hosts" table; q#template template let () = register_script run