Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -27,6 +27,10 @@ |
28 | 28 | * (bug 35303) Proxy and DNS blacklist blocking works again |
29 | 29 | * (bug 35294) jquery.byteLimit shouldn't set element specific variables outside |
30 | 30 | the "return this.each" loop. |
| 31 | +* (bug 21054) Remove or skip strip markers from tag hooks like <nowiki> in |
| 32 | + core parser functions which operate on strings, such as formatnum. |
| 33 | +* (bug 18295) Don't expose strip markers when a tag appears inside a link |
| 34 | + inside a heading. |
31 | 35 | |
32 | 36 | === Configuration changes in 1.19 === |
33 | 37 | * Removed SkinTemplateSetupPageCss hook; use BeforePageDisplay instead. |
Index: trunk/phase3/tests/parser/parserTests.txt |
— | — | @@ -9096,6 +9096,96 @@ |
9097 | 9097 | |
9098 | 9098 | !! end |
9099 | 9099 | |
| 9100 | +!! test |
| 9101 | +Strip marker in urlencode |
| 9102 | +!! input |
| 9103 | +{{urlencode:x<nowiki/>y}} |
| 9104 | +{{urlencode:x<nowiki/>y|wiki}} |
| 9105 | +{{urlencode:x<nowiki/>y|path}} |
| 9106 | +!! result |
| 9107 | +<p>xy |
| 9108 | +xy |
| 9109 | +xy |
| 9110 | +</p> |
| 9111 | +!! end |
| 9112 | + |
| 9113 | +!! test |
| 9114 | +Strip marker in lc |
| 9115 | +!! input |
| 9116 | +{{lc:x<nowiki/>y}} |
| 9117 | +!! result |
| 9118 | +<p>xy |
| 9119 | +</p> |
| 9120 | +!! end |
| 9121 | + |
| 9122 | +!! test |
| 9123 | +Strip marker in uc |
| 9124 | +!! input |
| 9125 | +{{uc:x<nowiki/>y}} |
| 9126 | +!! result |
| 9127 | +<p>XY |
| 9128 | +</p> |
| 9129 | +!! end |
| 9130 | + |
| 9131 | +!! test |
| 9132 | +Strip marker in formatNum |
| 9133 | +!! input |
| 9134 | +{{formatnum:1<nowiki/>2}} |
| 9135 | +{{formatnum:1<nowiki/>2|R}} |
| 9136 | +!! result |
| 9137 | +<p>12 |
| 9138 | +12 |
| 9139 | +</p> |
| 9140 | +!! end |
| 9141 | + |
| 9142 | +!! test |
| 9143 | +Strip marker in grammar |
| 9144 | +!! options |
| 9145 | +language=fi |
| 9146 | +!! input |
| 9147 | +{{grammar:elative|foo<nowiki/>bar}} |
| 9148 | +!! result |
| 9149 | +<p>foobarista |
| 9150 | +</p> |
| 9151 | +!! end |
| 9152 | + |
| 9153 | +!! test |
| 9154 | +Strip marker in padleft |
| 9155 | +!! input |
| 9156 | +{{padleft:|2|x<nowiki/>y}} |
| 9157 | +!! result |
| 9158 | +<p>xy |
| 9159 | +</p> |
| 9160 | +!! end |
| 9161 | + |
| 9162 | +!! test |
| 9163 | +Strip marker in padright |
| 9164 | +!! input |
| 9165 | +{{padright:|2|x<nowiki/>y}} |
| 9166 | +!! result |
| 9167 | +<p>xy |
| 9168 | +</p> |
| 9169 | +!! end |
| 9170 | + |
| 9171 | +!! test |
| 9172 | +Strip marker in anchorencode |
| 9173 | +!! input |
| 9174 | +{{anchorencode:x<nowiki/>y}} |
| 9175 | +!! result |
| 9176 | +<p>xy |
| 9177 | +</p> |
| 9178 | +!! end |
| 9179 | + |
| 9180 | +!! test |
| 9181 | +nowiki inside link inside heading (bug 18295) |
| 9182 | +!! input |
| 9183 | +==[[foo|x<nowiki>y</nowiki>z]]== |
| 9184 | +!! result |
| 9185 | +<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Parser_test&action=edit&section=1" title="Edit section: xyz">edit</a>]</span> <span class="mw-headline" id="xyz"><a href="https://www.mediawiki.org/index.php?title=Foo&action=edit&redlink=1" class="new" title="Foo (page does not exist)">xyz</a></span></h2> |
| 9186 | + |
| 9187 | +!! end |
| 9188 | + |
| 9189 | + |
9100 | 9190 | TODO: |
9101 | 9191 | more images |
9102 | 9192 | more tables |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4069,15 +4069,17 @@ |
4070 | 4070 | } |
4071 | 4071 | |
4072 | 4072 | # The safe header is a version of the header text safe to use for links |
4073 | | - # Avoid insertion of weird stuff like <math> by expanding the relevant sections |
4074 | | - $safeHeadline = $this->mStripState->unstripBoth( $headline ); |
4075 | 4073 | |
4076 | 4074 | # Remove link placeholders by the link text. |
4077 | 4075 | # <!--LINK number--> |
4078 | 4076 | # turns into |
4079 | 4077 | # link text with suffix |
4080 | | - $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline ); |
| 4078 | + # Do this before unstrip since link text can contain strip markers |
| 4079 | + $safeHeadline = $this->replaceLinkHoldersText( $headline ); |
4081 | 4080 | |
| 4081 | + # Avoid insertion of weird stuff like <math> by expanding the relevant sections |
| 4082 | + $safeHeadline = $this->mStripState->unstripBoth( $safeHeadline ); |
| 4083 | + |
4082 | 4084 | # Strip out HTML (first regex removes any tag not allowed) |
4083 | 4085 | # Allowed tags are <sup> and <sub> (bug 8393), <i> (bug 26375) and <b> (r105284) |
4084 | 4086 | # We strip any parameter from accepted tags (second regex) |
— | — | @@ -5647,6 +5649,16 @@ |
5648 | 5650 | } |
5649 | 5651 | |
5650 | 5652 | /** |
| 5653 | + * Remove any strip markers found in the given text. |
| 5654 | + * |
| 5655 | + * @param $text Input string |
| 5656 | + * @return string |
| 5657 | + */ |
| 5658 | + function killMarkers( $text ) { |
| 5659 | + return $this->mStripState->killMarkers( $text ); |
| 5660 | + } |
| 5661 | + |
| 5662 | + /** |
5651 | 5663 | * Save the parser state required to convert the given half-parsed text to |
5652 | 5664 | * HTML. "Half-parsed" in this context means the output of |
5653 | 5665 | * recursiveTagParse() or internalParse(). This output has strip markers |
Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -165,17 +165,21 @@ |
166 | 166 | |
167 | 167 | // Encode as though it's a wiki page, '_' for ' '. |
168 | 168 | case 'url_wiki': |
169 | | - return wfUrlencode( str_replace( ' ', '_', $s ) ); |
| 169 | + $func = 'wfUrlencode'; |
| 170 | + $s = str_replace( ' ', '_', $s ); |
| 171 | + break; |
170 | 172 | |
171 | 173 | // Encode for an HTTP Path, '%20' for ' '. |
172 | 174 | case 'url_path': |
173 | | - return rawurlencode( $s ); |
| 175 | + $func = 'rawurlencode'; |
| 176 | + break; |
174 | 177 | |
175 | 178 | // Encode for HTTP query, '+' for ' '. |
176 | 179 | case 'url_query': |
177 | 180 | default: |
178 | | - return urlencode( $s ); |
| 181 | + $func = 'urlencode'; |
179 | 182 | } |
| 183 | + return $parser->markerSkipCallback( $s, $func ); |
180 | 184 | } |
181 | 185 | |
182 | 186 | static function lcfirst( $parser, $s = '' ) { |
— | — | @@ -195,11 +199,7 @@ |
196 | 200 | */ |
197 | 201 | static function lc( $parser, $s = '' ) { |
198 | 202 | global $wgContLang; |
199 | | - if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) { |
200 | | - return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) ); |
201 | | - } else { |
202 | | - return $wgContLang->lc( $s ); |
203 | | - } |
| 203 | + return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) ); |
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
— | — | @@ -209,11 +209,7 @@ |
210 | 210 | */ |
211 | 211 | static function uc( $parser, $s = '' ) { |
212 | 212 | global $wgContLang; |
213 | | - if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) { |
214 | | - return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) ); |
215 | | - } else { |
216 | | - return $wgContLang->uc( $s ); |
217 | | - } |
| 213 | + return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) ); |
218 | 214 | } |
219 | 215 | |
220 | 216 | static function localurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getLocalURL', $s, $arg ); } |
— | — | @@ -253,12 +249,13 @@ |
254 | 250 | * @param null $raw |
255 | 251 | * @return |
256 | 252 | */ |
257 | | - static function formatNum( $parser, $num = '', $raw = null) { |
258 | | - if ( self::israw( $raw ) ) { |
259 | | - return $parser->getFunctionLang()->parseFormattedNumber( $num ); |
| 253 | + static function formatnum( $parser, $num = '', $raw = null) { |
| 254 | + if ( self::isRaw( $raw ) ) { |
| 255 | + $func = array( $parser->getFunctionLang(), 'parseFormattedNumber' ); |
260 | 256 | } else { |
261 | | - return $parser->getFunctionLang()->formatNum( $num ); |
| 257 | + $func = array( $parser->getFunctionLang(), 'formatNum' ); |
262 | 258 | } |
| 259 | + return $parser->markerSkipCallback( $num, $func ); |
263 | 260 | } |
264 | 261 | |
265 | 262 | /** |
— | — | @@ -268,6 +265,7 @@ |
269 | 266 | * @return |
270 | 267 | */ |
271 | 268 | static function grammar( $parser, $case = '', $word = '' ) { |
| 269 | + $word = $parser->killMarkers( $word ); |
272 | 270 | return $parser->getFunctionLang()->convertGrammar( $word, $case ); |
273 | 271 | } |
274 | 272 | |
— | — | @@ -637,7 +635,8 @@ |
638 | 636 | * Unicode-safe str_pad with the restriction that $length is forced to be <= 500 |
639 | 637 | * @return string |
640 | 638 | */ |
641 | | - static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) { |
| 639 | + static function pad( $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) { |
| 640 | + $padding = $parser->killMarkers( $padding ); |
642 | 641 | $lengthOfPadding = mb_strlen( $padding ); |
643 | 642 | if ( $lengthOfPadding == 0 ) return $string; |
644 | 643 | |
— | — | @@ -661,11 +660,11 @@ |
662 | 661 | } |
663 | 662 | |
664 | 663 | static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) { |
665 | | - return self::pad( $string, $length, $padding, STR_PAD_LEFT ); |
| 664 | + return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT ); |
666 | 665 | } |
667 | 666 | |
668 | 667 | static function padright( $parser, $string = '', $length = 0, $padding = '0' ) { |
669 | | - return self::pad( $string, $length, $padding ); |
| 668 | + return self::pad( $parser, $string, $length, $padding ); |
670 | 669 | } |
671 | 670 | |
672 | 671 | /** |
— | — | @@ -674,6 +673,7 @@ |
675 | 674 | * @return string |
676 | 675 | */ |
677 | 676 | static function anchorencode( $parser, $text ) { |
| 677 | + $text = $parser->killMarkers( $text ); |
678 | 678 | return substr( $parser->guessSectionNameFromWikiText( $text ), 1); |
679 | 679 | } |
680 | 680 | |
Index: trunk/phase3/includes/parser/StripState.php |
— | — | @@ -181,5 +181,15 @@ |
182 | 182 | $key = $m[1]; |
183 | 183 | return "{$this->prefix}{$this->tempMergePrefix}-$key" . Parser::MARKER_SUFFIX; |
184 | 184 | } |
| 185 | + |
| 186 | + /** |
| 187 | + * Remove any strip markers found in the given text. |
| 188 | + * |
| 189 | + * @param $text Input string |
| 190 | + * @return string |
| 191 | + */ |
| 192 | + function killMarkers( $text ) { |
| 193 | + return preg_replace( $this->regex, '', $text ); |
| 194 | + } |
185 | 195 | } |
186 | 196 | |