http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9969
Revision: 9969 Author: xqt Date: 2012-03-04 15:55:41 +0000 (Sun, 04 Mar 2012) Log Message: ----------- fixReferences(), some parts from AnomieBOT
Modified Paths: -------------- trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py =================================================================== --- trunk/pywikipedia/cosmetic_changes.py 2012-03-04 15:32:08 UTC (rev 9968) +++ trunk/pywikipedia/cosmetic_changes.py 2012-03-04 15:55:41 UTC (rev 9969) @@ -170,6 +170,7 @@ text = self.removeNonBreakingSpaceBeforePercent(text) text = self.fixSyntaxSave(text) text = self.fixHtml(text) + text = self.fixReferences(text) text = self.fixStyle(text) text = self.fixTypo(text) if self.site.lang in ['ckb', 'fa']: @@ -614,9 +615,18 @@ text = pywikibot.replaceExcept(text, r'(?i)([\r\n]) *<h%d> *([^<]+?) *</h%d> *([\r\n])'%(level, level), r'%s'%equals, exceptions) + # TODO: maybe we can make the bot replace <p> tags with \r\n's. + return text + + def fixReferences(self, text): + #http://en.wikipedia.org/wiki/User:AnomieBOT/source/tasks/OrphanReferenceFixe... + exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace'] + + # it should be name = " or name=" NOT name =" + text = re.sub(r'(?i)<ref +name(= *| *=)"', r'<ref name="', text) #remove empty <ref/>-tag text = pywikibot.replaceExcept(text, r'(?i)(<ref\s*/>|<ref *>\s*</ref>)', r'', exceptions) - # TODO: maybe we can make the bot replace <p> tags with \r\n's. + text = pywikibot.replaceExcept(text, r'(?i)<ref\s+([^>]+?)\s*>\s*</ref>', r'<ref \1/>', exceptions) return text
def fixStyle(self, text):
pywikipedia-svn@lists.wikimedia.org