Localisation updates from https://translatewiki.net.
[lhc/web/wiklou.git] / includes / filerepo / FileRepo.php
index e430bc8..858e124 100644 (file)
@@ -7,6 +7,8 @@
  * @details
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Base code for file repositories.
  *
@@ -78,10 +80,6 @@ class FileRepo {
         */
        protected $scriptDirUrl;
 
-       /** @var string Script extension of the MediaWiki installation, equivalent
-        *    to the old $wgScriptExtension, e.g. .php5 defaults to .php */
-       protected $scriptExtension;
-
        /** @var string Equivalent to $wgArticlePath, e.g. https://en.wikipedia.org/wiki/$1 */
        protected $articleUrl;
 
@@ -166,7 +164,7 @@ class FileRepo {
                $optionalSettings = [
                        'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
                        'thumbScriptUrl', 'pathDisclosureProtection', 'descriptionCacheExpiry',
-                       'scriptExtension', 'favicon', 'thumbProxyUrl', 'thumbProxySecret'
+                       'favicon', 'thumbProxyUrl', 'thumbProxySecret',
                ];
                foreach ( $optionalSettings as $var ) {
                        if ( isset( $info[$var] ) ) {
@@ -175,30 +173,20 @@ class FileRepo {
                }
 
                // Optional settings that have a default
-               $this->initialCapital = isset( $info['initialCapital'] )
-                       ? $info['initialCapital']
-                       : MWNamespace::isCapitalized( NS_FILE );
-               $this->url = isset( $info['url'] )
-                       ? $info['url']
-                       : false; // a subclass may set the URL (e.g. ForeignAPIRepo)
+               $this->initialCapital = $info['initialCapital'] ?? MWNamespace::isCapitalized( NS_FILE );
+               $this->url = $info['url'] ?? false; // a subclass may set the URL (e.g. ForeignAPIRepo)
                if ( isset( $info['thumbUrl'] ) ) {
                        $this->thumbUrl = $info['thumbUrl'];
                } else {
                        $this->thumbUrl = $this->url ? "{$this->url}/thumb" : false;
                }
-               $this->hashLevels = isset( $info['hashLevels'] )
-                       ? $info['hashLevels']
-                       : 2;
-               $this->deletedHashLevels = isset( $info['deletedHashLevels'] )
-                       ? $info['deletedHashLevels']
-                       : $this->hashLevels;
+               $this->hashLevels = $info['hashLevels'] ?? 2;
+               $this->deletedHashLevels = $info['deletedHashLevels'] ?? $this->hashLevels;
                $this->transformVia404 = !empty( $info['transformVia404'] );
-               $this->abbrvThreshold = isset( $info['abbrvThreshold'] )
-                       ? $info['abbrvThreshold']
-                       : 255;
+               $this->abbrvThreshold = $info['abbrvThreshold'] ?? 255;
                $this->isPrivate = !empty( $info['isPrivate'] );
                // Give defaults for the basic zones...
-               $this->zones = isset( $info['zones'] ) ? $info['zones'] : [];
+               $this->zones = $info['zones'] ?? [];
                foreach ( [ 'public', 'thumb', 'transcoded', 'temp', 'deleted' ] as $zone ) {
                        if ( !isset( $this->zones[$zone]['container'] ) ) {
                                $this->zones[$zone]['container'] = "{$this->name}-{$zone}";
@@ -432,7 +420,7 @@ class FileRepo {
                if ( isset( $options['bypassCache'] ) ) {
                        $options['latest'] = $options['bypassCache']; // b/c
                }
-               $time = isset( $options['time'] ) ? $options['time'] : false;
+               $time = $options['time'] ?? false;
                $flags = !empty( $options['latest'] ) ? File::READ_LATEST : 0;
                # First try the current version of the file to see if it precedes the timestamp
                $img = $this->newFile( $title );
@@ -538,7 +526,7 @@ class FileRepo {
         * @return File|bool False on failure
         */
        public function findFileFromKey( $sha1, $options = [] ) {
-               $time = isset( $options['time'] ) ? $options['time'] : false;
+               $time = $options['time'] ?? false;
                # First try to find a matching current version of a file...
                if ( !$this->fileFactoryKey ) {
                        return false; // find-by-sha1 not supported
@@ -582,8 +570,8 @@ class FileRepo {
         * Get an array of arrays or iterators of file objects for files that
         * have the given SHA-1 content hashes.
         *
-        * @param array $hashes An array of hashes
-        * @return array An Array of arrays or iterators of file objects and the hash as key
+        * @param string[] $hashes An array of hashes
+        * @return array[] An Array of arrays or iterators of file objects and the hash as key
         */
        public function findBySha1s( array $hashes ) {
                $result = [];
@@ -603,7 +591,7 @@ class FileRepo {
         * STUB
         * @param string $prefix The prefix to search for
         * @param int $limit The maximum amount of files to return
-        * @return array
+        * @return LocalFile[]
         */
        public function findFilesByPrefix( $prefix, $limit ) {
                return [];
@@ -652,11 +640,10 @@ class FileRepo {
         * @return string
         */
        public function getNameFromTitle( Title $title ) {
-               global $wgContLang;
                if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
                        $name = $title->getUserCaseDBKey();
                        if ( $this->initialCapital ) {
-                               $name = $wgContLang->ucfirst( $name );
+                               $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
                        }
                } else {
                        $name = $title->getDBkey();
@@ -694,7 +681,7 @@ class FileRepo {
         */
        public function getTempHashPath( $suffix ) {
                $parts = explode( '!', $suffix, 2 ); // format is <timestamp>!<name> or just <name>
-               $name = isset( $parts[1] ) ? $parts[1] : $suffix; // hash path is not based on timestamp
+               $name = $parts[1] ?? $suffix; // hash path is not based on timestamp
                return self::getHashPathForLevel( $name, $this->hashLevels );
        }
 
@@ -744,9 +731,7 @@ class FileRepo {
         */
        public function makeUrl( $query = '', $entry = 'index' ) {
                if ( isset( $this->scriptDirUrl ) ) {
-                       $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
-
-                       return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
+                       return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}.php", $query );
                }
 
                return false;
@@ -795,7 +780,7 @@ class FileRepo {
         * should use File::getDescriptionText().
         *
         * @param string $name Name of image to fetch
-        * @param string $lang Language to fetch it in, if any.
+        * @param string|null $lang Language to fetch it in, if any.
         * @return string|false
         */
        public function getDescriptionRenderUrl( $name, $lang = null ) {
@@ -934,7 +919,7 @@ class FileRepo {
         * Each file can be a (zone, rel) pair, virtual url, storage path.
         * It will try to delete each file, but ignores any errors that may occur.
         *
-        * @param array $files List of files to delete
+        * @param string[] $files List of files to delete
         * @param int $flags Bitwise combination of the following flags:
         *   self::SKIP_LOCKING      Skip any file locking when doing the deletions
         * @return Status
@@ -1193,11 +1178,7 @@ class FileRepo {
                if ( $status->successCount == 0 ) {
                        $status->setOK( false );
                }
-               if ( isset( $status->value[0] ) ) {
-                       $status->value = $status->value[0];
-               } else {
-                       $status->value = false;
-               }
+               $status->value = $status->value[0] ?? false;
 
                return $status;
        }
@@ -1231,7 +1212,7 @@ class FileRepo {
                        list( $src, $dstRel, $archiveRel ) = $ntuple;
                        $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
 
-                       $options = isset( $ntuple[3] ) ? $ntuple[3] : [];
+                       $options = $ntuple[3] ?? [];
                        // Resolve source to a storage path if virtual
                        $srcPath = $this->resolveToStoragePath( $srcPath );
                        if ( !$this->validateFilename( $dstRel ) ) {
@@ -1256,7 +1237,7 @@ class FileRepo {
                        }
 
                        // Set any desired headers to be use in GET/HEAD responses
-                       $headers = isset( $options['headers'] ) ? $options['headers'] : [];
+                       $headers = $options['headers'] ?? [];
 
                        // Archive destination file if it exists.
                        // This will check if the archive file also exists and fail if does.
@@ -1370,7 +1351,7 @@ class FileRepo {
        }
 
        /**
-        * Checks existence of a file
+        * Checks existence of a file
         *
         * @param string $file Virtual URL (or storage path) of file to check
         * @return bool
@@ -1384,7 +1365,7 @@ class FileRepo {
        /**
         * Checks existence of an array of files.
         *
-        * @param array $files Virtual URLs (or storage paths) of files to check
+        * @param string[] $files Virtual URLs (or storage paths) of files to check
         * @return array Map of files and existence flags, or false
         */
        public function fileExistsBatch( array $files ) {
@@ -1490,7 +1471,7 @@ class FileRepo {
         * Delete files in the deleted directory if they are not referenced in the filearchive table
         *
         * STUB
-        * @param array $storageKeys
+        * @param string[] $storageKeys
         */
        public function cleanupDeletedBatch( array $storageKeys ) {
                $this->assertWritableRepo();
@@ -1634,7 +1615,11 @@ class FileRepo {
                $status = $this->newGood();
                $status->merge( $this->backend->streamFile( $params ) );
 
-               ob_end_flush();
+               // T186565: Close the buffer, unless it has already been closed
+               // in HTTPFileStreamer::resetOutputBuffers().
+               if ( ob_get_status() ) {
+                       ob_end_flush();
+               }
 
                return $status;
        }
@@ -1706,7 +1691,7 @@ class FileRepo {
        /**
         * Get a callback function to use for cleaning error message parameters
         *
-        * @return array
+        * @return string[]
         */
        function getErrorCleanupFunction() {
                switch ( $this->pathDisclosureProtection ) {
@@ -1747,7 +1732,7 @@ class FileRepo {
         * @return Status
         */
        public function newFatal( $message /*, parameters...*/ ) {
-               $status = call_user_func_array( [ Status::class, 'newFatal' ], func_get_args() );
+               $status = Status::newFatal( ...func_get_args() );
                $status->cleanCallback = $this->getErrorCleanupFunction();
 
                return $status;
@@ -1852,7 +1837,7 @@ class FileRepo {
                $args = func_get_args();
                array_unshift( $args, 'filerepo', $this->getName() );
 
-               return call_user_func_array( 'wfMemcKey', $args );
+               return wfMemcKey( ...$args );
        }
 
        /**
@@ -1895,7 +1880,7 @@ class FileRepo {
        /**
         * Get an UploadStash associated with this repo.
         *
-        * @param User $user
+        * @param User|null $user
         * @return UploadStash
         */
        public function getUploadStash( User $user = null ) {
@@ -1928,7 +1913,7 @@ class FileRepo {
 
                $optionalSettings = [
                        'url', 'thumbUrl', 'initialCapital', 'descBaseUrl', 'scriptDirUrl', 'articleUrl',
-                       'fetchDescription', 'descriptionCacheExpiry', 'scriptExtension', 'favicon'
+                       'fetchDescription', 'descriptionCacheExpiry', 'favicon'
                ];
                foreach ( $optionalSettings as $k ) {
                        if ( isset( $this->$k ) ) {