(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: orphans.ml,v 1.4 2006/03/28 13:20:00 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 let run r (q : cgi) dbh hostid _ _ = let template = get_template dbh hostid "orphans.html" in (* Start with the front page, the contents of the site menu and the * special "copyright" page. *) 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 reachable from the front page. Once this list has been * constructed, any page not on the list is an orphan or part of * a group of orphans. * * XXX This does not properly handle redirects XXX *) let rec loop pages border = (* Preconditions: * pages <> [] * border <> [] * pages is a list of distinct pages * border is a list of distinct pages * pages @ border is a list of distinct pages *) let pages' = pages @ border 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 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 = List.map (fun (page, title) -> [ "page", Template.VarString page; "title", Template.VarString title ]) rows in template#table "pages" table; q#template template let () = register_script ~restrict:[CanView] run