r73567 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73566‎ | r73567 | r73568 >
Date:20:15, 22 September 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
* Added WebRequest::getFuzzyBool, which is a more JavaScript friendly version of getBool. Essentailly the same thing, except the string 'false' is also considered boolean false.
* Made use of getFuzzyBool where otherwise awkward and sometimes varied versions of 'flase' === false detection were being used.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderContext.php (modified) (history)
  • /trunk/phase3/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoaderContext.php
@@ -49,7 +49,7 @@
5050 $this->direction = $request->getVal( 'dir' );
5151 $this->skin = $request->getVal( 'skin' );
5252 $this->user = $request->getVal( 'user' );
53 - $this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
 53+ $this->debug = $request->getFuzzyBool( 'debug' );
5454 $this->only = $request->getVal( 'only' );
5555 $this->version = $request->getVal( 'version' );
5656
Index: trunk/phase3/includes/OutputPage.php
@@ -2286,7 +2286,7 @@
22872287 // TODO: Divide off modules starting with "user", and add the user parameter to them
22882288 $query = array(
22892289 'lang' => $wgLang->getCode(),
2290 - 'debug' => ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) == 'true' ) ? 'true' : 'false',
 2290+ 'debug' => $wgRequest->getFuzzyBool( 'debug' ) ? 'true' : 'false',
22912291 'skin' => $wgUser->getSkin()->getSkinName(),
22922292 'only' => $only,
22932293 );
@@ -2357,7 +2357,7 @@
23582358 $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
23592359
23602360 // Script and Messages "only"
2361 - if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) {
 2361+ if ( $wgRequest->getFuzzyBool( 'debug' ) ) {
23622362 // Scripts
23632363 foreach ( $this->getModuleScripts() as $name ) {
23642364 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'scripts' );
@@ -2526,7 +2526,7 @@
25272527 }
25282528
25292529 // Support individual script requests in debug mode
2530 - if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) {
 2530+ if ( $wgRequest->getFuzzyBool( 'debug' ) ) {
25312531 foreach ( $this->getModuleStyles() as $name ) {
25322532 $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles' );
25332533 }
Index: trunk/phase3/includes/WebRequest.php
@@ -347,6 +347,19 @@
348348 public function getBool( $name, $default = false ) {
349349 return $this->getVal( $name, $default ) ? true : false;
350350 }
 351+
 352+ /**
 353+ * Fetch a boolean value from the input or return $default if not set.
 354+ * Unlike getBool, the string "false" will result in boolean false, which is
 355+ * useful when interpreting information sent from JavaScript.
 356+ *
 357+ * @param $name String
 358+ * @param $default Boolean
 359+ * @return Boolean
 360+ */
 361+ public function getFuzzyBool( $name, $default = false ) {
 362+ return $this->getBool( $name, $default ) && $this->getVal( $name ) !== 'false';
 363+ }
351364
352365 /**
353366 * Return true if the named value is set in the input, whatever that

Follow-up revisions

RevisionCommit summaryAuthorDate
r73816* Improved on r73567, this makes WebRequest::getFuzzyBool case insensitive, m...tparscal15:59, 27 September 2010

Comments

#Comment by Platonides (talk | contribs)   17:03, 25 September 2010

I wonder if it should be case insensitive, too.

#Comment by Trevor Parscal (WMF) (talk | contribs)   15:41, 27 September 2010

This crossed my mind just after committing it. I think I will make it case insensitive if there are no objections.

#Comment by Catrope (talk | contribs)   15:44, 27 September 2010

I think that's a good idea. I don't think anyone expects "false" to evaluate to false but "FALSE" to evaluate to true.

#Comment by Trevor Parscal (WMF) (talk | contribs)   16:00, 27 September 2010

Agreed. r73816 supports my continued claim of sanity.

Status & tagging log