Revision: 5614 Author: nicdumz Date: 2008-06-23 08:28:03 +0000 (Mon, 23 Jun 2008)
Log Message: ----------- Adding crossnamespace interwiki linking support, based on patch #1992057 [Add support for cross-namespace interwiki] by Stig Meireles Johansen
Modified Paths: -------------- trunk/pywikipedia/families/wikipedia_family.py trunk/pywikipedia/family.py trunk/pywikipedia/interwiki.py
Modified: trunk/pywikipedia/families/wikipedia_family.py =================================================================== --- trunk/pywikipedia/families/wikipedia_family.py 2008-06-23 07:22:51 UTC (rev 5613) +++ trunk/pywikipedia/families/wikipedia_family.py 2008-06-23 08:28:03 UTC (rev 5614) @@ -837,6 +837,78 @@ 'id', 'lv', 'sw', 'tt', 'uk', 'vo', 'ga', 'na', 'es', 'nl', 'da', 'dk', 'sv', 'test']
+ self.crossnamespace[0] = { + '_default': { + 'pt': [102], + 'als': [104], + 'es': [104], + 'fr': [104], + 'lt': [104] + } + } + self.crossnamespace[1] = { + '_default': { + 'pt': [103], + 'als': [105], + 'es': [105], + 'fr': [105], + 'lt': [105] + } + } + self.crossnamespace[102] = { + 'pt': { + '_default': [0], + 'als': [0, 104], + 'es': [0, 104], + 'fr': [0, 104], + 'lt': [0, 104] + } + } + self.crossnamespace[103] = { + 'pt': { + '_default': [1], + 'als': [1, 105], + 'es': [1, 105], + 'fr': [1, 105], + 'lt': [1, 105] + } + } + self.crossnamespace[104] = { + 'als': { + '_default': [0], + 'pt': [0, 102] + }, + 'es': { + '_default': [0], + 'pt': [0, 102] + }, + 'fr': { + '_default': [0], + 'pt': [0, 102] + }, + 'lt': { + '_default': [0], + 'pt': [0, 102] + } + } + self.crossnamespace[105] = { + 'als': { + '_default': [1], + 'pt': [0, 103] + }, + 'es': { + '_default': [1], + 'pt': [0, 103] + }, + 'fr': { + '_default': [1], + 'pt': [0, 103] + }, + 'lt': { + '_default': [1], + 'pt': [0, 103] + } + } def get_known_families(self, site): # In Swedish Wikipedia 's:' is part of page title not a family # prefix for 'wikisource'.
Modified: trunk/pywikipedia/family.py =================================================================== --- trunk/pywikipedia/family.py 2008-06-23 07:22:51 UTC (rev 5613) +++ trunk/pywikipedia/family.py 2008-06-23 08:28:03 UTC (rev 5614) @@ -2637,6 +2637,25 @@ # http://www.mediawiki.org/wiki/Extension:LDAP_Authentication self.ldapDomain = ()
+ # Allows crossnamespace interwiki linking. + # Lists the possible crossnamespaces combinations + # keys are originating NS + # values are dicts where: + # keys are the originating langcode, or _default + # values are dicts where: + # keys are the languages that can be linked to from the lang+ns, or _default + # values are a list of namespace numbers + self.crossnamespace = {} + #### Examples : + ## Allowing linking to pt' 102 NS from any other lang' 0 NS is + # self.crossnamespace[0] = { + # '_default': { 'pt': [102]} + # } + ## While allowing linking from pt' 102 NS to any other lang' = NS is + # self.crossnamespace[102] = { + # 'pt': { '_default': [0]} + # } + def _addlang(self, code, location, namespaces = {}): """Add a new language to the langs and namespaces of the family. This is supposed to be called in the constructor of the family."""
Modified: trunk/pywikipedia/interwiki.py =================================================================== --- trunk/pywikipedia/interwiki.py 2008-06-23 07:22:51 UTC (rev 5613) +++ trunk/pywikipedia/interwiki.py 2008-06-23 08:28:03 UTC (rev 5614) @@ -591,6 +591,12 @@ # We have seen this page before, don't ask again. return False elif self.originPage.namespace() != linkedPage.namespace(): + # Allow for a mapping between different namespaces + crossFrom = self.originPage.site().family.crossnamespace.get(self.originPage.namespace(), {}) + crossTo = crossFrom.get(self.originPage.site().language(), crossFrom.get('_default', {})) + nsmatch = crossTo.get(linkedPage.site().language(), crossTo.get('_default', [])) + if linkedPage.namespace() in nsmatch: + return False if globalvar.autonomous: wikipedia.output(u"NOTE: Ignoring link from page %s in namespace %i to page %s in namespace %i." % (self.originPage.aslink(True), self.originPage.namespace(), linkedPage.aslink(True), linkedPage.namespace())) # Fill up foundIn, so that we will not write this notice