function WebRequest() {
$this->checkMagicQuotes();
global $wgUsePathInfo;
- if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
+ if( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != '') && $wgUsePathInfo ) {
# Stuff it!
- $_REQUEST['title'] = substr( $_SERVER['PATH_INFO'], 1 );
- }
- global $wgUseLatin1;
- if( !$wgUseLatin1 ) {
- require_once( 'normal/UtfNormal.php' );
- wfProfileIn( 'WebRequest:normalizeUnicode-fix' );
- $this->normalizeUnicode( $_REQUEST );
- wfProfileOut( 'WebRequest:normalizeUnicode-fix' );
+ $_GET['title'] = $_REQUEST['title'] =
+ substr( $_SERVER['PATH_INFO'], 1 );
}
}
/**
* Recursively normalizes UTF-8 strings in the given array.
- * @param array &$arr will be modified
+ * @param array $data string or array
+ * @return cleaned-up version of the given
* @private
*/
- function normalizeUnicode( &$arr ) {
- foreach( $arr as $key => $val ) {
- if( is_array( $val ) ) {
- $this->normalizeUnicode( $arr[$key ] );
- } else {
- $arr[$key] = UtfNormal::cleanUp( $val );
+ function normalizeUnicode( $data ) {
+ if( is_array( $data ) ) {
+ foreach( $data as $key => $val ) {
+ $data[$key] = $this->normalizeUnicode( $val );
}
+ } else {
+ $data = UtfNormal::cleanUp( $data );
}
+ return $data;
}
/**
* Fetch a value from the given array or return $default if it's not set.
+ *
* @param array &$arr
* @param string $name
* @param mixed $default
*/
function getGPCVal( &$arr, $name, $default ) {
if( isset( $arr[$name] ) ) {
- return $arr[$name];
+ global $wgServer, $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( $wgContLang ) ) {
+ $data = $wgContLang->checkTitleEncoding( $data );
+ }
+ }
+ require_once( 'normal/UtfNormal.php' );
+ $data = $this->normalizeUnicode( $data );
+ return $data;
} else {
return $default;
}
}
-
+
/**
- * Fetch a value from the given array or return $default if it's not set.
- * \r is stripped from the text, and with some language modules there is
- * an input transliteration applied.
- * @param array &$arr
+ * Fetch a scalar from the input or return $default if it's not set.
+ * Returns a string. Arrays are discarded.
+ *
* @param string $name
- * @param string $default
+ * @param string $default optional default (or NULL)
* @return string
- * @private
*/
- function getGPCText( &$arr, $name, $default ) {
- # Text fields may be in an alternate encoding which we should check.
- # Also, strip CRLF line endings down to LF to achieve consistency.
- global $wgLang;
- if( isset( $arr[$name] ) ) {
- return str_replace( "\r\n", "\n", $wgLang->recodeInput( $arr[$name] ) );
+ function getVal( $name, $default = NULL ) {
+ $val = $this->getGPCVal( $_REQUEST, $name, $default );
+ if( is_array( $val ) ) {
+ $val = $default;
+ }
+ if( is_null( $val ) ) {
+ return null;
} else {
- return $default;
+ return (string)$val;
}
}
/**
- * Fetch a value from the input or return $default if it's not set.
- * Value may be of a string or array, and is not altered.
+ * Fetch an array from the input or return $default if it's not set.
+ * If source was scalar, will return an array with a single element.
+ * If no source and no default, returns NULL.
+ *
* @param string $name
- * @param mixed $default optional default (or NULL)
- * @return mixed
+ * @param array $default optional default (or NULL)
+ * @return array
*/
- function getVal( $name, $default = NULL ) {
- return $this->getGPCVal( $_REQUEST, $name, $default );
+ function getArray( $name, $default = NULL ) {
+ $val = $this->getGPCVal( $_REQUEST, $name, $default );
+ if( is_null( $val ) ) {
+ return null;
+ } else {
+ return (array)$val;
+ }
}
-
+
/**
* Fetch an integer value from the input or return $default if not set.
* Guaranteed to return an integer; non-numeric input will typically
* @return string
*/
function getText( $name, $default = '' ) {
- return $this->getGPCText( $_REQUEST, $name, $default );
+ global $wgContLang;
+ $val = $this->getVal( $name, $default );
+ return str_replace( "\r\n", "\n",
+ $wgContLang->recodeInput( $val ) );
}
/**
# 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 = UtfNormal::cleanUp( $name );
- if( $wgUseLatin1 ) {
- $name = utf8_decode( $name );
- }
wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" );
return $name;
}
var $data = null;
var $wasPosted = false;
- function WebRequest( $data, $wasPosted = false ) {
+ function FauxRequest( $data, $wasPosted = false ) {
if( is_array( $data ) ) {
$this->data = $data;
} else {
- wfDebugDieBacktrace( "FauxReqeust() got bogus data" );
+ wfDebugDieBacktrace( "FauxRequest() got bogus data" );
}
$this->wasPosted = $wasPosted;
}