X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/upload/UploadFromFile.php diff --git a/includes/upload/UploadFromFile.php b/includes/upload/UploadFromFile.php index e67ec191..675bb8d4 100644 --- a/includes/upload/UploadFromFile.php +++ b/includes/upload/UploadFromFile.php @@ -1,65 +1,97 @@ getUpload( 'wpUploadFile' ); + $upload = $request->getUpload( 'wpUploadFile' ); $desiredDestName = $request->getText( 'wpDestFile' ); - if( !$desiredDestName ) + if ( !$desiredDestName ) { $desiredDestName = $upload->getName(); - - return $this->initialize( $desiredDestName, $upload ); + } + + $this->initialize( $desiredDestName, $upload ); } - + /** * Initialize from a filename and a WebRequestUpload + * @param string $name + * @param WebRequestUpload $webRequestUpload */ function initialize( $name, $webRequestUpload ) { $this->mUpload = $webRequestUpload; - return $this->initializePathInfo( $name, + $this->initializePathInfo( $name, $this->mUpload->getTempName(), $this->mUpload->getSize() ); } + + /** + * @param WebRequest $request + * @return bool + */ static function isValidRequest( $request ) { # Allow all requests, even if no file is present, so that an error # because a post_max_size or upload_max_filesize overflow return true; } - + + /** + * @return string + */ + public function getSourceType() { + return 'file'; + } + + /** + * @return array + */ public function verifyUpload() { - # Check for a post_max_size or upload_max_size overflow, so that a + # Check for a post_max_size or upload_max_size overflow, so that a # proper error can be shown to the user if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) { if ( $this->mUpload->isIniSizeOverflow() ) { - global $wgMaxUploadSize; - return array( + return [ 'status' => UploadBase::FILE_TOO_LARGE, - 'max' => min( - $wgMaxUploadSize, - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), - wfShorthandToInteger( ini_get( 'post_max_size' ) ) + 'max' => min( + self::getMaxUploadSize( $this->getSourceType() ), + self::getMaxPhpUploadSize() ), - ); + ]; } } - - return parent::verifyUpload(); - } - /** - * Get the path to the file underlying the upload - * @return String path to file - */ - public function getFileTempname() { - return $this->mUpload->getTempname(); + return parent::verifyUpload(); } - - }