Fix indentation of => added in r77366 to be in step with the rest
[lhc/web/wiklou.git] / includes / WebRequest.php
index bb1cfd3..4cd120a 100644 (file)
  */
 class WebRequest {
        protected $data, $headers = array();
-       private $_response;
+
+       /**
+        * Lazy-init response object
+        * @var WebResponse
+        */
+       private $response;
 
        public function __construct() {
                /// @todo Fixme: this preemptive de-quoting can interfere with other web libraries
@@ -345,7 +350,20 @@ class WebRequest {
         * @return Boolean
         */
        public function getBool( $name, $default = false ) {
-               return $this->getVal( $name, $default ) ? true : false;
+               return (bool)$this->getVal( $name, $default );
+       }
+       
+       /**
+        * 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 ) && strcasecmp( $this->getVal( $name ), 'false' ) !== 0;
        }
 
        /**
@@ -563,15 +581,23 @@ class WebRequest {
                global $wgUser;
 
                $limit = $this->getInt( 'limit', 0 );
-               if( $limit < 0 ) $limit = 0;
+               if( $limit < 0 ) {
+                       $limit = 0;
+               }
                if( ( $limit == 0 ) && ( $optionname != '' ) ) {
                        $limit = (int)$wgUser->getOption( $optionname );
                }
-               if( $limit <= 0 ) $limit = $deflimit;
-               if( $limit > 5000 ) $limit = 5000; # We have *some* limits...
+               if( $limit <= 0 ) {
+                       $limit = $deflimit;
+               }
+               if( $limit > 5000 ) {
+                       $limit = 5000; # We have *some* limits...
+               }
 
                $offset = $this->getInt( 'offset', 0 );
-               if( $offset < 0 ) $offset = 0;
+               if( $offset < 0 ) {
+                       $offset = 0;
+               }
 
                return array( $limit, $offset );
        }
@@ -639,14 +665,16 @@ class WebRequest {
        /**
         * Return a handle to WebResponse style object, for setting cookies,
         * headers and other stuff, for Request being worked on.
+        *
+        * @return WebResponse
         */
        public function response() {
                /* Lazy initialization of response object for this request */
-               if ( !is_object( $this->_response ) ) {
+               if ( !is_object( $this->response ) ) {
                        $class = ( $this instanceof FauxRequest ) ? 'FauxResponse' : 'WebResponse';
-                       $this->_response = new $class();
+                       $this->response = new $class();
                }
-               return $this->_response;
+               return $this->response;
        }
 
        /**
@@ -686,8 +714,9 @@ class WebRequest {
         * @return Mixed
         */
        public function getSessionData( $key ) {
-               if( !isset( $_SESSION[$key] ) )
+               if( !isset( $_SESSION[$key] ) ) {
                        return null;
+               }
                return $_SESSION[$key];
        }
 
@@ -939,13 +968,15 @@ class FauxRequest extends WebRequest {
                global $wgTitle;
                $basequery = '';
                foreach( $this->data as $var => $val ) {
-                       if ( $var == 'title' )
+                       if ( $var == 'title' ) {
                                continue;
-                       if ( is_array( $val ) )
+                       }
+                       if ( is_array( $val ) ) {
                                /* This will happen given a request like
                                 * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
                                 */
                                continue;
+                       }
                        $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
                }
                $basequery .= '&' . $query;