Updated deps.
Updated manifest.
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
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
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
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))
);
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
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 \
(* 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
(* 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)
(* 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
*)
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
(* 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
`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 ();
(* 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
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
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);
(* 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
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. *)