(* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: admin.ml,v 1.5 2004/09/09 09:35:34 rich Exp $ *) 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