changeset 2329:9a71ea0c941b

Add support for PageRenamed event. Not tested yet.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Tue, 26 Jun 2007 12:43:11 +0200
parents 495b09143c10
children 38f4f0311a98
files MoinMoin/PageEditor.py MoinMoin/events/__init__.py MoinMoin/events/jabbernotify.py MoinMoin/events/notification.py
diffstat 4 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Tue Jun 26 10:46:24 2007 +0200
+++ b/MoinMoin/PageEditor.py	Tue Jun 26 12:43:11 2007 +0200
@@ -30,7 +30,7 @@
 from MoinMoin.logfile import editlog, eventlog
 from MoinMoin.util import filesys, timefuncs, web
 from MoinMoin.mail import sendmail
-from MoinMoin.events import PageDeletedEvent, send_event
+from MoinMoin.events import PageDeletedEvent, PageRenamedEvent, send_event
 import MoinMoin.events.notification as notification
 
 # used for merging
@@ -625,6 +625,9 @@
                 if index.exists():
                     index.remove_item(self.page_name, now=0)
                     index.update_page(newpagename)
+                    
+            event = PageRenamedEvent(request, newpage, comment)
+            send_event(event)
 
             return True, None
         except OSError, err:
--- a/MoinMoin/events/__init__.py	Tue Jun 26 10:46:24 2007 +0200
+++ b/MoinMoin/events/__init__.py	Tue Jun 26 12:43:11 2007 +0200
@@ -49,7 +49,15 @@
 
         
 class PageRenamedEvent(PageEvent):
-    pass
+    
+    description = u"""Page has been renamed"""
+    req_superuser = False
+    
+    def __init__(self, request, page, old_page, comment):
+        PageEvent.__init__(self, request)
+        self.page = page
+        self.old_page = old_page
+        self.comment = comment
 
 
 class PageDeletedEvent(PageEvent):
--- a/MoinMoin/events/jabbernotify.py	Tue Jun 26 10:46:24 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Tue Jun 26 12:43:11 2007 +0200
@@ -41,6 +41,8 @@
         return handle_file_attached(event)
     elif isinstance(event, ev.PageDeletedEvent):
         return handle_page_deleted(event)
+    elif isinstance(event, ev.PageRenamedEvent):
+        return handle_page_renamed(event)
     elif isinstance(event, ev.UserCreatedEvent):
         return handle_user_created(event)
     
@@ -88,7 +90,6 @@
     """Handles event sent when a file is attached to a page"""
     
     request = event.request
-    server = request.cfg.notification_server
     page = Page(request, event.pagename)
     
     subscribers = page.getSubscribers(request, return_users=1)
@@ -101,7 +102,6 @@
 def handle_page_changed(event):
     """ Handles events related to page changes """
     request = event.request
-    server = request.cfg.notification_server
     page = event.page
     
     subscribers = page.getSubscribers(request, return_users=1, trivial=event.trivial)    
@@ -114,13 +114,23 @@
     """Handles event sent when a page is deleted"""
     
     request = event.request
-    server = request.cfg.notification_server
     page = event.page
     
     subscribers = page.getSubscribers(request, return_users=1)
     _filter_subscriber_list(event, subscribers)
     return page_change("page_deleted", request, page, subscribers)
 
+def handle_page_renamed(event):
+    """Handles event sent when a page is renamed"""
+    
+    request = event.request
+    page = event.page
+    old_name = event.old_page.page_name
+    
+    subscribers = page.getSubscribers(request, return_users=1)
+    _filter_subscriber_list(event, subscribers)
+    return page_change("page_renamed", request, page, subscribers, oldname=old.page_name)
+
 
 def handle_user_created(event):
     """Handles an event sent when a new user is being created"""
--- a/MoinMoin/events/notification.py	Tue Jun 26 10:46:24 2007 +0200
+++ b/MoinMoin/events/notification.py	Tue Jun 26 12:43:11 2007 +0200
@@ -123,6 +123,17 @@
                 'pagelink': pagelink,
                 'sitename': page.cfg.sitename or request.getBaseURL(),
         }
+            
+    elif msgtype == "page_renamed":
+        messageBody = _("Dear wiki user,\n\n"
+            'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
+            "The following page has been renamed from %(oldname)s by %(editor)s:\n"
+            "%(pagelink)s\n\n", formatted=False) % {
+                'editor': page.uid_override or user.getUserIdentification(request),
+                'pagelink': pagelink,
+                'sitename': page.cfg.sitename or request.getBaseURL(),
+                'oldname': kwargs['old_name']
+        }
     else:
         raise UnknownChangeType()