http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10425
Revision: 10425 Author: xqt Date: 2012-06-28 06:55:52 +0000 (Thu, 28 Jun 2012) Log Message: ----------- invalid replacements inside file links; fix for bug #3538506
Modified Paths: -------------- trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py =================================================================== --- trunk/pywikipedia/cosmetic_changes.py 2012-06-26 21:18:08 UTC (rev 10424) +++ trunk/pywikipedia/cosmetic_changes.py 2012-06-28 06:55:52 UTC (rev 10425) @@ -208,6 +208,7 @@ old instances standardizeInterwiki and standardizeCategories The page footer has the following section in that sequence: 1. categories + 2a TODO:template beyond categories 2. additional information depending on local site policy 3. stars templates for featured and good articles 4. interwiki links @@ -729,8 +730,8 @@ # This only works if there are only two items in digits dict old = digits[digits.keys()[0]] # do not change inside file links - namespaces = list(self.site.namespace(6, all = True)) - pattern = re.compile(u'[[(' + '|'.join(namespaces) + '):.+?..+?]]', + namespaces = list(self.site.namespace(6, all=True)) + pattern = re.compile(u'[[(' + '|'.join(namespaces) + '):.+?.\w+? *(|[^[]*?([[[^[]*?]][^[]*?)?)?]]', re.UNICODE) exceptions.append(pattern) text = pywikibot.replaceExcept(text, u',', u'،', exceptions) @@ -742,8 +743,8 @@ text = pywikibot.replaceExcept(text, u'ه', u'ھ', exceptions) text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions) text = pywikibot.replaceExcept(text, ur'[ىي]', u'ی', exceptions) - # replace persian digits - for i in range(0,10): + # replace persian/arabic digits + for i in xrange(0,10): text = pywikibot.replaceExcept(text, old[i], new[i], exceptions) # do not change digits in class, style and table params pattern = re.compile(u'\w+=(".+?"|\d+)', re.UNICODE) @@ -752,13 +753,14 @@ pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE) exceptions.append(pattern) exceptions.append('table') #exclude tables for now + # replace digits + for i in xrange(0, 10): + text = pywikibot.replaceExcept(text, str(i), new[i], exceptions) ##fixing pipe and trailing for fa. Thanks ZxxZxxZ if self.site.lang=='fa': faChrs = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + u'ًٌٍَُِّْٓٔ' text = re.sub(u'[[([^]|]*)]]([%s]+)' % faChrs, ur'[[\1|\1\2]]', text) text = re.sub(u'[[([^]|]*)|(.+?)]]([%s]+)' % faChrs, ur'[[\1|\2\3]]', text) - for i in range(0,10): - text = pywikibot.replaceExcept(text, str(i), new[i], exceptions) return text
# Retrieved from "http://commons.wikimedia.org/wiki/Commons:Tools/pywiki_file_description_clea..."
pywikipedia-svn@lists.wikimedia.org