r114338 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114337‎ | r114338 | r114339 >
Date:00:31, 21 March 2012
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
Backported the bug 22555 part of r114232 and cleaned up RELEASE-NOTES-1.18
Modified paths:
  • /branches/REL1_18/phase3/RELEASE-NOTES-1.18 (modified) (history)
  • /branches/REL1_18/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /branches/REL1_18/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/REL1_18/phase3/includes/parser/StripState.php (modified) (history)
  • /branches/REL1_18/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/RELEASE-NOTES-1.18
@@ -20,16 +20,11 @@
2121 * (bug 34528) Edit section tooltips show correction section name again
2222 * (bug 34246) MediaWiki:Whatlinkshere-summary message is displayed again in
2323 Special:Whatlinkshere
 24+* (bug 22555) Remove or skip strip markers from tag hooks like <nowiki> in
 25+ core parser functions which operate on strings, such as formatnum.
2426
25 -== MediaWiki 1.18.1 ==
26 -2012-01-11
27 -
28 -This a maintenance and security release of the MediaWiki 1.18 branch.
29 -
30 -=== Security changes ===
31 -* (bug 33117) prop=revisions allows deleted text to be exposed through cache pollution.
32 -
3327 === Changes since 1.18.0 ===
 28+
3429 * (bug 32712) Fix for search indexing of pages with certain unicode chars following URL.
3530 * (bug 3901) Lang, hreflang attribs added to sidebar interlanguage links for screen readers.
3631 * (bug 30774) mediawiki.html: Add support for numbers and booleans in the
@@ -55,6 +50,7 @@
5651 all pages.
5752 * Fixed recentchanges FK violation on page delete and cache purge error in updater
5853 for Oracle DB.
 54+* (bug 33117) prop=revisions allows deleted text to be exposed through cache pollution.
5955
6056 == MediaWiki 1.18 ==
6157 2011-11-24
Index: branches/REL1_18/phase3/tests/parser/parserTests.txt
@@ -8815,6 +8815,87 @@
88168816
88178817 !! end
88188818
 8819+!! test
 8820+Strip marker in urlencode
 8821+!! input
 8822+{{urlencode:x<nowiki/>y}}
 8823+{{urlencode:x<nowiki/>y|wiki}}
 8824+{{urlencode:x<nowiki/>y|path}}
 8825+!! result
 8826+<p>xy
 8827+xy
 8828+xy
 8829+</p>
 8830+!! end
 8831+
 8832+!! test
 8833+Strip marker in lc
 8834+!! input
 8835+{{lc:x<nowiki/>y}}
 8836+!! result
 8837+<p>xy
 8838+</p>
 8839+!! end
 8840+
 8841+!! test
 8842+Strip marker in uc
 8843+!! input
 8844+{{uc:x<nowiki/>y}}
 8845+!! result
 8846+<p>XY
 8847+</p>
 8848+!! end
 8849+
 8850+!! test
 8851+Strip marker in formatNum
 8852+!! input
 8853+{{formatnum:1<nowiki/>2}}
 8854+{{formatnum:1<nowiki/>2|R}}
 8855+!! result
 8856+<p>12
 8857+12
 8858+</p>
 8859+!! end
 8860+
 8861+!! test
 8862+Strip marker in grammar
 8863+!! options
 8864+language=fi
 8865+!! input
 8866+{{grammar:elative|foo<nowiki/>bar}}
 8867+!! result
 8868+<p>foobarista
 8869+</p>
 8870+!! end
 8871+
 8872+!! test
 8873+Strip marker in padleft
 8874+!! input
 8875+{{padleft:|2|x<nowiki/>y}}
 8876+!! result
 8877+<p>xy
 8878+</p>
 8879+!! end
 8880+
 8881+!! test
 8882+Strip marker in padright
 8883+!! input
 8884+{{padright:|2|x<nowiki/>y}}
 8885+!! result
 8886+<p>xy
 8887+</p>
 8888+!! end
 8889+
 8890+!! test
 8891+Strip marker in anchorencode
 8892+!! input
 8893+{{anchorencode:x<nowiki/>y}}
 8894+!! result
 8895+<p>xy
 8896+</p>
 8897+!! end
 8898+
 8899+
88198900 TODO:
88208901 more images
88218902 more tables
Index: branches/REL1_18/phase3/includes/parser/Parser.php
@@ -5403,6 +5403,16 @@
54045404 }
54055405
54065406 /**
 5407+ * Remove any strip markers found in the given text.
 5408+ *
 5409+ * @param $text Input string
 5410+ * @return string
 5411+ */
 5412+ function killMarkers( $text ) {
 5413+ return $this->mStripState->killMarkers( $text );
 5414+ }
 5415+
 5416+ /**
54075417 * Save the parser state required to convert the given half-parsed text to
54085418 * HTML. "Half-parsed" in this context means the output of
54095419 * recursiveTagParse() or internalParse(). This output has strip markers
Index: branches/REL1_18/phase3/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
@@ -624,7 +622,8 @@
625623 /**
626624 * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
627625 */
628 - static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
 626+ static function pad( $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
 627+ $padding = $parser->killMarkers( $padding );
629628 $lengthOfPadding = mb_strlen( $padding );
630629 if ( $lengthOfPadding == 0 ) return $string;
631630
@@ -648,11 +647,11 @@
649648 }
650649
651650 static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
652 - return self::pad( $string, $length, $padding, STR_PAD_LEFT );
 651+ return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
653652 }
654653
655654 static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
656 - return self::pad( $string, $length, $padding );
 655+ return self::pad( $parser, $string, $length, $padding );
657656 }
658657
659658 /**
@@ -661,6 +660,7 @@
662661 * @return string
663662 */
664663 static function anchorencode( $parser, $text ) {
 664+ $text = $parser->killMarkers( $text );
665665 return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
666666 }
667667
Index: branches/REL1_18/phase3/includes/parser/StripState.php
@@ -174,5 +174,15 @@
175175 $key = $m[1];
176176 return "{$this->prefix}{$this->tempMergePrefix}-$key" . Parser::MARKER_SUFFIX;
177177 }
 178+
 179+ /**
 180+ * Remove any strip markers found in the given text.
 181+ *
 182+ * @param $text Input string
 183+ * @return string
 184+ */
 185+ function killMarkers( $text ) {
 186+ return preg_replace( $this->regex, '', $text );
 187+ }
178188 }
179189

Follow-up revisions

RevisionCommit summaryAuthorDate
r114340Merge r114338 from 1.18: fix for bug 22555: strip markers in padleft etc.tstarling01:02, 21 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114231Fixed a few "strip tag exposed" bugs....tstarling04:39, 20 March 2012
r114232Better bug reference for r114231.tstarling04:52, 20 March 2012

Comments

#Comment by Tim Starling (talk | contribs)   22:08, 21 March 2012

Commit message should say r114231 (both were actually backported here).

Status & tagging log