Links table is now kept in synch when pages are edited and restored.
authorrich <rich>
Tue, 28 Sep 2004 11:28:38 +0000 (11:28 +0000)
committerrich <rich>
Tue, 28 Sep 2004 11:28:38 +0000 (11:28 +0000)
Updated deps.
Updated manifest.

MANIFEST
cocanwiki.sql
scripts/.depend
scripts/cocanwiki_links.ml
scripts/cocanwiki_links.mli
scripts/edit.ml
scripts/rebuild_links.ml
scripts/restore.ml

index e7ec2b4..cac79ce 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -57,6 +57,8 @@ scripts/cocanwiki_emailnotify.ml
 scripts/cocanwiki_files.ml
 scripts/cocanwiki_images.ml
 scripts/cocanwiki_images.mli
+scripts/cocanwiki_links.ml
+scripts/cocanwiki_links.mli
 scripts/cocanwiki_ok.ml
 scripts/cocanwiki_server_settings.ml
 scripts/cocanwiki_strings.ml
@@ -120,6 +122,7 @@ scripts/page_email_send.ml
 scripts/page_email_unsubscribe.ml
 scripts/pagestyle.ml
 scripts/preview.ml
+scripts/rebuild_links.ml
 scripts/recent.ml
 scripts/restore.ml
 scripts/restore_form.ml
@@ -189,6 +192,9 @@ templates/page.html
 templates/page_404.html
 templates/page_email_form.html
 templates/page_email_send.txt
+templates/rebuild_links.html
+templates/rebuild_links_done.html
+templates/rebuild_links_start.html
 templates/recent.html
 templates/restore_form.html
 templates/rss.xml
index af3ac70..785ac70 100644 (file)
@@ -476,7 +476,8 @@ GRANT ALL ON TABLE mailing_lists TO "www-data";
 CREATE TABLE links (
     hostid integer NOT NULL,
     from_url text NOT NULL,
-    to_url text NOT NULL
+    to_url text NOT NULL,
+    CONSTRAINT links_not_selfref_cn CHECK ((from_url <> to_url))
 );
 
 
index f840d1e..d821e35 100644 (file)
@@ -61,9 +61,11 @@ delete_user_form.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx
 diff.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_template.cmi 
 diff.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_template.cmx 
 edit.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \
-    cocanwiki_ok.cmo cocanwiki_strings.cmo cocanwiki_template.cmi 
+    cocanwiki_links.cmi cocanwiki_ok.cmo cocanwiki_strings.cmo \
+    cocanwiki_template.cmi 
 edit.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \
-    cocanwiki_ok.cmx cocanwiki_strings.cmx cocanwiki_template.cmx 
+    cocanwiki_links.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx \
+    cocanwiki_template.cmx 
 edit_contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo 
 edit_contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx 
 edit_contact_form.cmo: cocanwiki.cmo cocanwiki_template.cmi 
@@ -159,9 +161,9 @@ rebuild_links.cmx: cocanwiki.cmx cocanwiki_links.cmx cocanwiki_template.cmx
 recent.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi 
 recent.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx 
 restore.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \
-    cocanwiki_ok.cmo 
+    cocanwiki_links.cmi cocanwiki_ok.cmo 
 restore.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \
-    cocanwiki_ok.cmx 
+    cocanwiki_links.cmx cocanwiki_ok.cmx 
 restore_form.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_ok.cmo \
     cocanwiki_template.cmi 
 restore_form.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_ok.cmx \
index 417fe19..9d856d2 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: cocanwiki_links.ml,v 1.1 2004/09/28 10:56:39 rich Exp $
+ * $Id: cocanwiki_links.ml,v 1.2 2004/09/28 11:28:39 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
@@ -58,3 +58,41 @@ let get_links_from_section dbh hostid content =
 
   (* Return the list of links. *)
   links
+
+let insert_link dbh hostid from_url to_url =
+  if from_url <> to_url then (
+    let sth = dbh#prepare_cached "select 1 from links
+                                   where hostid = ?
+                                     and from_url = ? and to_url = ?" in
+    sth#execute [`Int hostid; `String from_url; `String to_url];
+
+    let exists = try sth#fetch1int () = 1 with Not_found -> false in
+
+    if not exists then (
+      let sth =
+       dbh#prepare_cached "insert into links (hostid, from_url, to_url)
+                            values (?, ?, ?)" in
+      sth#execute [`Int hostid; `String from_url; `String to_url]
+    )
+  )
+
+let update_links_for_page dbh hostid page =
+  (* Delete entries in the old links table. *)
+  let sth = dbh#prepare_cached "delete from links
+                                 where hostid = ? and from_url = ?" in
+  sth#execute [`Int hostid; `String page];
+
+  (* Get the sections from the page. *)
+  let sth = dbh#prepare_cached "select c.content from contents c, pages p
+                                 where c.pageid = p.id
+                                   and p.hostid = ?
+                                   and p.url = ?
+                                   and p.redirect is null" in
+  sth#execute [`Int hostid; `String page];
+
+  (* Get the links from each section. *)
+  sth#iter
+    (function [`String content] ->
+       let links = get_links_from_section dbh hostid content in
+       List.iter (insert_link dbh hostid page) links
+       | _ -> assert false)
index 0970b41..b55e26c 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: cocanwiki_links.mli,v 1.1 2004/09/28 10:56:39 rich Exp $
+ * $Id: cocanwiki_links.mli,v 1.2 2004/09/28 11:28:39 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
@@ -20,3 +20,5 @@
  *)
 
 val get_links_from_section : Dbi.connection -> int -> string -> string list
+val update_links_for_page : Dbi.connection -> int -> string -> unit
+val insert_link : Dbi.connection -> int -> string -> string -> unit
index e8cc7c5..8fd59fe 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: edit.ml,v 1.13 2004/09/28 10:56:39 rich Exp $
+ * $Id: edit.ml,v 1.14 2004/09/28 11:28:39 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
@@ -450,6 +450,9 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
                                `String content])
        model.contents;
 
+      (* Keep the links table in synch. *)
+      Cocanwiki_links.update_links_for_page dbh hostid url;
+
       (* Commit changes to the database. *)
       dbh#commit ();
 
index df3a707..91d206e 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: rebuild_links.ml,v 1.1 2004/09/28 10:56:40 rich Exp $
+ * $Id: rebuild_links.ml,v 1.2 2004/09/28 11:28:39 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
@@ -63,14 +63,6 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
   q#header ();
   print_string r template_start#to_string;
 
-  let insert_link =
-    let sth =
-      dbh#prepare_cached "insert into links (hostid, from_url, to_url)
-                          values (?, ?, ?)" in
-    fun from_url to_url ->
-      sth#execute [`Int hostid; `String from_url; `String to_url]
-  in
-
   (* Process each section ... *)
   let i = ref 0 in
 
@@ -83,7 +75,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
        print_string r template#to_string;
 
        let links = get_links_from_section dbh hostid content in
-       List.iter (insert_link url) links
+       List.iter (insert_link dbh hostid url) links
 
        | _ -> assert false);
 
index 3b7bd24..4efd03d 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: restore.ml,v 1.10 2004/09/28 10:56:40 rich Exp $
+ * $Id: restore.ml,v 1.11 2004/09/28 11:28:39 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
@@ -86,6 +86,9 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
                                    where pageid = ?" in
     sth#execute [`Int pageid; `Int version];
 
+    (* Keep the links table in synch. *)
+    Cocanwiki_links.update_links_for_page dbh hostid page;
+
     dbh#commit ();
 
     (* Email notify. *)