jenkins-bot has submitted this change and it was merged.
Change subject: Use the API to retrieve redirects to the category redirect template (this time with caching)
......................................................................
Use the API to retrieve redirects to the category redirect template
(this time with caching)
Change-Id: I7af283b3b7a18bd713627cb5f1d8667773e3f3c6
---
M pywikibot/families/wikipedia_family.py
M pywikibot/family.py
2 files changed, 24 insertions(+), 10 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/wikipedia_family.py b/pywikibot/families/wikipedia_family.py
index 0149a8e..67f3fd4 100644
--- a/pywikibot/families/wikipedia_family.py
+++ b/pywikibot/families/wikipedia_family.py
@@ -54,11 +54,7 @@
'arz': (u'تحويل تصنيف',),
'cs': (u'Zastaralá kategorie',),
'da': (u'Kategoriomdirigering',),
- 'en': (u'Category redirect',
- u'Category Redirect',
- u"Categoryredirect",
- u'Catredirect',
- u'Cat redirect',),
+ 'en': (u'Category redirect',),
'es': (u'Categoría redirigida',),
'eu': (u'Kategoria redirect',),
'fa': (u'رده بهتر',
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 59484c9..a7c58d4 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -653,7 +653,6 @@
}
# A list of category redirect template names in different languages
- # Note: It *is* necessary to list template redirects here
self.category_redirect_templates = {
'_default': []
}
@@ -858,15 +857,34 @@
% {'language_code': code})
def category_redirects(self, code, fallback="_default"):
- if code in self.category_redirect_templates:
- return self.category_redirect_templates[code]
- elif fallback:
- return self.category_redirect_templates[fallback]
+ if not hasattr(self, "_catredirtemplates") or code not in self._catredirtemplates:
+ self.get_cr_templates(code, fallback)
+ if code in self._catredirtemplates:
+ return self._catredirtemplates[code]
else:
raise KeyError(
"ERROR: title for category redirect template in language '%s' unknown"
% code)
+ def get_cr_templates(self, code, fallback):
+ if not hasattr(self, "_catredirtemplates"):
+ self._catredirtemplates = {}
+ if code in self.category_redirect_templates:
+ cr_template = self.category_redirect_templates[code][0]
+ else:
+ cr_template = self.category_redirect_templates[fallback][0]
+ # start with list of category redirect templates from family file
+ cr_page = pywikibot.Page(pywikibot.Site(code, self),
+ "Template:" + cr_template)
+ cr_list = list(self.category_redirect_templates[code])
+ # retrieve all redirects to primary template from API,
+ # add any that are not already on the list
+ for t in cr_page.backlinks(filterRedirects=True, namespaces=10):
+ newtitle = t.title(withNamespace=False)
+ if newtitle not in cr_list:
+ cr_list.append(newtitle)
+ self._catredirtemplates[code] = cr_list
+
def disambig(self, code, fallback='_default'):
if code in self.disambiguationTemplates:
return self.disambiguationTemplates[code]
--
To view, visit https://gerrit.wikimedia.org/r/85203
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7af283b3b7a18bd713627cb5f1d8667773e3f3c6
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Aligned help with implementation
......................................................................
Aligned help with implementation
Change-Id: I32340b0ed4e6bf39a793ccb6b7288c02ed1b941c
---
M pywikibot/config2.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index ee62581..1085ddc 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -105,7 +105,8 @@
provided in this argument
2. If the user has a PYWIKIBOT2_DIR environment variable, use the value
of it
- 3. Use (and if necessary create) a 'pywikibot' folder (Windows) or
+ 3. Use (and if necessary create) a 'pywikibot' folder under
+ 'Application Data' or 'AppData\Roaming' (Windows) or
'.pywikibot' directory (Unix and similar) under the user's home
directory.
--
To view, visit https://gerrit.wikimedia.org/r/87016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I32340b0ed4e6bf39a793ccb6b7288c02ed1b941c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Enabling usage of Disambiguator
......................................................................
Enabling usage of Disambiguator
Per help page [1] and some examples [2] [3] when someone runs isDisambig method this code checks if the Disambiguator is enabled,
By checking list of extensions in siteinfo, if the extension is not enabaled (like [4]) returns the old way
but if exists (like [5]) uses API to check being disambiguation. For more info see the examples I showed in [2] and [3]
It's prttey important, and please review as soon as possible because if the extension is enabled, the old way doens't work now.
See the bug.
[1]: https://www.mediawiki.org/wiki/Extension:Disambiguator
[2]: https://en.wikipedia.org/w/api.php?action=query&titles=Aa%20River&prop=page…
[3]: https://en.wikipedia.org/w/api.php?action=query&titles=Tehran&prop=pageprop…
[4]: http://tools.wmflabs.org/wikitest-rtl/w/index.php?title=Special:Disambiguat…
[5]: https://en.wikipedia.org/wiki/Special:DisambiguationPages
Bug: 54480
Change-Id: Ie3c46671d888cf917640fc732a28cc827028d0de
---
M wikipedia.py
1 file changed, 31 insertions(+), 6 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia.py b/wikipedia.py
index a044026..15a40f2 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -1510,11 +1510,38 @@
def isImage(self):
"""Return True if this is an image description page, False otherwise."""
return self.namespace() == 6
-
def isDisambig(self, get_Index=True):
- """Return True if this is a disambiguation page, False otherwise.
+ """Return True if this is a disambiguation page, False otherwise."""
+ if not hasattr(self, "_isDisambig"):
+ extensions = self._site.siteinfo('extensions')
+ namesofextensions = []
+ for extension in extensions:
+ namesofextensions.append(extension['name'])
+ if not u'Disambiguator' in namesofextensions:
+ return self._isDisambig_disambiguationspage(get_Index)
+ else:
+ return self._isDisambig_disambiguator(get_Index)
+ else:
+ return self._isDisambig
- Relies on the presence of specific templates, identified in
+ def _isDisambig_disambiguator(self, get_Index=True):
+ params = {
+ 'action' : 'query',
+ 'titles' : self.title(),
+ 'prop' : 'pageprops',
+ 'ppprop' : 'disambiguation'
+ }
+ data = query.GetData(params, self._site)['query']['pages'].values()[0]
+ self._isDisambig = False
+ if data.has_key(u'missing'):
+ raise NoPage('Page %s does not exist' % self.title(asLink=True))
+ if data.has_key(u'pageprops'):
+ if data[u'pageprops'].has_key(u'disambiguation'):
+ self._isDisambig = True
+ return self._isDisambig
+
+ def _isDisambig_disambiguationspage(self, get_Index=True):
+ """Relies on the presence of specific templates, identified in
the Family file or on a wiki page, to identify disambiguation
pages.
@@ -1527,9 +1554,7 @@
which are given on en-wiki
Template:Disambig is always assumed to be default, and will be
- appended regardless of its existence.
-
- """
+ appended regardless of its existence."""
if not hasattr(self, "_isDisambig"):
if not hasattr(self._site, "_disambigtemplates"):
try:
--
To view, visit https://gerrit.wikimedia.org/r/86047
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3c46671d888cf917640fc732a28cc827028d0de
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot