changeset 3546:c9494979fe7a

xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 03 May 2008 15:50:56 +0200
parents 7e4b68c11362
children 889b37b6441c
files MoinMoin/Page.py MoinMoin/_tests/test_Page.py MoinMoin/search/Xapian.py MoinMoin/xmlrpc/__init__.py docs/CHANGES
diffstat 5 files changed, 68 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Tue Apr 29 16:25:39 2008 +0200
+++ b/MoinMoin/Page.py	Sat May 03 15:50:56 2008 +0200
@@ -534,40 +534,51 @@
             request.cfg.cache.meta.putItem(request, cache_name, cache_key, log)
         return log
 
-    def last_edit(self, request):
-        """ Return the last edit.
+    def editlog_entry(self):
+        """ Return the edit-log entry for this Page object (can be an old revision)
+            or None if no edit-log entry has been found.
+        """
+        from MoinMoin.logfile import editlog
+        rev = self.get_real_rev()
+        for line in editlog.EditLog(self.request, rootpagename=self.page_name):
+            if int(line.rev) == rev:
+                break
+        else:
+            line = None
+        return line
+
+    def edit_info(self):
+        """ Return timestamp/editor info for this Page object (can be an old revision).
+
+            Note: if you ask about a deleted revision, it will report timestamp and editor
+                  for the delete action (in the edit-log, this is just a SAVE).
+
         This is used by MoinMoin/xmlrpc/__init__.py.
 
-        @param request: the request object
         @rtype: dict
         @return: timestamp and editor information
         """
-        if not self.exists():
-            return None
+        line = self.editlog_entry()
+        if line:
+            editordata = line.getInterwikiEditorData(self.request)
+            if editordata[0] == 'interwiki':
+                editor = "%s:%s" % editordata[1]
+            else:
+                editor = editordata[1] # ip or email
+            result = {
+                'timestamp': line.ed_time_usecs,
+                'editor': editor,
+            }
+            del line
+        else:
+            result = None
+        return result
 
-        result = None
-        if not self.rev:
-            log = self._last_edited(request)
-            if log:
-                editordata = log.getInterwikiEditorData(request)
-                editor = editordata[1]
-                if editordata[0] == 'interwiki':
-                    editor = "%s:%s" % editordata[1]
-                else: # 'ip'
-                    editor = editordata[1]
-                result = {
-                    'timestamp': log.ed_time_usecs,
-                    'editor': editor,
-                }
-                del log
-        if not result:
-            version = self.mtime_usecs()
-            result = {
-                'timestamp': version,
-                'editor': '?',
-            }
-
-        return result
+    def last_edit(self, request):
+        # XXX usage of last_edit is DEPRECATED - use edit_info()
+        if not self.exists(): # XXX doesn't make much sense, but still kept
+            return None       # XXX here until we remove last_edit()
+        return self.edit_info()
 
     def lastEditInfo(self, request=None):
         """ Return the last edit info.
--- a/MoinMoin/_tests/test_Page.py	Tue Apr 29 16:25:39 2008 +0200
+++ b/MoinMoin/_tests/test_Page.py	Sat May 03 15:50:56 2008 +0200
@@ -33,11 +33,12 @@
         assert not Page(self.request, 'ThisPageDoesNotExist').exists()
         assert not Page(self.request, '').exists()
 
-    def testLastEdit(self):
-        page = Page(self.request, u'FrontPage')
-        last_edit = page.last_edit(self.request)
-        assert 'editor' in last_edit
-        assert 'timestamp' in last_edit
+    def testEditInfoSystemPage(self):
+        # system pages have no edit-log (and only 1 revision),
+        # thus edit_info will return None
+        page = Page(self.request, u'RecentChanges')
+        edit_info = page.edit_info()
+        assert edit_info is None
 
     def testSplitTitle(self):
         page = Page(self.request, u"FrontPage")
--- a/MoinMoin/search/Xapian.py	Tue Apr 29 16:25:39 2008 +0200
+++ b/MoinMoin/search/Xapian.py	Sat May 03 15:50:56 2008 +0200
@@ -463,7 +463,7 @@
         mtime = page.mtime_usecs()
         revision = str(page.get_real_rev())
         itemid = "%s:%s:%s" % (wikiname, pagename, revision)
-        author = page.last_edit(request)['editor']
+        author = page.edit_info()['editor']
         # XXX: Hack until we get proper metadata
         language, stem_language = self._get_languages(page)
         categories = self._get_categories(page)
--- a/MoinMoin/xmlrpc/__init__.py	Tue Apr 29 16:25:39 2008 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Sat May 03 15:50:56 2008 +0200
@@ -202,6 +202,9 @@
     def noSuchPageFault(self):
         return xmlrpclib.Fault(1, "No such page was found.")
 
+    def noLogEntryFault(self):
+        return xmlrpclib.Fault(1, "No log entry was found.")
+
     #############################################################################
     ### System methods
     #############################################################################
@@ -408,8 +411,11 @@
             return self.noSuchPageFault()
 
         # Get page info
-        last_edit = page.last_edit(self.request)
-        mtime = wikiutil.version2timestamp(long(last_edit['timestamp'])) # must be long for py 2.2.x
+        edit_info = page.edit_info()
+        if not edit_info:
+            return self.noLogEntryFault()
+
+        mtime = wikiutil.version2timestamp(long(edit_info['timestamp'])) # must be long for py 2.2.x
         gmtuple = tuple(time.gmtime(mtime))
 
         version = rev # our new rev numbers: 1,2,3,4,....
@@ -428,7 +434,7 @@
         return {
             'name': self._outstr(page.page_name),
             'lastModified': xmlrpclib.DateTime(gmtuple),
-            'author': self._outstr(last_edit['editor']),
+            'author': self._outstr(edit_info['editor']),
             'version': version,
             }
 
--- a/docs/CHANGES	Tue Apr 29 16:25:39 2008 +0200
+++ b/docs/CHANGES	Sat May 03 15:50:56 2008 +0200
@@ -49,6 +49,19 @@
     make install
 
 
+Version 1.7.0current:
+
+  Bug Fixes:
+    * Wiki xmlrpc getPageInfoVersion() fixed:
+      * works correctly now for old page versions (was unsupported)
+      * works correctly now for current page version (reported wrong
+        data when a page had attachment uploads after the last page
+        edit)
+      * returns a Fault if it did not find a edit-log entry
+
+  Developer notes (these should be moved to the end in the release):
+    * Page.last_edit() is DEPRECATED, please use Page.edit_info().
+
 Version 1.7.0beta1:
 
   New Features: