From: Trevor Parscal Date: Wed, 22 Sep 2010 20:15:31 +0000 (+0000) Subject: * Added WebRequest::getFuzzyBool, which is a more JavaScript friendly version of... X-Git-Tag: 1.31.0-rc.0~34828 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=6de869074638d4683504cdaefa11f784d41ccfd9;p=lhc%2Fweb%2Fwiklou.git * 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. --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4a9c25e21f..6d0474c722 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2286,7 +2286,7 @@ class OutputPage { // TODO: Divide off modules starting with "user", and add the user parameter to them $query = array( 'lang' => $wgLang->getCode(), - 'debug' => ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) == 'true' ) ? 'true' : 'false', + 'debug' => $wgRequest->getFuzzyBool( 'debug' ) ? 'true' : 'false', 'skin' => $wgUser->getSkin()->getSkinName(), 'only' => $only, ); @@ -2357,7 +2357,7 @@ class OutputPage { $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; // Script and Messages "only" - if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) { + if ( $wgRequest->getFuzzyBool( 'debug' ) ) { // Scripts foreach ( $this->getModuleScripts() as $name ) { $scripts .= self::makeResourceLoaderLink( $sk, $name, 'scripts' ); @@ -2526,7 +2526,7 @@ class OutputPage { } // Support individual script requests in debug mode - if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) { + if ( $wgRequest->getFuzzyBool( 'debug' ) ) { foreach ( $this->getModuleStyles() as $name ) { $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles' ); } diff --git a/includes/ResourceLoaderContext.php b/includes/ResourceLoaderContext.php index e8737a5a73..6e553cdc48 100644 --- a/includes/ResourceLoaderContext.php +++ b/includes/ResourceLoaderContext.php @@ -49,7 +49,7 @@ class ResourceLoaderContext { $this->direction = $request->getVal( 'dir' ); $this->skin = $request->getVal( 'skin' ); $this->user = $request->getVal( 'user' ); - $this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true'; + $this->debug = $request->getFuzzyBool( 'debug' ); $this->only = $request->getVal( 'only' ); $this->version = $request->getVal( 'version' ); diff --git a/includes/WebRequest.php b/includes/WebRequest.php index a29d76c4da..3dede3c2dc 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -347,6 +347,19 @@ class WebRequest { public function getBool( $name, $default = false ) { return $this->getVal( $name, $default ) ? true : false; } + + /** + * Fetch a boolean value from the input or return $default if not set. + * Unlike getBool, the string "false" will result in boolean false, which is + * useful when interpreting information sent from JavaScript. + * + * @param $name String + * @param $default Boolean + * @return Boolean + */ + public function getFuzzyBool( $name, $default = false ) { + return $this->getBool( $name, $default ) && $this->getVal( $name ) !== 'false'; + } /** * Return true if the named value is set in the input, whatever that