Merge "Refactor content fetch condition in ApiQueryRevisionsBase"
[lhc/web/wiklou.git] / includes / WebResponse.php
index 75efce5..d39f884 100644 (file)
@@ -29,18 +29,34 @@ class WebResponse {
 
        /**
         * Output a HTTP header, wrapper for PHP's header()
-        * @param string $string header to output
-        * @param bool $replace replace current similar header
+        * @param string $string Header to output
+        * @param bool $replace Replace current similar header
         * @param null|int $http_response_code Forces the HTTP response code to the specified value.
         */
        public function header( $string, $replace = true, $http_response_code = null ) {
                header( $string, $replace, $http_response_code );
        }
 
+       /**
+        * Get a response header
+        * @param string $key The name of the header to get (case insensitive).
+        * @return string|null The header value (if set); null otherwise.
+        * @since 1.25
+        */
+       public function getHeader( $key ) {
+               foreach ( headers_list() as $header ) {
+                       list( $name, $val ) = explode( ':', $header, 2 );
+                       if ( !strcasecmp( $name, $key ) ) {
+                               return trim( $val );
+                       }
+               }
+               return null;
+       }
+
        /**
         * Set the browser cookie
-        * @param string $name name of cookie
-        * @param string $value value to give cookie
+        * @param string $name Name of cookie
+        * @param string $value Value to give cookie
         * @param int|null $expire Unix timestamp (in seconds) when the cookie should expire.
         *        0 (the default) causes it to expire $wgCookieExpiration seconds from now.
         *        null causes it to be a session cookie.
@@ -51,7 +67,7 @@ class WebResponse {
         *     secure: bool, secure attribute ($wgCookieSecure)
         *     httpOnly: bool, httpOnly attribute ($wgCookieHttpOnly)
         *     raw: bool, if true uses PHP's setrawcookie() instead of setcookie()
-        *   For backwards compatability, if $options is not an array then it and
+        *   For backwards compatibility, if $options is not an array then it and
         *   the following two parameters will be interpreted as values for
         *   'prefix', 'domain', and 'secure'
         * @since 1.22 Replaced $prefix, $domain, and $forceSecure with $options
@@ -61,7 +77,7 @@ class WebResponse {
                global $wgCookieSecure, $wgCookieExpiration, $wgCookieHttpOnly;
 
                if ( !is_array( $options ) ) {
-                       // Backwards compatability
+                       // Backwards compatibility
                        $options = array( 'prefix' => $options );
                        if ( func_num_args() >= 5 ) {
                                $options['domain'] = func_get_arg( 4 );
@@ -123,8 +139,8 @@ class FauxResponse extends WebResponse {
 
        /**
         * Stores a HTTP header
-        * @param string $string header to output
-        * @param bool $replace replace current similar header
+        * @param string $string Header to output
+        * @param bool $replace Replace current similar header
         * @param null|int $http_response_code Forces the HTTP response code to the specified value.
         */
        public function header( $string, $replace = true, $http_response_code = null ) {
@@ -150,7 +166,7 @@ class FauxResponse extends WebResponse {
         * @param string $key The name of the header to get (case insensitive).
         * @return string
         */
-       public function getheader( $key ) {
+       public function getHeader( $key ) {
                $key = strtoupper( $key );
 
                if ( isset( $this->headers[$key] ) ) {
@@ -171,10 +187,10 @@ class FauxResponse extends WebResponse {
        /**
         * @todo document. It just ignore optional parameters.
         *
-        * @param string $name name of cookie
-        * @param string $value value to give cookie
-        * @param int $expire number of seconds til cookie expires (Default: 0)
-        * @param array $options ignored
+        * @param string $name Name of cookie
+        * @param string $value Value to give cookie
+        * @param int $expire Number of seconds til cookie expires (Default: 0)
+        * @param array $options Ignored
         */
        public function setcookie( $name, $value, $expire = 0, $options = null ) {
                $this->cookies[$name] = $value;