jenkins-bot has submitted this change and it was merged.
Change subject: Namespaces initialisation bug ......................................................................
Namespaces initialisation bug
is_mw114 is set to be True for sites with mediawiki >= 1.14. Those sites use Image namespace, rather than File. The boolean needs to be reversed.
Also, when adding aliases, do not add an alias if it is already in the object.
Bug: 69278 Change-Id: Id85dea19554450f387c13f68f73ae54eeeaf941c --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 20 insertions(+), 2 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 060776b..47d170d 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1490,7 +1490,7 @@ # Remove the 'id' from nsdata nsdata[nskey].pop('id') namespace = Namespace(ns, canonical_name, custom_name, - use_image_name=is_mw114, **nsdata[nskey]) + use_image_name=not is_mw114, **nsdata[nskey])
self._namespaces[ns] = namespace
@@ -1498,7 +1498,8 @@ aliasdata = sidata['namespacealiases'] for item in aliasdata: ns = int(item['id']) - self._namespaces[ns].aliases.append(item['*']) + if item['*'] not in self._namespaces[ns]: + self._namespaces[ns].aliases.append(item['*'])
if 'extensions' in sidata: self._extensions = sidata['extensions'] diff --git a/tests/site_tests.py b/tests/site_tests.py index 6b9dd33..171bc4e 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -136,6 +136,23 @@ user_namespace = site.namespaces()[2] self.assertEquals(user_namespace.case, 'first-letter')
+ def testNamespaceAliases(self): + site = pywikibot.Site('nn', 'wikipedia') + + namespaces = site.namespaces() + image_namespace = namespaces[6] + self.assertEquals(image_namespace.custom_name, 'Fil') + self.assertEquals(image_namespace.canonical_name, 'File') + self.assertEquals(str(image_namespace), ':File:') + self.assertEquals(unicode(image_namespace), ':Fil:') + self.assertEquals(image_namespace.aliases, ['Image']) + self.assertEquals(len(image_namespace), 3) + + self.assertEquals(len(namespaces[1].aliases), 0) + self.assertEquals(len(namespaces[4].aliases), 1) + self.assertEquals(namespaces[4].aliases[0], 'WP') + self.assertIn('WP', namespaces[4]) + def testApiMethods(self): """Test generic ApiSite methods"""
pywikibot-commits@lists.wikimedia.org