Revision: 4818 Author: rotem Date: 2008-01-05 18:23:43 +0000 (Sat, 05 Jan 2008)
Log Message: ----------- Moving the obsolete language check before the check if the language code is listed, to make it possible to create a language without the obsolete languages in the langs variable. Raising a KeyError when a user tries to create a site using an obsolete language code. Removing the obsolete language codes from the self.langs of Wikimedia wikis. Several additional fixes.
Modified Paths: -------------- trunk/pywikipedia/families/commons_family.py trunk/pywikipedia/families/meta_family.py trunk/pywikipedia/families/species_family.py trunk/pywikipedia/families/test_family.py trunk/pywikipedia/families/wikibooks_family.py trunk/pywikipedia/families/wikinews_family.py trunk/pywikipedia/families/wikipedia_family.py trunk/pywikipedia/families/wikiquote_family.py trunk/pywikipedia/families/wikisource_family.py trunk/pywikipedia/families/wikiversity_family.py trunk/pywikipedia/families/wiktionary_family.py trunk/pywikipedia/family.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/families/commons_family.py =================================================================== --- trunk/pywikipedia/families/commons_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/commons_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -31,6 +31,3 @@
def version(self, code): return "1.12alpha" - - def shared_image_repository(self, code): - return ('commons', 'commons')
Modified: trunk/pywikipedia/families/meta_family.py =================================================================== --- trunk/pywikipedia/families/meta_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/meta_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -12,7 +12,7 @@ self.name = 'meta' self.langs = { 'meta': 'meta.wikimedia.org', - } + }
self.namespaces[4] = { '_default': [u'Meta', self.namespaces[4]['_default']],
Modified: trunk/pywikipedia/families/species_family.py =================================================================== --- trunk/pywikipedia/families/species_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/species_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -12,7 +12,7 @@ self.name = 'species' self.langs = { 'species': 'species.wikimedia.org', - } + }
self.namespaces[4] = { '_default': [u'Wikispecies', self.namespaces[4]['_default']],
Modified: trunk/pywikipedia/families/test_family.py =================================================================== --- trunk/pywikipedia/families/test_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/test_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -10,7 +10,7 @@ self.name = 'test' self.langs = { 'test': 'test.wikipedia.org', - } + }
self.namespaces[4] = { '_default': [u'Wikipedia', self.namespaces[4]['_default']], @@ -21,3 +21,6 @@
def version(self, code): return "1.12alpha" + + def shared_image_repository(self, code): + return ('commons', 'commons')
Modified: trunk/pywikipedia/families/wikibooks_family.py =================================================================== --- trunk/pywikipedia/families/wikibooks_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikibooks_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -11,15 +11,6 @@ family.Family.__init__(self) self.name = 'wikibooks'
- self.langs = { - 'dk':'da.wikibooks.org', - 'jp':'ja.wikibooks.org', - 'minnan':'zh-min-nan.wikibooks.org', - 'nb':'no.wikibooks.org', - 'zh-cn':'zh.wikibooks.org', - 'zh-tw':'zh.wikibooks.org' - } - for lang in self.knownlanguages: self.langs[lang] = '%s.wikibooks.org' % lang
Modified: trunk/pywikipedia/families/wikinews_family.py =================================================================== --- trunk/pywikipedia/families/wikinews_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikinews_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -13,7 +13,7 @@ self.name = 'wikinews'
for lang in self.knownlanguages: - self.langs[lang] = lang+'.wikinews.org' + self.langs[lang] = '%s.wikinews.org' % lang
# Override defaults self.namespaces[2]['pl'] = u'Wikireporter'
Modified: trunk/pywikipedia/families/wikipedia_family.py =================================================================== --- trunk/pywikipedia/families/wikipedia_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikipedia_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -12,18 +12,8 @@ family.Family.__init__(self) self.name = 'wikipedia'
- self.langs = { - 'dk':'da.wikipedia.org', - 'jp':'ja.wikipedia.org', - 'minnan':'zh-min-nan.wikipedia.org', - 'nb':'no.wikipedia.org', - 'test':'test.wikipedia.org', - 'zh-cn':'zh.wikipedia.org', - 'zh-tw':'zh.wikipedia.org', - } for lang in self.knownlanguages: - if lang not in self.langs: - self.langs[lang] = lang+'.wikipedia.org' + self.langs[lang] = '%s.wikipedia.org' % lang
# Override defaults self.namespaces[2]['cs'] = u'Wikipedista' @@ -723,7 +713,7 @@ 'ru','fi','no','zh','tr','eo','sk','cs','ca','ro', 'hu','da','id','vo','lt','sl','lmo','uk','he','et', 'hr','sr','ceb','bg','ko','gl','nn','ar','te','vi', - 'ms','bs','eu','simple','new','el','th','is','lb','sq', + 'ms','bs','eu','simple','new','el','th','is','lb','sq', 'fa','az','br','io','la','bpy','su','nap','sh','cy', 'ka','bn','scn','nds','lv','jv','oc','ku','pms','wa', 'ast','hi','af','roa-tara','mr','mk','ta','ht','ksh','an',
Modified: trunk/pywikipedia/families/wikiquote_family.py =================================================================== --- trunk/pywikipedia/families/wikiquote_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikiquote_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -11,14 +11,6 @@ family.Family.__init__(self) self.name = 'wikiquote'
- self.langs = { - 'dk':'da.wikiquote.org', - 'jp':'ja.wikiquote.org', - 'minnan':'zh-min-nan.wikiquote.org', - 'nb':'no.wikiquote.org', - 'zh-cn':'zh.wikiquote.org', - 'zh-tw':'zh.wikiquote.org' - } self.languages_by_size = [ 'en','de','pl','it','sk','ru','pt','bs','bg','sl', 'es','tr','he','zh','id','sv','lt','ja','no','hu', @@ -31,7 +23,7 @@ 'hy','ga','kk','ks','kw','tk',]
for lang in self.languages_by_size: - self.langs[lang] = lang+'.wikiquote.org' + self.langs[lang] = '%s.wikiquote.org' % lang
# Most namespaces are inherited from family.Family. # Translation used on all wikis for the different namespaces.
Modified: trunk/pywikipedia/families/wikisource_family.py =================================================================== --- trunk/pywikipedia/families/wikisource_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikisource_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -11,18 +11,10 @@ self.name = 'wikisource'
self.langs = { - '-':'wikisource.org', - 'dk':'da.wikisource.org', - 'jp':'ja.wikisource.org', - 'minnan':'zh-min-nan.wikisource.org', - 'nb':'no.wikisource.org', - 'zh-cn':'zh.wikisource.org', - 'zh-tw':'zh.wikisource.org' - } - + '-': 'wikisource.org', + } for lang in self.knownlanguages: - if lang not in self.langs: - self.langs[lang] = lang+'.wikisource.org' + self.langs[lang] = '%s.wikisource.org' % lang
# Override defaults self.namespaces[2]['pl'] = 'Wikiskryba'
Modified: trunk/pywikipedia/families/wikiversity_family.py =================================================================== --- trunk/pywikipedia/families/wikiversity_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wikiversity_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -14,10 +14,8 @@ self.langs = { 'beta': 'beta.wikiversity.org', } - for lang in self.knownlanguages: - if lang not in self.langs: - self.langs[lang] = lang+'.wikiversity.org' + self.langs[lang] = '%s.wikiversity.org' % lang
# Most namespaces are inherited from family.Family. # Translation used on all wikis for the different namespaces.
Modified: trunk/pywikipedia/families/wiktionary_family.py =================================================================== --- trunk/pywikipedia/families/wiktionary_family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/families/wiktionary_family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -11,18 +11,10 @@ def __init__(self): family.Family.__init__(self) self.name = 'wiktionary' - self.langs = { - 'dk':'da.wiktionary.org', - 'jp':'ja.wiktionary.org', - 'minnan':'zh-min-nan.wiktionary.org', - 'nb':'no.wiktionary.org', - 'zh-cn':'zh.wiktionary.org', - 'zh-tw':'zh.wiktionary.org' - }
for lang in self.knownlanguages: - if not lang in ['ee','ht','ny', 'se', 'tum']: - self.langs[lang] = lang+'.wiktionary.org' + if lang not in ['ee','ht','ny', 'se', 'tum']: + self.langs[lang] = '%s.wiktionary.org' % lang
# Override defaults self.namespaces[2]['pl'] = u'Wikipedysta'
Modified: trunk/pywikipedia/family.py =================================================================== --- trunk/pywikipedia/family.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/family.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -2409,7 +2409,7 @@ 'mn', 'os', 'ru', 'sr', 'tg', 'tk', 'udm', 'uk', 'xal' ], 'scand': [ - 'da', 'fo', 'is', 'nb', 'no', 'sv' + 'da', 'fo', 'is', 'no', 'sv' ], }
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-01-05 17:50:45 UTC (rev 4817) +++ trunk/pywikipedia/wikipedia.py 2008-01-05 18:23:43 UTC (rev 4818) @@ -3660,18 +3660,22 @@ self.family = Family(fam, fatal = False) else: self.family = fam - + + # if we got an outdated language code, use the new one instead. + if self.family.obsolete.has_key(self.lang): + if self.family.obsolete[self.lang] is not None: + self.lang = self.family.obsolete[self.lang] + else: + # no such language anymore + raise KeyError("Language %s in family %s is obsolete" % (self.lang, self.family.name)) + if self.lang not in self.languages(): if self.lang == 'zh-classic' and 'zh-classical' in self.languages(): self.lang = 'zh-classical' # ev0l database hack (database is varchar[10] -> zh-classical is cut to zh-classic. - else: + else: raise KeyError("Language %s does not exist in family %s"%(self.lang,self.family.name))
- # if we got an outdated language code, use the new one instead. - if self.lang in self.family.obsolete and self.family.obsolete[self.lang]: - self.lang = self.family.obsolete[self.lang] - self.messages=False self._mediawiki_messages = {} self.nocapitalize = self.lang in self.family.nocapitalize