* not create a second WebRequest object; make a FauxRequest object if
* you want to pass arbitrary data to some function in place of the web
* input.
- *
+ *
* @ingroup HTTP
*/
class WebRequest {
*/
public function interpolateTitle() {
global $wgUsePathInfo;
+
if ( $wgUsePathInfo ) {
// PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
// And also by Apache 2.x, double slashes are converted to single slashes.
// So we will use REQUEST_URI if possible.
$matches = array();
+
if ( !empty( $_SERVER['REQUEST_URI'] ) ) {
// Slurp out the path portion to examine...
$url = $_SERVER['REQUEST_URI'];
*/
private function checkMagicQuotes() {
$mustFixQuotes = function_exists( 'get_magic_quotes_gpc' )
- && get_magic_quotes_gpc();
+ && get_magic_quotes_gpc();
if( $mustFixQuotes ) {
$this->fix_magic_quotes( $_COOKIE );
$this->fix_magic_quotes( $_ENV );
$data[$key] = $this->normalizeUnicode( $val );
}
} else {
- $data = UtfNormal::cleanUp( $data );
+ global $wgContLang;
+ $data = $wgContLang->normalize( $data );
}
return $data;
}
return (string)$val;
}
}
-
+
/**
* Set an aribtrary value into our get/post data.
* @param $key string Key name to use
* @return string or NULL if no such file.
*/
public function getFileName( $key ) {
+ global $wgContLang;
if( !isset( $_FILES[$key] ) ) {
return null;
}
# Safari sends filenames in HTML-encoded Unicode form D...
# Horrid and evil! Let's try to make some kind of sense of it.
$name = Sanitizer::decodeCharReferences( $name );
- $name = UtfNormal::cleanUp( $name );
+ $name = $wgContLang->normalize( $name );
wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" );
return $name;
}
public function response() {
/* Lazy initialization of response object for this request */
if ( !is_object( $this->_response ) ) {
- $this->_response = new WebResponse;
+ $class = ( $this instanceof FauxRequest ) ? 'FauxResponse' : 'WebResponse';
+ $this->_response = new $class();
}
return $this->_response;
}
}
}
}
-
+
/*
* Get data from $_SESSION
* @param $key String Name of key in $_SESSION
return null;
return $_SESSION[$key];
}
-
+
/**
* Set session data
* @param $key String Name of key in $_SESSION
}
/**
- * Returns true if the PATH_INFO ends with an extension other than a script
+ * 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
+ * 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;
}
class FauxRequest extends WebRequest {
private $wasPosted = false;
private $session = array();
+ private $response;
/**
* @param $data Array of *non*-urlencoded key => value pairs, the
return isset( $this->headers[$name] ) ? $this->headers[$name] : false;
}
+ public function setHeader( $name, $val ) {
+ $this->headers[$name] = $val;
+ }
+
public function getSessionData( $key ) {
- if( !isset( $this->session[$key] ) )
- return null;
- return $this->session[$key];
+ if( isset( $this->session[$key] ) )
+ return $this->session[$key];
}
public function setSessionData( $key, $data ) {
public function isPathInfoBad() {
return false;
}
-
}