r8613 pywikipedia - Code Review archive

Repository:pywikipedia
Revision:r8612‎ | r8613 | r8614 >
Date:15:08, 6 October 2010
Author:xqt
Status:resolved (Comments)
Tags:
Comment:
None-Type entry in the family file is obsolete now. Template:Disambig is always assumed to be default regardless of its existence. If no templates are given in the family file and MediaWiki:Disambiguationspage doesn't exist, load the template from mediawiki_message. For en-wiki load index article templates if new parameter get_Index is True (bug #2968140)
Modified paths:
  • /trunk/pywikipedia/wikipedia.py (modified) (history)

Diff [purge]

Index: trunk/pywikipedia/wikipedia.py
@@ -1169,7 +1169,7 @@
11701170 """Return True if this is an image description page, False otherwise."""
11711171 return self.namespace() == 6
11721172
1173 - def isDisambig(self):
 1173+ def isDisambig(self, get_Index=True):
11741174 """Return True if this is a disambiguation page, False otherwise.
11751175
11761176 Relies on the presence of specific templates, identified in
@@ -1177,31 +1177,53 @@
11781178 pages.
11791179
11801180 By default, loads a list of template names from the Family file;
1181 - if the value in the Family file is None, looks for the list on
1182 - [[MediaWiki:Disambiguationspage]].
 1181+ if the value in the Family file is None no entry was made, looks for
 1182+ the list on [[MediaWiki:Disambiguationspage]]. If this page does not
 1183+ exist, take the mediawiki message.
11831184
 1185+ If get_Index is True then also load the templates for index articles
 1186+ which are given on en-wiki
 1187+
 1188+ Template:Disambig is always assumed to be default, and will be
 1189+ appended regardless of its existence.
 1190+
11841191 """
11851192 if not hasattr(self, "_isDisambig"):
11861193 if not hasattr(self._site, "_disambigtemplates"):
1187 - distl = self._site.family.disambig(self._site.lang)
 1194+ default = set(self._site.family.disambig('_default'))
 1195+ try:
 1196+ distl = self._site.family.disambig(self._site.lang,
 1197+ fallback=False)
 1198+ except KeyError:
 1199+ distl = None
11881200 if distl is None:
11891201 try:
11901202 disambigpages = Page(self._site,
11911203 "MediaWiki:Disambiguationspage")
1192 - self._site._disambigtemplates = set(
1193 - link.titleWithoutNamespace()
1194 - for link in disambigpages.linkedPages()
1195 - if link.namespace() == 10
1196 - )
 1204+ disambigs = set(link.titleWithoutNamespace()
 1205+ for link in disambigpages.linkedPages()
 1206+ if link.namespace() == 10)
 1207+ # add index article templates
 1208+ if get_Index and \
 1209+ self._site.sitename() == 'wikipedia:en':
 1210+ regex = re.compile('\(\((.+?)\)\)')
 1211+ content = disambigpages.get()
 1212+ for index in regex.findall(content):
 1213+ disambigs.add(index)
11971214 except NoPage:
1198 - self._site._disambigtemplates = set(['Disambig'])
 1215+ disambigs = set([self._site.mediawiki_message(
 1216+ 'Disambiguationspage').split(':', 1)[1]])
 1217+ # add the default template(s)
 1218+ self._site._disambigtemplates = disambigs | default
11991219 else:
12001220 # Normalize template capitalization
12011221 self._site._disambigtemplates = set(
12021222 t[:1].upper() + t[1:] for t in distl
12031223 )
1204 - disambigInPage = self._site._disambigtemplates.intersection(self.templates())
1205 - self._isDisambig = self.namespace() != 10 and len(disambigInPage) > 0
 1224+ disambigInPage = self._site._disambigtemplates.intersection(
 1225+ self.templates())
 1226+ self._isDisambig = self.namespace() != 10 and \
 1227+ len(disambigInPage) > 0
12061228 return self._isDisambig
12071229
12081230 def canBeEdited(self):

Follow-up revisions

RevisionCommit summaryAuthorDate
r8615update from trunk r8613xqt16:04, 6 October 2010
r8645follow up bugfix for r8613.xqt22:16, 12 October 2010

Comments

#Comment by Multichill (talk | contribs)   20:23, 12 October 2010

This breaks my bots.

 File "/home/multichill/pywikipedia/imagerecat.py", line 217, in filterDisambiguation
   cat, defaultNamespace=14).isDisambig()):
 File "/home/multichill/pywikipedia/wikipedia.py", line 1193, in isDisambig
   default = set(self._site.family.disambig('_default'))
 File "/home/multichill/pywikipedia/family.py", line 3590, in disambig
   return self.disambiguationTemplates[fallback]

KeyError: '_default'

#Comment by Xqt (talk | contribs)   22:30, 12 October 2010

commons has no _default fallback. isDisambig() fixed in r8645

Status & tagging log

  NODES