(bug 18317) Bolded selections in 1 | 3 | etc days on RecentChanges now use <strong...
[lhc/web/wiklou.git] / includes / WebRequest.php
index 63cd706..0928e4d 100644 (file)
@@ -46,18 +46,16 @@ class WebRequest {
        var $data = array();
        var $headers;
        private $_response;
-       private $cookies = array();
 
        function __construct() {
+               /// @fixme This preemptive de-quoting can interfere with other web libraries
+               ///        and increases our memory footprint. It would be cleaner to do on
+               ///        demand; but currently we have no wrapper for $_SERVER etc.
+               $this->checkMagicQuotes();
+
                // POST overrides GET data
                // We don't use $_REQUEST here to avoid interference from cookies...
-               $this->data = wfArrayMerge( $_GET, $_POST );
-               $this->cookies = $_COOKIE;
-
-               /// @fixme This preemptive de-quoting increases our memory footprint. 
-               /// It would be cleaner to do on demand; but currently we have no 
-               /// wrapper for $_SERVER etc.
-               $this->checkMagicQuotes();              
+               $this->data = $_POST + $_GET;
        }
 
        /**
@@ -185,9 +183,10 @@ class WebRequest {
         */
        function checkMagicQuotes() {
                if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
-                       $this->fix_magic_quotes( $this->cookies );
+                       $this->fix_magic_quotes( $_COOKIE );
                        $this->fix_magic_quotes( $_ENV );
-                       $this->fix_magic_quotes( $this->data );
+                       $this->fix_magic_quotes( $_GET );
+                       $this->fix_magic_quotes( $_POST );
                        $this->fix_magic_quotes( $_REQUEST );
                        $this->fix_magic_quotes( $_SERVER );
                }
@@ -232,6 +231,7 @@ class WebRequest {
                        $data = $this->normalizeUnicode( $data );
                        return $data;
                } else {
+                       taint( $default );
                        return $default;
                }
        }
@@ -252,11 +252,23 @@ class WebRequest {
                        $val = $default;
                }
                if( is_null( $val ) ) {
-                       return null;
+                       return $val;
                } else {
                        return (string)$val;
                }
        }
+       
+       /**
+        * Set an aribtrary value into our get/post data.
+        * @param $key string Key name to use
+        * @param $value mixed Value to set
+        * @return mixed old value if one was present, null otherwise
+        */
+       function setVal( $key, $value ) {
+               $ret = isset( $this->data[$key] ) ? $this->data[$key] : null;
+               $this->data[$key] = $value;
+               return $ret;
+       }
 
        /**
         * Fetch an array from the input or return $default if it's not set.
@@ -399,23 +411,6 @@ class WebRequest {
                return $_SERVER['REQUEST_METHOD'] == 'POST';
        }
 
-       /**
-        * Get a cookie that has been sent through fix_magic_quotes().
-        * $wgCookiePrefix added before requesting, so no need to do
-        * it yourself.
-        * 
-        * @param string $key Key of the cookie name
-        * @param bool $addPrefix Whether to append $wgCookiePrefix (ie: most of the time)
-        * @return mixed (value or null if not found)
-        */
-       function getCookie( $key, $addPrefix = true ) {
-               if ( $addPrefix ) {
-                       global $wgCookiePrefix;
-                       $key = $wgCookiePrefix . $key;
-               }
-               return isset( $this->cookies[$key] ) ? $this->cookies[$key] : null;
-       }
-
        /**
         * Returns true if there is a session cookie set.
         * This does not necessarily mean that the user is logged in!
@@ -428,7 +423,7 @@ class WebRequest {
         * @return bool
         */
        function checkSessionCookie() {
-               return !is_null( $this->getCookie( session_name(), false ) );
+               return isset( $_COOKIE[session_name()] );
        }
 
        /**