Merge "Do not split parser cache if limitation is reached."
[lhc/web/wiklou.git] / includes / WebRequest.php
index c99e484..f402f3b 100644 (file)
@@ -315,7 +315,9 @@ class WebRequest {
                        }
                } else {
                        global $wgContLang;
-                       $data = isset( $wgContLang ) ? $wgContLang->normalize( $data ) : UtfNormal\Validator::cleanUp( $data );
+                       $data = isset( $wgContLang ) ?
+                               $wgContLang->normalize( $data ) :
+                               UtfNormal\Validator::cleanUp( $data );
                }
                return $data;
        }
@@ -754,7 +756,8 @@ class WebRequest {
         * Appends or replaces value of query variables.
         *
         * @param array $array Array of values to replace/add to query
-        * @param bool $onlyquery Whether to only return the query string and not the complete URL [deprecated]
+        * @param bool $onlyquery Whether to only return the query string
+        *  and not the complete URL [deprecated]
         * @return string
         */
        public function appendQueryArray( $array, $onlyquery = true ) {
@@ -871,7 +874,7 @@ class WebRequest {
        /**
         * Initialise the header list
         */
-       private function initHeaders() {
+       protected function initHeaders() {
                if ( count( $this->headers ) ) {
                        return;
                }
@@ -1297,6 +1300,7 @@ class FauxRequest extends WebRequest {
        private $wasPosted = false;
        private $session = array();
        private $requestUrl;
+       protected $cookies = array();
 
        /**
         * @param array $data Array of *non*-urlencoded key => value pairs, the
@@ -1324,11 +1328,10 @@ class FauxRequest extends WebRequest {
        }
 
        /**
-        * @param string $method
-        * @throws MWException
+        * Initialise the header list
         */
-       private function notImplemented( $method ) {
-               throw new MWException( "{$method}() not implemented" );
+       protected function initHeaders() {
+               // Nothing to init
        }
 
        /**
@@ -1371,7 +1374,38 @@ class FauxRequest extends WebRequest {
        }
 
        public function getCookie( $key, $prefix = null, $default = null ) {
-               return $default;
+               if ( $prefix === null ) {
+                       global $wgCookiePrefix;
+                       $prefix = $wgCookiePrefix;
+               }
+               $name = $prefix . $key;
+               return isset( $this->cookies[$name] ) ? $this->cookies[$name] : $default;
+       }
+
+       /**
+        * @since 1.26
+        * @param string $name Unprefixed name of the cookie to set
+        * @param string|null $value Value of the cookie to set
+        * @param string|null $prefix Cookie prefix. Defaults to $wgCookiePrefix
+        */
+       public function setCookie( $key, $value, $prefix = null ) {
+               $this->setCookies( array( $key => $value ), $prefix );
+       }
+
+       /**
+        * @since 1.26
+        * @param array $cookies
+        * @param string|null $prefix Cookie prefix. Defaults to $wgCookiePrefix
+        */
+       public function setCookies( $cookies, $prefix = null ) {
+               if ( $prefix === null ) {
+                       global $wgCookiePrefix;
+                       $prefix = $wgCookiePrefix;
+               }
+               foreach ( $cookies as $key => $value ) {
+                       $name = $prefix . $key;
+                       $this->cookies[$name] = $value;
+               }
        }
 
        public function checkSessionCookie() {
@@ -1393,17 +1427,23 @@ class FauxRequest extends WebRequest {
                return $this->protocol;
        }
 
-       private function initHeaders() {
-               return;
-       }
-
        /**
         * @param string $name
         * @param string $val
         */
        public function setHeader( $name, $val ) {
-               $name = strtoupper( $name );
-               $this->headers[$name] = $val;
+               $this->setHeaders( array( $name => $val ) );
+       }
+
+       /**
+        * @since 1.26
+        * @param array $headers
+        */
+       public function setHeaders( $headers ) {
+               foreach ( $headers as $name => $val ) {
+                       $name = strtoupper( $name );
+                       $this->headers[$name] = $val;
+               }
        }
 
        /**