jenkins-bot has submitted this change and it was merged.
Change subject: Use the new 'restrictiontypes' property in the pageinfo API
......................................................................
Use the new 'restrictiontypes' property in the pageinfo API
I got 32083235eb332c419df2063cf966b3400be7ee8a merged in
MediaWiki but forgot to update Pywikibot.
Also created a new non-write test class
for test_applicable_protections().
Change-Id: I6d7d1880814b7235726c9cc7ed67b7258939f148
---
M pywikibot/data/api.py
M pywikibot/page.py
M tests/page_tests.py
3 files changed, 42 insertions(+), 16 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 3e82636..236f58a 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2599,6 +2599,10 @@
if 'touched' in pagedict:
page._timestamp = pagedict['touched']
if 'protection' in pagedict:
+ if 'restrictiontypes' in pagedict:
+ page._applicable_protections = set(pagedict['restrictiontypes'])
+ else:
+ page._applicable_protections = None
page._protection = {}
for item in pagedict['protection']:
page._protection[item['type']] = item['level'], item['expiry']
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 73cbd90..86a3393 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -53,7 +53,7 @@
UserRightsError,
)
from pywikibot.tools import (
- UnicodeMixin, DotReadableDict,
+ MediaWikiVersion, UnicodeMixin, DotReadableDict,
ComparableMixin, deprecated, deprecate_arg, deprecated_args,
first_upper, remove_last_args, _NotImplementedWarning,
OrderedDict, Counter,
@@ -926,8 +926,11 @@
@return: set of unicode
"""
- # Currently hard coded, but a future API update might allow us to
- # properly determine the applicable protection types
+ # New API since commit 32083235eb332c419df2063cf966b3400be7ee8a
+ if MediaWikiVersion(self.site.version()) >=
MediaWikiVersion('1.25wmf14'):
+ self.site.loadpageinfo(self)
+ return self._applicable_protections
+
p_types = set(self.site.protection_types())
if not self.exists():
return set(['create']) if 'create' in p_types else set()
diff --git a/tests/page_tests.py b/tests/page_tests.py
index c031da4..a23d6c6 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -793,6 +793,38 @@
self.assertEqual(revs[1].revid, revid)
+class TestApplicablePageProtections(TestCase):
+
+ """Test applicable restriction types."""
+
+ family = 'test'
+ code = 'test'
+
+ def test_applicable_protections(self):
+ """Test Page.applicable_protections."""
+ site = self.get_site()
+ p1 = pywikibot.Page(site, u'User:Unicodesnowman/NonexistentPage')
+ p2 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p3 = pywikibot.Page(site, u'File:Wiki.png')
+
+ # from the API, since 1.25wmf14
+ pp1 = p1.applicable_protections()
+ pp2 = p2.applicable_protections()
+ pp3 = p3.applicable_protections()
+
+ self.assertEqual(pp1, set(['create']))
+ self.assertIn('edit', pp2)
+ self.assertNotIn('create', pp2)
+ self.assertNotIn('upload', pp2)
+ self.assertIn('upload', pp3)
+
+ # inferred
+ site.version = lambda: '1.24'
+ self.assertEqual(pp1, p1.applicable_protections())
+ self.assertEqual(pp2, p2.applicable_protections())
+ self.assertEqual(pp3, p3.applicable_protections())
+
+
class TestPageProtect(TestCase):
"""Test page protect / unprotect actions."""
@@ -802,19 +834,6 @@
write = True
sysop = True
-
- def test_applicable_protections(self):
- """Test Page.applicable_protections."""
- site = self.get_site()
- p1 = pywikibot.Page(site, u'User:Unicodesnowman/NonexistentPage')
- p2 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
- p3 = pywikibot.Page(site, u'File:Wiki.png')
-
- self.assertEqual(p1.applicable_protections(), set(['create']))
- self.assertIn('edit', p2.applicable_protections())
- self.assertNotIn('create', p2.applicable_protections())
- self.assertNotIn('upload', p2.applicable_protections())
- self.assertIn('upload', p3.applicable_protections())
@unittest.expectedFailure
def test_protect(self):
--
To view, visit https://gerrit.wikimedia.org/r/216631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6d7d1880814b7235726c9cc7ed67b7258939f148
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits