Leveraging the links table:
authorrich <rich>
Tue, 28 Sep 2004 11:51:38 +0000 (11:51 +0000)
committerrich <rich>
Tue, 28 Sep 2004 11:51:38 +0000 (11:51 +0000)
 * '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.

MANIFEST
scripts/.depend
scripts/00-TEMPLATE.ml
scripts/Makefile
scripts/dead_ends.ml [new file with mode: 0644]
scripts/largest_pages.ml
scripts/what_links_here.ml [new file with mode: 0644]
templates/dead_ends.html [new file with mode: 0644]
templates/page.html
templates/what_links_here.html [new file with mode: 0644]

index cac79ce..8f5de7b 100644 (file)
--- 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
index d821e35..52b42f7 100644 (file)
@@ -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 
index 18d00bb..e2be28f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 3c4ca38..c4c23a5 100644 (file)
@@ -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 (file)
index 0000000..c2623a9
--- /dev/null
@@ -0,0 +1,57 @@
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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
index 7f1c53a..2b7fd72 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 (file)
index 0000000..ea9b572
--- /dev/null
@@ -0,0 +1,61 @@
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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 (file)
index 0000000..a0c7be1
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Dead end pages</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>Dead end pages</h1>
+
+<ul>
+::table(pages)::
+<li> <a href="/::page_html_tag::">::title_html::</a> </li>
+::end::
+</ul>
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;page</a> </li>
+::table(sitemenu)::<li> <a href="/::url_html_tag::">::label_html::</a> </li>
+::end::
+<li> <a href="/_sitemap">Sitemap</a> </li>
+</ul>
+</div>
+
+<div id="footer_div">
+<hr/>
+
+<ul id="footer" class="menu">
+<li class="first"> <a href="/copyright">Copyright &copy; ::year::</a> </li>
+<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
+</ul>
+</div>
+
+</body>
+</html>
\ No newline at end of file
index 58a4b70..13f69c4 100644 (file)
 <li> <a href="/::page_html_tag::/history">Versions of this page</a> </li>
 <li> <a href="/::page_html_tag::/editcss">Edit stylesheet for this page</a> </li>
 <li> <a href="/::page_html_tag::/edittitle">Edit title</a> </li>
+<li> <a href="/_bin/what_links_here.cmo?page=::page_url::">What links here?</a> </li>
 <li> <a href="/_bin/edit_sitemenu.cmo">Edit site menu</a> </li>
 <li> <a href="/_bin/largest_pages.cmo">Largest pages</a> </li>
+<li> <a href="/_bin/dead_ends.cmo">Dead end pages</a> </li>
 <li> <a href="/_images">Images</a> </li>
 <li> <a href="/_files">Files</a> </li>
 ::if(has_stats)::
diff --git a/templates/what_links_here.html b/templates/what_links_here.html
new file mode 100644 (file)
index 0000000..16ed0bf
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>What links to ::title_html::</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>What links to ::title_html::</h1>
+
+<p>
+List of pages which link to
+<a href="/::page_html_tag::">::title_html::</a>:
+</p>
+
+<ul>
+::table(pages)::
+<li> <a href="/::page_html_tag::">::title_html::</a> </li>
+::end::
+</ul>
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home&nbsp;page</a> </li>
+::table(sitemenu)::<li> <a href="/::url_html_tag::">::label_html::</a> </li>
+::end::
+<li> <a href="/_sitemap">Sitemap</a> </li>
+</ul>
+</div>
+
+<div id="footer_div">
+<hr/>
+
+<ul id="footer" class="menu">
+<li class="first"> <a href="/copyright">Copyright &copy; ::year::</a> </li>
+<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
+</ul>
+</div>
+
+</body>
+</html>
\ No newline at end of file