Index: trunk/pywikipedia/wikipedia.py |
— | — | @@ -1169,7 +1169,7 @@ |
1170 | 1170 | """Return True if this is an image description page, False otherwise.""" |
1171 | 1171 | return self.namespace() == 6 |
1172 | 1172 | |
1173 | | - def isDisambig(self): |
| 1173 | + def isDisambig(self, get_Index=True): |
1174 | 1174 | """Return True if this is a disambiguation page, False otherwise. |
1175 | 1175 | |
1176 | 1176 | Relies on the presence of specific templates, identified in |
— | — | @@ -1177,31 +1177,53 @@ |
1178 | 1178 | pages. |
1179 | 1179 | |
1180 | 1180 | 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. |
1183 | 1184 | |
| 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 | + |
1184 | 1191 | """ |
1185 | 1192 | if not hasattr(self, "_isDisambig"): |
1186 | 1193 | 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 |
1188 | 1200 | if distl is None: |
1189 | 1201 | try: |
1190 | 1202 | disambigpages = Page(self._site, |
1191 | 1203 | "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) |
1197 | 1214 | 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 |
1199 | 1219 | else: |
1200 | 1220 | # Normalize template capitalization |
1201 | 1221 | self._site._disambigtemplates = set( |
1202 | 1222 | t[:1].upper() + t[1:] for t in distl |
1203 | 1223 | ) |
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 |
1206 | 1228 | return self._isDisambig |
1207 | 1229 | |
1208 | 1230 | def canBeEdited(self): |