From 0d54e6e0bf5e3e5dc13a6a4278c914fe409a37cd Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 11 Apr 2014 23:50:58 -0700 Subject: [PATCH] Added unicode encoding support flags to FileBackend * Fixed bug where even using Swift/Azure on Windows would disallow non-ASCII file names. bug: 1780 Change-Id: I19ed72da0b099d35cae74fb08eeb22c113da1065 --- includes/filebackend/FSFileBackend.php | 4 ++++ includes/filebackend/FileBackend.php | 9 +++++---- includes/filebackend/SwiftFileBackend.php | 3 ++- includes/filerepo/FileRepo.php | 7 +++++++ includes/upload/UploadBase.php | 6 ++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php index 2b184436fb..9586657493 100644 --- a/includes/filebackend/FSFileBackend.php +++ b/includes/filebackend/FSFileBackend.php @@ -90,6 +90,10 @@ class FSFileBackend extends FileBackendStore { } } + public function getFeatures() { + return !wfIsWindows() ? FileBackend::ATTR_UNICODE_PATHS : 0; + } + protected function resolveContainerPath( $container, $relStoragePath ) { // Check that container has a root directory if ( isset( $this->containerPaths[$container] ) || isset( $this->basePath ) ) { diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php index f99da6dbc7..a9e312dafb 100644 --- a/includes/filebackend/FileBackend.php +++ b/includes/filebackend/FileBackend.php @@ -104,9 +104,10 @@ abstract class FileBackend { /** @var FileJournal */ protected $fileJournal; - /** Flags for supported features */ - const ATTR_HEADERS = 1; - const ATTR_METADATA = 2; + /** Bitfield flags for supported features */ + const ATTR_HEADERS = 1; // files can be tagged with standard HTTP headers + const ATTR_METADATA = 2; // files can be stored with metadata key/values + const ATTR_UNICODE_PATHS = 4; // files can have Unicode paths (not just ASCII) /** * Create a new backend instance from configuration. @@ -211,7 +212,7 @@ abstract class FileBackend { * @since 1.23 */ public function getFeatures() { - return 0; + return self::ATTR_UNICODE_PATHS; } /** diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 2f4be9ed4a..9249a0950e 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -146,7 +146,8 @@ class SwiftFileBackend extends FileBackendStore { } public function getFeatures() { - return ( FileBackend::ATTR_HEADERS | FileBackend::ATTR_METADATA ); + return ( FileBackend::ATTR_UNICODE_PATHS | + FileBackend::ATTR_HEADERS | FileBackend::ATTR_METADATA ); } protected function resolveContainerPath( $container, $relStoragePath ) { diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 7a30ccc26c..4c250baf9d 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -295,6 +295,13 @@ class FileRepo { } } + /** + * @return bool Whether non-ASCII path characters are allowed + */ + public function backendSupportsUnicodePaths() { + return ( $this->getBackend()->getFeatures() & FileBackend::ATTR_UNICODE_PATHS ); + } + /** * Get the backend storage path corresponding to a virtual URL. * Use this function wisely. diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 746c16d0e2..8071ad15c3 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -799,8 +799,10 @@ abstract class UploadBase { return $this->mTitle; } - // Windows may be broken with special characters, see bug XXX - if ( wfIsWindows() && !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) ) { + // Windows may be broken with special characters, see bug 1780 + if ( !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) + && !RepoGroup::singleton()->getLocalRepo()->backendSupportsUnicodePaths() + ) { $this->mTitleError = self::WINDOWS_NONASCII_FILENAME; $this->mTitle = null; return $this->mTitle; -- 2.20.1