XZise has uploaded a new change for review.

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

Change subject: [IMPROV] Namespace: Use default and fixed case
......................................................................

[IMPROV] Namespace: Use default and fixed case

For certain namespaces the case sensitivity is fixed and can't be
changed. This either asserts that the case or if the server doesn't
report the case sensitivity for the namespaces specifically uses that
default value.

This also applies to all namespaces created without the help of the API.

Change-Id: I097c4e52ad41bf531f2685e712bb0be27a225661
---
M pywikibot/site.py
1 file changed, 16 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/96/205596/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5848169..50cb4b8 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -368,10 +368,21 @@
                % (self.__class__.__name__, self.id, self.custom_name,
                   self.canonical_name, self.aliases, kwargs)
 
+    @staticmethod
+    def default_case(id, default_case=None):
+        """Return the default fixes case value for the namespace ID."""
+        if id > 0 and id % 2 == 1:  # the talk ns has the non-talk ns case
+            id -= 1
+        if id in (-1, 2, 8):
+            return 'first-letter'
+        else:
+            return default_case
+
     @classmethod
     def builtin_namespaces(cls, use_image_name=False, case='first-letter'):
         """Return a dict of the builtin namespaces."""
-        return dict((i, cls(i, use_image_name=use_image_name, case=case))
+        return dict((i, cls(i, use_image_name=use_image_name,
+                            case=cls.default_case(i, case)))
                      for i in range(-2, 16))
 
     @staticmethod
@@ -2139,8 +2150,11 @@
                 if is_mw114:
                     canonical_name = nsdata.pop('canonical')
 
+            default_case = Namespace.default_case(ns)
             if 'case' not in nsdata:
-                nsdata['case'] = self.siteinfo['case']
+                nsdata['case'] = default_case or self.siteinfo['case']
+            elif default_case is not None:
+                assert(default_case == nsdata['case'])
 
             namespace = Namespace(ns, canonical_name, custom_name,
                                   use_image_name=not is_mw114,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I097c4e52ad41bf531f2685e712bb0be27a225661
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to