r13298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13297‎ | r13298 | r13299 >
Date:16:36, 24 March 2006
Author:gabrielwicke
Status:old
Tags:
Comment:
Provide some cleanup if tidy is disabled:

* fix invalid nesting of anchors and i/b
* remove empty i/b tags
* remove divs inside anchors

Fixes several test cases
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -250,6 +250,32 @@
251251
252252 if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) {
253253 $text = Parser::tidy($text);
 254+ } else {
 255+ # attempt to sanitize at least some nesting problems
 256+ # (bug #2702 and quite a few others)
 257+ $tidyregs = array(
 258+ # ''Something [http://www.cool.com cool''] -->
 259+ # <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a>
 260+ '/(<([bi])>)(<([bi])>)?([^<]*)(<\/?a[^<]*>)([^<]*)(<\/\\4>)?(<\/\\2>)/' =>
 261+ '\\1\\3\\5\\8\\9\\6\\1\\3\\7\\8\\9',
 262+ # fix up an anchor inside another anchor, only
 263+ # at least for a single single nested link (bug 3695)
 264+ '/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\/a>(.*)<\/a>/' =>
 265+ '\\1\\2</a>\\3</a>\\1\\4</a>',
 266+ # fix div inside inline elements- doBlockLevels won't wrap a line which
 267+ # contains a div, so fix it up here; replace
 268+ # div with escaped text
 269+ '/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\/div>)([^<]*)(<\/\\2>)/' =>
 270+ '\\1\\3&lt;div\\5&gt;\\6&lt;/div&gt;\\8\\9',
 271+ # remove empty italic or bold tag pairs, some
 272+ # introduced by rules above
 273+ '/<([bi])><\/\\1>/' => ''
 274+ );
 275+
 276+ $text = preg_replace(
 277+ array_keys( $tidyregs ),
 278+ array_values( $tidyregs ),
 279+ $text );
254280 }
255281
256282 wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );

Status & tagging log