(bug 17941) $wgMaxUploadSize is now honored by all upload sources
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 15 Apr 2010 09:28:33 +0000 (09:28 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 15 Apr 2010 09:28:33 +0000 (09:28 +0000)
RELEASE-NOTES
includes/api/ApiUpload.php
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php
includes/upload/UploadFromUrl.php

index 7eaef4d..ed91637 100644 (file)
@@ -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
index 2ff58f8..f2c5269 100644 (file)
@@ -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;
index 33b53aa..d236f12 100644 (file)
@@ -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 = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\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',
index 09bf672..73031f0 100644 (file)
@@ -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
index 5f4912e..af97d9f 100644 (file)
@@ -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;
        }