jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/450460 )
Change subject: Use 'rvslots' when fetching revisions on MW 1.32+ ......................................................................
Use 'rvslots' when fetching revisions on MW 1.32+
The only places that use 'rvprop' parameter directly are in APISite.loadrevisions and APISite.preloadpages. Modify them to add rvslots to the query if the MW version is >= 1.32.
The recieved pagedata format will also change. Adapt the api._update_revisions method to the new format.
This is a temporary workaround to silence the API warnings. We perhaps need to update the Revision class for other slot types in the future.
Bug: T200955 Change-Id: Ia4d655a46bf83a969b907280c7a9e24e8782b9a8 --- M pywikibot/data/api.py M pywikibot/site.py M tests/api_tests.py 3 files changed, 14 insertions(+), 3 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 9d35047..188bd25 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -3291,6 +3291,8 @@ """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']), diff --git a/pywikibot/site.py b/pywikibot/site.py index 49db849..0adfbcc 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3371,6 +3371,8 @@ else: rvgen.request['titles'] = list(cache.keys()) rvgen.request['rvprop'] = rvprop + if self.version() >= MediaWikiVersion('1.32'): + rvgen.request['rvslots'] = '*' pywikibot.output(u"Retrieving %s pages from %s." % (len(cache), self))
@@ -4064,6 +4066,10 @@ rvargs = {'type_arg': 'info|revisions'}
rvargs['rvprop'] = ['ids', 'timestamp', 'flags', 'comment', 'user'] + if self.version() >= MediaWikiVersion('1.32'): + rvargs['rvslots'] = '*' + # 'roles' is not implemented in Revision class yet. + # rvargs['rvprop'].append('roles') if MediaWikiVersion(self.version()) >= MediaWikiVersion('1.21'): rvargs['rvprop'].append('contentmodel') if MediaWikiVersion(self.version()) >= MediaWikiVersion('1.19'): diff --git a/tests/api_tests.py b/tests/api_tests.py index 84157c7..0a04e61 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -783,12 +783,15 @@ links = list(self.site.pagelinks(mainpage, total=30)) titles = [l.title(with_section=False) for l in links] + params = { + 'rvprop': 'ids|flags|timestamp|user|comment|content', + 'titles': '|'.join(titles)} + if self.site.version() >= MediaWikiVersion('1.32'): + params['rvslots'] = 'main' gen = api.PropertyGenerator( site=self.site, prop='revisions|info|categoryinfo|langlinks|templates', - parameters={ - 'rvprop': 'ids|flags|timestamp|user|comment|content', - 'titles': '|'.join(titles)}) + parameters=params)
# An APIError is raised if set_maximum_items is not called. gen.set_maximum_items(-1) # suppress use of "rvlimit" parameter
pywikibot-commits@lists.wikimedia.org