From 7a92e75a9fc7ddee5257fcb9929d1986d4b2c9a3 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 15 Apr 2010 09:28:33 +0000 Subject: [PATCH] (bug 17941) $wgMaxUploadSize is now honored by all upload sources --- RELEASE-NOTES | 1 + includes/api/ApiUpload.php | 3 +++ includes/specials/SpecialUpload.php | 15 +++++++++++---- includes/upload/UploadBase.php | 10 ++++++++++ includes/upload/UploadFromUrl.php | 7 +++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 7eaef4de4c..ed91637c4c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -111,6 +111,7 @@ in a negative namespace (which is invalid). displays incorrect tabs * (bug 23190) Improved math representation for text browsers. * (bug 22015) Improved upload-by-url error handling and error display +* (bug 17941) $wgMaxUploadSize is now honored by all upload sources === API changes in 1.17 === * (bug 22738) Allow filtering by action type on query=logevent diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 2ff58f8629..f2c5269782 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -154,6 +154,9 @@ class ApiUpload extends ApiBase { case UploadBase::EMPTY_FILE: $this->dieUsage( 'The file you submitted was empty', 'empty-file' ); break; + case UploadBase::FILE_TOO_LARGE: + $this->dieUsage( 'The file you submitted was too large', 'file-too-large' ); + break; case UploadBase::FILETYPE_MISSING: $this->dieUsage( 'The file is missing an extension', 'filetype-missing' ); break; diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 33b53aaba6..d236f12a68 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -365,7 +365,7 @@ class SpecialUpload extends SpecialPage { /** * Show the upload form with error message, but do not stash the file. * - * @param $message String + * @param $message HTML string */ protected function showUploadError( $message ) { $message = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . @@ -522,7 +522,10 @@ class SpecialUpload extends SpecialPage { /** Statuses that require reuploading **/ case UploadBase::EMPTY_FILE: - $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) ); + $this->showUploadError( wfMsgHtml( 'emptyfile' ) ); + break; + case UploadBase::FILESIZE_TOO_LARGE: + $this->showUploadError( wfMsgHtml( 'largefileserver' ) ); break; case UploadBase::FILETYPE_BADTYPE: $finalExt = $details['finalExt']; @@ -744,6 +747,7 @@ class UploadForm extends HTMLForm { */ protected function getSourceSection() { global $wgLang, $wgUser, $wgRequest; + global $wgMaxUploadSize; if ( $this->mSessionKey ) { return array( @@ -783,13 +787,16 @@ class UploadForm extends HTMLForm { 'help' => wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), $wgLang->formatSize( - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) + wfShorthandToInteger( min( + wfShorthandToInteger( + ini_get( 'upload_max_filesize' ) + ), $wgMaxUploadSize + ) ) ) ) . ' ' . wfMsgHtml( 'upload_source_file' ), 'checked' => $selectedSourceType == 'file', ); if ( $canUploadByUrl ) { - global $wgMaxUploadSize; $descriptor['UploadFileURL'] = array( 'class' => 'UploadSourceField', 'section' => 'source', diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 09bf67227e..73031f0579 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -29,8 +29,10 @@ abstract class UploadBase { const FILETYPE_MISSING = 8; const FILETYPE_BADTYPE = 9; const VERIFICATION_ERROR = 10; + # HOOK_ABORTED is the new name of UPLOAD_VERIFICATION_ERROR const UPLOAD_VERIFICATION_ERROR = 11; const HOOK_ABORTED = 11; + const FILE_TOO_LARGE = 12; const SESSION_VERSION = 2; const SESSION_KEYNAME = 'wsUploadData'; @@ -199,6 +201,14 @@ abstract class UploadBase { if( $this->isEmptyFile() ) { return array( 'status' => self::EMPTY_FILE ); } + + /** + * Honor $wgMaxUploadSize + */ + global $wgMaxUploadSize; + if( $this->mFileSize > $wgMaxUploadSize ) { + return array( 'status' => self::FILE_TOO_LARGE ); + } /** * Look at the contents of the file; if we can recognize the diff --git a/includes/upload/UploadFromUrl.php b/includes/upload/UploadFromUrl.php index 5f4912ef53..af97d9fc80 100644 --- a/includes/upload/UploadFromUrl.php +++ b/includes/upload/UploadFromUrl.php @@ -96,6 +96,13 @@ class UploadFromUrl extends UploadBase { fclose( $this->mCurlDestHandle ); unset( $this->mCurlDestHandle ); + global $wgMaxUploadSize; + if ( $this->mFileSize > $wgMaxUploadSize ) { + # Just return an ok, so that the regular verifications can handle + # the file-too-large error + return Status::newGood(); + } + return $status; } -- 2.20.1