+ /**
+ * Check for limit and offset parameters on the input, and return sensible
+ * defaults if not given. The limit must be positive and is capped at 5000.
+ * Offset must be positive but is not capped.
+ *
+ * @param int $deflimit Limit to use if no input and the user hasn't set the option.
+ * @param string $optionname To specify an option other than rclimit to pull from.
+ * @return array first element is limit, second is offset
+ */
+ function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) {
+ global $wgUser;
+
+ $limit = $this->getInt( 'limit', 0 );
+ if( $limit < 0 ) $limit = 0;
+ if( ( $limit == 0 ) && ( $optionname != '' ) ) {
+ $limit = (int)$wgUser->getOption( $optionname );
+ }
+ if( $limit <= 0 ) $limit = $deflimit;
+ if( $limit > 5000 ) $limit = 5000; # We have *some* limits...
+
+ $offset = $this->getInt( 'offset', 0 );
+ if( $offset < 0 ) $offset = 0;
+
+ return array( $limit, $offset );
+ }
+
+ /**
+ * Return the path to the temporary file where PHP has stored the upload.
+ * @param string $key
+ * @return string or NULL if no such file.
+ */
+ function getFileTempname( $key ) {
+ if( !isset( $_FILES[$key] ) ) {
+ return NULL;
+ }
+ return $_FILES[$key]['tmp_name'];
+ }
+
+ /**
+ * Return the size of the upload, or 0.
+ * @param string $key
+ * @return integer
+ */
+ function getFileSize( $key ) {
+ if( !isset( $_FILES[$key] ) ) {
+ return 0;
+ }
+ return $_FILES[$key]['size'];
+ }
+
+ /**
+ * Return the original filename of the uploaded file, as reported by
+ * the submitting user agent. HTML-style character entities are
+ * interpreted and normalized to Unicode normalization form C, in part
+ * to deal with weird input from Safari with non-ASCII filenames.
+ *
+ * Other than this the name is not verified for being a safe filename.
+ *
+ * @param string $key
+ * @return string or NULL if no such file.
+ */
+ function getFileName( $key ) {
+ if( !isset( $_FILES[$key] ) ) {
+ return NULL;
+ }
+ $name = $_FILES[$key]['name'];
+
+ # Safari sends filenames in HTML-encoded Unicode form D...
+ # Horrid and evil! Let's try to make some kind of sense of it.
+ $name = wfMungeToUtf8( $name );
+ $name = UtfNormal::cleanUp( $name );
+ wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" );
+ return $name;
+ }
+}
+
+/**
+ * WebRequest clone which takes values from a provided array.
+ *
+ * @package MediaWiki
+ */
+class FauxRequest extends WebRequest {
+ var $data = null;
+ var $wasPosted = false;
+
+ function FauxRequest( $data, $wasPosted = false ) {
+ if( is_array( $data ) ) {
+ $this->data = $data;
+ } else {
+ wfDebugDieBacktrace( "FauxRequest() got bogus data" );
+ }
+ $this->wasPosted = $wasPosted;
+ }
+
+ function getVal( $name, $default = NULL ) {
+ return $this->getGPCVal( $this->data, $name, $default );
+ }
+
+ function getText( $name, $default = '' ) {
+ # Override; don't recode since we're using internal data
+ return $this->getVal( $name, $default );
+ }
+
+ function getValues() {
+ return $this->data;
+ }
+
+ function wasPosted() {
+ return $this->wasPosted;
+ }
+
+ function checkSessionCookie() {
+ return false;
+ }
+
+ function getRequestURL() {
+ wfDebugDieBacktrace( 'FauxRequest::getRequestURL() not implemented' );
+ }
+
+ function appendQuery( $query ) {
+ wfDebugDieBacktrace( 'FauxRequest::appendQuery() not implemented' );
+ }
+