Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -33,6 +33,18 @@ |
34 | 34 | blah blah |
35 | 35 | !! endarticle |
36 | 36 | |
| 37 | +!!article |
| 38 | +Template:Foo |
| 39 | +!!text |
| 40 | +FOO |
| 41 | +!!endarticle |
| 42 | + |
| 43 | +!! article |
| 44 | +Template:Blank |
| 45 | +!! text |
| 46 | +!! endarticle |
| 47 | + |
| 48 | + |
37 | 49 | ### |
38 | 50 | ### Basic tests |
39 | 51 | ### |
— | — | @@ -278,7 +290,27 @@ |
279 | 291 | |
280 | 292 | !! end |
281 | 293 | |
| 294 | +!! test |
| 295 | +Comment in template title |
| 296 | +!! input |
| 297 | +{{f<!---->oo}} |
| 298 | +!! result |
| 299 | +<p>FOO |
| 300 | +</p> |
| 301 | +!! end |
282 | 302 | |
| 303 | +!! test |
| 304 | +Comment on its own line post-expand |
| 305 | +!! input |
| 306 | +a |
| 307 | +{{blank}}<!----> |
| 308 | +b |
| 309 | +!! result |
| 310 | +<p>a |
| 311 | +</p><p>b |
| 312 | +</p> |
| 313 | +!! end |
| 314 | + |
283 | 315 | ### |
284 | 316 | ### Preformatted text |
285 | 317 | ### |
Index: trunk/phase3/includes/Parser.php |
— | — | @@ -2693,18 +2693,18 @@ |
2694 | 2694 | $endpos = strpos( $text, '-->', $i + 4 ); |
2695 | 2695 | if ( $endpos === false ) { |
2696 | 2696 | // Unclosed comment in input, runs to end |
2697 | | - $accum .= htmlspecialchars( substr( $text, $i ) ); |
| 2697 | + $inner = substr( $text, $i ); |
2698 | 2698 | if ( $this->ot['html'] ) { |
2699 | 2699 | // Close it so later stripping can remove it |
2700 | | - $accum .= htmlspecialchars( '-->' ); |
| 2700 | + $inner .= '-->'; |
2701 | 2701 | } |
| 2702 | + $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>'; |
2702 | 2703 | $i = strlen( $text ); |
2703 | | - continue; |
| 2704 | + } else { |
| 2705 | + $inner = substr( $text, $i, $endpos - $i + 3 ); |
| 2706 | + $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>'; |
| 2707 | + $i = $endpos + 3; |
2704 | 2708 | } |
2705 | | - $accum .= htmlspecialchars( substr( $text, $i, $endpos - $i + 3 ) ); |
2706 | | - #$inner = substr( $text, $i + 4, $endpos - $i - 4 ); |
2707 | | - #$accum .= '<ext><name>!--</name><inner>' . htmlspecialchars( $inner ) . '</inner></ext>'; |
2708 | | - $i = $endpos + 3; |
2709 | 2709 | continue; |
2710 | 2710 | } |
2711 | 2711 | $name = $matches[1]; |
— | — | @@ -3047,6 +3047,12 @@ |
3048 | 3048 | throw new MWException( __METHOD__ . ' called using the old argument format' ); |
3049 | 3049 | } |
3050 | 3050 | |
| 3051 | + # Remove comments |
| 3052 | + # This could theoretically be merged into preprocessToDom() |
| 3053 | + if ( $this->ot['html'] || ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) ) { |
| 3054 | + $text = Sanitizer::removeHTMLcomments( $text ); |
| 3055 | + } |
| 3056 | + |
3051 | 3057 | $dom = $this->preprocessToDom( $text ); |
3052 | 3058 | $flags = $argsOnly ? PPFrame::NO_TEMPLATES : 0; |
3053 | 3059 | $text = $frame->expand( $dom, $flags ); |
— | — | @@ -3439,6 +3445,12 @@ |
3440 | 3446 | $text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) ); |
3441 | 3447 | } |
3442 | 3448 | |
| 3449 | + # Remove comments |
| 3450 | + # This could theoretically be merged into preprocessToDom() |
| 3451 | + if ( $this->ot['html'] || ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) ) { |
| 3452 | + $text = Sanitizer::removeHTMLcomments( $text ); |
| 3453 | + } |
| 3454 | + |
3443 | 3455 | $dom = $this->preprocessToDom( $text ); |
3444 | 3456 | |
3445 | 3457 | $this->mTplDomCache[ $titleText ] = $dom; |
— | — | @@ -3626,9 +3638,6 @@ |
3627 | 3639 | $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $n++) . $this->mMarkerSuffix; |
3628 | 3640 | |
3629 | 3641 | if ( $this->ot['html'] ) { |
3630 | | - if ( $name == '!--' ) { |
3631 | | - return ''; |
3632 | | - } |
3633 | 3642 | $name = strtolower( $name ); |
3634 | 3643 | |
3635 | 3644 | $params = Sanitizer::decodeTagAttributes( $attrText ); |
— | — | @@ -3659,15 +3668,11 @@ |
3660 | 3669 | } |
3661 | 3670 | } |
3662 | 3671 | } else { |
3663 | | - if ( $name == '!--' ) { |
3664 | | - $output = '<!--' . $content . '-->'; |
| 3672 | + if ( $content === null ) { |
| 3673 | + $output = "<$name$attrText/>"; |
3665 | 3674 | } else { |
3666 | | - if ( $content === null ) { |
3667 | | - $output = "<$name$attrText/>"; |
3668 | | - } else { |
3669 | | - $close = is_null( $params['close'] ) ? '' : $frame->expand( $params['close'] ); |
3670 | | - $output = "<$name$attrText>$content$close"; |
3671 | | - } |
| 3675 | + $close = is_null( $params['close'] ) ? '' : $frame->expand( $params['close'] ); |
| 3676 | + $output = "<$name$attrText>$content$close"; |
3672 | 3677 | } |
3673 | 3678 | } |
3674 | 3679 | |
— | — | @@ -4961,7 +4966,9 @@ |
4962 | 4967 | * for "replace", the whole page with the section replaced. |
4963 | 4968 | */ |
4964 | 4969 | private function extractSections( $text, $section, $mode, $newText='' ) { |
| 4970 | + global $wgTitle; |
4965 | 4971 | $this->clearState(); |
| 4972 | + $this->mTitle = $wgTitle; // not generally used but removes an ugly failure mode |
4966 | 4973 | $this->mOptions = new ParserOptions; |
4967 | 4974 | $this->setOutputType( OT_WIKI ); |
4968 | 4975 | $curIndex = 0; |
— | — | @@ -5179,6 +5186,7 @@ |
5180 | 5187 | function srvus( $text ) { |
5181 | 5188 | $text = $this->replaceVariables( $text ); |
5182 | 5189 | $text = $this->mStripState->unstripBoth( $text ); |
| 5190 | + $text = Sanitizer::removeHTMLtags( $text ); |
5183 | 5191 | return $text; |
5184 | 5192 | } |
5185 | 5193 | } |
— | — | @@ -5252,6 +5260,8 @@ |
5253 | 5261 | |
5254 | 5262 | const NO_ARGS = 1; |
5255 | 5263 | const NO_TEMPLATES = 2; |
| 5264 | + const STRIP_COMMENTS = 4; |
| 5265 | + |
5256 | 5266 | const RECOVER_ORIG = 3; |
5257 | 5267 | |
5258 | 5268 | /** |
— | — | @@ -5287,7 +5297,7 @@ |
5288 | 5298 | $name = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent; |
5289 | 5299 | } else { |
5290 | 5300 | // Named parameter |
5291 | | - $name = $this->expand( $nameNodes->item( 0 ) ); |
| 5301 | + $name = $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS ); |
5292 | 5302 | } |
5293 | 5303 | |
5294 | 5304 | $value = $xpath->query( 'value', $arg ); |
— | — | @@ -5355,6 +5365,13 @@ |
5356 | 5366 | $params = array( 'title' => $title, 'parts' => $parts, 'text' => 'FIXME' ); |
5357 | 5367 | $s = $this->parser->argSubstitution( $params, $this ); |
5358 | 5368 | } |
| 5369 | + } elseif ( $root->nodeName == 'comment' ) { |
| 5370 | + # HTML-style comment |
| 5371 | + if ( $flags & self::STRIP_COMMENTS ) { |
| 5372 | + $s = ''; |
| 5373 | + } else { |
| 5374 | + $s = $root->textContent; |
| 5375 | + } |
5359 | 5376 | } elseif ( $root->nodeName == 'ext' ) { |
5360 | 5377 | # Extension tag |
5361 | 5378 | $xpath = new DOMXPath( $root->ownerDocument ); |
Index: trunk/phase3/includes/Parser_OldPP.php |
— | — | @@ -4918,6 +4918,7 @@ |
4919 | 4919 | */ |
4920 | 4920 | function srvus( $text ) { |
4921 | 4921 | $text = $this->strip( $text, $this->mStripState ); |
| 4922 | + $text = Sanitizer::removeHTMLtags( $text ); |
4922 | 4923 | $text = $this->replaceVariables( $text ); |
4923 | 4924 | $text = preg_replace( '/<!--MWTEMPLATESECTION.*?-->/', '', $text ); |
4924 | 4925 | $text = $this->mStripState->unstripBoth( $text ); |
Index: trunk/extensions/ParserFunctions/Expr.php |
— | — | @@ -103,21 +103,13 @@ |
104 | 104 | $operands = array(); |
105 | 105 | $operators = array(); |
106 | 106 | |
107 | | - # Remove HTML-style comments |
108 | | - # Not necessary in versions where StringUtils::delimiterReplace didn't exist |
109 | | - if ( is_callable( array( 'StringUtils', 'delimiterReplace' ) ) ) { |
110 | | - $expr = StringUtils::delimiterReplace( '<!--', '-->', '', $expr ); |
111 | | - } |
112 | | - |
113 | 107 | # Unescape inequality operators |
114 | 108 | $expr = strtr( $expr, array( '<' => '<', '>' => '>' ) ); |
115 | 109 | |
116 | | - |
117 | 110 | $p = 0; |
118 | 111 | $end = strlen( $expr ); |
119 | 112 | $expecting = 'expression'; |
120 | 113 | |
121 | | - |
122 | 114 | while ( $p < $end ) { |
123 | 115 | if ( count( $operands ) > $this->maxStackSize || count( $operators ) > $this->maxStackSize ) { |
124 | 116 | throw new ExprError('stack_exhausted'); |