diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
commit | 9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch) | |
tree | 46d1a0dee7febef5c2d57a9f7b972be16a163b3d /includes/upload/UploadFromFile.php | |
parent | 78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff) |
update to MediaWiki 1.17.0
Diffstat (limited to 'includes/upload/UploadFromFile.php')
-rw-r--r-- | includes/upload/UploadFromFile.php | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/includes/upload/UploadFromFile.php b/includes/upload/UploadFromFile.php index 73581a61..e67ec191 100644 --- a/includes/upload/UploadFromFile.php +++ b/includes/upload/UploadFromFile.php @@ -1,32 +1,65 @@ <?php /** + * Implements regular file uploads + * * @file * @ingroup upload - * * @author Bryan Tong Minh - * - * Implements regular file uploads */ -class UploadFromFile extends UploadBase { +class UploadFromFile extends UploadBase { + protected $mUpload = null; function initializeFromRequest( &$request ) { + $upload = $request->getUpload( 'wpUploadFile' ); $desiredDestName = $request->getText( 'wpDestFile' ); if( !$desiredDestName ) - $desiredDestName = $request->getFileName( 'wpUploadFile' ); - return $this->initializePathInfo( - $desiredDestName, - $request->getFileTempName( 'wpUploadFile' ), - $request->getFileSize( 'wpUploadFile' ) - ); + $desiredDestName = $upload->getName(); + + return $this->initialize( $desiredDestName, $upload ); } + /** - * Entry point for upload from file. + * Initialize from a filename and a WebRequestUpload */ - function initialize( $name, $tempPath, $fileSize ) { - return $this->initializePathInfo( $name, $tempPath, $fileSize ); + function initialize( $name, $webRequestUpload ) { + $this->mUpload = $webRequestUpload; + return $this->initializePathInfo( $name, + $this->mUpload->getTempName(), $this->mUpload->getSize() ); } static function isValidRequest( $request ) { - return (bool)$request->getFileTempName( 'wpUploadFile' ); + # 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; + } + + public function verifyUpload() { + # 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( + 'status' => UploadBase::FILE_TOO_LARGE, + 'max' => min( + $wgMaxUploadSize, + wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), + wfShorthandToInteger( ini_get( 'post_max_size' ) ) + ), + ); + } + } + + return parent::verifyUpload(); + } + + /** + * Get the path to the file underlying the upload + * @return String path to file + */ + public function getFileTempname() { + return $this->mUpload->getTempname(); } + + } |