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