(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: dead_ends.ml,v 1.1 2004/09/28 11:51:38 rich Exp $
+ * $Id: dead_ends.ml,v 1.4 2006/12/06 09:46:57 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
open Cocanwiki
open Cocanwiki_template
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
- let template = get_template dbh hostid "dead_ends.html" in
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template r dbh hostid "dead_ends.html" in
- let sth =
- dbh#prepare_cached
+ let rows =
+ PGSQL(dbh)
"select p.url, p.title, count (l.to_url)
from pages p left outer join links l
on p.hostid = l.hostid and p.url = l.from_url
- where p.hostid = ?
+ where p.hostid = $hostid
and p.url is not null
and p.redirect is null
group by 1, 2
having count(l.to_url) = 0
order by 1" in
- sth#execute [`Int hostid];
let table =
- sth#map (function [`String page; `String title; _] ->
- [ "page", Template.VarString page;
- "title", Template.VarString title ]
- | _ -> assert false) in
+ List.map (
+ fun (page, title, _) ->
+ let page = Option.get page in
+ [ "page", Template.VarString page;
+ "title", Template.VarString title ]
+ ) rows in
template#table "pages" table;
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanView] run