r99224 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99223‎ | r99224 | r99225 >
Date:18:20, 7 October 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
Follow-up r98430, use dedicated error message for filename too long error. Adds 'filename-toolong' message.
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1273,6 +1273,7 @@
12741274 'ignorewarnings',
12751275 'minlength1',
12761276 'illegalfilename',
 1277+ 'filename-toolong',
12771278 'badfilename',
12781279 'filetype-mime-mismatch',
12791280 'filetype-badmime',
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -37,6 +37,7 @@
3838 const HOOK_ABORTED = 11;
3939 const FILE_TOO_LARGE = 12;
4040 const WINDOWS_NONASCII_FILENAME = 13;
 41+ const FILENAME_TOO_LONG = 14;
4142
4243 public function getVerificationErrorCode( $error ) {
4344 $code_to_status = array(self::EMPTY_FILE => 'empty-file',
@@ -49,6 +50,7 @@
5051 self::VERIFICATION_ERROR => 'verification-error',
5152 self::HOOK_ABORTED => 'hookaborted',
5253 self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
 54+ self::FILENAME_TOO_LONG => 'filename-toolong',
5355 );
5456 if( isset( $code_to_status[$error] ) ) {
5557 return $code_to_status[$error];
@@ -617,6 +619,13 @@
618620 $this->mFilteredName = $this->mDesiredDestName;
619621 }
620622
 623+ # oi_archive_name is max 255 bytes, which include a timestamp and an
 624+ # exclamation mark, so restrict file name to 240 bytes.
 625+ if ( strlen( $this->mFilteredName ) > 240 ) {
 626+ $this->mTitleError = self::FILENAME_TOO_LONG;
 627+ return $this->mTitle = null;
 628+ }
 629+
621630 /**
622631 * Chop off any directories in the given filename. Then
623632 * filter out illegal characters, and try to make a legible name
@@ -631,13 +640,7 @@
632641 }
633642 $this->mFilteredName = $nt->getDBkey();
634643
635 - # oi_archive_name is max 255 bytes, which include a timestamp and an
636 - # exclamation mark, so restrict file name to 240 bytes. Return
637 - # ILLEGAL_FILENAME, just like would have happened for >255 bytes
638 - if ( strlen( $this->mFilteredName ) > 240 ) {
639 - $this->mTitleError = self::ILLEGAL_FILENAME;
640 - return $this->mTitle = null;
641 - }
 644+
642645
643646 /**
644647 * We'll want to blacklist against *any* 'extension', and use
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -350,6 +350,9 @@
351351 $this->dieRecoverableError( 'illegal-filename', 'filename',
352352 array( 'filename' => $verification['filtered'] ) );
353353 break;
 354+ case UploadBase::FILENAME_TOO_LONG:
 355+ $this->dieRecoverableError( 'filename-toolong', 'filename' );
 356+ break;
354357 case UploadBase::FILETYPE_MISSING:
355358 $this->dieRecoverableError( 'filetype-missing', 'filename' );
356359 break;
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -558,6 +558,9 @@
559559 $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
560560 'parseinline', $details['filtered'] ) );
561561 break;
 562+ case UploadBase::FILENAME_TOO_LONG:
 563+ $this->showRecoverableUploadError( wfMsgHtml( 'filename-toolong' ) );
 564+ break;
562565 case UploadBase::FILETYPE_MISSING:
563566 $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
564567 'parseinline' ) );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2119,6 +2119,7 @@
21202120 'minlength1' => 'File names must be at least one letter.',
21212121 'illegalfilename' => 'The filename "$1" contains characters that are not allowed in page titles.
21222122 Please rename the file and try uploading it again.',
 2123+'filename-toolong' => 'File names may not be longer than 240 bytes.',
21232124 'badfilename' => 'File name has been changed to "$1".',
21242125 'filetype-mime-mismatch' => 'File extension ".$1" does not match the detected MIME type of the file ($2).',
21252126 'filetype-badmime' => 'Files of the MIME type "$1" are not allowed to be uploaded.',

Sign-offs

UserFlagDate
תומר א.inspected19:36, 7 October 2011
תומר א.tested19:36, 7 October 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r99225Follow-up r99224, fix unit tests.btongminh18:32, 7 October 2011
r102988Followup r99224: add message to ApiBase::$messageMap toocatrope14:40, 14 November 2011
r104311Qqq for r99224btongminh21:41, 26 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98430(bug 30202) Restrict file names on upload to 240 bytes, because wfTimestamp( ...btongminh19:00, 29 September 2011

Comments

#Comment by Duplicatebug (talk | contribs)   19:24, 7 October 2011

Hardcoding numbers in messages in unflexibel. It is better to give the number per parameter, than you can also add formatnum and plural support, maybe a language need that.

#Comment by Catrope (talk | contribs)   14:41, 14 November 2011

It's a hardcoded unconfigurable limit that will probably never change, so I don't see why that's necessary.

#Comment by Duplicatebug (talk | contribs)   16:03, 14 November 2011

The formatnum rules are applied automatic to the number and the plural rules also to the text. The translater has not to do that for his language manually.

Nobody can accidental change the number by customizied the message.

But it is your choice. Maybe add a hint to /qqq for translater, that he can format the number in his language style.

#Comment by תומר א. (talk | contribs)   19:36, 7 October 2011

I verified this bug in r99224 and it works well for me.

Status & tagging log