r112644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112643‎ | r112644 | r112645 >
Date:21:13, 28 February 2012
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/REL1_19/phase3 (modified) (history)
  • /branches/REL1_19/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /branches/REL1_19/phase3/includes (modified) (history)
  • /branches/REL1_19/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/REL1_19/phase3/includes/PathRouter.php (modified) (history)
  • /branches/REL1_19/phase3/includes/api (modified) (history)
  • /branches/REL1_19/phase3/includes/api/ApiParamInfo.php (modified) (history)
  • /branches/REL1_19/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php (modified) (history)
  • /branches/REL1_19/phase3/resources/Resources.php (modified) (history)
  • /branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.css (added) (history)
  • /branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.js (modified) (history)
  • /branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.spinner.gif (added) (history)
  • /branches/REL1_19/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)
  • /branches/REL1_19/phase3/tests/phpunit/includes/PathRouterTest.php (modified) (history)

Diff [purge]

Index: branches/REL1_19/phase3/RELEASE-NOTES-1.19
@@ -248,6 +248,8 @@
249249 around a bug where not all styles were applied in Internet Explorer
250250 * (bug 28936, bug 5280) Broken or invalid titles can't be removed from watchlist.* (Bug 33087) Exchange server rejected mail sent by MediaWiki
251251 * (bug 34600) Older skins using useHeadElement=false were broken in 1.18
 252+* (bug 34604) [mw.config] wgActionPaths should be an object instead of a numeral
 253+ array.
252254
253255 === API changes in 1.19 ===
254256 * Made action=edit less likely to return "unknownerror", by returning the actual error
Index: branches/REL1_19/phase3/tests/phpunit/includes/PathRouterTest.php
@@ -125,6 +125,16 @@
126126 }
127127
128128 /**
 129+ * Test to ensure that matches are not made if a parameter expects nonexistent input
 130+ */
 131+ public function testFail() {
 132+ $router = new PathRouter;
 133+ $router->add( "/wiki/$1", array( 'title' => "$1$2" ) );
 134+ $matches = $router->parse( "/wiki/A" );
 135+ $this->assertEquals( array(), $matches );
 136+ }
 137+
 138+ /**
129139 * Test to ensure weight of paths is handled correctly
130140 */
131141 public function testWeight() {
@@ -172,12 +182,30 @@
173183 $this->assertEquals( $matches, array( 'title' => "Title_With Space" ) );
174184 }
175185
 186+ public function dataRegexpChars() {
 187+ return array(
 188+ array( "$" ),
 189+ array( "$1" ),
 190+ array( "\\" ),
 191+ array( "\\$1" ),
 192+ );
 193+ }
 194+
176195 /**
 196+ * Make sure the router doesn't break on special characters like $ used in regexp replacements
 197+ * @dataProvider dataRegexpChars
 198+ */
 199+ public function testRegexpChars( $char ) {
 200+ $matches = $this->basicRouter->parse( "/wiki/$char" );
 201+ $this->assertEquals( $matches, array( 'title' => "$char" ) );
 202+ }
 203+
 204+ /**
177205 * Make sure the router handles characters like +&() properly
178206 */
179207 public function testCharacters() {
180 - $matches = $this->basicRouter->parse( "/wiki/Plus+And&Stuff()" );
181 - $this->assertEquals( $matches, array( 'title' => "Plus+And&Stuff()" ) );
 208+ $matches = $this->basicRouter->parse( "/wiki/Plus+And&Dollar\\Stuff();[]{}*" );
 209+ $this->assertEquals( $matches, array( 'title' => "Plus+And&Dollar\\Stuff();[]{}*" ) );
182210 }
183211
184212 /**
Index: branches/REL1_19/phase3/includes/api/ApiParamInfo.php
@@ -147,6 +147,9 @@
148148 $examples = $obj->getExamples();
149149 $retval['allexamples'] = array();
150150 if ( $examples !== false ) {
 151+ if ( is_string( $examples ) ) {
 152+ $examples = array( $examples );
 153+ }
151154 foreach( $examples as $k => $v ) {
152155 if ( strlen( $retval['examples'] ) ) {
153156 $retval['examples'] .= ' ';
Property changes on: branches/REL1_19/phase3/includes/api
___________________________________________________________________
Modified: svn:mergeinfo
154157 Merged /trunk/phase3/includes/api:r112290,112313
Index: branches/REL1_19/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -68,7 +68,9 @@
6969 'wgScriptExtension' => $wgScriptExtension,
7070 'wgScript' => $wgScript,
7171 'wgVariantArticlePath' => $wgVariantArticlePath,
72 - 'wgActionPaths' => $wgActionPaths,
 72+ // Force object to avoid "empty" associative array from
 73+ // becoming [] instead of {} in JS (bug 34604)
 74+ 'wgActionPaths' => (object)$wgActionPaths,
7375 'wgServer' => $wgServer,
7476 'wgUserLanguage' => $context->getLanguage(),
7577 'wgContentLanguage' => $wgContLang->getCode(),
Index: branches/REL1_19/phase3/includes/PathRouter.php
@@ -278,20 +278,14 @@
279279 } elseif ( isset( $paramData['pattern'] ) ) {
280280 // For patterns we have to make value replacements on the string
281281 $value = $paramData['pattern'];
282 - // For each $# match replace any $# within the value
283 - foreach ( $m as $matchKey => $matchValue ) {
284 - if ( preg_match( '/^par\d+$/u', $matchKey ) ) {
285 - $n = intval( substr( $matchKey, 3 ) );
286 - $value = str_replace( '$' . $n, rawurldecode( $matchValue ), $value );
287 - }
288 - }
289 - // If a key was set replace any $key within the value
 282+ $replacer = new PathRouterPatternReplacer;
 283+ $replacer->params = $m;
290284 if ( isset( $pattern->key ) ) {
291 - $value = str_replace( '$key', $pattern->key, $value );
 285+ $replacer->key = $pattern->key;
292286 }
293 - if ( preg_match( '/\$(\d+|key)/u', $value ) ) {
294 - // Still contains $# or $key patterns after replacement
295 - // Seams like we don't have all the data, abort
 287+ $value = $replacer->replace( $value );
 288+ if ( $value === false ) {
 289+ // Pattern required data that wasn't available, abort
296290 return null;
297291 }
298292 }
@@ -317,3 +311,41 @@
318312 }
319313
320314 }
 315+
 316+class PathRouterPatternReplacer {
 317+
 318+ public $key, $params, $error;
 319+
 320+ /**
 321+ * Replace keys inside path router patterns with text.
 322+ * We do this inside of a replacement callback because after replacement we can't tell the
 323+ * difference between a $1 that was not replaced and a $1 that was part of
 324+ * the content a $1 was replaced with.
 325+ */
 326+ public function replace( $value ) {
 327+ $this->error = false;
 328+ $value = preg_replace_callback( '/\$(\d+|key)/u', array( $this, 'callback' ), $value );
 329+ if ( $this->error ) {
 330+ return false;
 331+ }
 332+ return $value;
 333+ }
 334+
 335+ protected function callback( $m ) {
 336+ if ( $m[1] == "key" ) {
 337+ if ( is_null( $this->key ) ) {
 338+ $this->error = true;
 339+ return '';
 340+ }
 341+ return $this->key;
 342+ } else {
 343+ $d = $m[1];
 344+ if ( !isset( $this->params["par$d"] ) ) {
 345+ $this->error = true;
 346+ return '';
 347+ }
 348+ return rawurldecode( $this->params["par$d"] );
 349+ }
 350+ }
 351+
 352+}
\ No newline at end of file
Index: branches/REL1_19/phase3/includes/AutoLoader.php
@@ -162,6 +162,7 @@
163163 'Pager' => 'includes/Pager.php',
164164 'PasswordError' => 'includes/User.php',
165165 'PathRouter' => 'includes/PathRouter.php',
 166+ 'PathRouterPatternReplacer' => 'includes/PathRouter.php',
166167 'PermissionsError' => 'includes/Exception.php',
167168 'PhpHttpRequest' => 'includes/HttpFunctions.php',
168169 'PoolCounter' => 'includes/PoolCounter.php',
Property changes on: branches/REL1_19/phase3/includes/AutoLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
169170 Merged /trunk/phase3/includes/AutoLoader.php:r112313
Property changes on: branches/REL1_19/phase3/includes
___________________________________________________________________
Modified: svn:mergeinfo
170171 Merged /trunk/phase3/includes:r112184,112290,112313
Index: branches/REL1_19/phase3/resources/Resources.php
@@ -554,6 +554,7 @@
555555 ),
556556 'mediawiki.feedback' => array(
557557 'scripts' => 'resources/mediawiki/mediawiki.feedback.js',
 558+ 'styles' => 'resources/mediawiki/mediawiki.feedback.css',
558559 'dependencies' => array(
559560 'mediawiki.api.edit',
560561 'mediawiki.Title',
Index: branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.js
@@ -106,7 +106,7 @@
107107 $( '<div class="feedback-mode feedback-submitting" style="text-align:center;margin:3em 0;"></div>' ).append(
108108 mw.msg( 'feedback-adding' ),
109109 $( '<br/>' ),
110 - $( '<img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" />' )
 110+ $( '<span class="feedback-spinner"></span>' )
111111 ),
112112 $( '<div class="feedback-mode feedback-thanks" style="text-align:center;margin:1em"></div>' ).msg(
113113 'feedback-thanks', _this.title.getNameText(), $feedbackPageLink.clone()
Index: branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.spinner.gif
Cannot display: file marked as a binary type.
svn:mime-type = image/gif
Property changes on: branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.spinner.gif
___________________________________________________________________
Added: svn:mime-type
114114 + image/gif
Index: branches/REL1_19/phase3/resources/mediawiki/mediawiki.util.js
@@ -2,7 +2,7 @@
33 * Implements mediaWiki.util library
44 */
55 ( function ( $, mw ) {
6 -"use strict";
 6+ "use strict";
77
88 // Local cache and alias
99 var util = {
@@ -121,19 +121,19 @@
122122 * @param str string String to be encoded
123123 */
124124 wikiUrlencode: function ( str ) {
125 - return this.rawurlencode( str )
 125+ return util.rawurlencode( str )
126126 .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
127127 },
128128
129129 /**
130130 * Get the link to a page name (relative to wgServer)
131131 *
132 - * @param str string Page name to get the link for.
133 - * @return string Location for a page with name of 'str' or boolean false on error.
 132+ * @param str String: Page name to get the link for.
 133+ * @return String: Location for a page with name of 'str' or boolean false on error.
134134 */
135135 wikiGetlink: function ( str ) {
136136 return mw.config.get( 'wgArticlePath' ).replace( '$1',
137 - this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
 137+ util.wikiUrlencode( typeof str === 'string' ? str : mw.config.get( 'wgPageName' ) ) );
138138 },
139139
140140 /**
@@ -384,7 +384,7 @@
385385 $link.attr( 'title', tooltip );
386386 }
387387 if ( accesskey && tooltip ) {
388 - this.updateTooltipAccessKeys( $link );
 388+ util.updateTooltipAccessKeys( $link );
389389 }
390390
391391 // Where to put our node ?
Index: branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.css
@@ -0,0 +1,9 @@
 2+.feedback-spinner {
 3+ display: inline-block;
 4+ zoom: 1;
 5+ *display: inline; /* IE7 and below */
 6+ /* @embed */
 7+ background: url(mediawiki.feedback.spinner.gif);
 8+ width: 18px;
 9+ height: 18px;
 10+}
Property changes on: branches/REL1_19/phase3/resources/mediawiki/mediawiki.feedback.css
___________________________________________________________________
Added: svn:eol-style
111 + native
Property changes on: branches/REL1_19/phase3
___________________________________________________________________
Modified: svn:mergeinfo
212 Merged /trunk/phase3:r112169-112170,112172-112173,112179,112184,112290,112313

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112169bug 34599: special:uploadwizard loading insecure content from commons...brion00:37, 23 February 2012
r112170[mw.util] bug fix and minor clean up...krinkle00:39, 23 February 2012
r112172* (bug 33045) Use locally-sourced spinner image for mediawiki.feedback module...brion00:53, 23 February 2012
r112173Follow-up r112172: embedkrinkle01:00, 23 February 2012
r112179Follow-up r112172: fix inline-block support for IE6/IE7krinkle01:25, 23 February 2012
r112184Bug 34604 - [mw.config] wgActionPaths should be an object instead of a numera...krinkle02:45, 23 February 2012
r112290Examples can just be a string...reedy02:06, 24 February 2012
r112313Fix bug 34684 in my PathRouter code:...dantman11:31, 24 February 2012

Status & tagging log