Revision: 8613 Author: xqt Date: 2010-10-06 15:08:59 +0000 (Wed, 06 Oct 2010)
Log Message: ----------- 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: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2010-10-06 14:55:50 UTC (rev 8612) +++ trunk/pywikipedia/wikipedia.py 2010-10-06 15:08:59 UTC (rev 8613) @@ -1169,7 +1169,7 @@ """Return True if this is an image description page, False otherwise.""" return self.namespace() == 6
- def isDisambig(self): + def isDisambig(self, get_Index=True): """Return True if this is a disambiguation page, False otherwise.
Relies on the presence of specific templates, identified in @@ -1177,31 +1177,53 @@ pages.
By default, loads a list of template names from the Family file; - if the value in the Family file is None, looks for the list on - [[MediaWiki:Disambiguationspage]]. + if the value in the Family file is None no entry was made, looks for + the list on [[MediaWiki:Disambiguationspage]]. If this page does not + exist, take the mediawiki message.
+ If get_Index is True then also load the templates for index articles + which are given on en-wiki + + Template:Disambig is always assumed to be default, and will be + appended regardless of its existence. + """ if not hasattr(self, "_isDisambig"): if not hasattr(self._site, "_disambigtemplates"): - distl = self._site.family.disambig(self._site.lang) + default = set(self._site.family.disambig('_default')) + try: + distl = self._site.family.disambig(self._site.lang, + fallback=False) + except KeyError: + distl = None if distl is None: try: disambigpages = Page(self._site, "MediaWiki:Disambiguationspage") - self._site._disambigtemplates = set( - link.titleWithoutNamespace() - for link in disambigpages.linkedPages() - if link.namespace() == 10 - ) + disambigs = set(link.titleWithoutNamespace() + for link in disambigpages.linkedPages() + if link.namespace() == 10) + # add index article templates + if get_Index and \ + self._site.sitename() == 'wikipedia:en': + regex = re.compile('(((.+?)))') + content = disambigpages.get() + for index in regex.findall(content): + disambigs.add(index) except NoPage: - self._site._disambigtemplates = set(['Disambig']) + disambigs = set([self._site.mediawiki_message( + 'Disambiguationspage').split(':', 1)[1]]) + # add the default template(s) + self._site._disambigtemplates = disambigs | default else: # Normalize template capitalization self._site._disambigtemplates = set( t[:1].upper() + t[1:] for t in distl ) - disambigInPage = self._site._disambigtemplates.intersection(self.templates()) - self._isDisambig = self.namespace() != 10 and len(disambigInPage) > 0 + disambigInPage = self._site._disambigtemplates.intersection( + self.templates()) + self._isDisambig = self.namespace() != 10 and \ + len(disambigInPage) > 0 return self._isDisambig
def canBeEdited(self):
pywikipedia-svn@lists.wikimedia.org