function WebRequest() {
$this->checkMagicQuotes();
global $wgUsePathInfo;
- if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
+ if( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != '') && $wgUsePathInfo ) {
# Stuff it!
$_GET['title'] = $_REQUEST['title'] =
substr( $_SERVER['PATH_INFO'], 1 );
/**
* If magic_quotes_gpc option is on, run the global arrays
- * through fix_magic_quotes to strip out the stupid dlashes.
+ * through fix_magic_quotes to strip out the stupid slashes.
* WARNING: This should only be done once! Running a second
* time could damage the values.
* @private
/**
* Fetch a value from the given array or return $default if it's not set.
- * @param array &$arr
+ *
+ * @param array $arr
* @param string $name
* @param mixed $default
* @return mixed
* @private
*/
- function getGPCVal( &$arr, $name, $default ) {
+ function getGPCVal( $arr, $name, $default ) {
if( isset( $arr[$name] ) ) {
- global $wgUseLatin1, $wgServer, $wgContLang;
+ global $wgContLang;
$data = $arr[$name];
- if( isset( $_GET[$name] ) &&
- !is_array( $data ) &&
- ( empty( $_SERVER['HTTP_REFERER'] ) ||
- strncmp($wgServer, $_SERVER['HTTP_REFERER'], strlen( $wgServer ) ) ) ) {
- # For links that came from outside, check for alternate/legacy
- # character encoding.
+ if( isset( $_GET[$name] ) && !is_array( $data ) ) {
+ # Check for alternate/legacy character encoding.
if( isset( $wgContLang ) ) {
$data = $wgContLang->checkTitleEncoding( $data );
}
}
- if( !$wgUseLatin1 ) {
- require_once( 'normal/UtfNormal.php' );
- $data = $this->normalizeUnicode( $data );
- }
+ require_once( 'normal/UtfNormal.php' );
+ $data = $this->normalizeUnicode( $data );
return $data;
} else {
return $default;
* @return int
*/
function getInt( $name, $default = 0 ) {
- return IntVal( $this->getVal( $name, $default ) );
+ return intval( $this->getVal( $name, $default ) );
+ }
+
+ /**
+ * Fetch an integer value from the input or return null if empty.
+ * Guaranteed to return an integer or null; non-numeric input will
+ * typically return null.
+ * @param string $name
+ * @return int
+ */
+ function getIntOrNull( $name ) {
+ $val = $this->getVal( $name );
+ return is_numeric( $val )
+ ? intval( $val )
+ : null;
}
/**
* @return string
*/
function getRequestURL() {
- return $_SERVER['REQUEST_URI'];
+ $base = $_SERVER['REQUEST_URI'];
+ if( $base{0} == '/' ) {
+ return $base;
+ } else {
+ // We may get paths with a host prepended; strip it.
+ return preg_replace( '!^[^:]+://[^/]+/!', '/', $base );
+ }
}
/**
return $_FILES[$key]['size'];
}
+ /**
+ * Return the upload error or 0
+ * @param string $key
+ * @return integer
+ */
+ function getUploadError( $key ) {
+ if( !isset( $_FILES[$key] ) || !isset( $_FILES[$key]['error'] ) ) {
+ return 0/*UPLOAD_ERR_OK*/;
+ }
+ return $_FILES[$key]['error'];
+ }
+
/**
* Return the original filename of the uploaded file, as reported by
* the submitting user agent. HTML-style character entities are
# Safari sends filenames in HTML-encoded Unicode form D...
# Horrid and evil! Let's try to make some kind of sense of it.
- global $wgUseLatin1;
- if( $wgUseLatin1 ) {
- $name = utf8_encode( $name );
- }
- $name = wfMungeToUtf8( $name );
+ $name = Sanitizer::decodeCharReferences( $name );
$name = UtfNormal::cleanUp( $name );
- if( $wgUseLatin1 ) {
- $name = utf8_decode( $name );
- }
wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" );
return $name;
}