jenkins-bot merged this change.
[cleanup] remove code duplication of moved_links dict
move moved_links to library part to prevent code duplication
Change-Id: I5e4b55314de54630e6f12e139b25b408935daf23
---
M pywikibot/cosmetic_changes.py
M scripts/interwiki.py
2 files changed, 43 insertions(+), 73 deletions(-)
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 94af12a..f9488c2 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -76,32 +76,56 @@
from pywikibot.tools import MediaWikiVersion
-# This is from interwiki.py;
-# move it to family file and implement global instances
+# Subpage templates. Must be in lower case,
+# whereas subpage itself must be case sensitive
+# This is also used by interwiki.py
+# TODO: Maybe move it to family file and implement global instances
moved_links = {
+ 'ar': (['documentation', 'template documentation', 'شرح', 'توثيق'],
+ '/doc'),
+ 'bn': ('documentation', '/doc'),
'ca': (u'ús de la plantilla', u'/ús'),
- 'cs': (u'dokumentace', u'/doc'),
+ 'cs': ('dokumentace', '/doc'),
+ 'da': ('dokumentation', '/doc'),
'de': (u'dokumentation', u'/Meta'),
- 'en': ([u'documentation',
- u'template documentation',
- u'template doc',
- u'doc',
- u'documentation, template'], u'/doc'),
+ 'dsb': (['dokumentacija', 'doc'], '/Dokumentacija'),
+ 'en': (['documentation', 'template documentation', 'template doc',
+ 'doc', 'documentation, template'], '/doc'),
'es': ([u'documentación', u'documentación de plantilla'], u'/doc'),
- 'fa': ([u'documentation', u'توضیحات', u'توضیحات الگو',
- u'doc'], u'/توضیحات'),
- 'fr': (u'/documentation', u'/Documentation'),
+ 'eu': ('txantiloi dokumentazioa', '/dok'),
+ 'fa': (['documentation', 'template documentation', 'template doc',
+ 'doc', 'توضیحات', 'زیرصفحه توضیحات'], '/doc'),
+ # fi: no idea how to handle this type of subpage at :Metasivu:
+ 'fi': ('mallineohje', None),
+ 'fr': (['/documentation', 'documentation', 'doc_modèle',
+ 'documentation modèle', 'documentation modèle compliqué',
+ 'documentation modèle en sous-page',
+ 'documentation modèle compliqué en sous-page',
+ 'documentation modèle utilisant les parserfunctions en sous-page',
+ ],
+ '/Documentation'),
+ 'hsb': (['dokumentacija', 'doc'], '/Dokumentacija'),
'hu': (u'sablondokumentáció', u'/doc'),
- 'id': (u'template doc', u'/doc'),
+ 'id': ('template doc', '/doc'),
+ 'ilo': ('documentation', '/doc'),
'ja': (u'documentation', u'/doc'),
- 'ka': (u'თარგის ინფო', u'/ინფო'),
+ 'ka': ('თარგის ინფო', '/ინფო'),
'ko': (u'documentation', u'/설명문서'),
'ms': (u'documentation', u'/doc'),
- 'pl': (u'dokumentacja', u'/opis'),
+ 'no': ('dokumentasjon', '/dok'),
+ 'nn': ('dokumentasjon', '/dok'),
+ 'pl': ('dokumentacja', '/opis'),
'pt': ([u'documentação', u'/doc'], u'/doc'),
- 'ro': (u'documentaţie', u'/doc'),
+ 'ro': ('documentaţie', '/doc'),
'ru': (u'doc', u'/doc'),
+ 'simple': (['documentation',
+ 'template documentation',
+ 'template doc',
+ 'doc',
+ 'documentation, template'], '/doc'),
+ 'sk': ('dokumentácia', '/Dokumentácia'),
'sv': (u'dokumentation', u'/dok'),
+ 'uk': (['документація', 'doc', 'documentation'], '/Документація'),
'vi': (u'documentation', u'/doc'),
'zh': ([u'documentation', u'doc'], u'/doc'),
}
@@ -325,12 +349,11 @@
if not self.talkpage:
subpage = False
if self.template:
- loc = None
try:
tmpl, loc = moved_links[self.site.code]
del tmpl
except KeyError:
- pass
+ loc = None
if loc is not None and loc in self.title:
subpage = True
interwikiLinks = textlib.getLanguageLinks(
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 33b67e2..6b9f336 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -359,6 +359,7 @@
from pywikibot import titletranslate
from pywikibot.bot import ListOption, StandardOption
+from pywikibot.cosmetic_changes import moved_links
from pywikibot.tools import first_upper
from pywikibot.tools.formatter import color_format
@@ -389,58 +390,6 @@
pass
-
-# Subpage templates. Must be in lower case,
-# whereas subpage itself must be case sensitive
-moved_links = {
- 'ar': ([u'documentation', u'template documentation', u'شرح', u'توثيق'],
- u'/doc'),
- 'bn': (u'documentation', u'/doc'),
- 'ca': (u'ús de la plantilla', u'/ús'),
- 'cs': ('dokumentace', '/doc'),
- 'da': (u'dokumentation', u'/doc'),
- 'de': (u'dokumentation', u'/Meta'),
- 'dsb': ([u'dokumentacija', u'doc'], u'/Dokumentacija'),
- 'en': ([u'documentation', u'template documentation', u'template doc',
- u'doc', u'documentation, template'], u'/doc'),
- 'es': ([u'documentación', u'documentación de plantilla'], u'/doc'),
- 'eu': (u'txantiloi dokumentazioa', u'/dok'),
- 'fa': ([u'documentation', u'template documentation', u'template doc',
- u'doc', u'توضیحات', u'زیرصفحه توضیحات'], u'/doc'),
- # fi: no idea how to handle this type of subpage at :Metasivu:
- 'fi': (u'mallineohje', None),
- 'fr': ([u'/documentation', u'documentation', u'doc_modèle',
- u'documentation modèle', u'documentation modèle compliqué',
- u'documentation modèle en sous-page',
- u'documentation modèle compliqué en sous-page',
- u'documentation modèle utilisant les parserfunctions en sous-page',
- ],
- u'/Documentation'),
- 'hsb': ([u'dokumentacija', u'doc'], u'/Dokumentacija'),
- 'hu': (u'sablondokumentáció', u'/doc'),
- 'id': ('template doc', '/doc'),
- 'ilo': (u'documentation', u'/doc'),
- 'ja': (u'documentation', u'/doc'),
- 'ka': ('თარგის ინფო', '/ინფო'),
- 'ko': (u'documentation', u'/설명문서'),
- 'ms': (u'documentation', u'/doc'),
- 'no': (u'dokumentasjon', u'/dok'),
- 'nn': (u'dokumentasjon', u'/dok'),
- 'pl': ('dokumentacja', '/opis'),
- 'pt': ([u'documentação', u'/doc'], u'/doc'),
- 'ro': ('documentaţie', '/doc'),
- 'ru': (u'doc', u'/doc'),
- 'simple': ([u'documentation',
- u'template documentation',
- u'template doc',
- u'doc',
- u'documentation, template'], u'/doc'),
- 'sk': (u'dokumentácia', u'/Dokumentácia'),
- 'sv': (u'dokumentation', u'/dok'),
- 'uk': ([u'документація', u'doc', u'documentation'], u'/Документація'),
- 'vi': (u'documentation', u'/doc'),
- 'zh': ([u'documentation', u'doc'], u'/doc'),
-}
# A list of template names in different languages.
# Pages which contain these shouldn't be changed.
@@ -2175,12 +2124,11 @@
pywikibot.output(u'Skipping: %s is a talk page' % page)
continue
if page.namespace() == 10:
- loc = None
try:
tmpl, loc = moved_links[page.site.code]
del tmpl
except KeyError:
- pass
+ loc = None
if loc is not None and loc in page.title():
pywikibot.output(
'Skipping: %s is a templates subpage'
@@ -2401,11 +2349,10 @@
def botMayEdit(page):
"""Test for allowed edits."""
- tmpl = []
try:
tmpl, loc = moved_links[page.site.code]
except KeyError:
- pass
+ tmpl = []
if not isinstance(tmpl, list):
tmpl = [tmpl]
try:
To view, visit change 416225. To unsubscribe, visit settings.