diff -Naur trac-0.9b2-orig/templates/wiki_notify_email.cs trac-0.9b2/templates/wiki_notify_email.cs
--- trac-0.9b2-orig/templates/wiki_notify_email.cs Thu Jan 1 01:00:00 1970
+++ trac-0.9b2/templates/wiki_notify_email.cs Wed Oct 5 13:30:14 2005
@@ -0,0 +1,11 @@
+The wiki page has been by .
+
+Comment on change was:
+
+
+To see the page, follow this link:
+
+
+--
+ The project is homed at:
+ To stop receiving these notices, log in and change your settings at
diff -Naur trac-0.9b2-orig/trac/Notify.py trac-0.9b2/trac/Notify.py
--- trac-0.9b2-orig/trac/Notify.py Sun Sep 25 16:48:00 2005
+++ trac-0.9b2/trac/Notify.py Wed Oct 5 13:39:47 2005
@@ -19,6 +19,7 @@
from trac.util import CRLF, TRUE, FALSE, enum, wrap
from trac.web.clearsilver import HDFWrapper
from trac.web.main import populate_hdf
+from trac.perm import PermissionCache
import md5
import time
@@ -325,3 +326,72 @@
hdrs['In-Reply-To'] = self.get_message_id(rcpt)
hdrs['References'] = self.get_message_id(rcpt)
NotifyEmail.send(self, rcpt, hdrs)
+
+
+class WikiNotifyEmail(NotifyEmail):
+ """Notification of wiki changes."""
+
+ template_name = "wiki_notify_email.cs"
+ modtime = 0
+ from_email = 'trac+wiki@localhost'
+ COLS = 75
+
+ def __init__(self, env):
+ NotifyEmail.__init__(self, env)
+
+ def notify(self, wikipage, newpage=False, author="anonymous", comment=""):
+ self.wikipage = wikipage
+ self.newpage = newpage
+ self.hdf['email.wikipage'] = wikipage
+ self.hdf['email.action'] = "changed"
+ if newpage:
+ self.hdf['email.action'] = "created"
+ self.hdf['email.urlpage'] = self.env.abs_href.wiki(wikipage)
+ self.hdf['email.author'] = author
+ self.hdf['email.comment'] = comment
+ self.hdf['email.projname'] = self.config.get('project', 'name')
+ self.hdf['email.projurl'] = self.env.abs_href()
+ self.hdf['email.settings'] = self.env.abs_href.settings()
+ NotifyEmail.notify(self, wikipage, self.format_subj())
+
+ def get_recipients(self, ignored):
+ recipients = []
+ cursor = self.db.cursor()
+
+ # notify authenticated users having notify rights
+ cursor.execute("SELECT sid,var_value FROM session WHERE var_name='email' AND sid in "
+ "( SELECT sid FROM session WHERE authenticated=1 AND var_name='wiki_notify' and var_value='yes' )");
+ rows = cursor.fetchall()
+ for sid,email in rows:
+ p = PermissionCache(self.env, sid)
+ if p.has_permission('WIKI_NOTIFY') and email and email.find("@")>0:
+ recipients.append(email)
+
+ # notify anonymous users, if "anonymous" has permissions
+ cursor.execute("SELECT sid,var_value FROM session WHERE var_name='email' AND sid in "
+ "( SELECT sid FROM session WHERE authenticated=0 AND var_name='wiki_notify' and var_value='yes' )");
+ rows = cursor.fetchall()
+ p = PermissionCache(self.env, "anonymous")
+ if p.has_permission('WIKI_NOTIFY'):
+ for sid,email in rows:
+ if email and email.find("@")>0:
+ recipients.append(email)
+
+ # Add smtp_always_cc address
+ acc = self.config.get('notification', 'smtp_always_cc')
+ if acc:
+ recipients += acc.replace(',', ' ').split()
+
+ # Remove duplicates
+ result = []
+ for e in recipients:
+ if e not in result:
+ result.append(e)
+
+ print repr(result)
+ return result
+
+ def format_subj(self):
+ projname = self.config.get('project', 'name')
+ return '[%s] changed page %s' % (projname, self.wikipage)
+
diff -Naur trac-0.9b2-orig/trac/Settings.py trac-0.9b2/trac/Settings.py
--- trac-0.9b2-orig/trac/Settings.py Sun Sep 25 16:48:00 2005
+++ trac-0.9b2/trac/Settings.py Wed Oct 5 13:39:47 2005
@@ -25,7 +25,7 @@
implements(INavigationContributor, IRequestHandler)
- _form_fields = ['newsid','name', 'email']
+ _form_fields = ['newsid','name', 'email', 'wiki_notify']
# INavigationContributor methods
@@ -41,6 +41,9 @@
def match_request(self, req):
return req.path_info == '/settings'
+ def can_set_wiki_notifies(self, req):
+ return req.perm.has_permission('WIKI_NOTIFY') or req.perm.has_permission('TRAC_ADMIN')
+
def process_request(self, req):
action = req.args.get('action')
@@ -52,6 +55,7 @@
req.hdf['title'] = 'Settings'
req.hdf['settings'] = req.session
+ req.hdf['has_wiki_notify_permission'] = self.can_set_wiki_notifies(req)
if req.authname == 'anonymous':
req.hdf['settings.session_id'] = req.session.sid
@@ -61,13 +65,20 @@
def _do_save(self, req):
for field in self._form_fields:
+ if not self.can_set_wiki_notifies(req) and field == 'wiki_notify':
+ continue
val = req.args.get(field)
if val:
if field == 'newsid' and val:
req.session.change_sid(val)
else:
req.session[field] = val
- req.redirect(self.env.href.settings())
+ if self.can_set_wiki_notifies(req):
+ if req.args.get('wiki_notify'):
+ req.session['wiki_notify'] = req.args.get('wiki_notify')
+ else:
+ req.session['wiki_notify'] = 'no'
+ req.redirect(self.env.href.settings())
def _do_load(self, req):
if req.authname == 'anonymous':
diff -Naur trac-0.9b2-orig/trac/wiki/web_ui.py trac-0.9b2/trac/wiki/web_ui.py
--- trac-0.9b2-orig/trac/wiki/web_ui.py Sun Sep 25 16:47:59 2005
+++ trac-0.9b2/trac/wiki/web_ui.py Wed Oct 5 13:39:47 2005
@@ -32,6 +32,7 @@
from trac.web import IRequestHandler
from trac.wiki.model import WikiPage
from trac.wiki.formatter import wiki_to_html, wiki_to_oneliner
+from trac.Notify import WikiNotifyEmail
class WikiModule(Component):
@@ -55,7 +56,7 @@
# IPermissionRequestor methods
def get_permission_actions(self):
- actions = ['WIKI_CREATE', 'WIKI_DELETE', 'WIKI_MODIFY', 'WIKI_VIEW']
+ actions = ['WIKI_CREATE', 'WIKI_DELETE', 'WIKI_MODIFY', 'WIKI_VIEW', 'WIKI_NOTIFY']
return actions + [('WIKI_ADMIN', actions)]
# IRequestHandler methods
@@ -176,6 +177,8 @@
else:
req.perm.assert_permission('WIKI_MODIFY')
+ newpage = page.exists == False
+
page.text = req.args.get('text')
if req.perm.has_permission('WIKI_ADMIN'):
# Modify the read-only flag if it has been changed and the user is
@@ -184,6 +187,15 @@
page.save(req.args.get('author'), req.args.get('comment'),
req.remote_addr)
+
+ # Notify
+ try:
+ wn = WikiNotifyEmail(self.env)
+ wn.notify(page.name, newpage=newpage, author=req.args.get('author'), comment=req.args.get('comment'))
+ except Exception, e:
+ self.log.exception("Failure sending notification on editing of "
+ "wiki page #%s: %s" % (page.name, e))
+
req.redirect(self.env.href.wiki(page.name))
def _render_confirm(self, req, db, page):
diff -Naur trac-0.9b2-orig/wiki-default/TracNotification trac-0.9b2/wiki-default/TracNotification
--- trac-0.9b2-orig/wiki-default/TracNotification Sun Sep 25 16:47:56 2005
+++ trac-0.9b2/wiki-default/TracNotification Wed Oct 5 13:41:40 2005
@@ -1,17 +1,24 @@
= Email Notification of Ticket Changes =
[[TracGuideToc]]
-Trac supports basic notification for ticket changes using email.
+Trac supports basic notification for ticket and wiki changes using email.
-Email notification is useful to keep users up-to-date on tickets/issues of interest, and also provides a convenient way to post ticket changes to a dedicated mailing list. '''Note:''' As an example, this is how the [http://lists.edgewall.com/archive/trac-tickets/ Trac-tickets] mailing list works.
+Email notification is useful to keep users up-to-date on tickets/issues of interest, published data, and also provides a convenient way to post ticket changes to a dedicated mailing list. '''Note:''' As an example, this is how the [http://lists.edgewall.com/archive/trac-tickets/ Trac-tickets] mailing list works.
Disabled by default, notification can be activated and configured in [wiki:TracIni trac.ini].
-== Receiving Notification ==
+== Receiving Ticket Notification ==
When reporting a new ticket or adding a comment, enter a valid email address in the ''reporter'', ''editor'' or ''cc'' field. Trac will automatically send you an email when changes are made to the ticket.
This is useful to keep up-to-date on an issue or enhancement request that interests you.
+== Receiving Wiki Notification ==
+When a page is edited, Trac can notify the change via email to every user with WIKI_NOTIFY permission which has enabled the "''Allow me to receive edit notifies via email''" checkbox in the ''Settings'' form.
+
+This works for anonymous users too. Just give the "anonymous" user WIKI_NOTIFY permission.
+
+This is useful to to broadcast a change in the wiki contents to all interested users at once.
+
== Configuring SMTP Notification ==
=== Config Options ===
@@ -65,4 +72,4 @@
My Project
}}}
----
-See also: TracTickets, TracIni, TracGuide
\ No newline at end of file
+See also: TracTickets, TracIni, TracGuide
diff -Naur trac-0.9b2-orig/wiki-default/TracPermissions trac-0.9b2/wiki-default/TracPermissions
--- trac-0.9b2-orig/wiki-default/TracPermissions Sun Sep 25 16:47:56 2005
+++ trac-0.9b2/wiki-default/TracPermissions Wed Oct 5 13:41:40 2005
@@ -21,7 +21,7 @@
* {{{BROWSER_VIEW}}}
* {{{TICKET_VIEW, TICKET_CREATE, TICKET_APPEND, TICKET_CHGPROP, TICKET_MODIFY, TICKET_ADMIN}}}
* {{{REPORT_VIEW, REPORT_CREATE, REPORT_MODIFY, REPORT_DELETE, REPORT_ADMIN, REPORT_SQL_VIEW}}}
- * {{{WIKI_VIEW, WIKI_CREATE, WIKI_MODIFY, WIKI_DELETE, WIKI_ADMIN}}}
+ * {{{WIKI_VIEW, WIKI_CREATE, WIKI_MODIFY, WIKI_DELETE, WIKI_ADMIN, WIKI_NOTIFY}}}
* {{{MILESTONE_VIEW, MILESTONE_CREATE, MILESTONE_MODIFY, MILESTONE_DELETE}}}
* {{{ROADMAP_VIEW, ROADMAP_ADMIN}}}
* {{{TIMELINE_VIEW}}}
@@ -68,4 +68,4 @@
In the same way, privileges granted to the special user ''authenticated'' will apply to any authenticated (logged in) user.
----
-See also: TracAdmin, TracGuide
\ No newline at end of file
+See also: TracAdmin, TracGuide