From 35b2ec9fc10c423a7645e4e423c1557135a4d950 Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea@codelabs.ru>
Date: Tue, 26 Feb 2008 18:47:02 +0300
Subject: [PATCH] Implement VCS-like commit messages.

This patch enables MoinMoin to send commit mails for every change
of every Wiki page: the Wiki-wide changes subscription.  Patch is
based on the ASF's work [1]: it is sligtly modified to work for
1.6.1 and additional configuration directive, commit_mail_fancy_diff,
was added.

[1] http://moinmo.in/MoinMoinPatch/CommitMails

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
---
 MoinMoin/Page.py               |   24 ++++++++++++++++++++++++
 MoinMoin/config/multiconfig.py |    5 +++++
 wiki/config/wikiconfig.py      |   15 +++++++++++++++
 3 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/MoinMoin/Page.py b/MoinMoin/Page.py
index 667e48a..4bafa63 100644
--- a/MoinMoin/Page.py
+++ b/MoinMoin/Page.py
@@ -824,6 +824,25 @@ class Page(object):
             link += AttachFile.getIndicator(request, self.page_name)
 
         return link
+ 
+    def _addMailingListSubscriber(self, subscriber_list, request, return_users):
+        """
+        Create a "bogus" user for a change notification mailing list.
+        """
+        if not return_users:
+            subscriber_list.append(self.cfg.mail_to_address)
+        else:
+            name = self.cfg.commit_mail_to_name or ""
+            subscriber = user.User(request,
+                         name="commit_mailer", auth_username=name)
+            subscriber.email = self.cfg.commit_mail_to_address
+            subscriber.trusted = 0
+            subscriber.language = self.cfg.language_default
+            subscriber.subscribed_pages = [".*"]
+            subscriber.show_fancy_diff = self.cfg.commit_mail_fancy_diff
+            subscriber.want_trivial = 1
+            subscriber.remember_me = 0
+            subscriber_list.append(subscriber)
 
     def getSubscribers(self, request, **kw):
         """ Get all subscribers of this page.
@@ -882,6 +901,11 @@ class Page(object):
                 else:
                     subscriber_list[lang].append(subscriber.email)
 
+        # send cvs-style commit messages please
+        if not subscriber_list.has_key('en'): subscriber_list['en'] = []
+        if getattr(self.cfg, "cvs_style_commit_messages", None):
+                self._addMailingListSubscriber(subscriber_list['en'], request, return_users)
+
         return subscriber_list
 
     def parse_processing_instructions(self):
diff --git a/MoinMoin/config/multiconfig.py b/MoinMoin/config/multiconfig.py
index f0da526..5d88f4e 100644
--- a/MoinMoin/config/multiconfig.py
+++ b/MoinMoin/config/multiconfig.py
@@ -369,6 +369,11 @@ Lists: * bullets; 1., a. numbered items.
     mail_from = None # u'Juergen Wiki <noreply@jhwiki.org>'
     mail_expand_to = False # set to True if you want all recipients to be listed in To: field
  
+    cvs_style_commit_messages = 0
+    commit_mail_to_name = None
+    commit_mail_to_address = None
+    commit_mail_fancy_diff = 0
+
     mail_import_subpage_template = u"$from-$date-$subject" # used for mail import
     mail_import_pagename_search = ['subject', 'to', ] # where to look for target pagename (and in which order)
     mail_import_pagename_envelope = u"%s" # use u"+ %s/" to add "+ " and "/" automatically
diff --git a/wiki/config/wikiconfig.py b/wiki/config/wikiconfig.py
index 15c5cd8..8063ef2 100644
--- a/wiki/config/wikiconfig.py
+++ b/wiki/config/wikiconfig.py
@@ -124,6 +124,21 @@ class Config(DefaultConfig):
     # Default is to use 'mail_from' as a To: field contents.
     #mail_expand_to = False
 
+    # Send CVS-style commit messages for every change, as an anti-spam
+    # measure?  Off by default, set to 1 to enable
+    #cvs_style_commit_messages = 0
+
+    # The name to use in the To line of CVS-style commit messages,
+    # e.g. u"Jürgen Wiki" [Unicode]
+    #commit_mail_to_name = u""
+
+    # The address to send CVS-style commit messages to, e.g.
+    # "<allcommits@mywiki.org>"
+    #commit_mail_to_address = ""
+
+    # Use fancy diffs or the plain ones?
+    #commit_mail_fancy_diff = False
+
 
     # User interface ----------------------------------------------------
 
-- 
1.5.5.3

