Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / filerepo / FileRepo.php
index 24c3964..15821ea 100644 (file)
@@ -956,7 +956,7 @@ class FileRepo {
         * This function can be used to write to otherwise read-only foreign repos.
         * This is intended for copying generated thumbnails into the repo.
         *
-        * @param string $src Source file system path, storage path, or virtual URL
+        * @param string|FSFile $src Source file system path, storage path, or virtual URL
         * @param string $dst Virtual URL or storage path
         * @param array|string|null $options An array consisting of a key named headers
         *   listing extra headers. If a string, taken as content-disposition header.
@@ -1003,7 +1003,7 @@ class FileRepo {
         * All path parameters may be a file system path, storage path, or virtual URL.
         * When "headers" are given they are used as HTTP headers if supported.
         *
-        * @param array $triples List of (source path, destination path, disposition)
+        * @param array $triples List of (source path or FSFile, destination path, disposition)
         * @return FileRepoStatus
         */
        public function quickImportBatch( array $triples ) {
@@ -1011,7 +1011,12 @@ class FileRepo {
                $operations = [];
                foreach ( $triples as $triple ) {
                        list( $src, $dst ) = $triple;
-                       $src = $this->resolveToStoragePath( $src );
+                       if ( $src instanceof FSFile ) {
+                               $op = 'store';
+                       } else {
+                               $src = $this->resolveToStoragePath( $src );
+                               $op = FileBackend::isStoragePath( $src ) ? 'copy' : 'store';
+                       }
                        $dst = $this->resolveToStoragePath( $dst );
 
                        if ( !isset( $triple[2] ) ) {
@@ -1026,7 +1031,7 @@ class FileRepo {
                        }
 
                        $operations[] = [
-                               'op' => FileBackend::isStoragePath( $src ) ? 'copy' : 'store',
+                               'op' => $op,
                                'src' => $src,
                                'dst' => $dst,
                                'headers' => $headers
@@ -1110,7 +1115,7 @@ class FileRepo {
         * @param array $srcPaths Ordered list of source virtual URLs/storage paths
         * @param string $dstPath Target file system path
         * @param int $flags Bitwise combination of the following flags:
-        *   self::DELETE_SOURCE     Delete the source files
+        *   self::DELETE_SOURCE     Delete the source files on success
         * @return FileRepoStatus
         */
        public function concatenate( array $srcPaths, $dstPath, $flags = 0 ) {
@@ -1153,7 +1158,7 @@ class FileRepo {
         * Options to $options include:
         *   - headers : name/value map of HTTP headers to use in response to GET/HEAD requests
         *
-        * @param string $srcPath The source file system path, storage path, or URL
+        * @param string|FSFile $src The source file system path, storage path, or URL
         * @param string $dstRel The destination relative path
         * @param string $archiveRel The relative path where the existing file is to
         *   be archived, if there is one. Relative to the public zone root.
@@ -1163,12 +1168,12 @@ class FileRepo {
         * @return FileRepoStatus
         */
        public function publish(
-               $srcPath, $dstRel, $archiveRel, $flags = 0, array $options = []
+               $src, $dstRel, $archiveRel, $flags = 0, array $options = []
        ) {
                $this->assertWritableRepo(); // fail out if read-only
 
                $status = $this->publishBatch(
-                       [ [ $srcPath, $dstRel, $archiveRel, $options ] ], $flags );
+                       [ [ $src, $dstRel, $archiveRel, $options ] ], $flags );
                if ( $status->successCount == 0 ) {
                        $status->ok = false;
                }
@@ -1207,7 +1212,9 @@ class FileRepo {
                $sourceFSFilesToDelete = []; // cleanup for disk source files
                // Validate each triplet and get the store operation...
                foreach ( $ntuples as $ntuple ) {
-                       list( $srcPath, $dstRel, $archiveRel ) = $ntuple;
+                       list( $src, $dstRel, $archiveRel ) = $ntuple;
+                       $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
+
                        $options = isset( $ntuple[3] ) ? $ntuple[3] : [];
                        // Resolve source to a storage path if virtual
                        $srcPath = $this->resolveToStoragePath( $srcPath );
@@ -1270,7 +1277,7 @@ class FileRepo {
                        } else { // FS source path
                                $operations[] = [
                                        'op' => 'store',
-                                       'src' => $srcPath,
+                                       'src' => $src, // prefer FSFile objects
                                        'dst' => $dstPath,
                                        'overwrite' => true, // replace current
                                        'headers' => $headers
@@ -1899,7 +1906,7 @@ class FileRepo {
 
        /**
         * Returns whether or not storage is SHA-1 based
-        * @return boolean
+        * @return bool
         */
        public function hasSha1Storage() {
                return $this->hasSha1Storage;
@@ -1907,7 +1914,7 @@ class FileRepo {
 
        /**
         * Returns whether or not repo supports having originals SHA-1s in the thumb URLs
-        * @return boolean
+        * @return bool
         */
        public function supportsSha1URLs() {
                return $this->supportsSha1URLs;