Added unicode encoding support flags to FileBackend
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 12 Apr 2014 06:50:58 +0000 (23:50 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 13 May 2014 21:11:36 +0000 (14:11 -0700)
* Fixed bug where even using Swift/Azure on Windows
  would disallow non-ASCII file names.

bug: 1780
Change-Id: I19ed72da0b099d35cae74fb08eeb22c113da1065

includes/filebackend/FSFileBackend.php
includes/filebackend/FileBackend.php
includes/filebackend/SwiftFileBackend.php
includes/filerepo/FileRepo.php
includes/upload/UploadBase.php

index 2b18443..9586657 100644 (file)
@@ -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 ) ) {
index f99da6d..a9e312d 100644 (file)
@@ -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;
        }
 
        /**
index 2f4be9e..9249a09 100644 (file)
@@ -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 ) {
index 7a30ccc..4c250ba 100644 (file)
@@ -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.
index 746c16d..8071ad1 100644 (file)
@@ -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;