jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] enable misspelling.py for misspellingTemplate localisation
......................................................................
[bugfix] enable misspelling.py for misspellingTemplate localisation
disambPage.templatesWithParams() return the template page and
page.title() includes the namespace. The misspellingTemplate names doesn't
include the namespace and comparing both does never fit.
The generator is assigned after the constructor of the super class was
called because it uses the class' site object.
- remove obsolete misspellingTemplate entries
- Add method docs
- shorten lines beneath 80 chars
- change lang code index and comparing operator
- use placeholders for arguments in setSummaryMessage
- enable self.site and inherit mysite, mylang
- add script to flake8-docstrings-mandatory
Change-Id: I907bb4047d42afa4f9044a870f18cbaa724302c8
---
M scripts/misspelling.py
M scripts/solve_disambiguation.py
M tox.ini
3 files changed, 35 insertions(+), 21 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/misspelling.py b/scripts/misspelling.py
index 6285bb2..3ccb4b4 100755
--- a/scripts/misspelling.py
+++ b/scripts/misspelling.py
@@ -22,7 +22,7 @@
wikipedia, user, etc. namespaces.
"""
# (C) Daniel Herding, 2007
-# (C) Pywikibot team, 2007-2014
+# (C) Pywikibot team, 2007-2015
#
# Distributed under the terms of the MIT license.
#
@@ -50,11 +50,7 @@
"""Spelling bot."""
misspellingTemplate = {
- 'da': None, # uses simple redirects
'de': u'Falschschreibung',
- 'en': None, # uses simple redirects
- 'hu': None, # uses simple redirects
- 'nl': None,
}
# Optional: if there is a category, one can use the -start
@@ -68,22 +64,28 @@
}
def __init__(self, always, firstPageTitle, main_only):
+ """Constructor."""
super(MisspellingRobot, self).__init__(
- always, [], True, False,
- self.createPageGenerator(firstPageTitle), False, main_only)
+ always, [], True, False, None, False, main_only)
+ self.generator = self.createPageGenerator(firstPageTitle)
def createPageGenerator(self, firstPageTitle):
- mysite = pywikibot.Site()
- mylang = mysite.code
+ """
+ Generator to retrieve misspelling pages or misspelling redirects.
+
+ @rtype: generator
+ """
+ mylang = self.site.code
if mylang in self.misspellingCategory:
misspellingCategoryTitle = self.misspellingCategory[mylang]
- misspellingCategory = pywikibot.Category(mysite,
+ misspellingCategory = pywikibot.Category(self.site,
misspellingCategoryTitle)
generator = pagegenerators.CategorizedPageGenerator(
misspellingCategory, recurse=True, start=firstPageTitle)
elif mylang in self.misspellingTemplate:
- misspellingTemplateName = 'Template:%s' %
self.misspellingTemplate[mylang]
- misspellingTemplate = pywikibot.Page(mysite,
+ misspellingTemplateName = ('Template:%s'
+ % self.misspellingTemplate[mylang])
+ misspellingTemplate = pywikibot.Page(self.site,
misspellingTemplateName)
generator = pagegenerators.ReferringPageGenerator(
misspellingTemplate, onlyTemplateInclusion=True)
@@ -92,7 +94,7 @@
u'-start parameter unsupported on this wiki because there '
u'is no category for misspellings.')
else:
- pywikibot.output(HELP_MSG.format(site=mysite))
+ pywikibot.output(HELP_MSG.format(site=self.site))
empty_gen = (i for i in [])
return empty_gen
@@ -100,14 +102,22 @@
preloadingGen = pagegenerators.PreloadingGenerator(generator)
return preloadingGen
- # Overrides the DisambiguationRobot method.
def findAlternatives(self, disambPage):
+ """
+ Append link target to a list of alternative links.
+
+ Overrides the DisambiguationRobot method.
+
+ @return: True if alternate link was appended
+ @rtype: bool or None
+ """
if disambPage.isRedirectPage():
self.alternatives.append(disambPage.getRedirectTarget().title())
return True
- elif self.misspellingTemplate[disambPage.site.lang] is not None:
+ if self.misspellingTemplate.get(disambPage.site.code) is not None:
for template, params in disambPage.templatesWithParams():
- if template.title() in self.misspellingTemplate[self.mylang]:
+ if (template.title(withNamespace=False) ==
+ self.misspellingTemplate[disambPage.site.code]):
# The correct spelling is in the last paramter.
correctSpelling = params[-1]
# On de.wikipedia, there are some cases where the
@@ -122,12 +132,15 @@
self.alternatives.append(correctSpelling)
return True
- # Overrides the DisambiguationRobot method.
- def setSummaryMessage(self, disambPage, new_targets=[], unlink=False,
- dn=False):
+ def setSummaryMessage(self, disambPage, *args, **kwargs):
+ """
+ Setup the summary message.
+
+ Overrides the DisambiguationRobot method.
+ """
# TODO: setSummaryMessage() in solve_disambiguation now has parameters
# new_targets and unlink. Make use of these here.
- self.comment = i18n.twtranslate(self.mysite, 'misspelling-fixing',
+ self.comment = i18n.twtranslate(self.site, 'misspelling-fixing',
{'page': disambPage.title()})
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 0e108c5..2c2dd26 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -567,7 +567,7 @@
self.main_only = main_only
self.minimum = minimum
- self.mysite = pywikibot.Site()
+ self.site = self.mysite = pywikibot.Site()
self.mylang = self.mysite.lang
self.comment = None
diff --git a/tox.ini b/tox.ini
index ebfd765..5a75cec 100644
--- a/tox.ini
+++ b/tox.ini
@@ -89,6 +89,7 @@
scripts/listpages.py \
scripts/login.py \
scripts/maintenance/__init__.py \
+ scripts/misspelling.py \
scripts/newitem.py \
scripts/noreferences.py \
scripts/pagefromfile.py \
--
To view, visit
https://gerrit.wikimedia.org/r/223270
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I907bb4047d42afa4f9044a870f18cbaa724302c8
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>