Index: trunk/phase3/includes/Parser.php |
— | — | @@ -250,6 +250,32 @@ |
251 | 251 | |
252 | 252 | if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) { |
253 | 253 | $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<div\\5>\\6</div>\\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 ); |
254 | 280 | } |
255 | 281 | |
256 | 282 | wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) ); |