Merge "Improved/added parameter documentation"
authorSiebrand <s.mazeland@xs4all.nl>
Mon, 21 May 2012 16:27:56 +0000 (16:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 21 May 2012 16:27:57 +0000 (16:27 +0000)
1  2 
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIRepo.php
includes/filerepo/backend/FileBackendStore.php
includes/filerepo/backend/FileOpBatch.php

@@@ -60,6 -60,10 +60,10 @@@ class FileRepo 
        var $oldFileFactory = false;
        var $fileFactoryKey = false, $oldFileFactoryKey = false;
  
+       /**
+        * @param $info array|null
+        * @throws MWException
+        */
        function __construct( array $info = null ) {
                // Verify required settings presence
                if(
         * Check if a single zone or list of zones is defined for usage
         *
         * @param $doZones Array Only do a particular zones
+        * @throws MWException
         * @return Status
         */
        protected function initZones( $doZones = array() ) {
         * The suffix, if supplied, is considered to be unencoded, and will be
         * URL-encoded before being returned.
         *
-        * @param $suffix string
+        * @param $suffix string|bool
         * @return string
         */
        public function getVirtualUrl( $suffix = false ) {
         * Use this function wisely.
         *
         * @param $url string
+        * @throws MWException
         * @return string
         */
        public function resolveVirtualUrl( $url ) {
         * SHA-1 content hash.
         *
         * STUB
+        * @param $hash
         * @return array
         */
        public function findBySha1( $hash ) {
         *     self::OVERWRITE_SAME    Overwrite the file if the destination exists and has the
         *                             same contents as the source
         *     self::SKIP_LOCKING      Skip any file locking when doing the store
+        * @throws MWException
         * @return FileRepoStatus
         */
        public function storeBatch( array $triplets, $flags = 0 ) {
         * 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 $pairs array List of files to delete
+        * @param $files array List of files to delete
         * @param $flags Integer: bitwise combination of the following flags:
         *     self::SKIP_LOCKING      Skip any file locking when doing the deletions
         * @return FileRepoStatus
         * This function can be used to write to otherwise read-only foreign repos.
         * This is intended for copying generated thumbnails into the repo.
         *
-        * @param $src Array List of tuples (file system path, virtual URL or storage path)
+        * @param $pairs Array List of tuples (file system path, virtual URL or storage path)
         * @return FileRepoStatus
         */
        public function quickImportBatch( array $pairs ) {
                        $operations[] = array(
                                'op'        => 'store',
                                'src'       => $src,
 -                              'dst'       => $this->resolveToStoragePath( $dst ),
 -                              'overwrite' => true
 +                              'dst'       => $this->resolveToStoragePath( $dst )
                        );
                        $this->backend->prepare( array( 'dir' => dirname( $dst ) ) );
                }
 -              $status->merge( $this->backend->doOperations( $operations,
 -                      array( 'force' => 1, 'nonLocking' => 1, 'allowStale' => 1, 'nonJournaled' => 1 )
 -              ) );
 +              $status->merge( $this->backend->doQuickOperations( $operations ) );
  
                return $status;
        }
         * This function can be used to write to otherwise read-only foreign repos.
         * This does no locking nor journaling and is intended for purging thumbnails.
         *
-        * @param $path Array List of virtual URLs or storage paths
+        * @param $paths Array List of virtual URLs or storage paths
         * @return FileRepoStatus
         */
        public function quickPurgeBatch( array $paths ) {
                                'ignoreMissingSource' => true
                        );
                }
 -              $status->merge( $this->backend->doOperations( $operations,
 -                      array( 'force' => 1, 'nonLocking' => 1, 'allowStale' => 1, 'nonJournaled' => 1 )
 -              ) );
 +              $status->merge( $this->backend->doQuickOperations( $operations ) );
  
                return $status;
        }
         * @param $triplets Array: (source, dest, archive) triplets as per publish()
         * @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
         *        that the source files should be deleted if possible
+        * @throws MWException
         * @return FileRepoStatus
         */
        public function publishBatch( array $triplets, $flags = 0 ) {
         *        is a two-element array containing the source file path relative to the
         *        public root in the first element, and the archive file path relative
         *        to the deleted zone root in the second element.
+        * @throws MWException
         * @return FileRepoStatus
         */
        public function deleteBatch( array $sourceDestPairs ) {
         * Get a relative path for a deletion archive key,
         * e.g. s/z/a/ for sza251lrxrc1jad41h5mgilp8nysje52.jpg
         *
+        * @param $key string
         * @return string
         */
        public function getDeletedHashPath( $key ) {
        /**
         * Create a new good result
         *
+        * @param $value null|string
         * @return FileRepoStatus
         */
        public function newGood( $value = null ) {
@@@ -51,6 -51,9 +51,9 @@@ class ForeignAPIRepo extends FileRepo 
        protected $mQueryCache = array();
        protected $mFileExists = array();
  
+       /**
+        * @param $info array|null
+        */
        function __construct( $info ) {
                global $wgLocalFileRepo;
                parent::__construct( $info );
@@@ -81,6 -84,8 +84,8 @@@
         * Per docs in FileRepo, this needs to return false if we don't support versioned
         * files. Well, we don't.
         *
+        * @param $title Title
+        * @param $time string|bool
         * @return File
         */
        function newFile( $title, $time = false ) {
                return parent::newFile( $title, $time );
        }
  
+       /**
+        * @param $files array
+        * @return array
+        */
        function fileExistsBatch( array $files ) {
                $results = array();
                foreach ( $files as $k => $f ) {
                return $results;
        }
  
+       /**
+        * @param $virtualUrl string
+        * @return bool
+        */
        function getFileProps( $virtualUrl ) {
                return false;
        }
  
+       /**
+        * @param $query array
+        * @return string
+        */
        function fetchImageQuery( $query ) {
                global $wgMemc;
  
                return FormatJson::decode( $this->mQueryCache[$url], true );
        }
  
+       /**
+        * @param $data array
+        * @return bool|array
+        */
        function getImageInfo( $data ) {
                if( $data && isset( $data['query']['pages'] ) ) {
                        foreach( $data['query']['pages'] as $info ) {
                return false;
        }
  
+       /**
+        * @param $hash string
+        * @return array
+        */
        function findBySha1( $hash ) {
                $results = $this->fetchImageQuery( array(
                                                                                'aisha1base36' => $hash,
                return $ret;
        }
  
+       /**
+        * @param $name string
+        * @param $width int
+        * @param $height int
+        * @param $result null
+        * @param $otherParams string
+        * @return bool
+        */
        function getThumbUrl( $name, $width = -1, $height = -1, &$result = null, $otherParams = '' ) {
                $data = $this->fetchImageQuery( array(
                        'titles' => 'File:' . $name,
         * @param $name String is a dbkey form of a title
         * @param $width
         * @param $height
-        * @param String $param Other rendering parameters (page number, etc) from handler's makeParamString.
+        * @param String $params Other rendering parameters (page number, etc) from handler's makeParamString.
         * @return bool|string
         */
-       function getThumbUrlFromCache( $name, $width, $height, $params="" ) {
+       function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
                global $wgMemc;
                // We can't check the local cache using FileRepo functions because
                // we override fileExistsBatch(). We have to use the FileBackend directly.
                $op = array( 'op' => 'create', 'dst' => $localFilename, 'content' => $thumb );
                if( !$backend->doOperation( $op )->isOK() ) {
                        wfRestoreWarnings();
 -                      wfDebug( __METHOD__ . " could not write to thumb path\n" );
 +                      wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" );
                        return $foreignUrl;
                }
                $knownThumbUrls[$sizekey] = $localUrl;
  
        /**
         * @see FileRepo::getZoneUrl()
+        * @param $zone String
         * @return String
         */
        function getZoneUrl( $zone ) {
  
        /**
         * Get the local directory corresponding to one of the basic zones
+        * @param $zone string
         * @return bool|null|string
         */
        function getZonePath( $zone ) {
        /**
         * Like a Http:get request, but with custom User-Agent.
         * @see Http:get
+        * @param $url string
+        * @param $timeout string
+        * @param $options array
         * @return bool|String
         */
        public static function httpGet( $url, $timeout = 'default', $options = array() ) {
                }
        }
  
+       /**
+        * @param $callback Array|string
+        * @throws MWException
+        */
        function enumFiles( $callback ) {
                throw new MWException( 'enumFiles is not supported by ' . get_class( $this ) );
        }
  
+       /**
+        * @throws MWException
+        */
        protected function assertWritableRepo() {
                throw new MWException( get_class( $this ) . ': write operations are not supported.' );
        }
@@@ -564,8 -564,6 +564,8 @@@ abstract class FileBackendStore extend
                        $this->trimCache(); // limit memory
                        $this->cache[$path]['stat'] = $stat;
                        $this->setFileCache( $path, $stat ); // update persistent cache
 +              } else {
 +                      wfDebug( __METHOD__ . ": File $path does not exist.\n" );
                }
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
                wfProfileIn( __METHOD__ . '-' . $this->name );
                $status = Status::newGood();
  
 +              $supportedOps = array( 'create', 'store', 'copy', 'move', 'delete', 'null' );
                $async = ( $this->parallelize === 'implicit' );
                $maxConcurrency = $this->concurrency; // throttle
  
                $curFileOpHandles = array(); // current handle batch
                // Perform the sync-only ops and build up op handles for the async ops...
                foreach ( $ops as $index => $params ) {
 -                      $method = $params['op'] . 'Internal'; // e.g. "storeInternal"
 -                      if ( !MWInit::methodExists( __CLASS__, $method ) ) {
 +                      if ( !in_array( $params['op'], $supportedOps ) ) {
                                wfProfileOut( __METHOD__ . '-' . $this->name );
                                wfProfileOut( __METHOD__ );
                                throw new MWException( "Operation '{$params['op']}' is not supported." );
                        }
 +                      $method = $params['op'] . 'Internal'; // e.g. "storeInternal"
                        $subStatus = $this->$method( array( 'async' => $async ) + $params );
                        if ( $subStatus->value instanceof FileBackendStoreOpHandle ) { // async
                                if ( count( $curFileOpHandles ) >= $maxConcurrency ) {
        /**
         * @see FileBackendStore::executeOpHandlesInternal()
         * @return Array List of corresponding Status objects
-        * @throws MWException
         */
        protected function doExecuteOpHandlesInternal( array $fileOpHandles ) {
                foreach ( $fileOpHandles as $fileOpHandle ) { // OK if empty
         * Any empty suffix means the container is not sharded.
         *
         * @param $container string Container name
-        * @param $relStoragePath string Storage path relative to the container
+        * @param $relPath string Storage path relative to the container
         * @return string|null Returns null if shard could not be determined
         */
        final protected function getContainerShard( $container, $relPath ) {
         *
         * @param $container string Resolved container name
         * @param $val mixed Information to cache
-        * @return void
         */
        final protected function setContainerCache( $container, $val ) {
                $this->memCache->set( $this->containerCacheKey( $container ), $val, 14*86400 );
        /**
         * Delete the cached info for a container
         *
-        * @param $containers string Resolved container name
-        * @return void
+        * @param $container string Resolved container name
         */
        final protected function deleteContainerCache( $container ) {
                if ( !$this->memCache->delete( $this->containerCacheKey( $container ) ) ) {
         *
         * @param $path string Storage path
         * @param $val mixed Information to cache
-        * @return void
         */
        final protected function setFileCache( $path, $val ) {
                $this->memCache->set( $this->fileCacheKey( $path ), $val, 7*86400 );
         * Delete the cached stat info for a file path
         *
         * @param $path string Storage path
-        * @return void
         */
        final protected function deleteFileCache( $path ) {
                if ( !$this->memCache->delete( $this->fileCacheKey( $path ) ) ) {
@@@ -1686,6 -1678,12 +1681,12 @@@ abstract class FileBackendStoreShardLis
   * Iterator for listing directories
   */
  class FileBackendStoreShardDirIterator extends FileBackendStoreShardListIterator {
+       /**
+        * @param string $container
+        * @param string $dir
+        * @param array $params
+        * @return Array|null|Traversable
+        */
        protected function listFromShard( $container, $dir, array $params ) {
                return $this->backend->getDirectoryListInternal( $container, $dir, $params );
        }
   * Iterator for listing regular files
   */
  class FileBackendStoreShardFileIterator extends FileBackendStoreShardListIterator {
+       /**
+        * @param string $container
+        * @param string $dir
+        * @param array $params
+        * @return Array|null|Traversable
+        */
        protected function listFromShard( $container, $dir, array $params ) {
                return $this->backend->getFileListInternal( $container, $dir, $params );
        }
@@@ -1,22 -1,5 +1,22 @@@
  <?php
  /**
 + * Helper class for representing batch file operations.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License along
 + * with this program; if not, write to the Free Software Foundation, Inc.,
 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + * http://www.gnu.org/copyleft/gpl.html
 + *
   * @file
   * @ingroup FileBackend
   * @author Aaron Schulz
@@@ -186,7 -169,7 +186,7 @@@ class FileOpBatch 
         * within any given sub-batch do not depend on each other.
         * This will abort remaining ops on failure.
         *
-        * @param $performOps Array
+        * @param $pPerformOps Array
         * @param $status Status
         * @return bool Success
         */
                        }
                        // Try to do all the operations concurrently...
                        $statuses = $statuses + $backend->executeOpHandlesInternal( $opHandles );
-                       // Marshall and merge all the responses...
+                       // Marshall and merge all the responses (blocking)...
                        foreach ( $performOpsBatch as $i => $fileOp ) {
                                if ( !$fileOp->failed() ) { // failed => already has Status
                                        $subStatus = $statuses[$i];