(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: orphans.ml,v 1.3 2006/03/27 18:09:46 rich Exp $
+ * $Id: orphans.ml,v 1.6 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_template
let run r (q : cgi) dbh hostid _ _ =
- let template = get_template dbh hostid "orphans.html" in
+ let template = get_template r dbh hostid "orphans.html" in
(* Start with the front page, the contents of the site menu and the
* special "copyright" page.
*)
- let sth = dbh#prepare_cached "select url from sitemenu where hostid = ?" in
- sth#execute [Some hostid];
-
- let start_pages = sth#map (function [Some s] -> s | _ -> assert false) in
+ let start_pages =
+ PGSQL(dbh) "select url from sitemenu where hostid = $hostid" in
let start_pages = "index" :: "copyright" :: start_pages in
(* The find the list of orphans, we first construct the list of
* pages @ border is a list of distinct pages
*)
let pages' = pages @ border in
- let qs = Dbi.placeholders (List.length border) in
- let qs' = Dbi.placeholders (List.length pages') in
- let sth =
- dbh#prepare_cached ("select distinct to_url from links
- where hostid = ? and from_url in " ^ qs ^ "
- and to_url not in " ^ qs') in
- sth#execute (Some hostid ::
- (List.map (fun s -> Some s) border) @
- (List.map (fun s -> Some s) pages'));
- let border' = sth#map (function [Some s] -> s | _ -> assert false) in
-
+ let border' =
+ PGSQL(dbh) "select distinct to_url from links
+ where hostid = $hostid and from_url in $@border
+ and to_url not in $@pages'" in
if border' = [] then pages'
else loop pages' border'
in
let non_orphans = loop [] start_pages in
(* Get the actual orphans, which are pages which do not appear in this list*)
- let qs = Dbi.placeholders (List.length non_orphans) in
- let sth = dbh#prepare_cached ("select url, title from pages
- where hostid = ?
- and url is not null
- and redirect is null
- and url not in " ^ qs ^ "
- order by 1") in
- sth#execute (Some hostid :: (List.map (fun s -> Some s) non_orphans));
+ let rows = PGSQL(dbh)
+ "select url, title from pages
+ where hostid = $hostid
+ and url is not null and redirect is null
+ and url not in $@non_orphans
+ order by 1" in
let table =
- sth#map (function [Some page; Some 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;