Merge "Adding output parameter to PageHistoryBeforeList hook"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendStore.php
index a7df19d..3f1d185 100644 (file)
@@ -57,8 +57,8 @@ abstract class FileBackendStore extends FileBackend {
         */
        public function __construct( array $config ) {
                parent::__construct( $config );
-               $this->memCache       = new EmptyBagOStuff(); // disabled by default
-               $this->cheapCache     = new ProcessCacheLRU( 300 );
+               $this->memCache = new EmptyBagOStuff(); // disabled by default
+               $this->cheapCache = new ProcessCacheLRU( 300 );
                $this->expensiveCache = new ProcessCacheLRU( 5 );
        }
 
@@ -100,7 +100,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - dstExists   : Whether a file exists at the destination (optimization).
         *                   Callers can use "false" if no existing file is being changed.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function createInternal( array $params ) {
@@ -143,7 +143,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - dstExists   : Whether a file exists at the destination (optimization).
         *                   Callers can use "false" if no existing file is being changed.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function storeInternal( array $params ) {
@@ -186,7 +186,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - dstExists           : Whether a file exists at the destination (optimization).
         *                           Callers can use "false" if no existing file is being changed.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function copyInternal( array $params ) {
@@ -219,7 +219,7 @@ abstract class FileBackendStore extends FileBackend {
         *                           If the status is OK, then its value field will be
         *                           set to a FileBackendStoreOpHandle object.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function deleteInternal( array $params ) {
@@ -255,7 +255,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - dstExists           : Whether a file exists at the destination (optimization).
         *                           Callers can use "false" if no existing file is being changed.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function moveInternal( array $params ) {
@@ -300,7 +300,7 @@ abstract class FileBackendStore extends FileBackend {
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function describeInternal( array $params ) {
@@ -326,7 +326,7 @@ abstract class FileBackendStore extends FileBackend {
         * No-op file operation that does nothing.
         * Do not call this function from places outside FileBackend and FileOp.
         *
-        * @param $params Array
+        * @param array $params
         * @return Status
         */
        final public function nullInternal( array $params ) {
@@ -366,12 +366,8 @@ abstract class FileBackendStore extends FileBackend {
         */
        protected function doConcatenate( array $params ) {
                $status = Status::newGood();
-
                $tmpPath = $params['dst']; // convenience
                unset( $params['latest'] ); // sanity
-               $callback = isset( $params['callback'] )
-                       ? $params['callback']
-                       : function( Status $status, $segment ) {};
 
                // Check that the specified temp file is valid...
                wfSuppressWarnings();
@@ -379,7 +375,6 @@ abstract class FileBackendStore extends FileBackend {
                wfRestoreWarnings();
                if ( !$ok ) { // not present or not empty
                        $status->fatal( 'backend-fail-opentemp', $tmpPath );
-                       $callback( $status, null ); // update progress
                        return $status;
                }
 
@@ -390,7 +385,6 @@ abstract class FileBackendStore extends FileBackend {
                                $fsFile = $this->getLocalReference( array( 'src' => $path ) );
                                if ( !$fsFile ) { // retry failed?
                                        $status->fatal( 'backend-fail-read', $path );
-                                       $callback( $status, null ); // update progress
                                        return $status;
                                }
                        }
@@ -401,20 +395,16 @@ abstract class FileBackendStore extends FileBackend {
                $tmpHandle = fopen( $tmpPath, 'ab' );
                if ( $tmpHandle === false ) {
                        $status->fatal( 'backend-fail-opentemp', $tmpPath );
-                       $callback( $status, null ); // update progress
                        return $status;
                }
 
-               $segment = 0; // segment number
                // Build up the temp file using the source chunks (in order)...
                foreach ( $fsFiles as $virtualSource => $fsFile ) {
-                       ++$segment; // first segment is "1"
                        // Get a handle to the local FS version
                        $sourceHandle = fopen( $fsFile->getPath(), 'rb' );
                        if ( $sourceHandle === false ) {
                                fclose( $tmpHandle );
                                $status->fatal( 'backend-fail-read', $virtualSource );
-                               $callback( $status, null ); // update progress
                                return $status;
                        }
                        // Append chunk to file (pass chunk size to avoid magic quotes)
@@ -422,20 +412,16 @@ abstract class FileBackendStore extends FileBackend {
                                fclose( $sourceHandle );
                                fclose( $tmpHandle );
                                $status->fatal( 'backend-fail-writetemp', $tmpPath );
-                               $callback( $status , null );
                                return $status;
                        }
                        fclose( $sourceHandle );
-                       $callback( $status, $segment ); // update progress (chunk success)
                }
                if ( !fclose( $tmpHandle ) ) {
                        $status->fatal( 'backend-fail-closetemp', $tmpPath );
-                       $callback( $status, null ); // update progress
                        return $status;
                }
 
                clearstatcache(); // temp file changed
-               $callback( $status, null ); // update progress (full success)
 
                return $status;
        }
@@ -461,7 +447,7 @@ abstract class FileBackendStore extends FileBackend {
                        $status->merge( $this->doPrepareInternal( $fullCont, $dir, $params ) );
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $status->merge( $this->doPrepareInternal( "{$fullCont}{$suffix}", $dir, $params ) );
                        }
@@ -501,7 +487,7 @@ abstract class FileBackendStore extends FileBackend {
                        $status->merge( $this->doSecureInternal( $fullCont, $dir, $params ) );
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $status->merge( $this->doSecureInternal( "{$fullCont}{$suffix}", $dir, $params ) );
                        }
@@ -541,7 +527,7 @@ abstract class FileBackendStore extends FileBackend {
                        $status->merge( $this->doPublishInternal( $fullCont, $dir, $params ) );
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $status->merge( $this->doPublishInternal( "{$fullCont}{$suffix}", $dir, $params ) );
                        }
@@ -603,7 +589,7 @@ abstract class FileBackendStore extends FileBackend {
                        $this->deleteContainerCache( $fullCont ); // purge cache
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $status->merge( $this->doCleanInternal( "{$fullCont}{$suffix}", $dir, $params ) );
                                $this->deleteContainerCache( "{$fullCont}{$suffix}" ); // purge cache
@@ -781,10 +767,7 @@ abstract class FileBackendStore extends FileBackend {
                $hash = $this->doGetFileSha1Base36( $params );
                wfProfileOut( __METHOD__ . '-miss-' . $this->name );
                wfProfileOut( __METHOD__ . '-miss' );
-               if ( $hash ) { // don't cache negatives
-                       $this->cheapCache->set( $path, 'sha1',
-                               array( 'hash' => $hash, 'latest' => $latest ) );
-               }
+               $this->cheapCache->set( $path, 'sha1', array( 'hash' => $hash, 'latest' => $latest ) );
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
                return $hash;
@@ -968,7 +951,7 @@ abstract class FileBackendStore extends FileBackend {
                        return $this->doDirectoryExists( $fullCont, $dir, $params );
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        $res = false; // response
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $exists = $this->doDirectoryExists( "{$fullCont}{$suffix}", $dir, $params );
@@ -986,9 +969,9 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * @see FileBackendStore::directoryExists()
         *
-        * @param $container string Resolved container name
-        * @param $dir string Resolved path relative to container
-        * @param $params Array
+        * @param string $container Resolved container name
+        * @param string $dir Resolved path relative to container
+        * @param array $params
         * @return bool|null
         */
        abstract protected function doDirectoryExists( $container, $dir, array $params );
@@ -1008,7 +991,7 @@ abstract class FileBackendStore extends FileBackend {
                } else {
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
                        // File listing spans multiple containers/shards
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        return new FileBackendStoreShardDirIterator( $this,
                                $fullCont, $dir, $this->getContainerSuffixes( $shortCont ), $params );
                }
@@ -1019,9 +1002,9 @@ abstract class FileBackendStore extends FileBackend {
         *
         * @see FileBackendStore::getDirectoryList()
         *
-        * @param $container string Resolved container name
-        * @param $dir string Resolved path relative to container
-        * @param $params Array
+        * @param string $container Resolved container name
+        * @param string $dir Resolved path relative to container
+        * @param array $params
         * @return Traversable|Array|null Returns null on failure
         */
        abstract public function getDirectoryListInternal( $container, $dir, array $params );
@@ -1041,7 +1024,7 @@ abstract class FileBackendStore extends FileBackend {
                } else {
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
                        // File listing spans multiple containers/shards
-                       list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
+                       list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
                        return new FileBackendStoreShardFileIterator( $this,
                                $fullCont, $dir, $this->getContainerSuffixes( $shortCont ), $params );
                }
@@ -1052,9 +1035,9 @@ abstract class FileBackendStore extends FileBackend {
         *
         * @see FileBackendStore::getFileList()
         *
-        * @param $container string Resolved container name
-        * @param $dir string Resolved path relative to container
-        * @param $params Array
+        * @param string $container Resolved container name
+        * @param string $dir Resolved path relative to container
+        * @param array $params
         * @return Traversable|Array|null Returns null on failure
         */
        abstract public function getFileListInternal( $container, $dir, array $params );
@@ -1066,7 +1049,7 @@ abstract class FileBackendStore extends FileBackend {
         * The result must have the same number of items as the input.
         * An exception is thrown if an unsupported operation is requested.
         *
-        * @param $ops Array Same format as doOperations()
+        * @param array $ops Same format as doOperations()
         * @return Array List of FileOp objects
         * @throws MWException
         */
@@ -1105,7 +1088,7 @@ abstract class FileBackendStore extends FileBackend {
         * each corresponding to a list of storage paths to be locked.
         * All returned paths are normalized.
         *
-        * @param $performOps Array List of FileOp objects
+        * @param array $performOps List of FileOp objects
         * @return Array ('sh' => list of paths, 'ex' => list of paths)
         */
        final public function getPathsToLockForOpsInternal( array $performOps ) {
@@ -1257,7 +1240,7 @@ abstract class FileBackendStore extends FileBackend {
         * The resulting Status object fields will correspond
         * to the order in which the handles where given.
         *
-        * @param $handles Array List of FileBackendStoreOpHandle objects
+        * @param array $handles List of FileBackendStoreOpHandle objects
         * @return Array Map of Status objects
         * @throws MWException
         */
@@ -1296,7 +1279,7 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * Strip long HTTP headers from a file operation
         *
-        * @param $op array Same format as doOperation()
+        * @param array $op Same format as doOperation()
         * @return Array
         */
        protected function stripInvalidHeadersFromOp( array $op ) {
@@ -1319,7 +1302,7 @@ abstract class FileBackendStore extends FileBackend {
        final public function preloadCache( array $paths ) {
                $fullConts = array(); // full container names
                foreach ( $paths as $path ) {
-                       list( $fullCont, $r, $s ) = $this->resolveStoragePath( $path );
+                       list( $fullCont, , ) = $this->resolveStoragePath( $path );
                        $fullConts[] = $fullCont;
                }
                // Load from the persistent file and container caches
@@ -1352,7 +1335,7 @@ abstract class FileBackendStore extends FileBackend {
         *
         * @see FileBackend::clearCache()
         *
-        * @param $paths Array Storage paths (optional)
+        * @param array $paths Storage paths (optional)
         * @return void
         */
        protected function doClearCache( array $paths = null ) {}
@@ -1441,8 +1424,8 @@ abstract class FileBackendStore extends FileBackend {
         * Get the container name shard suffix for a given path.
         * Any empty suffix means the container is not sharded.
         *
-        * @param $container string Container name
-        * @param $relPath string Storage path relative to the container
+        * @param string $container Container name
+        * @param string $relPath Storage path relative to the container
         * @return string|null Returns null if shard could not be determined
         */
        final protected function getContainerShard( $container, $relPath ) {
@@ -1478,11 +1461,11 @@ abstract class FileBackendStore extends FileBackend {
         * Container dirs like "a", where the container shards on "x/xy",
         * can reside on several shards. Such paths are tricky to handle.
         *
-        * @param $storagePath string Storage path
+        * @param string $storagePath Storage path
         * @return bool
         */
        final public function isSingleShardPathInternal( $storagePath ) {
-               list( $c, $r, $shard ) = $this->resolveStoragePath( $storagePath );
+               list( , $shard ) = $this->resolveStoragePath( $storagePath );
                return ( $shard !== null );
        }
 
@@ -1558,8 +1541,8 @@ abstract class FileBackendStore extends FileBackend {
         * getting absolute paths (e.g. FS based backends). Note that the relative path
         * may be the empty string (e.g. the path is simply to the container).
         *
-        * @param $container string Container name
-        * @param $relStoragePath string Storage path relative to the container
+        * @param string $container Container name
+        * @param string $relStoragePath Storage path relative to the container
         * @return string|null Path or null if not valid
         */
        protected function resolveContainerPath( $container, $relStoragePath ) {
@@ -1569,7 +1552,7 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * Get the cache key for a container
         *
-        * @param $container string Resolved container name
+        * @param string $container Resolved container name
         * @return string
         */
        private function containerCacheKey( $container ) {
@@ -1579,7 +1562,7 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * Set the cached info for a container
         *
-        * @param $container string Resolved container name
+        * @param string $container Resolved container name
         * @param $val mixed Information to cache
         */
        final protected function setContainerCache( $container, $val ) {
@@ -1590,7 +1573,7 @@ abstract class FileBackendStore extends FileBackend {
         * Delete the cached info for a container.
         * The cache key is salted for a while to prevent race conditions.
         *
-        * @param $container string Resolved container name
+        * @param string $container Resolved container name
         */
        final protected function deleteContainerCache( $container ) {
                if ( !$this->memCache->set( $this->containerCacheKey( $container ), 'PURGED', 300 ) ) {
@@ -1625,7 +1608,7 @@ abstract class FileBackendStore extends FileBackend {
                }
                // Get all the corresponding cache keys for paths...
                foreach ( $paths as $path ) {
-                       list( $fullCont, $r, $s ) = $this->resolveStoragePath( $path );
+                       list( $fullCont, , ) = $this->resolveStoragePath( $path );
                        if ( $fullCont !== null ) { // valid path for this backend
                                $contNames[$this->containerCacheKey( $fullCont )] = $fullCont;
                        }
@@ -1650,7 +1633,7 @@ abstract class FileBackendStore extends FileBackend {
         * resolved container names and their corresponding cached info.
         * Only containers that actually exist should appear in the map.
         *
-        * @param $containerInfo Array Map of resolved container names to cached info
+        * @param array $containerInfo Map of resolved container names to cached info
         * @return void
         */
        protected function doPrimeContainerCache( array $containerInfo ) {}
@@ -1658,7 +1641,7 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * Get the cache key for a file path
         *
-        * @param $path string Normalized storage path
+        * @param string $path Normalized storage path
         * @return string
         */
        private function fileCacheKey( $path ) {
@@ -1670,7 +1653,7 @@ abstract class FileBackendStore extends FileBackend {
         * Negatives (404s) are not cached. By not caching negatives, we can skip cache
         * salting for the case when a file is created at a path were there was none before.
         *
-        * @param $path string Storage path
+        * @param string $path Storage path
         * @param $val mixed Information to cache
         */
        final protected function setFileCache( $path, $val ) {
@@ -1687,7 +1670,7 @@ abstract class FileBackendStore extends FileBackend {
         * Since negatives (404s) are not cached, this does not need to be called when
         * a file is created at a path were there was none before.
         *
-        * @param $path string Storage path
+        * @param string $path Storage path
         */
        final protected function deleteFileCache( $path ) {
                $path = FileBackend::normalizeStoragePath( $path );
@@ -1704,7 +1687,7 @@ abstract class FileBackendStore extends FileBackend {
         * used in a list of storage paths or FileOp objects.
         * This loads the persistent cache values into the process cache.
         *
-        * @param $items Array List of storage paths or FileOps
+        * @param array $items List of storage paths or FileOps
         * @return void
         */
        final protected function primeFileCache( array $items ) {
@@ -1726,7 +1709,7 @@ abstract class FileBackendStore extends FileBackend {
                $paths = array_filter( $paths, 'strlen' ); // remove nulls
                // Get all the corresponding cache keys for paths...
                foreach ( $paths as $path ) {
-                       list( $cont, $rel, $s ) = $this->resolveStoragePath( $path );
+                       list( , $rel, ) = $this->resolveStoragePath( $path );
                        if ( $rel !== null ) { // valid path for this backend
                                $pathNames[$this->fileCacheKey( $path )] = $path;
                        }
@@ -1751,7 +1734,7 @@ abstract class FileBackendStore extends FileBackend {
        /**
         * Set the 'concurrency' option from a list of operation options
         *
-        * @param $opts array Map of operation options
+        * @param array $opts Map of operation options
         * @return Array
         */
        final protected function setConcurrencyFlags( array $opts ) {
@@ -1823,10 +1806,10 @@ abstract class FileBackendStoreShardListIterator implements Iterator {
 
        /**
         * @param $backend FileBackendStore
-        * @param $container string Full storage container name
-        * @param $dir string Storage directory relative to container
-        * @param $suffixes Array List of container shard suffixes
-        * @param $params Array
+        * @param string $container Full storage container name
+        * @param string $dir Storage directory relative to container
+        * @param array $suffixes List of container shard suffixes
+        * @param array $params
         */
        public function __construct(
                FileBackendStore $backend, $container, $dir, array $suffixes, array $params
@@ -1952,9 +1935,9 @@ abstract class FileBackendStoreShardListIterator implements Iterator {
        /**
         * Get the list for a given container shard
         *
-        * @param $container string Resolved container name
-        * @param $dir string Resolved path relative to container
-        * @param $params Array
+        * @param string $container Resolved container name
+        * @param string $dir Resolved path relative to container
+        * @param array $params
         * @return Traversable|Array|null
         */
        abstract protected function listFromShard( $container, $dir, array $params );