(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: admin.ml,v 1.8 2006/03/28 16:24:08 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 _ _ _ = (* Select out the alternative hostnames. *) let hostnames = PGSQL(dbh) "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 (* Pull out the details of all the wikis on the server. *) let rows = PGSQL(dbh) "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 let table = List.map ( function (id, canonical_hostname, page_count, last_modified_date) -> let page_count = match page_count with | None -> 0L | Some n -> n in let last_modified_date = match last_modified_date with | None -> "-" | Some 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 (Int32.to_string id); "canonical_hostname", Template.VarString canonical_hostname; "page_count", Template.VarString (Int64.to_string page_count); "last_modified_date", Template.VarString last_modified_date; "hostnames", Template.VarTable hostnames ] ) rows in template#table "hosts" table; q#template template let () = register_script run