Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/154390

Change subject: new method APISite.restrictions() to reduce duplicate code
......................................................................

new method APISite.restrictions() to reduce duplicate code

The recently added methods:
.protection_types() and .protection_levels()
have been removed; no 'deprecated' notice has been added.

Change-Id: I7199e78c6600beb21736031e8f4a4a13a3cc27f4
---
M pywikibot/page.py
M pywikibot/site.py
M scripts/protect.py
3 files changed, 21 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/90/154390/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 7108a2b..7c04821 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -840,7 +840,7 @@
         """
         # Currently hard coded, but a future API update might allow us to
         # properly determine the applicable protection types
-        p_types = set(self.site.protection_types())
+        p_types = set(self.site.restrictions()['types'])
         if not self.exists():
             return set(['create']) if 'create' in p_types else set()
         else:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 63fca60..3b9370a 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3500,41 +3500,30 @@
         "protect-invalidlevel": "Invalid protection level"
     }
 
-    def protection_types(self):
+    def restrictions(self):
         """
-        Return the protection types available on this site.
+        Return the page restrictions available on this site.
 
-        With MediaWiki version 1.23 protection types can be retrieved. To
-        support older wikis, the default protection types 'create', 'edit',
-        'move' and 'upload' are returned.
+        Since MediaWiki 1.23, restrictions can be retrieved via the API.
+        For older wikis, the default restrictions are returned.
 
-        @return protection types available
-        @rtype: set of unicode instances
+        @return: available page restrictions
+        @rtype: dict
         """
         # implemented in b73b5883d486db0e9278ef16733551f28d9e096d
         restrictions = self._add_siteinfo('restrictions', True)
-        if restrictions is None or 'types' not in restrictions:
-            return set([u'create', u'edit', u'move', u'upload'])
-        else:
-            return set(restrictions['types'])
-
-    def protection_levels(self):
-        """
-        Return the protection levels available on this site.
-
-        With MediaWiki version 1.23 protection levels can be retrieved. To
-        support older wikis, the default protection levels '', 'autoconfirmed',
-        and 'sysop' are returned.
-
-        @return protection types available
-        @rtype: set of unicode instances
-        """
-        # implemented in b73b5883d486db0e9278ef16733551f28d9e096d
-        restrictions = self._add_siteinfo('restrictions', True)
-        if restrictions is None or 'levels' not in restrictions:
-            return set([u'', u'autoconfirmed', u'sysop'])
-        else:
-            return set(restrictions['levels'])
+        default = {
+            'cascadinglevels': ['sysop'],
+            'semiprotectedlevels': ['autoconfirmed'],
+            'levels': ['', 'autoconfirmed', 'sysop'],
+            'types': ['create', 'edit', 'move', 'upload']
+        }
+        if restrictions is None:
+            restrictions = default
+        for key, val in restrictions.items():
+            if isinstance(val, list):
+                restrictions[key] = set(val)
+        return restrictions
 
     @must_be(group='sysop')
     @deprecate_arg("summary", "reason")
diff --git a/scripts/protect.py b/scripts/protect.py
index 256d76b..c3a9567 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -156,8 +156,8 @@
     genFactory = pagegenerators.GeneratorFactory()
     site = pywikibot.Site()
 
-    protection_levels = set(site.protection_levels())
-    protection_types = site.protection_types()
+    protection_levels = site.restrictions()['levels']
+    protection_types = site.restrictions()['types']
     if '' in protection_levels:
         protection_levels.remove('')
         protection_levels.add('none')

-- 
To view, visit https://gerrit.wikimedia.org/r/154390
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7199e78c6600beb21736031e8f4a4a13a3cc27f4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to