jenkins-bot has submitted this change and it was merged.
Change subject: Add Page.revisions, getCreator, getLatestEditors ......................................................................
Add Page.revisions, getCreator, getLatestEditors
Adds Page.getCreator() and Page.getLatestEditors() to be the same as the original compat methods. They were just added for compatibility but are deprecated. The newly added Page property 'oldest_revision' now returns a Revision object.
Page.revisions() is a generator to retrieve Revision objects and similar to Page.getVersionHistory().
Bug: T75023 Change-Id: Ifee5de37e6feb7855550c2d8c9eeebc70ac542da --- M pywikibot/page.py M tests/page_tests.py 2 files changed, 44 insertions(+), 1 deletion(-)
Approvals: John Vandenberg: Looks good to me, approved Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 2d71d8a..f4aeeaf 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -578,7 +578,12 @@
@property def oldest_revision(self): - return self.getVersionHistory(reverseOrder=True, total=1)[0] + """ + Return the first revision of this page. + + @rtype: L{Revision} + """ + return next(self.revisions(reverseOrder=True, total=1))
def isRedirectPage(self): """Return True if this is a redirect, False if not or not existing.""" @@ -1384,6 +1389,14 @@ """ return self.site.getredirtarget(self)
+ def revisions(self, reverseOrder=False, step=None, total=None): + """Generator which loads the version history as Revision instances.""" + # TODO: Only request uncached revisions + self.site.loadrevisions(self, getText=False, rvdir=reverseOrder, + step=step, total=total) + return (self._revisions[rev] for rev in + sorted(self._revisions, reverse=not reverseOrder)[:total]) + # BREAKING CHANGE: in old framework, default value for getVersionHistory # returned no more than 500 revisions; now, it iterates # all revisions unless 'total' argument is used @@ -1450,6 +1463,30 @@ users = set(entry.user for entry in history) return users
+ @deprecated('oldest_revision') + def getCreator(self): + """Get the first revision of the page. + + DEPRECATED: Use Page.oldest_revision. + + @rtype: tuple(username, Timestamp) + """ + result = self.oldest_revision + return result.user, result.timestamp + + @deprecated('revisions') + @deprecated_args(limit="total") + def getLatestEditors(self, total=1): + """Get a list of revision informations of the last total edits. + + DEPRECATED: Use Page.revisions. + + @param total: iterate no more than this number of revisions in total + @rtype: list of dict, each dict containing the username and Timestamp + """ + return [{'user': rev.user, 'timestamp': rev.timestamp} + for rev in self.revisions(total=total)] + @deprecate_arg("throttle", None) def move(self, newtitle, reason=None, movetalkpage=True, sysop=False, deleteAndMove=False, safe=True): diff --git a/tests/page_tests.py b/tests/page_tests.py index 1bb1fde..66059ad 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -252,6 +252,12 @@ withNamespace=False, insite=site), u"[[:File:Jean-Léon Gérôme 003.jpg|Jean-Léon Gérôme 003.jpg]]")
+ def test_creation(self): + mainpage = self.get_mainpage() + creation = mainpage.getCreator() + self.assertEqual(creation[0], 'TwoOneTwo') + self.assertIsInstance(creation[1], pywikibot.Timestamp) +
class TestPageObject(DefaultSiteTestCase):
pywikibot-commits@lists.wikimedia.org