r114347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114346‎ | r114347 | r114348 >
Date:05:19, 21 March 2012
Author:tstarling
Status:ok
Tags:
Comment:
MFT r114231: strip marker exposed
Modified paths:
  • /branches/wmf/1.19wmf1/includes/parser/CoreParserFunctions.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/parser/Parser.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/parser/StripState.php (modified) (history)
  • /branches/wmf/1.19wmf1/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/tests/parser/parserTests.txt
@@ -9096,6 +9096,96 @@
90979097
90989098 !! end
90999099
 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&amp;action=edit&amp;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&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">xyz</a></span></h2>
 9186+
 9187+!! end
 9188+
 9189+
91009190 TODO:
91019191 more images
91029192 more tables
Index: branches/wmf/1.19wmf1/includes/parser/Parser.php
@@ -4065,15 +4065,17 @@
40664066 }
40674067
40684068 # The safe header is a version of the header text safe to use for links
4069 - # Avoid insertion of weird stuff like <math> by expanding the relevant sections
4070 - $safeHeadline = $this->mStripState->unstripBoth( $headline );
40714069
40724070 # Remove link placeholders by the link text.
40734071 # <!--LINK number-->
40744072 # turns into
40754073 # link text with suffix
4076 - $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline );
 4074+ # Do this before unstrip since link text can contain strip markers
 4075+ $safeHeadline = $this->replaceLinkHoldersText( $headline );
40774076
 4077+ # Avoid insertion of weird stuff like <math> by expanding the relevant sections
 4078+ $safeHeadline = $this->mStripState->unstripBoth( $safeHeadline );
 4079+
40784080 # Strip out HTML (first regex removes any tag not allowed)
40794081 # Allowed tags are <sup> and <sub> (bug 8393), <i> (bug 26375) and <b> (r105284)
40804082 # We strip any parameter from accepted tags (second regex)
@@ -5638,6 +5640,16 @@
56395641 }
56405642
56415643 /**
 5644+ * Remove any strip markers found in the given text.
 5645+ *
 5646+ * @param $text Input string
 5647+ * @return string
 5648+ */
 5649+ function killMarkers( $text ) {
 5650+ return $this->mStripState->killMarkers( $text );
 5651+ }
 5652+
 5653+ /**
56425654 * Save the parser state required to convert the given half-parsed text to
56435655 * HTML. "Half-parsed" in this context means the output of
56445656 * recursiveTagParse() or internalParse(). This output has strip markers
Index: branches/wmf/1.19wmf1/includes/parser/CoreParserFunctions.php
@@ -164,17 +164,21 @@
165165
166166 // Encode as though it's a wiki page, '_' for ' '.
167167 case 'url_wiki':
168 - return wfUrlencode( str_replace( ' ', '_', $s ) );
 168+ $func = 'wfUrlencode';
 169+ $s = str_replace( ' ', '_', $s );
 170+ break;
169171
170172 // Encode for an HTTP Path, '%20' for ' '.
171173 case 'url_path':
172 - return rawurlencode( $s );
 174+ $func = 'rawurlencode';
 175+ break;
173176
174177 // Encode for HTTP query, '+' for ' '.
175178 case 'url_query':
176179 default:
177 - return urlencode( $s );
 180+ $func = 'urlencode';
178181 }
 182+ return $parser->markerSkipCallback( $s, $func );
179183 }
180184
181185 static function lcfirst( $parser, $s = '' ) {
@@ -194,11 +198,7 @@
195199 */
196200 static function lc( $parser, $s = '' ) {
197201 global $wgContLang;
198 - if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
199 - return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
200 - } else {
201 - return $wgContLang->lc( $s );
202 - }
 202+ return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
203203 }
204204
205205 /**
@@ -208,11 +208,7 @@
209209 */
210210 static function uc( $parser, $s = '' ) {
211211 global $wgContLang;
212 - if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
213 - return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
214 - } else {
215 - return $wgContLang->uc( $s );
216 - }
 212+ return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
217213 }
218214
219215 static function localurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getLocalURL', $s, $arg ); }
@@ -252,12 +248,13 @@
253249 * @param null $raw
254250 * @return
255251 */
256 - static function formatNum( $parser, $num = '', $raw = null) {
257 - if ( self::israw( $raw ) ) {
258 - return $parser->getFunctionLang()->parseFormattedNumber( $num );
 252+ static function formatnum( $parser, $num = '', $raw = null) {
 253+ if ( self::isRaw( $raw ) ) {
 254+ $func = array( $parser->getFunctionLang(), 'parseFormattedNumber' );
259255 } else {
260 - return $parser->getFunctionLang()->formatNum( $num );
 256+ $func = array( $parser->getFunctionLang(), 'formatNum' );
261257 }
 258+ return $parser->markerSkipCallback( $num, $func );
262259 }
263260
264261 /**
@@ -267,6 +264,7 @@
268265 * @return
269266 */
270267 static function grammar( $parser, $case = '', $word = '' ) {
 268+ $word = $parser->killMarkers( $word );
271269 return $parser->getFunctionLang()->convertGrammar( $word, $case );
272270 }
273271
@@ -637,7 +635,8 @@
638636 /**
639637 * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
640638 */
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 );
642641 $lengthOfPadding = mb_strlen( $padding );
643642 if ( $lengthOfPadding == 0 ) return $string;
644643
@@ -661,11 +660,11 @@
662661 }
663662
664663 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 );
666665 }
667666
668667 static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
669 - return self::pad( $string, $length, $padding );
 668+ return self::pad( $parser, $string, $length, $padding );
670669 }
671670
672671 /**
@@ -674,6 +673,7 @@
675674 * @return string
676675 */
677676 static function anchorencode( $parser, $text ) {
 677+ $text = $parser->killMarkers( $text );
678678 return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
679679 }
680680
Index: branches/wmf/1.19wmf1/includes/parser/StripState.php
@@ -181,5 +181,15 @@
182182 $key = $m[1];
183183 return "{$this->prefix}{$this->tempMergePrefix}-$key" . Parser::MARKER_SUFFIX;
184184 }
 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+ }
185195 }
186196

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114231Fixed a few "strip tag exposed" bugs....tstarling04:39, 20 March 2012

Status & tagging log