From: rich Date: Tue, 28 Sep 2004 11:51:38 +0000 (+0000) Subject: Leveraging the links table: X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=a24ca0230d6c23bdbcddc9690ea66b0682630e84;p=cocanwiki.git Leveraging the links table: * 'What links here?' and 'Dead ends' Don't compile 00-TEMPLATE.ml each time. Change restrict clause in 00-TEMPLATE.ml so it will cause a compile error if we don't set up the permissions for each script. Updated MANIFEST. Updated deps. --- diff --git a/MANIFEST b/MANIFEST index cac79ce..8f5de7b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -74,6 +74,7 @@ scripts/create_contact_form.ml scripts/create_form.ml scripts/create_user.ml scripts/create_user_form.ml +scripts/dead_ends.ml scripts/delete_contact.ml scripts/delete_contact_form.ml scripts/delete_file.ml @@ -145,6 +146,7 @@ scripts/upload_file_form.ml scripts/upload_image.ml scripts/upload_image_form.ml scripts/users.ml +scripts/what_links_here.ml scripts/wikilib.ml scripts/wikilib.mli templates/00-TEMPLATE.html @@ -161,6 +163,7 @@ templates/contacts.html templates/create_contact_form.html templates/create_form.html templates/create_user_form.html +templates/dead_ends.html templates/delete_contact_form.html templates/delete_file_form.html templates/delete_image_form.html @@ -209,3 +212,4 @@ templates/undelete_image_form.html templates/upload_file_form.html templates/upload_image_form.html templates/users.html +templates/what_links_here.html \ No newline at end of file diff --git a/scripts/.depend b/scripts/.depend index d821e35..52b42f7 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -42,6 +42,8 @@ create_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo create_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx create_user_form.cmo: cocanwiki.cmo cocanwiki_template.cmi create_user_form.cmx: cocanwiki.cmx cocanwiki_template.cmx +dead_ends.cmo: cocanwiki.cmo cocanwiki_template.cmi +dead_ends.cmx: cocanwiki.cmx cocanwiki_template.cmx delete_contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo delete_contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx delete_contact_form.cmo: cocanwiki.cmo cocanwiki_template.cmi @@ -214,6 +216,8 @@ upload_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi upload_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx users.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi users.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx +what_links_here.cmo: cocanwiki.cmo cocanwiki_template.cmi +what_links_here.cmx: cocanwiki.cmx cocanwiki_template.cmx wikilib.cmo: cocanwiki_strings.cmo wikilib.cmi wikilib.cmx: cocanwiki_strings.cmx wikilib.cmi admin/admin.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi diff --git a/scripts/00-TEMPLATE.ml b/scripts/00-TEMPLATE.ml index 18d00bb..e2be28f 100644 --- a/scripts/00-TEMPLATE.ml +++ b/scripts/00-TEMPLATE.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: 00-TEMPLATE.ml,v 1.3 2004/09/09 12:21:21 rich Exp $ + * $Id: 00-TEMPLATE.ml,v 1.4 2004/09/28 11:51:38 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 @@ -37,4 +37,4 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = q#template template let () = - register_script ~restrict:[CanManageUsers] run + register_script ~restrict:[Put_Restrictions_Here] run diff --git a/scripts/Makefile b/scripts/Makefile index 3c4ca38..c4c23a5 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.29 2004/09/28 10:56:39 rich Exp $ +# $Id: Makefile,v 1.30 2004/09/28 11:51:38 rich Exp $ include ../Makefile.config @@ -22,8 +22,7 @@ LIB_OBJS := \ wikilib.cmo \ cocanwiki_links.cmo -OBJS := 00-TEMPLATE.cmo \ - change_password.cmo \ +OBJS := change_password.cmo \ change_password_form.cmo \ contact.cmo \ contact_show.cmo \ @@ -34,6 +33,7 @@ OBJS := 00-TEMPLATE.cmo \ create_contact_form.cmo \ create_user.cmo \ create_user_form.cmo \ + dead_ends.cmo \ delete_contact.cmo \ delete_contact_form.cmo \ delete_file.cmo \ @@ -104,7 +104,8 @@ OBJS := 00-TEMPLATE.cmo \ upload_file_form.cmo \ upload_image.cmo \ upload_image_form.cmo \ - users.cmo + users.cmo \ + what_links_here.cmo ADMIN_OBJS := \ admin/admin.cmo \ diff --git a/scripts/dead_ends.ml b/scripts/dead_ends.ml new file mode 100644 index 0000000..c2623a9 --- /dev/null +++ b/scripts/dead_ends.ml @@ -0,0 +1,57 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: dead_ends.ml,v 1.1 2004/09/28 11:51:38 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 "dead_ends.html" in + + let sth = + dbh#prepare_cached + "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 = ? + 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 + + template#table "pages" table; + + q#template template + +let () = + register_script run diff --git a/scripts/largest_pages.ml b/scripts/largest_pages.ml index 7f1c53a..2b7fd72 100644 --- a/scripts/largest_pages.ml +++ b/scripts/largest_pages.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: largest_pages.ml,v 1.1 2004/09/21 17:07:58 rich Exp $ + * $Id: largest_pages.ml,v 1.2 2004/09/28 11:51:38 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 @@ -72,4 +72,4 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = q#template template let () = - register_script ~restrict:[CanManageUsers] run + register_script run diff --git a/scripts/what_links_here.ml b/scripts/what_links_here.ml new file mode 100644 index 0000000..ea9b572 --- /dev/null +++ b/scripts/what_links_here.ml @@ -0,0 +1,61 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: what_links_here.ml,v 1.1 2004/09/28 11:51:38 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 "what_links_here.html" in + + let page = q#param "page" in + template#set "page" page; + + let sth = dbh#prepare_cached "select title from pages + where hostid = ? and url = ?" in + sth#execute [`Int hostid; `String page]; + + let title = sth#fetch1string () in + template#set "title" title; + + let sth = + dbh#prepare_cached "select l.from_url, p.title from links l, pages p + where l.hostid = ? and l.to_url = ? + and l.hostid = p.hostid and l.from_url = p.url" in + sth#execute [`Int hostid; `String page]; + + 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 run diff --git a/templates/dead_ends.html b/templates/dead_ends.html new file mode 100644 index 0000000..a0c7be1 --- /dev/null +++ b/templates/dead_ends.html @@ -0,0 +1,43 @@ + + + +Dead end pages + + + + + +

Dead end pages

+ + + + + + + + + + + \ No newline at end of file diff --git a/templates/page.html b/templates/page.html index 58a4b70..13f69c4 100644 --- a/templates/page.html +++ b/templates/page.html @@ -63,8 +63,10 @@
  • Versions of this page
  • Edit stylesheet for this page
  • Edit title
  • +
  • What links here?
  • Edit site menu
  • Largest pages
  • +
  • Dead end pages
  • Images
  • Files
  • ::if(has_stats):: diff --git a/templates/what_links_here.html b/templates/what_links_here.html new file mode 100644 index 0000000..16ed0bf --- /dev/null +++ b/templates/what_links_here.html @@ -0,0 +1,48 @@ + + + +What links to ::title_html:: + + + + + +

    What links to ::title_html::

    + +

    +List of pages which link to +::title_html::: +

    + + + + + + + + + + + \ No newline at end of file