r70583 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70582‎ | r70583 | r70584 >
Date:18:56, 6 August 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Using FormatJson::encode instead of json_encode, also messed with the 'true', 'false', 1, 0 thing a bit. Also added 'server' back into the config output.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -219,7 +219,7 @@
220220 'script' => null,
221221 'locales' => null,
222222 'raw' => false,
223 - // An empty array is used for needs to make json_encode output [] instead of null which is shorted and
 223+ // An empty array is used for needs to make FormatJson::encode output [] instead of null which is shorted and
224224 // results in easier to work with data on the client
225225 'needs' => array(),
226226 'loader' => null,
@@ -272,12 +272,11 @@
273273 'lang' => $request->getVal( 'lang', $wgLang->getCode() ),
274274 'skin' => $request->getVal( 'skin', $wgDefaultSkin ),
275275 'debug' => $request->getVal( 'debug' ),
276 - 'server' => $server,
277276 );
278277 // Mediawiki's WebRequest::getBool is a bit on the annoying side - we need to allow 'true' and 'false' values
279278 // to be converted to boolean true and false
280 - $parameters['user'] = $parameters['user'] === 'true';
281 - $parameters['debug'] = $parameters['debug'] === 'true';
 279+ $parameters['user'] = $parameters['user'] === 'true' || $parameters['user'];
 280+ $parameters['debug'] = $parameters['debug'] === 'true' || $parameters['debug'];
282281 // Get the direction from the requested language
283282 if ( !isset( $parameters['dir'] ) ) {
284283 $lang = $wgLang->factory( $parameters['lang'] );
@@ -309,7 +308,8 @@
310309 }
311310 // Special meta-information for the 'mediawiki' module
312311 if ( in_array( 'mediawiki', $modules ) ) {
313 - echo "mediaWiki.config.set( 'debug', " . ( $parameters['debug'] ? 'true' : 'false' ) . " );\n";
 312+ $config = array( 'server' => $server, 'debug', 'debug' => $parameters['debug'] );
 313+ echo "mediaWiki.config.set( " . FormatJson::encode( $config ) . " );\n";
314314 // Generate list of registrations and collect all loader scripts
315315 $loaders = array();
316316 $registrations = array();
@@ -332,7 +332,7 @@
333333 // Include loaders
334334 self::read( $loaders, true );
335335 // Register modules without loaders
336 - echo "mediaWiki.loader.register( " . json_encode( array_values( $registrations ) ) . " );\n";
 336+ echo "mediaWiki.loader.register( " . FormatJson::encode( array_values( $registrations ) ) . " );\n";
337337 }
338338 // Output non-raw modules
339339 $blobs = MessageBlobStore::get( $modules, $parameters['lang'] );

Comments

#Comment by Catrope (talk | contribs)   13:50, 7 August 2010
-		$parameters['user'] = $parameters['user'] === 'true';
-		$parameters['debug'] = $parameters['debug'] === 'true';
+		$parameters['user'] = $parameters['user'] === 'true' || $parameters['user'];
+		$parameters['debug'] = $parameters['debug'] === 'true' || $parameters['debug'];

This makes 'true' work but breaks 'false'. Yes, this is a nightmare :(

+			$config = array( 'server' => $server, 'debug', 'debug' => $parameters['debug'] );

I'm assuming you don't want the 0 => 'debug' entry in here.

#Comment by Trevor Parscal (WMF) (talk | contribs)   18:34, 12 October 2010

1. This has been resolved with the addition of WebRequest::getFuzzyBool 2. I'm having a hard time finding the rev, but this code has been replaced with something different that doesn't have this bug.

Status & tagging log