From: Tim Starling Date: Wed, 20 Feb 2008 04:07:26 +0000 (+0000) Subject: * Relocate misplaced declaration of $_response X-Git-Tag: 1.31.0-rc.0~49430 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=801a155961641cae93efc47522845231e42855e5;p=lhc%2Fweb%2Fwiklou.git * Relocate misplaced declaration of $_response * Added getHeader() function * Check function_exists('get_magic_quotes_gpc') on rumours that it will be removed in a future version of PHP --- diff --git a/includes/WebRequest.php b/includes/WebRequest.php index a7dd12b292..fd8acc533c 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -43,6 +43,8 @@ if ( !function_exists( '__autoload' ) ) { */ class WebRequest { var $data = array(); + var $headers; + private $_response; function __construct() { /// @fixme This preemptive de-quoting can interfere with other web libraries @@ -152,8 +154,6 @@ class WebRequest { } return array(); } - - private $_response; /** * Recursively strips slashes from the given array; @@ -181,7 +181,7 @@ class WebRequest { * @private */ function checkMagicQuotes() { - if ( get_magic_quotes_gpc() ) { + if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) { $this->fix_magic_quotes( $_COOKIE ); $this->fix_magic_quotes( $_ENV ); $this->fix_magic_quotes( $_GET ); @@ -588,7 +588,34 @@ class WebRequest { } return $this->_response; } - + + /** + * Get a request header, or false if it isn't set + * @param string $name Case-insensitive header name + */ + function getHeader( $name ) { + $name = strtoupper( $name ); + if ( function_exists( 'apache_request_headers' ) ) { + if ( !isset( $this->headers ) ) { + $this->headers = array(); + foreach ( apache_request_headers() as $tempName => $tempValue ) { + $this->headers[ strtoupper( $tempName ) ] = $tempValue; + } + } + if ( isset( $this->headers[$name] ) ) { + return $this->headers[$name]; + } else { + return false; + } + } else { + $name = 'HTTP_' . str_replace( '-', '_', $name ); + if ( isset( $_SERVER[$name] ) ) { + return $_SERVER[$name]; + } else { + return false; + } + } + } } /** @@ -610,6 +637,7 @@ class FauxRequest extends WebRequest { throw new MWException( "FauxRequest() got bogus data" ); } $this->wasPosted = $wasPosted; + $this->headers = array(); } function getText( $name, $default = '' ) { @@ -637,6 +665,10 @@ class FauxRequest extends WebRequest { throw new MWException( 'FauxRequest::appendQuery() not implemented' ); } + function getHeader( $name ) { + return isset( $this->headers[$name] ) ? $this->headers[$name] : false; + } + }