Revision: 5711
Author: russblau
Date: 2008-07-13 20:56:14 +0000 (Sun, 13 Jul 2008)
Log Message:
-----------
Change page.isDisambig() method to allow retrieval of disambig template names from the live wiki instead of the Family file, and implement for English Wikipedia; not implemented for all sites by default because users need to decide whether the list on their local [[MediaWiki:Disambiguationspage]] is adequate.
Modified Paths:
--------------
trunk/pywikipedia/families/wikipedia_family.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/families/wikipedia_family.py
===================================================================
--- trunk/pywikipedia/families/wikipedia_family.py 2008-07-12 18:18:22 UTC (rev 5710)
+++ trunk/pywikipedia/families/wikipedia_family.py 2008-07-13 20:56:14 UTC (rev 5711)
@@ -513,6 +513,8 @@
}
self.disambiguationTemplates = {
+ # set value to None, instead of a list, to retrieve names from
+ # the live wiki ([[MediaWiki:Disambiguationspage]]
'_default': [u'Disambig'],
'af': [u'Dubbelsinnig', u'Disambig'],
'als': [u'Begriffsklärung', u'Disambig'],
@@ -536,13 +538,7 @@
'da': [u'Flertydig'],
'de': [u'Begriffsklärung', u'BKS', u'Disambig'],
'el': [u'Disambig', u'Αποσαφ', u'Αποσαφήνιση'],
- 'en': [u'Disambig', u'Disambiguation', u'Dab', u'Disamb',
- u'Disambig-cleanup', u'Diasmbig', u'Bio-dab',
- u'Geodis', u'Given name', u'Hndis', u'Hndisambig',
- u'Hndis-cleanup', u'Hospitaldis', u'Letter disambig',
- u'Mathdab', u'NA Broadcast List', u'Numberdis',
- u'POWdis', u'Roadis', u'Roaddis', u'Schooldis',
- u'Shipindex', u'SIA', u'Surname', u'TLA', u'Airport disambig' ],
+ 'en': None,
'eo': [u'Apartigilo', u'Disambig'],
'es': [u'Desambiguacion', u'Desambiguación', u'Desambig', u'Disambig',u'Des'],
'et': [u'Täpsustuslehekülg', u'Täpsustus', u'Disambig'],
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2008-07-12 18:18:22 UTC (rev 5710)
+++ trunk/pywikipedia/wikipedia.py 2008-07-13 20:56:14 UTC (rev 5711)
@@ -983,12 +983,35 @@
def isDisambig(self):
"""Return True if this is a disambiguation page, False otherwise.
- Relies on the presence of specific templates, identified in the Family
- file, to identify disambiguation pages.
+ Relies on the presence of specific templates, identified in
+ the Family file or on a wiki page, to identify disambiguation
+ 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 not hasattr(self, '_isDisambig'):
- foo = self.templates()
+ if not hasattr(self, "_isDisambig"):
+ if not hasattr(self.site(), "_disambigtemplates"):
+ self.site()._disambigtemplates = self.site().family.disambig(self.site().lang)
+ if self.site()._disambigtemplates is None:
+ try:
+ disambigpages = Page(self.site(),
+ "MediaWiki:Disambiguationspage")
+ self.site()._disambigtemplates = [
+ link.titleWithoutNamespace()
+ for link in disambigpages.linkedPages()
+ if link.namespace() == 10
+ ]
+ except NoPage:
+ self.site()._disambigtemplates = ['Disambig']
+ for t in self.templates():
+ if t in self.site()._disambigtemplates:
+ self._isDisambig = True
+ break
+ else:
+ self._isDisambig = False
return self._isDisambig
def getReferences(self,
@@ -1679,7 +1702,12 @@
Template parameters are ignored.
"""
- return [template for (template, param) in self.templatesWithParams(get_redirect=get_redirect)]
+ if not hasattr(self, "_templates"):
+ self._templates = [template
+ for (template, param)
+ in self.templatesWithParams(
+ get_redirect=get_redirect)]
+ return self._templates
def templatesWithParams(self, thistxt=None, get_redirect=False):
"""Return a list of templates used on this Page.
@@ -1690,12 +1718,10 @@
If thistxt is set, it is used instead of current page content.
"""
- check_disambig = (thistxt is None)
if not thistxt:
try:
thistxt = self.get(get_redirect=get_redirect)
except (IsRedirectPage, NoPage):
- self._isDisambig = False
return []
# remove commented-out stuff etc.
@@ -1746,9 +1772,6 @@
u"Page %s contains invalid template name {{%s}}."
% (self.title(), name.strip()))
continue
- if check_disambig and \
- name in self.site().family.disambig(self.site().lang):
- self._isDisambig = True
# Parameters
paramString = m.group('params')
params = []
@@ -1776,8 +1799,6 @@
# Add it to the result
result.append((name, params))
- if check_disambig and not hasattr(self, "_isDisambig"):
- self._isDisambig = False
return result
def getRedirectTarget(self):