http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73567

Revision: 73567
Author:   tparscal
Date:     2010-09-22 20:15:31 +0000 (Wed, 22 Sep 2010)

Log Message:
-----------
* 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
    trunk/phase3/includes/ResourceLoaderContext.php
    trunk/phase3/includes/WebRequest.php

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2010-09-22 20:11:30 UTC (rev 
73566)
+++ trunk/phase3/includes/OutputPage.php        2010-09-22 20:15:31 UTC (rev 
73567)
@@ -2286,7 +2286,7 @@
                // 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 @@
                $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 @@
                }
 
                // 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' );
                        }

Modified: trunk/phase3/includes/ResourceLoaderContext.php
===================================================================
--- trunk/phase3/includes/ResourceLoaderContext.php     2010-09-22 20:11:30 UTC 
(rev 73566)
+++ trunk/phase3/includes/ResourceLoaderContext.php     2010-09-22 20:15:31 UTC 
(rev 73567)
@@ -49,7 +49,7 @@
                $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' );
 

Modified: trunk/phase3/includes/WebRequest.php
===================================================================
--- trunk/phase3/includes/WebRequest.php        2010-09-22 20:11:30 UTC (rev 
73566)
+++ trunk/phase3/includes/WebRequest.php        2010-09-22 20:15:31 UTC (rev 
73567)
@@ -347,6 +347,19 @@
        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



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to