Commits

Olemis Lang committed e944ce9

Trac #11148 : Initial compatibility with wiki listeners

  • Participants
  • Parent commits 31c7796
  • Branches trac_t11148

Comments (0)

Files changed (2)

 t11148/t11148_r11784_IEntityListener_compat_attachment.diff
 t11148/t11148_r11784_IEntityListener_compat_ticket.diff
 t11148/t11148_r11784_IEntityListener_compat_versioncontrol.diff
+t11148/t11148_r11784_IEntityListener_compat_wiki.diff
 #t11148/t11148_r11767_IResourceChangeListener.diff

File t11148/t11148_r11784_IEntityListener_compat_wiki.diff

+# HG changeset patch
+# Parent e4ab81782045017e600aa19b5323665f9f3e9524
+Trac #11148 : 'IWikiChangeListener' notifications powered by 'ListenerNotifier.notify' [ok]
+
+diff --git a/trac/wiki/model.py b/trac/wiki/model.py
+--- a/trac/wiki/model.py
++++ b/trac/wiki/model.py
+@@ -21,10 +21,11 @@
+ from datetime import datetime
+ 
+ from trac.core import *
++from trac.core import ListenerNotifier
+ from trac.resource import Resource
+ from trac.util.datefmt import from_utimestamp, to_utimestamp, utc
+ from trac.util.translation import _
+-from trac.wiki.api import WikiSystem, validate_page_name
++from trac.wiki.api import WikiSystem, validate_page_name, IWikiChangeListener
+ 
+ 
+ class WikiPage(object):
+@@ -110,12 +111,18 @@
+ 
+         # Let change listeners know about the deletion
+         if not self.exists:
+-            for listener in WikiSystem(self.env).change_listeners:
+-                listener.wiki_page_deleted(self)
++#            for listener in WikiSystem(self.env).change_listeners:
++#                listener.wiki_page_deleted(self)
++            ListenerNotifier(self.env).notify(
++                             IWikiChangeListener.wiki_page_deleted,
++                             entity=self)
+         else:
+-            for listener in WikiSystem(self.env).change_listeners:
+-                if hasattr(listener, 'wiki_page_version_deleted'):
+-                    listener.wiki_page_version_deleted(self)
++#            for listener in WikiSystem(self.env).change_listeners:
++#                if hasattr(listener, 'wiki_page_version_deleted'):
++#                    listener.wiki_page_version_deleted(self)
++            ListenerNotifier(self.env).notify(
++                             IWikiChangeListener.wiki_page_version_deleted,
++                             entity=self)
+ 
+     def save(self, author, comment, remote_addr, t=None, db=None):
+         """Save a new version of a page.
+@@ -153,12 +160,22 @@
+         self.comment = comment
+         self.time = t
+ 
+-        for listener in WikiSystem(self.env).change_listeners:
+-            if self.version == 1:
+-                listener.wiki_page_added(self)
+-            else:
+-                listener.wiki_page_changed(self, self.version, t, comment,
+-                                           author, remote_addr)
++#        for listener in WikiSystem(self.env).change_listeners:
++#            if self.version == 1:
++#                listener.wiki_page_added(self)
++#            else:
++#                listener.wiki_page_changed(self, self.version, t, comment,
++#                                           author, remote_addr)
++        if self.version == 1:
++            ListenerNotifier(self.env).notify(
++                             IWikiChangeListener.wiki_page_added,
++                             entity=self)
++        else:
++            ListenerNotifier(self.env).notify(
++                             IWikiChangeListener.wiki_page_changed,
++                             entity=self, version=self.version, 
++                             t=t, comment=comment, author=author, 
++                             ipnr=remote_addr)
+ 
+         self.old_readonly = self.readonly
+         self.old_text = self.text
+@@ -192,9 +209,12 @@
+         self.name = self.resource.id = new_name
+         self.env.log.info('Renamed page %s to %s', old_name, new_name)
+ 
+-        for listener in WikiSystem(self.env).change_listeners:
+-            if hasattr(listener, 'wiki_page_renamed'):
+-                listener.wiki_page_renamed(self, old_name)
++#        for listener in WikiSystem(self.env).change_listeners:
++#            if hasattr(listener, 'wiki_page_renamed'):
++#                listener.wiki_page_renamed(self, old_name)
++        ListenerNotifier(self.env).notify(
++                         IWikiChangeListener.wiki_page_renamed,
++                         entity=self, old_name=old_name)
+ 
+     def get_history(self, db=None):
+         """Retrieve the edit history of a wiki page.
+diff --git a/trac/wiki/tests/model.py b/trac/wiki/tests/model.py
+--- a/trac/wiki/tests/model.py
++++ b/trac/wiki/tests/model.py
+@@ -12,6 +12,7 @@
+ from trac.attachment import Attachment
+ from trac.core import *
+ from trac.test import EnvironmentStub
++from trac.tests.core import GenericEntitiesChangeListenerMock
+ from trac.util.datefmt import utc, to_utimestamp
+ from trac.wiki import WikiPage, IWikiChangeListener
+ 
+@@ -115,6 +116,10 @@
+         listener = TestWikiChangeListener(self.env)
+         self.assertEqual(page, listener.added[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'created', 'entity' : page}], 
++                         generic_listener.details)
++
+     def test_update_page(self):
+         t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
+         t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
+@@ -149,6 +154,12 @@
+         self.assertEqual((page, 2, t2, 'Changing', 'kate', '192.168.0.101'),
+                          listener.changed[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'changed', 'entity' : page,
++                           'version' : 2, 't' : t2 , 'comment' : 'Changing',
++                           'author' : 'kate', 'ipnr' : '192.168.0.101'}], 
++                         generic_listener.details)
++
+         page = WikiPage(self.env, 'TestPage')
+         history = list(page.get_history())
+         self.assertEqual(2, len(history))
+@@ -174,6 +185,10 @@
+         listener = TestWikiChangeListener(self.env)
+         self.assertEqual(page, listener.deleted[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'deleted', 'entity' : page}], 
++                         generic_listener.details)
++
+     def test_delete_page_version(self):
+         self.env.db_transaction.executemany(
+             "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
+@@ -194,6 +209,10 @@
+         listener = TestWikiChangeListener(self.env)
+         self.assertEqual(page, listener.deleted_version[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'version_deleted', 'entity' : page}], 
++                         generic_listener.details)
++
+     def test_delete_page_last_version(self):
+         self.env.db_transaction(
+             "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
+@@ -212,6 +231,10 @@
+         listener = TestWikiChangeListener(self.env)
+         self.assertEqual(page, listener.deleted[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'deleted', 'entity' : page}], 
++                         generic_listener.details)
++
+     def test_rename_page(self):
+         data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
+         self.env.db_transaction(
+@@ -247,6 +270,17 @@
+         listener = TestWikiChangeListener(self.env)
+         self.assertEqual((page, 'TestPage'), listener.renamed[0])
+ 
++        generic_listener = GenericEntitiesChangeListenerMock(self.env)
++        self.assertEqual([{'action' : 'added', 'entity' : attachment},
++                          {'action' : 'reparented', 'entity' : attachment,
++                           'old_parent_realm' : 'wiki', 
++                           'old_parent_id' : 'TestPage'},
++                          {'action' : 'renamed', 'entity' : page,
++                           'old_name' : 'TestPage'},
++                          {'action' : 'deleted', 'entity' : attachment}], 
++                         generic_listener.details)
++
++
+     def test_invalid_page_name(self):
+         invalid_names = ('../Page', 'Page/..', 'Page/////SubPage',
+                          'Page/./SubPage', '/PagePrefix', 'PageSuffix/')