From b21d160c83522c8e601475b35317a979eb309400 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 15 May 2011 12:35:50 +0000 Subject: [PATCH] (bug 1780) Uploading files with non-ascii characters are now forbidden on Windows. PHP on Windows does not reliably support non-ascii characters to forbid them all. Theoretically we could detect the filesystem locale and iconv the filename, but that is just too much hassle. Added message 'windows-nonascii-filename'. --- RELEASE-NOTES-1.19 | 2 ++ includes/api/ApiUpload.php | 3 +++ includes/specials/SpecialUpload.php | 4 ++++ includes/upload/UploadBase.php | 8 ++++++++ languages/messages/MessagesEn.php | 1 + maintenance/language/messages.inc | 1 + 6 files changed, 19 insertions(+) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index ab134faa2f..4b9012a987 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -49,6 +49,8 @@ used in Tiff files. * (bug 28287) The "your changes" box for edit conflicts is now read-only. * (bug 28940) When making a thumb of an SVG, and only specifying the height make the width be the max SVG size, not the natrual width of the SVG. +* (bug 1780) Uploading files with non-ascii characters are now forbidden on + Windows. === API changes in 1.19 === * (bug 27790) add query type for querymodules to action=paraminfo diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index f21408c078..a84f15c6db 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -294,6 +294,9 @@ class ApiUpload extends ApiBase { case UploadBase::FILETYPE_MISSING: $this->dieRecoverableError( 'filetype-missing', 'filename' ); break; + case UploadBase::WINDOWS_NONASCII_FILENAME: + $this->dieRecoverableError( 'windows-nonascii-filename', 'filename' ); + break; // Unrecoverable errors case UploadBase::EMPTY_FILE: diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 82863403fb..32b8ab6d11 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -583,6 +583,10 @@ class SpecialUpload extends SpecialPage { $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing', 'parseinline' ) ); break; + case UploadBase::WINDOWS_NONASCII_FILENAME: + $this->showRecoverableUploadError( wfMsgExt( 'windows-nonascii-filename', + 'parseinline' ) ); + break; /** Statuses that require reuploading **/ case UploadBase::EMPTY_FILE: diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 0741326bb1..2d351ac512 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -36,6 +36,7 @@ abstract class UploadBase { const UPLOAD_VERIFICATION_ERROR = 11; const HOOK_ABORTED = 11; const FILE_TOO_LARGE = 12; + const WINDOWS_NONASCII_FILENAME = 13; const SESSION_VERSION = 2; const SESSION_KEYNAME = 'wsUploadData'; @@ -54,6 +55,7 @@ abstract class UploadBase { self::OVERWRITE_EXISTING_FILE => 'overwrite', self::VERIFICATION_ERROR => 'verification-error', self::HOOK_ABORTED => 'hookaborted', + self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename', ); if( isset( $code_to_status[$error] ) ) { return $code_to_status[$error]; @@ -658,6 +660,12 @@ abstract class UploadBase { $this->mTitleError = self::FILETYPE_BADTYPE; return $this->mTitle = null; } + + // Windows may be broken with special characters, see bug XXX + if ( wfIsWindows() && !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) ) { + $this->mTitleError = self::WINDOWS_NONASCII_FILENAME; + return $this->mTitle = null; + } # If there was more than one "extension", reassemble the base # filename to prevent bogus complaints about length diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a9d2ad2cc2..01c9c7f191 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2163,6 +2163,7 @@ If you still want to upload your file, please go back and use a new name. 'file-exists-duplicate' => 'This file is a duplicate of the following {{PLURAL:$1|file|files}}:', 'file-deleted-duplicate' => "A file identical to this file ([[:$1]]) has previously been deleted. You should check that file's deletion history before proceeding to re-upload it.", +'windows-nonascii-filename' => 'The server does not support filenames with special characters.', 'uploadwarning' => 'Upload warning', 'uploadwarning-text' => 'Please modify the file description below and try again.', 'savefile' => 'Save file', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 46e0d393fe..80b0d175e1 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1282,6 +1282,7 @@ $wgMessageStructure = array( 'large-file', 'largefileserver', 'emptyfile', + 'windows-nonascii-filename', 'fileexists', 'filepageexists', 'fileexists-extension', -- 2.20.1