Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / includes / filebackend / FSFileBackend.php
index c953d77..dd43f82 100644 (file)
@@ -43,6 +43,8 @@ class FSFileBackend extends FileBackendStore {
        /** @var Array Map of container names to root paths */
        protected $containerPaths = array(); // for custom container paths
        protected $fileMode; // integer; file permission mode
+       protected $fileOwner; // string; required OS username to own files
+       protected $currentUser; // string; OS username running this script
 
        protected $hadWarningErrors = array();
 
@@ -71,9 +73,12 @@ class FSFileBackend extends FileBackendStore {
                        }
                }
 
-               $this->fileMode = isset( $config['fileMode'] )
-                       ? $config['fileMode']
-                       : 0644;
+               $this->fileMode = isset( $config['fileMode'] ) ? $config['fileMode'] : 0644;
+               if ( isset( $config['fileOwner'] ) && function_exists( 'posix_getuid' ) ) {
+                       $this->fileOwner = $config['fileOwner'];
+                       $info = posix_getpwuid( posix_getuid() );
+                       $this->currentUser = $info['name']; // cache this, assuming it doesn't change
+               }
        }
 
        /**
@@ -164,6 +169,11 @@ class FSFileBackend extends FileBackendStore {
                        $ok = is_dir( $parentDir ) && is_writable( $parentDir );
                }
 
+               if ( $this->fileOwner !== null && $this->currentUser !== $this->fileOwner ) {
+                       $ok = false;
+                       trigger_error( __METHOD__ . ": PHP process owner is not '{$this->fileOwner}'." );
+               }
+
                return $ok;
        }
 
@@ -634,7 +644,7 @@ class FSFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::getFileListInternal()
-        * @return array|FSFileBackendFileList|null
+        * @return Array|FSFileBackendFileList|null
         */
        public function getFileListInternal( $fullCont, $dirRel, array $params ) {
                list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
@@ -652,44 +662,58 @@ class FSFileBackend extends FileBackendStore {
        }
 
        /**
-        * @see FileBackendStore::getLocalReference()
-        * @return FSFile|null
+        * @see FileBackendStore::doGetLocalReferenceMulti()
+        * @return Array
         */
-       public function getLocalReference( array $params ) {
-               $source = $this->resolveToFSPath( $params['src'] );
-               if ( $source === null ) {
-                       return null;
+       protected function doGetLocalReferenceMulti( array $params ) {
+               $fsFiles = array(); // (path => FSFile)
+
+               foreach ( $params['srcs'] as $src ) {
+                       $source = $this->resolveToFSPath( $src );
+                       if ( $source === null || !is_file( $source ) ) {
+                               $fsFiles[$src] = null; // invalid path or file does not exist
+                       } else {
+                               $fsFiles[$src] = new FSFile( $source );
+                       }
                }
-               return new FSFile( $source );
+
+               return $fsFiles;
        }
 
        /**
-        * @see FileBackendStore::getLocalCopy()
-        * @return null|TempFSFile
+        * @see FileBackendStore::doGetLocalCopyMulti()
+        * @return Array
         */
-       public function getLocalCopy( array $params ) {
-               $source = $this->resolveToFSPath( $params['src'] );
-               if ( $source === null ) {
-                       return null;
-               }
+       protected function doGetLocalCopyMulti( array $params ) {
+               $tmpFiles = array(); // (path => TempFSFile)
 
-               // Create a new temporary file with the same extension...
-               $ext = FileBackend::extensionFromPath( $params['src'] );
-               $tmpFile = TempFSFile::factory( wfBaseName( $source ) . '_', $ext );
-               if ( !$tmpFile ) {
-                       return null;
-               }
-               $tmpPath = $tmpFile->getPath();
-
-               // Copy the source file over the temp file
-               $ok = copy( $source, $tmpPath );
-               if ( !$ok ) {
-                       return null;
+               foreach ( $params['srcs'] as $src ) {
+                       $source = $this->resolveToFSPath( $src );
+                       if ( $source === null ) {
+                               $tmpFiles[$src] = null; // invalid path
+                       } else {
+                               // Create a new temporary file with the same extension...
+                               $ext = FileBackend::extensionFromPath( $src );
+                               $tmpFile = TempFSFile::factory( 'localcopy_', $ext );
+                               if ( !$tmpFile ) {
+                                       $tmpFiles[$src] = null;
+                               } else {
+                                       $tmpPath = $tmpFile->getPath();
+                                       // Copy the source file over the temp file
+                                       wfSuppressWarnings();
+                                       $ok = copy( $source, $tmpPath );
+                                       wfRestoreWarnings();
+                                       if ( !$ok ) {
+                                               $tmpFiles[$src] = null;
+                                       } else {
+                                               $this->chmod( $tmpPath );
+                                               $tmpFiles[$src] = $tmpFile;
+                                       }
+                               }
+                       }
                }
 
-               $this->chmod( $tmpPath );
-
-               return $tmpFile;
+               return $tmpFiles;
        }
 
        /**