(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_links.ml,v 1.4 2004/10/10 14:44:50 rich Exp $
+ * $Id: cocanwiki_links.ml,v 1.6 2004/10/17 20:03:23 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
* page isn't a matter of just doing 'select from_url from links ...'.
* We also look at pages which redirect to this URL (for redirections
* of degrees 1 through 4 = max_redirect).
+ *
+ * XXX If page A links both to pages B and C, and page B is a redirect
+ * to page C, then querying what links to page C will list page A twice.
+ * This is a bug.
*)
let what_links_here (dbh : Dbi.connection) hostid page =
(* Build up the complete list of URLs which redirect to the target
let qs = Dbi.placeholders (List.length urls) in
let sth =
dbh#prepare_cached
- ("select li.from_url, p.title
+ ("select li.from_url, p.title, li.from_url = 'index'
from links li, pages p
where li.hostid = ? and li.to_url in " ^ qs ^ "
- and li.hostid = p.hostid and li.from_url = p.url") in
+ and li.hostid = p.hostid and li.from_url = p.url
+ order by 3 desc, 2, 1") in
sth#execute (`Int hostid :: (List.map (fun s -> `String s) urls));
sth#map (function
- | [`String url; `String title] -> url, title
+ | [`String url; `String title; _] -> url, title
| _ -> assert false)