Skip to content

Commit

Permalink
Merge "Replace MW API deprecated inprop=preload with preloadcontent"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 1, 2023
2 parents df64681 + ae5760f commit dbd652d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pywikibot/data/api/_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,10 @@ def update_page(page, pagedict: dict, props=None):
elif 'pageprops' in props:
page._pageprops = {}

if 'preload' in pagedict:
# preload is deprecated in MW 1.41, try preloadcontent first
if 'preloadcontent' in pagedict:
page._preloadedtext = pagedict['preloadcontent']['*']
elif 'preload' in pagedict:
page._preloadedtext = pagedict['preload']

if 'flowinfo' in pagedict:
Expand Down
9 changes: 6 additions & 3 deletions pywikibot/site/_apisite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import pywikibot
from pywikibot import login
from pywikibot.backports import DefaultDict, Dict, List, Match
from pywikibot.backports import DefaultDict, Dict, Iterable, List, Match
from pywikibot.backports import OrderedDict as OrderedDictType
from pywikibot.backports import Iterable, Set, Tuple, removesuffix
from pywikibot.backports import Set, Tuple, removesuffix
from pywikibot.comms import http
from pywikibot.data import api
from pywikibot.exceptions import (
Expand Down Expand Up @@ -1336,7 +1336,10 @@ def loadpageinfo(
title = page.title(with_section=False)
inprop = 'protection'
if preload:
inprop += '|preload'
if self.mw_version >= MediaWikiVersion('1.41'):
inprop += '|preloadcontent'
else:
inprop += '|preload'

query = self._generator(api.PropertyGenerator,
type_arg='info',
Expand Down
2 changes: 2 additions & 0 deletions tests/dry_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class ParamInfoDictTests(DefaultDrySiteTestCase):
'url',
'watched',
'watchers',
'preloadcontent',
'preload',
'readable',
],
Expand Down Expand Up @@ -417,6 +418,7 @@ def test_info_parameter(self):
self.assertIn('deprecatedvalues', param)
self.assertIsInstance(param['type'], list)
self.assertIn('preload', param['type'])
self.assertIn('preloadcontent', param['type'])

def test_tokens_parameter(self):
"""Test parameter() method with 'tokens' module."""
Expand Down

0 comments on commit dbd652d

Please sign in to comment.