r70355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70354‎ | r70355 | r70356 >
Date:19:44, 2 August 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Added ability to accept 'true' and 'false' for debug and user parameters, since json_encode in PHP and jQuery.param() in JavaScript both think that way.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -189,11 +189,15 @@
190190 global $wgUser, $wgLang, $wgDefaultSkin;
191191 // Fallback on system settings
192192 $parameters = array(
193 - 'user' => $request->getBool( 'user', $wgUser->isLoggedIn() ),
 193+ 'user' => $request->getVal( 'user', $wgUser->isLoggedIn() ),
194194 'lang' => $request->getVal( 'lang', $wgLang->getCode() ),
195195 'skin' => $request->getVal( 'skin', $wgDefaultSkin ),
196 - 'debug' => $request->getBool( 'debug' ),
 196+ 'debug' => $request->getVal( 'debug' ),
197197 );
 198+ // Mediawiki's WebRequest::getBool is a bit on the annoying side - we need to allow 'true' and 'false' values
 199+ // to be converted to boolean true and false
 200+ $parameters['user'] = $parameters['user'] === 'true' || $parameters['user'] === true ? true : false;
 201+ $parameters['debug'] = $parameters['debug'] === 'true' || $parameters['debug'] === true ? true : false;
198202 // Get the direction from the requested language
199203 if ( !isset( $parameters['dir'] ) ) {
200204 $lang = $wgLang->factory( $parameters['lang'] );

Follow-up revisions

RevisionCommit summaryAuthorDate
r70468Removed unnessecary terinary expression added in r70355.tparscal17:42, 4 August 2010

Comments

#Comment by Catrope (talk | contribs)   14:20, 4 August 2010
+		$parameters['user'] = $parameters['user'] === 'true' || $parameters['user'] === true ? true : false;
+		$parameters['debug'] = $parameters['debug'] === 'true' || $parameters['debug'] === true ? true : false;

You don't need ? true : false ever, nor do you need === true (the latter is actually undesirable because strings unequal to '0' don't evaluate to true that way). The result of an || is a boolean in PHP (this isn't true in JS BTW).

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:42, 4 August 2010

I don't know what I was smoking... Fixed up in r70468

#Comment by Catrope (talk | contribs)   19:32, 4 August 2010

That didn't address the === true issue.

#Comment by Catrope (talk | contribs)   11:41, 6 August 2010

Addressed in r70483

Status & tagging log