From f3fc3c7f43fec53714d58155bbd3f5e2a6e38089 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Fri, 7 Oct 2011 18:20:55 +0000 Subject: [PATCH] Follow-up r98430, use dedicated error message for filename too long error. Adds 'filename-toolong' message. --- includes/api/ApiUpload.php | 3 +++ includes/specials/SpecialUpload.php | 3 +++ includes/upload/UploadBase.php | 17 ++++++++++------- languages/messages/MessagesEn.php | 1 + maintenance/language/messages.inc | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 961081dfe8..947e015c35 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -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; diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index d6b8d0abc2..724e77a580 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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' ) ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 3c66086f50..3a9170b72e 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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 diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index be5bcbe0fa..23c389b2f4 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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.', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 01a7859e90..0ee9f38e35 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1273,6 +1273,7 @@ $wgMessageStructure = array( 'ignorewarnings', 'minlength1', 'illegalfilename', + 'filename-toolong', 'badfilename', 'filetype-mime-mismatch', 'filetype-badmime', -- 2.20.1