Follow-up r98430, use dedicated error message for filename too long error. Adds ...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 7 Oct 2011 18:20:55 +0000 (18:20 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 7 Oct 2011 18:20:55 +0000 (18:20 +0000)
includes/api/ApiUpload.php
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 961081d..947e015 100644 (file)
@@ -350,6 +350,9 @@ class ApiUpload extends ApiBase {
                                $this->dieRecoverableError( 'illegal-filename', 'filename',
                                                array( 'filename' => $verification['filtered'] ) );
                                break;
+                       case UploadBase::FILENAME_TOO_LONG:
+                               $this->dieRecoverableError( 'filename-toolong', 'filename' );
+                               break;
                        case UploadBase::FILETYPE_MISSING:
                                $this->dieRecoverableError( 'filetype-missing', 'filename' );
                                break;
index d6b8d0a..724e77a 100644 (file)
@@ -558,6 +558,9 @@ class SpecialUpload extends SpecialPage {
                                $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
                                        'parseinline', $details['filtered'] ) );
                                break;
+                       case UploadBase::FILENAME_TOO_LONG:
+                               $this->showRecoverableUploadError( wfMsgHtml( 'filename-toolong' ) );
+                               break;
                        case UploadBase::FILETYPE_MISSING:
                                $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
                                        'parseinline' ) );
index 3c66086..3a9170b 100644 (file)
@@ -37,6 +37,7 @@ abstract class UploadBase {
        const HOOK_ABORTED = 11;
        const FILE_TOO_LARGE = 12;
        const WINDOWS_NONASCII_FILENAME = 13;
+       const FILENAME_TOO_LONG = 14;
 
        public function getVerificationErrorCode( $error ) {
                $code_to_status = array(self::EMPTY_FILE => 'empty-file',
@@ -49,6 +50,7 @@ abstract class UploadBase {
                                                                self::VERIFICATION_ERROR => 'verification-error',
                                                                self::HOOK_ABORTED =>  'hookaborted',
                                                                self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
+                                                               self::FILENAME_TOO_LONG => 'filename-toolong',
                );
                if( isset( $code_to_status[$error] ) ) {
                        return $code_to_status[$error];
@@ -617,6 +619,13 @@ abstract class UploadBase {
                        $this->mFilteredName = $this->mDesiredDestName;
                }
 
+               # oi_archive_name is max 255 bytes, which include a timestamp and an
+               # exclamation mark, so restrict file name to 240 bytes.
+               if ( strlen( $this->mFilteredName ) > 240 ) {
+                       $this->mTitleError = self::FILENAME_TOO_LONG;
+                       return $this->mTitle = null;                    
+               }
+               
                /**
                 * Chop off any directories in the given filename. Then
                 * filter out illegal characters, and try to make a legible name
@@ -631,13 +640,7 @@ abstract class UploadBase {
                }
                $this->mFilteredName = $nt->getDBkey();
 
-               # oi_archive_name is max 255 bytes, which include a timestamp and an
-               # exclamation mark, so restrict file name to 240 bytes. Return
-               # ILLEGAL_FILENAME, just like would have happened for >255 bytes
-               if ( strlen( $this->mFilteredName ) > 240 ) {
-                       $this->mTitleError = self::ILLEGAL_FILENAME;
-                       return $this->mTitle = null;                    
-               }
+
                
                /**
                 * We'll want to blacklist against *any* 'extension', and use
index be5bcbe..23c389b 100644 (file)
@@ -2119,6 +2119,7 @@ See the [[Special:NewFiles|gallery of new files]] for a more visual overview.',
 'minlength1'                  => 'File names must be at least one letter.',
 'illegalfilename'             => 'The filename "$1" contains characters that are not allowed in page titles.
 Please rename the file and try uploading it again.',
+'filename-toolong'            => 'File names may not be longer than 240 bytes.',
 'badfilename'                 => 'File name has been changed to "$1".',
 'filetype-mime-mismatch'      => 'File extension ".$1" does not match the detected MIME type of the file ($2).',
 'filetype-badmime'            => 'Files of the MIME type "$1" are not allowed to be uploaded.',
index 01a7859..0ee9f38 100644 (file)
@@ -1273,6 +1273,7 @@ $wgMessageStructure = array(
                'ignorewarnings',
                'minlength1',
                'illegalfilename',
+               'filename-toolong',
                'badfilename',
                'filetype-mime-mismatch',
                'filetype-badmime',