Removed use of the email_notify table (prior to actually removing the
authorrich <rich>
Thu, 21 Oct 2004 19:54:28 +0000 (19:54 +0000)
committerrich <rich>
Thu, 21 Oct 2004 19:54:28 +0000 (19:54 +0000)
table).  Emails are now sent to all registered users for a host,
unless they opt out of receiving them.

16 files changed:
cocanwiki.sql
scripts/admin/edit_emails.ml [deleted file]
scripts/admin/edit_emails_form.ml [deleted file]
scripts/admin/host.ml
scripts/delete_file.ml
scripts/delete_image.ml
scripts/edit.ml
scripts/edit_page_css.ml
scripts/edit_page_title.ml
scripts/edit_sitemenu.ml
scripts/lib/cocanwiki_emailnotify.ml
scripts/restore.ml
scripts/upload_file.ml
scripts/upload_image.ml
templates/admin/edit_emails_form.html [deleted file]
templates/admin/host.html

index b9ab1c3..9e657ca 100644 (file)
@@ -266,7 +266,8 @@ CREATE TABLE users (
     can_manage_site boolean DEFAULT false NOT NULL,
     can_edit_global_css boolean DEFAULT false NOT NULL,
     force_password_change boolean DEFAULT false NOT NULL,
-    can_import_mail boolean DEFAULT false NOT NULL
+    can_import_mail boolean DEFAULT false NOT NULL,
+    email_notify boolean DEFAULT true NOT NULL
 );
 
 
@@ -601,7 +602,7 @@ GRANT ALL ON TABLE msg_references TO "www-data";
 
 
 --
--- TOC entry 61 (OID 536388)
+-- TOC entry 63 (OID 536388)
 -- Name: hostnames_hostid_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -609,7 +610,7 @@ CREATE UNIQUE INDEX hostnames_hostid_name_uq ON hostnames USING btree (hostid, n
 
 
 --
--- TOC entry 62 (OID 536389)
+-- TOC entry 64 (OID 536389)
 -- Name: hostnams_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -617,7 +618,7 @@ CREATE UNIQUE INDEX hostnams_name_uq ON hostnames USING btree (name);
 
 
 --
--- TOC entry 58 (OID 536419)
+-- TOC entry 60 (OID 536419)
 -- Name: pages_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -625,7 +626,7 @@ CREATE UNIQUE INDEX pages_url_uq ON pages USING btree (hostid, url);
 
 
 --
--- TOC entry 63 (OID 536924)
+-- TOC entry 65 (OID 536924)
 -- Name: email_notify_email_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -633,7 +634,7 @@ CREATE UNIQUE INDEX email_notify_email_uq ON email_notify USING btree (hostid, e
 
 
 --
--- TOC entry 64 (OID 540251)
+-- TOC entry 66 (OID 540251)
 -- Name: images_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -641,7 +642,7 @@ CREATE UNIQUE INDEX images_name_uq ON images USING btree (hostid, name);
 
 
 --
--- TOC entry 66 (OID 540252)
+-- TOC entry 68 (OID 540252)
 -- Name: files_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -649,7 +650,7 @@ CREATE UNIQUE INDEX files_name_uq ON files USING btree (hostid, name);
 
 
 --
--- TOC entry 69 (OID 540831)
+-- TOC entry 71 (OID 540831)
 -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -657,7 +658,7 @@ CREATE UNIQUE INDEX users_name_uq ON users USING btree (hostid, name);
 
 
 --
--- TOC entry 68 (OID 540946)
+-- TOC entry 70 (OID 540946)
 -- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -665,7 +666,7 @@ CREATE UNIQUE INDEX users_id_uq ON users USING btree (hostid, id);
 
 
 --
--- TOC entry 71 (OID 540970)
+-- TOC entry 73 (OID 540970)
 -- Name: sitemenu_ordering_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -673,7 +674,7 @@ CREATE UNIQUE INDEX sitemenu_ordering_uq ON sitemenu USING btree (hostid, orderi
 
 
 --
--- TOC entry 72 (OID 540971)
+-- TOC entry 74 (OID 540971)
 -- Name: sitemenu_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -681,7 +682,7 @@ CREATE UNIQUE INDEX sitemenu_url_uq ON sitemenu USING btree (hostid, url);
 
 
 --
--- TOC entry 75 (OID 542626)
+-- TOC entry 77 (OID 542626)
 -- Name: contact_emails_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -689,7 +690,7 @@ CREATE UNIQUE INDEX contact_emails_uq ON contact_emails USING btree (contactid,
 
 
 --
--- TOC entry 76 (OID 543505)
+-- TOC entry 78 (OID 543505)
 -- Name: themes_theme_css_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -697,7 +698,7 @@ CREATE UNIQUE INDEX themes_theme_css_uq ON themes USING btree (theme_css);
 
 
 --
--- TOC entry 77 (OID 543763)
+-- TOC entry 79 (OID 543763)
 -- Name: page_emails_email_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -705,7 +706,7 @@ CREATE UNIQUE INDEX page_emails_email_uq ON page_emails USING btree (hostid, url
 
 
 --
--- TOC entry 78 (OID 543795)
+-- TOC entry 80 (OID 543795)
 -- Name: mailing_lists_email_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -713,7 +714,7 @@ CREATE UNIQUE INDEX mailing_lists_email_uq ON mailing_lists USING btree (hostid,
 
 
 --
--- TOC entry 73 (OID 543880)
+-- TOC entry 75 (OID 543880)
 -- Name: contacts_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -721,7 +722,7 @@ CREATE UNIQUE INDEX contacts_name_uq ON contacts USING btree (hostid, name);
 
 
 --
--- TOC entry 79 (OID 544454)
+-- TOC entry 81 (OID 544454)
 -- Name: links_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -729,7 +730,7 @@ CREATE UNIQUE INDEX links_uq ON links USING btree (hostid, from_url, to_url);
 
 
 --
--- TOC entry 80 (OID 547951)
+-- TOC entry 82 (OID 547951)
 -- Name: templates_ext_ord_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -737,7 +738,7 @@ CREATE UNIQUE INDEX templates_ext_ord_uq ON templates USING btree (extension, or
 
 
 --
--- TOC entry 82 (OID 547952)
+-- TOC entry 84 (OID 547952)
 -- Name: templates_title_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -745,7 +746,7 @@ CREATE UNIQUE INDEX templates_title_uq ON templates USING btree (title_regexp);
 
 
 --
--- TOC entry 83 (OID 547953)
+-- TOC entry 85 (OID 547953)
 -- Name: templates_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -753,7 +754,7 @@ CREATE UNIQUE INDEX templates_url_uq ON templates USING btree (url_regexp);
 
 
 --
--- TOC entry 84 (OID 551151)
+-- TOC entry 86 (OID 551151)
 -- Name: recently_visited_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -761,7 +762,7 @@ CREATE UNIQUE INDEX recently_visited_uq ON recently_visited USING btree (userid,
 
 
 --
--- TOC entry 85 (OID 552155)
+-- TOC entry 87 (OID 552155)
 -- Name: messages_inet_message_id_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -769,6 +770,22 @@ CREATE UNIQUE INDEX messages_inet_message_id_uq ON messages USING btree (hostid,
 
 
 --
+-- TOC entry 59 (OID 552684)
+-- Name: pages_url_ix; Type: INDEX; Schema: public; Owner: rich
+--
+
+CREATE INDEX pages_url_ix ON pages USING btree (url);
+
+
+--
+-- TOC entry 58 (OID 552685)
+-- Name: pages_redirect_ix; Type: INDEX; Schema: public; Owner: rich
+--
+
+CREATE INDEX pages_redirect_ix ON pages USING btree (redirect);
+
+
+--
 -- TOC entry 57 (OID 536012)
 -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
@@ -778,7 +795,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 59 (OID 536027)
+-- TOC entry 61 (OID 536027)
 -- Name: contents_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -787,7 +804,7 @@ ALTER TABLE ONLY contents
 
 
 --
--- TOC entry 60 (OID 536377)
+-- TOC entry 62 (OID 536377)
 -- Name: hosts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -796,7 +813,7 @@ ALTER TABLE ONLY hosts
 
 
 --
--- TOC entry 65 (OID 537158)
+-- TOC entry 67 (OID 537158)
 -- Name: images_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -805,7 +822,7 @@ ALTER TABLE ONLY images
 
 
 --
--- TOC entry 67 (OID 537173)
+-- TOC entry 69 (OID 537173)
 -- Name: files_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -814,7 +831,7 @@ ALTER TABLE ONLY files
 
 
 --
--- TOC entry 70 (OID 540825)
+-- TOC entry 72 (OID 540825)
 -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -823,7 +840,7 @@ ALTER TABLE ONLY users
 
 
 --
--- TOC entry 74 (OID 542611)
+-- TOC entry 76 (OID 542611)
 -- Name: contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -832,7 +849,7 @@ ALTER TABLE ONLY contacts
 
 
 --
--- TOC entry 81 (OID 547945)
+-- TOC entry 83 (OID 547945)
 -- Name: templates_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -841,7 +858,7 @@ ALTER TABLE ONLY templates
 
 
 --
--- TOC entry 86 (OID 551681)
+-- TOC entry 88 (OID 551681)
 -- Name: messages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -850,7 +867,7 @@ ALTER TABLE ONLY messages
 
 
 --
--- TOC entry 91 (OID 536029)
+-- TOC entry 93 (OID 536029)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -859,7 +876,7 @@ ALTER TABLE ONLY contents
 
 
 --
--- TOC entry 94 (OID 536384)
+-- TOC entry 96 (OID 536384)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -868,7 +885,7 @@ ALTER TABLE ONLY hostnames
 
 
 --
--- TOC entry 92 (OID 536394)
+-- TOC entry 94 (OID 536394)
 -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -877,7 +894,7 @@ ALTER TABLE ONLY hosts
 
 
 --
--- TOC entry 87 (OID 536404)
+-- TOC entry 89 (OID 536404)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -886,7 +903,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 95 (OID 536920)
+-- TOC entry 97 (OID 536920)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -895,7 +912,7 @@ ALTER TABLE ONLY email_notify
 
 
 --
--- TOC entry 96 (OID 537160)
+-- TOC entry 98 (OID 537160)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -904,7 +921,7 @@ ALTER TABLE ONLY images
 
 
 --
--- TOC entry 97 (OID 537175)
+-- TOC entry 99 (OID 537175)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -913,7 +930,7 @@ ALTER TABLE ONLY files
 
 
 --
--- TOC entry 88 (OID 539155)
+-- TOC entry 90 (OID 539155)
 -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -922,7 +939,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 98 (OID 540827)
+-- TOC entry 100 (OID 540827)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -931,7 +948,7 @@ ALTER TABLE ONLY users
 
 
 --
--- TOC entry 99 (OID 540837)
+-- TOC entry 101 (OID 540837)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -940,7 +957,7 @@ ALTER TABLE ONLY usercookies
 
 
 --
--- TOC entry 89 (OID 540942)
+-- TOC entry 91 (OID 540942)
 -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -949,7 +966,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 90 (OID 540947)
+-- TOC entry 92 (OID 540947)
 -- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -958,7 +975,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 100 (OID 540966)
+-- TOC entry 102 (OID 540966)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -967,7 +984,7 @@ ALTER TABLE ONLY sitemenu
 
 
 --
--- TOC entry 101 (OID 540972)
+-- TOC entry 103 (OID 540972)
 -- Name: sitemenu_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -976,7 +993,7 @@ ALTER TABLE ONLY sitemenu
 
 
 --
--- TOC entry 102 (OID 542613)
+-- TOC entry 104 (OID 542613)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -985,7 +1002,7 @@ ALTER TABLE ONLY contacts
 
 
 --
--- TOC entry 103 (OID 542622)
+-- TOC entry 105 (OID 542622)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -994,7 +1011,7 @@ ALTER TABLE ONLY contact_emails
 
 
 --
--- TOC entry 93 (OID 543506)
+-- TOC entry 95 (OID 543506)
 -- Name: hosts_theme_css_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1003,7 +1020,7 @@ ALTER TABLE ONLY hosts
 
 
 --
--- TOC entry 104 (OID 543759)
+-- TOC entry 106 (OID 543759)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1012,7 +1029,7 @@ ALTER TABLE ONLY page_emails
 
 
 --
--- TOC entry 105 (OID 543764)
+-- TOC entry 107 (OID 543764)
 -- Name: page_emails_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1021,7 +1038,7 @@ ALTER TABLE ONLY page_emails
 
 
 --
--- TOC entry 106 (OID 543791)
+-- TOC entry 108 (OID 543791)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1030,7 +1047,7 @@ ALTER TABLE ONLY mailing_lists
 
 
 --
--- TOC entry 107 (OID 544450)
+-- TOC entry 109 (OID 544450)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1039,7 +1056,7 @@ ALTER TABLE ONLY links
 
 
 --
--- TOC entry 108 (OID 544455)
+-- TOC entry 110 (OID 544455)
 -- Name: links_from_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1048,7 +1065,7 @@ ALTER TABLE ONLY links
 
 
 --
--- TOC entry 109 (OID 551129)
+-- TOC entry 111 (OID 551129)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1057,7 +1074,7 @@ ALTER TABLE ONLY recently_visited
 
 
 --
--- TOC entry 110 (OID 551133)
+-- TOC entry 112 (OID 551133)
 -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1066,7 +1083,7 @@ ALTER TABLE ONLY recently_visited
 
 
 --
--- TOC entry 111 (OID 551137)
+-- TOC entry 113 (OID 551137)
 -- Name: recently_visited_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1075,7 +1092,7 @@ ALTER TABLE ONLY recently_visited
 
 
 --
--- TOC entry 112 (OID 551141)
+-- TOC entry 114 (OID 551141)
 -- Name: recently_visited_userid_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1084,7 +1101,7 @@ ALTER TABLE ONLY recently_visited
 
 
 --
--- TOC entry 114 (OID 551690)
+-- TOC entry 116 (OID 551690)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1093,7 +1110,7 @@ ALTER TABLE ONLY msg_references
 
 
 --
--- TOC entry 113 (OID 551694)
+-- TOC entry 115 (OID 551694)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -1162,6 +1179,7 @@ SET search_path = public, pg_catalog;
 
 COPY themes (theme_css, name, description) FROM stdin;
 /_css/easyweb.css      Merjis Easy Web Marketing       This is the easy web marketing stylesheet developed by Merjis Ltd.  Please see http://www.merjis.com/
+/_css/basic.css        Basic styles only       Only the most essential styles.  This is a good starting point if you want to completely restyle pages using site-specific CSS.
 \.
 
 
diff --git a/scripts/admin/edit_emails.ml b/scripts/admin/edit_emails.ml
deleted file mode 100644 (file)
index a1d0cc6..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-(* COCANWIKI - a wiki written in Objective CAML.
- * Written by Richard W.M. Jones <rich@merjis.com>.
- * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_emails.ml,v 1.6 2004/09/23 11:56:47 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_ok
-open Cocanwiki_strings
-
-let split_re = Pcre.regexp "[\\r\\n,;]+"
-let email_re = Pcre.regexp "(.*)<(.*)>"
-
-let run r (q : cgi) (dbh : Dbi.connection) _ host' _ =
-  let hostid = int_of_string (q#param "hostid") in
-
-  if q#param_true "cancel" then (
-    let { hostname = hostname } = host' in
-    q#redirect ("http://" ^ hostname ^ "/_bin/admin/host.cmo?hostid=" ^
-               string_of_int hostid);
-    return ()
-  );
-
-  let emails = try q#param "emails" with Not_found -> "" in
-
-  (* It's very hard to verify email addresses.  Thus this script
-   * should not be exposed to untrusted users.
-   *)
-  let check_email str =
-    let name, email =
-      try
-       let subs = Pcre.exec ~rex:email_re str in
-       Pcre.get_substring subs 1, Pcre.get_substring subs 2
-      with
-         Not_found ->
-           "", str in
-
-    (* Trim whitespace. *)
-    trim name, trim email
-  in
-
-  let emails = Pcre.split ~rex:split_re emails in
-  let emails = List.map check_email emails in
-  let emails = List.filter ((<>) ("","")) emails in
-
-  (* Update the database. *)
-  let sth = dbh#prepare_cached
-             "delete from email_notify where hostid = ?" in
-  sth#execute [`Int hostid];
-  let sth = dbh#prepare_cached "insert into email_notify (hostid, email, name)
-                                values (?, ?, ?)" in
-  List.iter (fun (name, email) ->
-              if name = "" then
-                sth#execute [`Int hostid; `String email; `Null]
-              else
-                sth#execute [`Int hostid; `String email; `String name])
-    emails;
-
-  (* Commit to the database. *)
-  dbh#commit ();
-
-  (* Print confirmation page. *)
-  let buttons = [
-    { StdPages.label = "OK";
-      StdPages.link = "/_bin/admin/host.cmo";
-      StdPages.method_ = None;
-      StdPages.params = [ "hostid", string_of_int hostid ] }
-  ] in
-
-  ok ~title:"Saved" ~buttons
-    q "Email notifications updated."
-
-let () =
-  register_script run
diff --git a/scripts/admin/edit_emails_form.ml b/scripts/admin/edit_emails_form.ml
deleted file mode 100644 (file)
index 5dabb2e..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-(* COCANWIKI - a wiki written in Objective CAML.
- * Written by Richard W.M. Jones <rich@merjis.com>.
- * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_emails_form.ml,v 1.5 2004/09/09 12:21:22 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 template = _get_template "admin/edit_emails_form.html"
-
-let run r (q : cgi) (dbh : Dbi.connection) _ _ _ =
-  let hostid = int_of_string (q#param "hostid") in
-
-  template#set "id" (string_of_int hostid);
-
-  let sth = dbh#prepare_cached
-             "select canonical_hostname from hosts where id = ?" in
-  sth#execute [`Int hostid];
-
-  let canonical_hostname = sth#fetch1string () in
-  template#set "canonical_hostname" canonical_hostname;
-
-  let sth = dbh#prepare_cached
-             "select email, name from email_notify where hostid = ?" in
-  sth#execute [`Int hostid];
-
-  let emails = sth#map (function
-                           [`String email; `Null] ->
-                             email
-                         | [`String email; `String name] ->
-                             sprintf "%s <%s>" name email
-                         | _ -> assert false) in
-
-  template#set "emails" (String.concat "\n" emails);
-
-  q#template template
-
-let () =
-  register_script run
index 732e5d0..4cec09c 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: host.ml,v 1.6 2004/09/09 12:21:22 rich Exp $
+ * $Id: host.ml,v 1.7 2004/10/21 19:54:29 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
@@ -92,21 +92,6 @@ let run r (q : cgi) (dbh : Dbi.connection) _ _ _ =
                         | _ -> assert false) in
   template#table "hostnames" table;
 
-  (* Pull out any email notifications. *)
-  let sth = dbh#prepare_cached "select email, name from email_notify
-                                 where hostid = ?" in
-  sth#execute [`Int hostid];
-
-  let table = sth#map (function
-                          [`String email; `Null] ->
-                            [ "email", Template.VarString email;
-                              "name", Template.VarString "" ]
-                        | [ `String email; `String name] ->
-                            [ "email", Template.VarString email;
-                              "name", Template.VarString name ]
-                        | _ -> assert false) in
-  template#table "emails" table;
-
   q#template template
 
 let () =
index fbfacff..9c1ac60 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: delete_file.ml,v 1.6 2004/09/09 12:21:22 rich Exp $
+ * $Id: delete_file.ml,v 1.7 2004/10/21 19:54:29 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
@@ -28,7 +28,7 @@ open Cocanwiki
 open Cocanwiki_ok
 open Cocanwiki_emailnotify
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } =
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } user=
   let id = int_of_string (q#param "id") in
 
   if q#param_true "yes" then (
@@ -46,7 +46,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
     let body = fun () ->
       "Page: http://" ^ hostname ^ "/_files?deleted=1" in
 
-    email_notify ~body ~subject dbh hostid;
+    email_notify ~body ~subject ~user dbh hostid;
 
     (* Done. *)
     let buttons = [ ok_button "/_files" ] in
index dcb4522..5b64357 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: delete_image.ml,v 1.6 2004/09/09 12:21:22 rich Exp $
+ * $Id: delete_image.ml,v 1.7 2004/10/21 19:54:29 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
@@ -28,7 +28,7 @@ open Cocanwiki
 open Cocanwiki_ok
 open Cocanwiki_emailnotify
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } =
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } user=
   let id = int_of_string (q#param "id") in
 
   if q#param_true "yes" then (
@@ -46,7 +46,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
     let body = fun () ->
       "Page: http://" ^ hostname ^ "/_images?deleted=1" in
 
-    email_notify ~body ~subject dbh hostid;
+    email_notify ~body ~subject ~user dbh hostid;
     (* Done. *)
     let buttons = [ ok_button "/_images" ] in
     ok ~title:"Image deleted" ~buttons
index 2e4a6cd..af885a1 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.20 2004/10/11 14:13:04 rich Exp $
+ * $Id: edit.ml,v 1.21 2004/10/21 19:54:29 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
@@ -431,7 +431,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
        "Page: http://" ^ hostname ^ "/" ^ url ^ "\n\n" ^
        diff in
 
-      email_notify ~body ~subject dbh hostid;
+      email_notify ~body ~subject ~user dbh hostid;
 
       (* Redirect back to the URL. *)
       q#redirect ("http://" ^ hostname ^ "/" ^ url);
index b9f1ecd..22cab69 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_page_css.ml,v 1.12 2004/10/10 16:14:43 rich Exp $
+ * $Id: edit_page_css.ml,v 1.13 2004/10/21 19:54:29 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
@@ -99,7 +99,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
     "Page: http://" ^ hostname ^ "/" ^ page ^ "\n\n" ^
     diff in
 
-  email_notify ~subject ~body dbh hostid;
+  email_notify ~subject ~body ~user dbh hostid;
 
   let buttons = [ ok_button ("/" ^ page);
                  { StdPages.label = "Edit stylesheet again";
index a410d5c..bc51f67 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_page_title.ml,v 1.4 2004/10/10 16:14:43 rich Exp $
+ * $Id: edit_page_title.ml,v 1.5 2004/10/21 19:54:29 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
@@ -130,7 +130,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
     "Old title: " ^ old_title ^ "\n" ^
     "New title: " ^ new_title ^ "\n" in
 
-  email_notify ~subject ~body dbh hostid;
+  email_notify ~subject ~body ~user dbh hostid;
 
   let buttons = [ ok_button ("/" ^ page) ] in
   ok ~title:"Title changed" ~buttons
index 38cba43..975ee71 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_sitemenu.ml,v 1.5 2004/09/23 11:56:47 rich Exp $
+ * $Id: edit_sitemenu.ml,v 1.6 2004/10/21 19:54:29 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
@@ -38,7 +38,7 @@ open Cocanwiki_strings
  *)
 type model_t = (string * string) list  (* label, url *)
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } =
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } user=
   let template = get_template dbh hostid "edit_sitemenu.html" in
 
   (* Workaround bugs in IE, specifically lack of support for <button>
@@ -273,7 +273,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
 
       let body = fun () -> "Site: http://" ^ hostname ^ "/\n\n" in
 
-      email_notify ~body ~subject dbh hostid;
+      email_notify ~body ~subject ~user dbh hostid;
 
       let buttons = [ ok_button "/" ] in
       ok ~title:"Saved" ~buttons
index ef844a8..648a746 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_emailnotify.ml,v 1.1 2004/10/21 11:42:05 rich Exp $
+ * $Id: cocanwiki_emailnotify.ml,v 1.2 2004/10/21 19:54:29 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
@@ -24,23 +24,53 @@ open Registry
 open Cgi
 open Printf
 
+open Cocanwiki
+
 (* This is where we coordinate email notification from various
  * scripts which create or update the wiki.
  *)
-let email_notify ~subject ~body (dbh : Dbi.connection) hostid =
-  (* Is anyone listed for email notification at this host? *)
-  let sth = dbh#prepare_cached "select email, name from email_notify
-                                where hostid = ?" in
-  sth#execute [`Int hostid];
+let email_notify ~subject ~body ?user (dbh : Dbi.connection) hostid =
+  (* Get own userid, if we have it.  Don't want to send email
+   * notification back to the person who changed the page.  If
+   * we don't have a userid, set it to 0, because no real user can
+   * have userid = 0.
+   *)
+  let own_userid =
+    match user with
+      | None
+      | Some Anonymous -> 0
+      | Some (User (userid, _, _)) -> userid in
+
+  (* Send a change email to everyone who hasn't opted out using
+   * their preferences.  This behaviour replaces the old
+   * 'email_notify' table.
+   *)
+  let sth = dbh#prepare_cached "select email, name from users
+                                 where hostid = ? and id <> ? and email_notify
+                                   and email is not null" in
+  sth#execute [`Int hostid; `Int own_userid];
 
   let to_addr = sth#map (function
                           | [`String email; `String name] ->
-                              name ^ " <" ^ email ^ ">"
-                          | [`String email; `Null] ->
-                              email
+                              "\"" ^ name ^ "\" <" ^ email ^ ">"
                           | _ -> assert false) in
 
   if to_addr <> [] then (
+    (* Get the from address of the user, if available. *)
+    let from =
+      match user with
+       | None
+       | Some Anonymous -> None
+       | Some (User (userid, _, _)) ->
+           let sth = dbh#prepare_cached "select email from users
+                                           where hostid = ? and id = ?" in
+           sth#execute [`Int hostid; `Int userid];
+
+           match sth#fetch1 () with
+             | [ `Null ] -> None
+             | [ `String email ] -> Some email
+             | _ -> assert false in
+
     (* Prepare the body of the message.  The assumption is that
      * this takes time and database access, so we defer the creation
      * of the body until we know that someone needs to be notified.
@@ -50,5 +80,5 @@ let email_notify ~subject ~body (dbh : Dbi.connection) hostid =
     let subject = "Site notice: " ^ subject in
 
     (* Send the email. *)
-    Sendmail.send_mail ~subject ~to_addr ~body ()
+    Sendmail.send_mail ~subject ~to_addr ~body ?from ()
   )
index 33f0774..97fae79 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.13 2004/10/10 16:14:43 rich Exp $
+ * $Id: restore.ml,v 1.14 2004/10/21 19:54:29 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
@@ -100,7 +100,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
       "Page: http://" ^ hostname ^ "/" ^ page ^ "\n\n" ^
       diff in
 
-    email_notify ~body ~subject dbh hostid;
+    email_notify ~body ~subject ~user dbh hostid;
 
     (* Done. *)
     let buttons = [ ok_button ("/" ^ page) ] in
index a6ed439..543cd66 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: upload_file.ml,v 1.7 2004/09/23 11:56:47 rich Exp $
+ * $Id: upload_file.ml,v 1.8 2004/10/21 19:54:29 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
@@ -38,7 +38,7 @@ let is_whitespace str = Pcre.pmatch ~rex:is_ws_re str
 (* Valid file names. *)
 let file_ok_re = Pcre.regexp "^[a-z0-9][-._a-z0-9]*$"
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } =
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } user=
   let name = q#param "name" in
   let title = q#param "title" in
 
@@ -81,7 +81,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
   let body = fun () ->
     "Page: http://" ^ hostname ^ "/_files" in
 
-  email_notify ~body ~subject dbh hostid;
+  email_notify ~body ~subject ~user dbh hostid;
 
   let buttons = [ ok_button "/_files" ] in
   ok ~title:"File uploaded" ~buttons
index c6d11e2..5b74bb9 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: upload_image.ml,v 1.7 2004/09/23 11:56:47 rich Exp $
+ * $Id: upload_image.ml,v 1.8 2004/10/21 19:54:29 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,7 +37,7 @@ let is_whitespace str = Pcre.pmatch ~rex:is_ws_re str
 (* Valid image names. *)
 let image_ok_re = Pcre.regexp "^[a-z0-9][_a-z0-9]*\\.(jpg|jpeg|gif|ico|png)$"
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } =
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } user=
   let name = q#param "name" in
   let alt = q#param "alt" in
   let title = q#param "title" in
@@ -130,7 +130,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
   let body = fun () ->
     "Page: http://" ^ hostname ^ "/_images" in
 
-  email_notify ~body ~subject dbh hostid;
+  email_notify ~body ~subject ~user dbh hostid;
 
   let buttons = [ ok_button "/_images" ] in
   ok ~title:"Image uploaded" ~buttons
diff --git a/templates/admin/edit_emails_form.html b/templates/admin/edit_emails_form.html
deleted file mode 100644 (file)
index 6c5107f..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!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>Edit email change notification for ::canonical_hostname_html::</title>
-<meta name="author" content="http://www.merjis.com/" />
-<link rel="stylesheet" href="/_css/standard.css" type="text/css" title="Standard"/>
-<link rel="stylesheet" href="/_css/admin.css" type="text/css" title="Standard"/>
-</head><body>
-
-<h1>Edit email change notification for ::canonical_hostname_html::</h1>
-
-<form action="edit_emails.cmo" method="post">
-<input type="hidden" name="hostid" value="::id::"/>
-<table id="host">
-<tr>
-<th> Email addresses: </th>
-<td> <textarea name="emails" rows="10" cols="40">::emails_html_textarea::</textarea> </td>
-</tr>
-<tr>
-<td></td>
-<td>
-<input type="submit" name="save" value="Save"/>
-<input type="submit" name="cancel" value="Cancel"/>
-</td>
-</tr>
-</table>
-</form>
-
-<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>
-
-<ul id="bottommenu" 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>
-
-<hr/>
-
-<ul id="footer" class="menu">
-<li> <a href="/copyright">Copyright &copy; 2004</a> </li>
-</ul>
-
-</body>
-</html>
\ No newline at end of file
index 83a353b..d9e5646 100644 (file)
   <td> ::total_count_html:: </td>
 </tr>
 <tr>
-  <th> Email notification: </th>
-  <td>
-    ::table(emails):: ::name_html:: &lt;::email_html::&gt; <br/> ::end::
-    <a href="/_bin/admin/edit_emails_form.cmo?hostid=::id::">Edit
-      email notification ...</a>
-  </td>
-</tr>
-<tr>
   <th> Global stylesheet: </th>
   <td>
     ::if(has_css)::This wiki has a global stylesheet.::end::