http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10251
Revision: 10251 Author: amir Date: 2012-05-24 18:56:28 +0000 (Thu, 24 May 2012) Log Message: ----------- Reverting my edit+disabling trailing feature for fa.wp+adding feature of changing trail to pipe if there is ZWNJ for fa.wp
Modified Paths: -------------- trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py =================================================================== --- trunk/pywikipedia/cosmetic_changes.py 2012-05-24 14:59:29 UTC (rev 10250) +++ trunk/pywikipedia/cosmetic_changes.py 2012-05-24 18:56:28 UTC (rev 10251) @@ -295,14 +295,14 @@
# Adding categories if categories: - #Sorting categories in alphabetic order. beta test only on Persian Wikipedia - if self.site.language() == 'fa': - categories.sort() - #Taking main cats to top - for name in categories: - if re.search(u"(.+?)|(.{,1}?)",name.title()) or name.title()==name.title().split(":")[0]+title: - categories.remove(name) - categories.insert(0, name) + ##Sorting categories in alphabetic order. beta test only on Persian Wikipedia, TODO fix bug for sorting + #if self.site.language() == 'fa': + # categories.sort() + ##Taking main cats to top + # for name in categories: + # if re.search(u"(.+?)|(.{,1}?)",name.title()) or name.title()==name.title().split(":")[0]+title: + # categories.remove(name) + # categories.insert(0, name) text = pywikibot.replaceCategoryLinks(text, categories, site=self.site) # Put the iw message back @@ -443,7 +443,7 @@ newLink = "[[%s]]" % label # Check if we can create a link with trailing characters # instead of a pipelink - elif len(titleWithSection) <= len(label) and \ + elif self.site.sitename() != 'wikipedia:fa' and len(titleWithSection) <= len(label) and \ label[:len(titleWithSection)] == titleWithSection and \ re.sub(trailR, '', label[len(titleWithSection):]) == '': @@ -707,6 +707,11 @@ pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE) exceptions.append(pattern) exceptions.append('table') #exclude tables for now + ##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
pywikipedia-svn@lists.wikimedia.org