1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: admin.ml,v 1.6 2004/09/09 12:21:22 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
28 open Cocanwiki_template
31 let template = _get_template "admin/admin.html"
33 let run r (q : cgi) (dbh : Dbi.connection) _ _ _ =
34 (* Select out the alternative hostnames. *)
35 let sth = dbh#prepare_cached
36 "select hs.hostid, hs.name from hostnames hs
37 where not exists (select 1 from hosts
39 and canonical_hostname = hs.name)" in
42 let hostnames = sth#map (function [`Int hostid; `String name] ->
44 | _ -> assert false) in
46 (* Pull out the details of all the wikis on the server. *)
47 let sth = dbh#prepare_cached
48 "select h.id, h.canonical_hostname,
49 (select count(*) from pages
50 where hostid = h.id and url is not null),
51 (select max(last_modified_date) from pages
52 where hostid = h.id and url is not null)
59 (function [`Int id; `String canonical_hostname;
60 (`Null | `Int _) as page_count;
61 (`Null | `Timestamp _) as last_modified_date] ->
62 let page_count = match page_count with
65 let last_modified_date = match last_modified_date with
67 | `Timestamp date -> printable_date date in
70 List.filter (fun (i, _) -> i = id) hostnames in
72 List.map (fun (_, hostname) ->
73 [ "hostname", Template.VarString hostname ])
76 [ "id", Template.VarString (string_of_int id);
77 "canonical_hostname", Template.VarString canonical_hostname;
78 "page_count", Template.VarString (string_of_int page_count);
79 "last_modified_date", Template.VarString last_modified_date;
80 "hostnames", Template.VarTable hostnames ]
82 | _ -> assert false) in
84 template#table "hosts" table;