From: rich Date: Sat, 6 Nov 2004 17:26:08 +0000 (+0000) Subject: Find orphan pages. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=beee5bf06fd433c105fda1386b3e288768221216;p=cocanwiki.git Find orphan pages. --- diff --git a/MANIFEST b/MANIFEST index 4a2c344..a74aa3c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -170,6 +170,7 @@ scripts/mailing_list_send.ml scripts/mailing_list_unsubscribe.ml scripts/mailing_list_view.ml scripts/new_page_form.ml +scripts/orphans.ml scripts/page.ml scripts/page_email_confirm.ml scripts/page_email_form.ml @@ -267,6 +268,7 @@ templates/mailing_list_view.html templates/mailing_list_view.txt templates/new_page_form.html templates/ok_error.html +templates/orphans.html templates/page.html templates/page_404.html templates/page_email_form.html diff --git a/scripts/.depend b/scripts/.depend index d45740b..87cd697 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -246,6 +246,8 @@ mailing_list_view.cmx: lib/cocanwiki.cmx lib/cocanwiki_date.cmx \ lib/cocanwiki_template.cmx new_page_form.cmo: lib/cocanwiki.cmo lib/cocanwiki_template.cmi new_page_form.cmx: lib/cocanwiki.cmx lib/cocanwiki_template.cmx +orphans.cmo: lib/cocanwiki.cmo lib/cocanwiki_template.cmi +orphans.cmx: lib/cocanwiki.cmx lib/cocanwiki_template.cmx page.cmo: lib/cocanwiki.cmo lib/cocanwiki_date.cmo lib/cocanwiki_links.cmi \ lib/cocanwiki_ok.cmo lib/cocanwiki_server_settings.cmo \ lib/cocanwiki_template.cmi lib/wikilib.cmi diff --git a/scripts/orphans.ml b/scripts/orphans.ml new file mode 100644 index 0000000..0ab5272 --- /dev/null +++ b/scripts/orphans.ml @@ -0,0 +1,93 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: orphans.ml,v 1.1 2004/11/06 17:26:10 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 : Dbi.connection) 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 sth = dbh#prepare_cached "select url from sitemenu where hostid = ?" in + sth#execute [`Int hostid]; + + let start_pages = sth#map (function [`String s] -> s | _ -> assert false) 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. + *) + 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 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 (`Int hostid :: + (List.map (fun s -> `String s) border) @ + (List.map (fun s -> `String s) pages')); + let border' = sth#map (function [`String s] -> s | _ -> assert false) 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 (`Int hostid :: (List.map (fun s -> `String s) non_orphans)); + + let table = + sth#map (function [`String page; `String title] -> + [ "page", Template.VarString page; + "title", Template.VarString title ] + | _ -> assert false) in + + template#table "pages" table; + + q#template template + +let () = + register_script ~restrict:[CanView] run diff --git a/templates/host_menu.html b/templates/host_menu.html index 229f3f7..322dda0 100644 --- a/templates/host_menu.html +++ b/templates/host_menu.html @@ -9,11 +9,18 @@

Sitewide settings

+

Interesting pages and links

+ + +

Site management

+