Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1083866?usp=email )
Change subject: [FEAT] Add BasePage.get_revision
......................................................................
[FEAT] Add BasePage.get_revision
BasePage.getOldVersion returns just the revision text.
For advanced scripts, like patrolling bots, it's useful
to analyze the revision's metadata as well.
Change-Id: I6f9f7136d0d484535917e4d12c18fa78db883775
---
M pywikibot/page/_basepage.py
1 file changed, 15 insertions(+), 4 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 1d675fe..1d50f3a 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -452,16 +452,27 @@
self._getexception = IsRedirectPageError(self)
raise self._getexception
+ def get_revision(
+ self, oldid: int, *, force: bool = False, content: bool = False
+ ) -> pywikibot.page.Revision:
+ """Return an old revision of this page.
+
+ :param oldid: The revid of the revision desired.
+ :param content: if True, retrieve the content of the revision
+ (default False)
+ """
+ if force or oldid not in self._revisions \
+ or (content and self._revisions[oldid].text is None):
+ self.site.loadrevisions(self, content=content, revids=oldid)
+ return self._revisions[oldid]
+
@remove_last_args(['get_redirect'])
def getOldVersion(self, oldid, force: bool = False) -> str:
"""Return text of an old revision of this page.
:param oldid: The revid of the revision desired.
"""
- if force or oldid not in self._revisions \
- or self._revisions[oldid].text is None:
- self.site.loadrevisions(self, content=True, revids=oldid)
- return self._revisions[oldid].text
+ return self.get_revision(oldid, content=True, force=force).text
def permalink(self, oldid=None, percent_encoded: bool = True,
with_protocol: bool = False) -> str:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1083866?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6f9f7136d0d484535917e4d12c18fa78db883775
Gerrit-Change-Number: 1083866
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]