jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/573259 )
Change subject: [FEAT] Make Revision support slots ......................................................................
[FEAT] Make Revision support slots
In new MediaWiki versions, one revision can hold more than just one content. This feature is called "slot".
Bug: T226544 Change-Id: Ic926b34980f7b61b8447acc0631b7649c3130ed7 --- M pywikibot/data/api.py M pywikibot/page.py 2 files changed, 31 insertions(+), 6 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 0702d38..eae947f 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -3249,8 +3249,6 @@ """Update page revisions.""" # TODO: T102735: Use the page content model for <1.21 for rev in revisions: - if 'slots' in rev and 'main' in rev['slots']: # MW 1.32+ - rev.update(rev['slots']['main']) revision = pywikibot.page.Revision( revid=rev['revid'], timestamp=pywikibot.Timestamp.fromISOformat(rev['timestamp']), @@ -3258,10 +3256,11 @@ anon='anon' in rev, comment=rev.get('comment', ''), minor='minor' in rev, - text=rev.get('*'), + slots=rev.get('slots'), # MW 1.32+ + text=rev.get('*'), # b/c rollbacktoken=rev.get('rollbacktoken'), parentid=rev.get('parentid'), - contentmodel=rev.get('contentmodel'), + contentmodel=rev.get('contentmodel'), # b/c sha1=rev.get('sha1') ) page._revisions[revision.revid] = revision diff --git a/pywikibot/page.py b/pywikibot/page.py index b9f4f35..8172689 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -5606,7 +5606,7 @@
def __init__(self, revid, timestamp, user, anon=False, comment='', text=None, minor=False, rollbacktoken=None, parentid=None, - contentmodel=None, sha1=None): + contentmodel=None, sha1=None, slots=None): """ Initializer.
@@ -5635,9 +5635,11 @@ @type contentmodel: str @param sha1: sha1 of revision text (v1.19+) @type sha1: str + @param slots: revision slots (v1.32+) + @type slots: dict """ self.revid = revid - self.text = text + self._text = text self.timestamp = timestamp self.user = user self.anon = anon @@ -5647,6 +5649,7 @@ self._parent_id = parentid self._content_model = contentmodel self._sha1 = sha1 + self.slots = slots
@property def parent_id(self): @@ -5666,15 +5669,38 @@ return self._parent_id
@property + def text(self): + """ + Return text of this revision. + + This is meant for compatibility with older MW version which + didn't support revisions with slots. For newer MW versions, + this returns the contents of the main slot. + + @return: text of the revision + @rtype: str or None if text not yet retrieved + """ + if self.slots is not None: + return self.slots.get('main', {}).get('*') + return self._text + + @property def content_model(self): """ Return content model of the revision.
+ This is meant for compatibility with older MW version which + didn't support revisions with slots. For newer MW versions, + this returns the content model of the main slot. + @return: content model @rtype: str @raises AssertionError: content model not supplied to the constructor which always occurs for MediaWiki versions lower than 1.21. """ + if self._content_model is None and self.slots is not None: + self._content_model = self.slots.get('main', {}).get( + 'contentmodel') # TODO: T102735: Add a sane default of 'wikitext' and others for <1.21 assert self._content_model is not None, ( 'Revision {0} was instantiated without a content model'