Merge "Upgrade wikimedia/remex-html to 2.0.1" into REL1_31
[lhc/web/wiklou.git] / includes / filerepo / FileRepo.php
index 5005280..b15f81f 100644 (file)
@@ -78,10 +78,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;
 
@@ -124,7 +120,7 @@ class FileRepo {
        protected $isPrivate;
 
        /** @var array callable Override these in the base class */
-       protected $fileFactory = [ 'UnregisteredLocalFile', 'newFromTitle' ];
+       protected $fileFactory = [ UnregisteredLocalFile::class, 'newFromTitle' ];
        /** @var array callable|bool Override these in the base class */
        protected $oldFileFactory = false;
        /** @var array callable|bool Override these in the base class */
@@ -132,6 +128,13 @@ class FileRepo {
        /** @var array callable|bool Override these in the base class */
        protected $oldFileFactoryKey = false;
 
+       /** @var string URL of where to proxy thumb.php requests to.
+        *    Example: http://127.0.0.1:8888/wiki/dev/thumb/
+        */
+       protected $thumbProxyUrl;
+       /** @var string Secret key to pass as an X-Swift-Secret header to the proxied thumb service */
+       protected $thumbProxySecret;
+
        /**
         * @param array|null $info
         * @throws MWException
@@ -159,7 +162,7 @@ class FileRepo {
                $optionalSettings = [
                        'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
                        'thumbScriptUrl', 'pathDisclosureProtection', 'descriptionCacheExpiry',
-                       'scriptExtension', 'favicon'
+                       'favicon', 'thumbProxyUrl', 'thumbProxySecret',
                ];
                foreach ( $optionalSettings as $var ) {
                        if ( isset( $info[$var] ) ) {
@@ -575,8 +578,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 = [];
@@ -596,7 +599,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 [];
@@ -611,6 +614,24 @@ class FileRepo {
                return $this->thumbScriptUrl;
        }
 
+       /**
+        * Get the URL thumb.php requests are being proxied to
+        *
+        * @return string
+        */
+       public function getThumbProxyUrl() {
+               return $this->thumbProxyUrl;
+       }
+
+       /**
+        * Get the secret key for the proxied thumb service
+        *
+        * @return string
+        */
+       public function getThumbProxySecret() {
+               return $this->thumbProxySecret;
+       }
+
        /**
         * Returns true if the repository can transform files via a 404 handler
         *
@@ -719,9 +740,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;
@@ -770,7 +789,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 ) {
@@ -909,7 +928,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
@@ -1293,9 +1312,9 @@ class FileRepo {
                }
                // Cleanup for disk source files...
                foreach ( $sourceFSFilesToDelete as $file ) {
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
                        unlink( $file ); // FS cleanup
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                }
 
                return $status;
@@ -1359,7 +1378,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 ) {
@@ -1465,7 +1484,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();
@@ -1543,7 +1562,7 @@ class FileRepo {
         */
        public function getFileProps( $virtualUrl ) {
                $fsFile = $this->getLocalReference( $virtualUrl );
-               $mwProps = new MWFileProps( MimeMagic::singleton() );
+               $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
                if ( $fsFile ) {
                        $props = $mwProps->getPropsFromPath( $fsFile->getPath(), true );
                } else {
@@ -1609,7 +1628,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;
        }
@@ -1681,7 +1704,7 @@ class FileRepo {
        /**
         * Get a callback function to use for cleaning error message parameters
         *
-        * @return array
+        * @return string[]
         */
        function getErrorCleanupFunction() {
                switch ( $this->pathDisclosureProtection ) {
@@ -1722,7 +1745,7 @@ class FileRepo {
         * @return Status
         */
        public function newFatal( $message /*, parameters...*/ ) {
-               $status = call_user_func_array( [ 'Status', 'newFatal' ], func_get_args() );
+               $status = call_user_func_array( [ Status::class, 'newFatal' ], func_get_args() );
                $status->cleanCallback = $this->getErrorCleanupFunction();
 
                return $status;
@@ -1870,7 +1893,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 ) {
@@ -1903,7 +1926,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 ) ) {