2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: admin.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
13 open Cocanwiki_template
16 let template = get_template "admin/admin.html"
18 let run r (q : cgi) (dbh : Dbi.connection) _ _ =
19 (* Select out the alternative hostnames. *)
20 let sth = dbh#prepare_cached
21 "select hs.hostid, hs.name from hostnames hs
22 where not exists (select 1 from hosts
24 and canonical_hostname = hs.name)" in
27 let hostnames = sth#map (function [`Int hostid; `String name] ->
29 | _ -> assert false) in
31 (* Pull out the details of all the wikis on the server. *)
32 let sth = dbh#prepare_cached
33 "select h.id, h.canonical_hostname,
34 (select count(*) from pages
35 where hostid = h.id and url is not null),
36 (select max(last_modified_date) from pages
37 where hostid = h.id and url is not null)
44 (function [`Int id; `String canonical_hostname;
45 (`Null | `Int _) as page_count;
46 (`Null | `Timestamp _) as last_modified_date] ->
47 let page_count = match page_count with
50 let last_modified_date = match last_modified_date with
52 | `Timestamp date -> printable_date date in
55 List.filter (fun (i, _) -> i = id) hostnames in
57 List.map (fun (_, hostname) ->
58 [ "hostname", Template.VarString hostname ])
61 [ "id", Template.VarString (string_of_int id);
62 "canonical_hostname", Template.VarString canonical_hostname;
63 "page_count", Template.VarString (string_of_int page_count);
64 "last_modified_date", Template.VarString last_modified_date;
65 "hostnames", Template.VarTable hostnames ]
67 | _ -> assert false) in
69 template#table "hosts" table;