http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9278
Revision: 9278 Author: xqt Date: 2011-05-29 09:40:40 +0000 (Sun, 29 May 2011) Log Message: ----------- prevents category removals from leaving gaps in category listings - update from trunk r9225
Modified Paths: -------------- branches/rewrite/pywikibot/textlib.py
Modified: branches/rewrite/pywikibot/textlib.py =================================================================== --- branches/rewrite/pywikibot/textlib.py 2011-05-29 09:32:20 UTC (rev 9277) +++ branches/rewrite/pywikibot/textlib.py 2011-05-29 09:40:40 UTC (rev 9278) @@ -584,9 +584,18 @@ title = title.replace(r"\ ", "[ _]+").replace(r"_", "[ _]+") categoryR = re.compile(r'[[\s*(%s)\s*:\s*%s\s*((?:|[^]]+)?]])' % (catNamespace, title), re.I) + categoryRN = re.compile(r'^[^\S\n]*[[\s*(%s)\s*:\s*%s\s*((?:|[^]]+)?]])[^\S\n]*\n' + % (catNamespace, title), re.I | re.M) if newcat is None: - text = replaceExcept(oldtext, categoryR, '', + """ First go through and try the more restrictive regex that removes + an entire line, if the category is the only thing on that line (this + prevents blank lines left over in category lists following a removal.) + """ + + text = replaceExcept(oldtext, categoryRN, '' ['nowiki', 'comment', 'math', 'pre', 'source']) + text = replaceExcept(text, categoryR, '', + ['nowiki', 'comment', 'math', 'pre', 'source']) else: text = replaceExcept(oldtext, categoryR, '[[%s:%s\2' % (site.namespace(14),
pywikipedia-svn@lists.wikimedia.org