+ public function getFileName( $key ) {
+ $file = new WebRequestUpload( $this, $key );
+ return $file->getName();
+ }
+
+ /**
+ * Return a WebRequestUpload object corresponding to the key
+ *
+ * @param @key string
+ * @return WebRequestUpload
+ */
+ public function getUpload( $key ) {
+ return new WebRequestUpload( $this, $key );
+ }
+
+ /**
+ * 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 ) ) {
+ $class = ( $this instanceof FauxRequest ) ? 'FauxResponse' : 'WebResponse';
+ $this->response = new $class();
+ }
+ return $this->response;
+ }
+
+ /**
+ * Get a request header, or false if it isn't set
+ * @param $name String: case-insensitive header name
+ */
+ public function getHeader( $name ) {
+ $name = strtoupper( $name );
+ if ( function_exists( 'apache_request_headers' ) ) {
+ if ( !$this->headers ) {
+ 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 ( $name === 'HTTP_CONTENT_LENGTH' && !isset( $_SERVER[$name] ) ) {
+ $name = 'CONTENT_LENGTH';
+ }
+ if ( isset( $_SERVER[$name] ) ) {
+ return $_SERVER[$name];
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Get data from $_SESSION
+ *
+ * @param $key String: name of key in $_SESSION
+ * @return Mixed
+ */
+ public function getSessionData( $key ) {
+ if( !isset( $_SESSION[$key] ) ) {
+ return null;
+ }
+ return $_SESSION[$key];
+ }
+
+ /**
+ * Set session data
+ *
+ * @param $key String: name of key in $_SESSION
+ * @param $data Mixed
+ */
+ public function setSessionData( $key, $data ) {
+ $_SESSION[$key] = $data;
+ }
+
+ /**
+ * Returns true if the PATH_INFO ends with an extension other than a script
+ * extension. This could confuse IE for scripts that send arbitrary data which
+ * is not HTML but may be detected as such.
+ *
+ * Various past attempts to use the URL to make this check have generally
+ * run up against the fact that CGI does not provide a standard method to
+ * determine the URL. PATH_INFO may be mangled (e.g. if cgi.fix_pathinfo=0),
+ * but only by prefixing it with the script name and maybe some other stuff,
+ * the extension is not mangled. So this should be a reasonably portable
+ * way to perform this security check.
+ */
+ public function isPathInfoBad() {
+ global $wgScriptExtension;
+
+ if ( !isset( $_SERVER['PATH_INFO'] ) ) {
+ return false;
+ }
+ $pi = $_SERVER['PATH_INFO'];
+ $dotPos = strrpos( $pi, '.' );
+ if ( $dotPos === false ) {
+ return false;
+ }
+ $ext = substr( $pi, $dotPos );
+ return !in_array( $ext, array( $wgScriptExtension, '.php', '.php5' ) );
+ }
+
+ /**
+ * Parse the Accept-Language header sent by the client into an array
+ * @return array( languageCode => q-value ) sorted by q-value in descending order
+ * May contain the "language" '*', which applies to languages other than those explicitly listed.
+ * This is aligned with rfc2616 section 14.4
+ */
+ public function getAcceptLang() {
+ // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
+ $acceptLang = $this->getHeader( 'Accept-Language' );
+ if ( !$acceptLang ) {
+ return array();