Merge "Satisfy code analyzer by ensuring $urls is defined"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index fe769be..dd8e38a 100644 (file)
@@ -46,44 +46,81 @@ define( 'MW_FILE_VERSION', 9 );
 class LocalFile extends File {
        const CACHE_FIELD_MAX_LEN = 1000;
 
-       /**#@+
-        * @private
-        */
-       var
-               $fileExists,       # does the file exist on disk? (loadFromXxx)
-               $historyLine,      # Number of line to return by nextHistoryLine() (constructor)
-               $historyRes,       # result of the query for the file's history (nextHistoryLine)
-               $width,            # \
-               $height,           #  |
-               $bits,             #   --- returned by getimagesize (loadFromXxx)
-               $attr,             # /
-               $media_type,       # MEDIATYPE_xxx (bitmap, drawing, audio...)
-               $mime,             # MIME type, determined by MimeMagic::guessMimeType
-               $major_mime,       # Major mime type
-               $minor_mime,       # Minor mime type
-               $size,             # Size in bytes (loadFromXxx)
-               $metadata,         # Handler-specific metadata
-               $timestamp,        # Upload timestamp
-               $sha1,             # SHA-1 base 36 content hash
-               $user, $user_text, # User, who uploaded the file
-               $description,      # Description of current revision of the file
-               $dataLoaded,       # Whether or not core data has been loaded from the database (loadFromXxx)
-               $extraDataLoaded,  # Whether or not lazy-loaded data has been loaded from the database
-               $upgraded,         # Whether the row was upgraded on load
-               $locked,           # True if the image row is locked
-               $lockedOwnTrx,     # True if the image row is locked with a lock initiated transaction
-               $missing,          # True if file is not present in file system. Not to be cached in memcached
-               $deleted;          # Bitfield akin to rev_deleted
-
-       /**#@-*/
-
-       /**
-        * @var LocalRepo
-        */
-       var $repo;
+       /** @var bool Does the file exist on disk? (loadFromXxx) */
+       protected $fileExists;
 
+       /** @var int image width */
+       protected $width;
+
+       /** @var int image height */
+       protected $height;
+
+       /** @var int Returned by getimagesize (loadFromXxx) */
+       protected $bits;
+
+       /** @var string MEDIATYPE_xxx (bitmap, drawing, audio...) */
+       protected $media_type;
+
+       /** @var string MIME type, determined by MimeMagic::guessMimeType */
+       protected $mime;
+
+       /** @var int Size in bytes (loadFromXxx) */
+       protected $size;
+
+       /** @var string Handler-specific metadata */
+       protected $metadata;
+
+       /** @var string SHA-1 base 36 content hash */
+       protected $sha1;
+
+       /** @var bool Whether or not core data has been loaded from the database (loadFromXxx) */
+       protected $dataLoaded;
+
+       /** @var bool Whether or not lazy-loaded data has been loaded from the database */
+       protected $extraDataLoaded;
+
+       /** @var int Bitfield akin to rev_deleted */
+       protected $deleted;
+
+       /** @var string */
        protected $repoClass = 'LocalRepo';
 
+       /** @var int Number of line to return by nextHistoryLine() (constructor) */
+       private $historyLine;
+
+       /** @var int Result of the query for the file's history (nextHistoryLine) */
+       private $historyRes;
+
+       /** @var string Major mime type */
+       private $major_mime;
+
+       /** @var string Minor mime type */
+       private $minor_mime;
+
+       /** @var string Upload timestamp */
+       private $timestamp;
+
+       /** @var int User ID of uploader */
+       private $user;
+
+       /** @var string User name of uploader */
+       private $user_text;
+
+       /** @var string Description of current revision of the file */
+       private $description;
+
+       /** @var bool Whether the row was upgraded on load */
+       private $upgraded;
+
+       /** @var bool True if the image row is locked */
+       private $locked;
+
+       /** @var bool True if the image row is locked with a lock initiated transaction */
+       private $lockedOwnTrx;
+
+       /** @var bool True if file is not present in file system. Not to be cached in memcached */
+       private $missing;
+
        const LOAD_ALL = 1; // integer; load all the lazy fields too (like metadata)
 
        /**
@@ -92,8 +129,8 @@ class LocalFile extends File {
         *
         * Note: $unused param is only here to avoid an E_STRICT
         *
-        * @param $title
-        * @param $repo
+        * @param Title $title
+        * @param FileRepo $repo
         * @param $unused
         *
         * @return LocalFile
@@ -106,8 +143,8 @@ class LocalFile extends File {
         * Create a LocalFile from a title
         * Do not call this except from inside a repo class.
         *
-        * @param $row
-        * @param $repo
+        * @param stdClass $row
+        * @param FileRepo $repo
         *
         * @return LocalFile
         */
@@ -124,9 +161,8 @@ class LocalFile extends File {
         * Do not call this except from inside a repo class.
         *
         * @param string $sha1 base-36 SHA-1
-        * @param $repo LocalRepo
+        * @param LocalRepo $repo
         * @param string|bool $timestamp MW_timestamp (optional)
-        *
         * @return bool|LocalFile
         */
        static function newFromKey( $sha1, $repo, $timestamp = false ) {
@@ -210,6 +246,7 @@ class LocalFile extends File {
 
                if ( !$key ) {
                        wfProfileOut( __METHOD__ );
+
                        return false;
                }
 
@@ -236,6 +273,7 @@ class LocalFile extends File {
                }
 
                wfProfileOut( __METHOD__ );
+
                return $this->dataLoaded;
        }
 
@@ -289,7 +327,8 @@ class LocalFile extends File {
         */
        function getCacheFields( $prefix = 'img_' ) {
                static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
-                       'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text', 'description' );
+                       'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user',
+                       'user_text', 'description' );
                static $results = array();
 
                if ( $prefix == '' ) {
@@ -308,6 +347,7 @@ class LocalFile extends File {
        }
 
        /**
+        * @param string $prefix
         * @return array
         */
        function getLazyCacheFields( $prefix = 'img_' ) {
@@ -390,9 +430,10 @@ class LocalFile extends File {
        }
 
        /**
-        * @param Row $row
-        * @param $prefix string
-        * @return Array
+        * @param array $row Row
+        * @param string $prefix
+        * @throws MWException
+        * @return array
         */
        protected function unprefixRow( $row, $prefix = 'img_' ) {
                $array = (array)$row;
@@ -407,6 +448,7 @@ class LocalFile extends File {
                foreach ( $array as $name => $value ) {
                        $decoded[substr( $name, $prefixLength )] = $value;
                }
+
                return $decoded;
        }
 
@@ -518,6 +560,7 @@ class LocalFile extends File {
                if ( !$this->fileExists ) {
                        wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
                        wfProfileOut( __METHOD__ );
+
                        return;
                }
 
@@ -526,6 +569,7 @@ class LocalFile extends File {
 
                if ( wfReadOnly() ) {
                        wfProfileOut( __METHOD__ );
+
                        return;
                }
                wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" );
@@ -539,7 +583,7 @@ class LocalFile extends File {
                                'img_media_type' => $this->media_type,
                                'img_major_mime' => $major,
                                'img_minor_mime' => $minor,
-                               'img_metadata' => $dbw->encodeBlob($this->metadata),
+                               'img_metadata' => $dbw->encodeBlob( $this->metadata ),
                                'img_sha1' => $this->sha1,
                        ),
                        array( 'img_name' => $this->getName() ),
@@ -597,13 +641,14 @@ class LocalFile extends File {
                        list( $fileExists ) = $this->repo->fileExists( $this->getVirtualUrl() );
                        $this->missing = !$fileExists;
                }
+
                return $this->missing;
        }
 
        /**
         * Return the width of the image
         *
-        * @param $page int
+        * @param int $page
         * @return int
         */
        public function getWidth( $page = 1 ) {
@@ -630,7 +675,7 @@ class LocalFile extends File {
        /**
         * Return the height of the image
         *
-        * @param $page int
+        * @param int $page
         * @return int
         */
        public function getHeight( $page = 1 ) {
@@ -684,15 +729,17 @@ class LocalFile extends File {
         */
        function getBitDepth() {
                $this->load();
+
                return $this->bits;
        }
 
        /**
-        * Return the size of the image file, in bytes
+        * Returns the size of the image file, in bytes
         * @return int
         */
        public function getSize() {
                $this->load();
+
                return $this->size;
        }
 
@@ -702,16 +749,18 @@ class LocalFile extends File {
         */
        function getMimeType() {
                $this->load();
+
                return $this->mime;
        }
 
        /**
-        * Return the type of the media in the file.
+        * Returns the type of the media in the file.
         * Use the value returned by this function with the MEDIATYPE_xxx constants.
         * @return string
         */
        function getMediaType() {
                $this->load();
+
                return $this->media_type;
        }
 
@@ -723,10 +772,11 @@ class LocalFile extends File {
 
        /**
         * Returns true if the file exists on disk.
-        * @return boolean Whether file exist on disk.
+        * @return bool Whether file exist on disk.
         */
        public function exists() {
                $this->load();
+
                return $this->fileExists;
        }
 
@@ -738,9 +788,9 @@ class LocalFile extends File {
 
        /**
         * Fix thumbnail files from 1.4 or before, with extreme prejudice
-        * @todo : do we still care about this? Perhaps a maintenance script
-        *        can be made instead. Enabling this code results in a serious
-        *        RTT regression for wikis without 404 handling.
+        * @todo Do we still care about this? Perhaps a maintenance script
+        *   can be made instead. Enabling this code results in a serious
+        *   RTT regression for wikis without 404 handling.
         */
        function migrateThumbFile( $thumbName ) {
                /* Old code for bug 2532
@@ -761,7 +811,6 @@ class LocalFile extends File {
                        clearstatcache();
                }
                */
-
                /*
                if ( $this->repo->fileExists( $thumbDir ) ) {
                        // Delete file where directory should be
@@ -793,7 +842,8 @@ class LocalFile extends File {
                        foreach ( $iterator as $file ) {
                                $files[] = $file;
                        }
-               } catch ( FileBackendError $e ) {} // suppress (bug 54674)
+               } catch ( FileBackendError $e ) {
+               } // suppress (bug 54674)
 
                return $files;
        }
@@ -826,7 +876,7 @@ class LocalFile extends File {
        /**
         * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid.
         *
-        * @param Array $options An array potentially with the key forThumbRefresh.
+        * @param array $options An array potentially with the key forThumbRefresh.
         *
         * @note This used to purge old thumbnails by default as well, but doesn't anymore.
         */
@@ -845,7 +895,7 @@ class LocalFile extends File {
 
        /**
         * Delete cached transformed files for an archived version only.
-        * @param string $archiveName name of the archived file
+        * @param string $archiveName Name of the archived file
         */
        function purgeOldThumbnails( $archiveName ) {
                global $wgUseSquid;
@@ -881,8 +931,8 @@ class LocalFile extends File {
                // Delete thumbnails
                $files = $this->getThumbnails();
                // Always purge all files from squid regardless of handler filters
+               $urls = array();
                if ( $wgUseSquid ) {
-                       $urls = array();
                        foreach ( $files as $file ) {
                                $urls[] = $this->getThumbUrl( $file );
                        }
@@ -913,8 +963,8 @@ class LocalFile extends File {
 
        /**
         * Delete a list of thumbnails visible at urls
-        * @param string $dir base dir of the files.
-        * @param array $files of strings: relative filenames (to $dir)
+        * @param string $dir Base dir of the files.
+        * @param array $files Array of strings: relative filenames (to $dir)
         */
        protected function purgeThumbList( $dir, $files ) {
                $fileListDebug = strtr(
@@ -944,10 +994,10 @@ class LocalFile extends File {
        /** purgeEverything inherited */
 
        /**
-        * @param $limit null
-        * @param $start null
-        * @param $end null
-        * @param $inc bool
+        * @param int $limit Optional: Limit to number of results
+        * @param int $start Optional: Timestamp, start from
+        * @param int $end Optional: Timestamp, end at
+        * @param bool $inc
         * @return array
         */
        function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
@@ -982,11 +1032,7 @@ class LocalFile extends File {
                $r = array();
 
                foreach ( $res as $row ) {
-                       if ( $this->repo->oldFileFromRowFactory ) {
-                               $r[] = call_user_func( $this->repo->oldFileFromRowFactory, $row, $this->repo );
-                       } else {
-                               $r[] = OldLocalFile::newFromRow( $row, $this->repo );
-                       }
+                       $r[] = $this->repo->newFileFromRow( $row );
                }
 
                if ( $order == 'ASC' ) {
@@ -997,7 +1043,7 @@ class LocalFile extends File {
        }
 
        /**
-        * Return the history of this file, line by line.
+        * Returns the history of this file, line by line.
         * starts with current version, then old versions.
         * uses $this->historyLine to check which line to return:
         *  0      return line for current version
@@ -1011,7 +1057,7 @@ class LocalFile extends File {
 
                $dbr = $this->repo->getSlaveDB();
 
-               if ( $this->historyLine == 0 ) {// called for the first time, return line from cur
+               if ( $this->historyLine == 0 ) { // called for the first time, return line from cur
                        $this->historyRes = $dbr->select( 'image',
                                array(
                                        '*',
@@ -1025,6 +1071,7 @@ class LocalFile extends File {
 
                        if ( 0 == $dbr->numRows( $this->historyRes ) ) {
                                $this->historyRes = null;
+
                                return false;
                        }
                } elseif ( $this->historyLine == 1 ) {
@@ -1034,7 +1081,7 @@ class LocalFile extends File {
                                array( 'ORDER BY' => 'oi_timestamp DESC' )
                        );
                }
-               $this->historyLine ++;
+               $this->historyLine++;
 
                return $dbr->fetchObject( $this->historyRes );
        }
@@ -1064,21 +1111,24 @@ class LocalFile extends File {
 
        /**
         * Upload a file and record it in the DB
-        * @param string $srcPath source storage path, virtual URL, or filesystem path
-        * @param string $comment upload description
-        * @param string $pageText text to use for the new description page,
-        *                  if a new description page is created
-        * @param $flags Integer|bool: flags for publish()
-        * @param array|bool $props File properties, if known. This can be used to reduce the
-        *               upload time when uploading virtual URLs for which the file info
-        *               is already known
-        * @param string|bool $timestamp timestamp for img_timestamp, or false to use the current time
-        * @param $user User|null: User object or null to use $wgUser
+        * @param string $srcPath Source storage path, virtual URL, or filesystem path
+        * @param string $comment Upload description
+        * @param string $pageText Text to use for the new description page,
+        *   if a new description page is created
+        * @param int|bool $flags Flags for publish()
+        * @param array|bool $props File properties, if known. This can be used to
+        *   reduce the upload time when uploading virtual URLs for which the file
+        *   info is already known
+        * @param string|bool $timestamp Timestamp for img_timestamp, or false to use the
+        *   current time
+        * @param User|null $user User object or null to use $wgUser
         *
         * @return FileRepoStatus object. On success, the value member contains the
         *     archive name, or an empty string if it was a new file.
         */
-       function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null ) {
+       function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false,
+               $timestamp = false, $user = null
+       ) {
                global $wgContLang;
 
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
@@ -1088,8 +1138,8 @@ class LocalFile extends File {
                if ( !$props ) {
                        wfProfileIn( __METHOD__ . '-getProps' );
                        if ( $this->repo->isVirtualUrl( $srcPath )
-                               || FileBackend::isStoragePath( $srcPath ) )
-                       {
+                               || FileBackend::isStoragePath( $srcPath )
+                       {
                                $props = $this->repo->getFileProps( $srcPath );
                        } else {
                                $props = FSFile::getPropsFromPath( $srcPath );
@@ -1130,19 +1180,18 @@ class LocalFile extends File {
 
        /**
         * Record a file upload in the upload log and the image table
-        * @param $oldver
-        * @param $desc string
-        * @param $license string
-        * @param $copyStatus string
-        * @param $source string
-        * @param $watch bool
-        * @param $timestamp string|bool
-        * @param $user User object or null to use $wgUser
+        * @param string $oldver
+        * @param string $desc
+        * @param string $license
+        * @param string $copyStatus
+        * @param string $source
+        * @param bool $watch
+        * @param string|bool $timestamp
+        * @param User|null $user User object or null to use $wgUser
         * @return bool
         */
        function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
-               $watch = false, $timestamp = false, User $user = null )
-       {
+               $watch = false, $timestamp = false, User $user = null ) {
                if ( !$user ) {
                        global $wgUser;
                        $user = $wgUser;
@@ -1157,17 +1206,18 @@ class LocalFile extends File {
                if ( $watch ) {
                        $user->addWatch( $this->getTitle() );
                }
+
                return true;
        }
 
        /**
         * Record a file upload in the upload log and the image table
-        * @param $oldver
-        * @param $comment string
-        * @param $pageText string
-        * @param $props bool|array
-        * @param $timestamp bool|string
-        * @param $user null|User
+        * @param string $oldver
+        * @param string $comment
+        * @param string $pageText
+        * @param bool|array $props
+        * @param string|bool $timestamp
+        * @param null|User $user
         * @return bool
         */
        function recordUpload2(
@@ -1203,6 +1253,7 @@ class LocalFile extends File {
                if ( !$this->fileExists ) {
                        wfDebug( __METHOD__ . ": File " . $this->getRel() . " went missing!\n" );
                        wfProfileOut( __METHOD__ );
+
                        return false;
                }
 
@@ -1225,7 +1276,7 @@ class LocalFile extends File {
                                'img_description' => $comment,
                                'img_user' => $user->getId(),
                                'img_user_text' => $user->getName(),
-                               'img_metadata' => $dbw->encodeBlob($this->metadata),
+                               'img_metadata' => $dbw->encodeBlob( $this->metadata ),
                                'img_sha1' => $this->sha1
                        ),
                        __METHOD__,
@@ -1242,21 +1293,21 @@ class LocalFile extends File {
                        # Insert previous contents into oldimage
                        $dbw->insertSelect( 'oldimage', 'image',
                                array(
-                                       'oi_name'         => 'img_name',
+                                       'oi_name' => 'img_name',
                                        'oi_archive_name' => $dbw->addQuotes( $oldver ),
-                                       'oi_size'         => 'img_size',
-                                       'oi_width'        => 'img_width',
-                                       'oi_height'       => 'img_height',
-                                       'oi_bits'         => 'img_bits',
-                                       'oi_timestamp'    => 'img_timestamp',
-                                       'oi_description'  => 'img_description',
-                                       'oi_user'         => 'img_user',
-                                       'oi_user_text'    => 'img_user_text',
-                                       'oi_metadata'     => 'img_metadata',
-                                       'oi_media_type'   => 'img_media_type',
-                                       'oi_major_mime'   => 'img_major_mime',
-                                       'oi_minor_mime'   => 'img_minor_mime',
-                                       'oi_sha1'         => 'img_sha1'
+                                       'oi_size' => 'img_size',
+                                       'oi_width' => 'img_width',
+                                       'oi_height' => 'img_height',
+                                       'oi_bits' => 'img_bits',
+                                       'oi_timestamp' => 'img_timestamp',
+                                       'oi_description' => 'img_description',
+                                       'oi_user' => 'img_user',
+                                       'oi_user_text' => 'img_user_text',
+                                       'oi_metadata' => 'img_metadata',
+                                       'oi_media_type' => 'img_media_type',
+                                       'oi_major_mime' => 'img_major_mime',
+                                       'oi_minor_mime' => 'img_minor_mime',
+                                       'oi_sha1' => 'img_sha1'
                                ),
                                array( 'img_name' => $this->getName() ),
                                __METHOD__
@@ -1265,19 +1316,19 @@ class LocalFile extends File {
                        # Update the current image row
                        $dbw->update( 'image',
                                array( /* SET */
-                                       'img_size'        => $this->size,
-                                       'img_width'       => intval( $this->width ),
-                                       'img_height'      => intval( $this->height ),
-                                       'img_bits'        => $this->bits,
-                                       'img_media_type'  => $this->media_type,
-                                       'img_major_mime'  => $this->major_mime,
-                                       'img_minor_mime'  => $this->minor_mime,
-                                       'img_timestamp'   => $timestamp,
+                                       'img_size' => $this->size,
+                                       'img_width' => intval( $this->width ),
+                                       'img_height' => intval( $this->height ),
+                                       'img_bits' => $this->bits,
+                                       'img_media_type' => $this->media_type,
+                                       'img_major_mime' => $this->major_mime,
+                                       'img_minor_mime' => $this->minor_mime,
+                                       'img_timestamp' => $timestamp,
                                        'img_description' => $comment,
-                                       'img_user'        => $user->getId(),
-                                       'img_user_text'   => $user->getName(),
-                                       'img_metadata'    => $dbw->encodeBlob($this->metadata),
-                                       'img_sha1'        => $this->sha1
+                                       'img_user' => $user->getId(),
+                                       'img_user_text' => $user->getName(),
+                                       'img_metadata' => $dbw->encodeBlob( $this->metadata ),
+                                       'img_sha1' => $this->sha1
                                ),
                                array( 'img_name' => $this->getName() ),
                                __METHOD__
@@ -1356,7 +1407,13 @@ class LocalFile extends File {
                        # There's already a log entry, so don't make a second RC entry
                        # Squid and file cache for the description page are purged by doEditContent.
                        $content = ContentHandler::makeContent( $pageText, $descTitle );
-                       $status = $wikiPage->doEditContent( $content, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user );
+                       $status = $wikiPage->doEditContent(
+                               $content,
+                               $comment,
+                               EDIT_NEW | EDIT_SUPPRESS_RC,
+                               false,
+                               $user
+                       );
 
                        $dbw->begin( __METHOD__ ); // XXX; doEdit() uses a transaction
                        // Now that the page exists, make an RC entry.
@@ -1371,7 +1428,6 @@ class LocalFile extends File {
                        $dbw->commit( __METHOD__ ); // commit before anything bad can happen
                }
 
-
                wfProfileOut( __METHOD__ . '-edit' );
 
                # Save to cache and purge the squid
@@ -1414,6 +1470,7 @@ class LocalFile extends File {
                }
 
                wfProfileOut( __METHOD__ );
+
                return true;
        }
 
@@ -1425,11 +1482,11 @@ class LocalFile extends File {
         * The archive name should be passed through to recordUpload for database
         * registration.
         *
-        * @param string $srcPath local filesystem path to the source image
-        * @param $flags Integer: a bitwise combination of:
-        *     File::DELETE_SOURCE      Delete the source file, i.e. move rather than copy
+        * @param string $srcPath Local filesystem path to the source image
+        * @param int $flags A bitwise combination of:
+        *     File::DELETE_SOURCE    Delete the source file, i.e. move rather than copy
         * @param array $options Optional additional parameters
-        * @return FileRepoStatus object. On success, the value member contains the
+        * @return FileRepoStatus On success, the value member contains the
         *     archive name, or an empty string if it was a new file.
         */
        function publish( $srcPath, $flags = 0, array $options = array() ) {
@@ -1443,12 +1500,12 @@ class LocalFile extends File {
         * The archive name should be passed through to recordUpload for database
         * registration.
         *
-        * @param string $srcPath local filesystem path to the source image
-        * @param string $dstRel target relative path
-        * @param $flags Integer: a bitwise combination of:
-        *     File::DELETE_SOURCE      Delete the source file, i.e. move rather than copy
+        * @param string $srcPath Local filesystem path to the source image
+        * @param string $dstRel Target relative path
+        * @param int $flags A bitwise combination of:
+        *     File::DELETE_SOURCE    Delete the source file, i.e. move rather than copy
         * @param array $options Optional additional parameters
-        * @return FileRepoStatus object. On success, the value member contains the
+        * @return FileRepoStatus On success, the value member contains the
         *     archive name, or an empty string if it was a new file.
         */
        function publishTo( $srcPath, $dstRel, $flags = 0, array $options = array() ) {
@@ -1488,8 +1545,8 @@ class LocalFile extends File {
         * Cache purging is done; checks for validity
         * and logging are caller's responsibility
         *
-        * @param $target Title New file name
-        * @return FileRepoStatus object.
+        * @param Title $target New file name
+        * @return FileRepoStatus
         */
        function move( $target ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
@@ -1513,7 +1570,7 @@ class LocalFile extends File {
                // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
                // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
                $this->getRepo()->getMasterDB()->onTransactionIdle(
-                       function() use ( $oldTitleFile, $newTitleFile, $archiveNames ) {
+                       function () use ( $oldTitleFile, $newTitleFile, $archiveNames ) {
                                $oldTitleFile->purgeEverything();
                                foreach ( $archiveNames as $archiveName ) {
                                        $oldTitleFile->purgeOldThumbnails( $archiveName );
@@ -1541,9 +1598,9 @@ class LocalFile extends File {
         *
         * Cache purging is done; logging is caller's responsibility.
         *
-        * @param $reason
-        * @param $suppress
-        * @return FileRepoStatus object.
+        * @param string $reason
+        * @param bool $suppress
+        * @return FileRepoStatus
         */
        function delete( $reason, $suppress = false ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
@@ -1567,7 +1624,7 @@ class LocalFile extends File {
                // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
                $file = $this;
                $this->getRepo()->getMasterDB()->onTransactionIdle(
-                       function() use ( $file, $archiveNames ) {
+                       function () use ( $file, $archiveNames ) {
                                global $wgUseSquid;
 
                                $file->purgeEverything();
@@ -1597,11 +1654,11 @@ class LocalFile extends File {
         *
         * Cache purging is done; logging is caller's responsibility.
         *
-        * @param $archiveName String
-        * @param $reason String
-        * @param $suppress Boolean
-        * @throws MWException or FSException on database or file store failure
-        * @return FileRepoStatus object.
+        * @param string $archiveName
+        * @param string $reason
+        * @param bool $suppress
+        * @throws MWException Exception on database or file store failure
+        * @return FileRepoStatus
         */
        function deleteOld( $archiveName, $reason, $suppress = false ) {
                global $wgUseSquid;
@@ -1637,8 +1694,8 @@ class LocalFile extends File {
         * May throw database exceptions on error.
         *
         * @param array $versions set of record ids of deleted items to restore,
-        *                    or empty to restore all revisions.
-        * @param $unsuppress Boolean
+        *   or empty to restore all revisions.
+        * @param bool $unsuppress
         * @return FileRepoStatus
         */
        function restore( $versions = array(), $unsuppress = false ) {
@@ -1673,7 +1730,7 @@ class LocalFile extends File {
 
        /**
         * Get the URL of the file description page.
-        * @return String
+        * @return string
         */
        function getDescriptionUrl() {
                return $this->title->getLocalURL();
@@ -1684,7 +1741,7 @@ class LocalFile extends File {
         * This is not used by ImagePage for local files, since (among other things)
         * it skips the parser cache.
         *
-        * @param $lang Language What language to get description in (Optional)
+        * @param Language $lang What language to get description in (Optional)
         * @return bool|mixed
         */
        function getDescriptionText( $lang = null ) {
@@ -1697,10 +1754,13 @@ class LocalFile extends File {
                        return false;
                }
                $pout = $content->getParserOutput( $this->title, null, new ParserOptions( null, $lang ) );
+
                return $pout->getText();
        }
 
        /**
+        * @param int $audience
+        * @param User $user
         * @return string
         */
        function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
@@ -1708,8 +1768,8 @@ class LocalFile extends File {
                if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) {
                        return '';
                } elseif ( $audience == self::FOR_THIS_USER
-                       && !$this->userCan( self::DELETED_COMMENT, $user ) )
-               {
+                       && !$this->userCan( self::DELETED_COMMENT, $user )
+               {
                        return '';
                } else {
                        return $this->description;
@@ -1721,6 +1781,7 @@ class LocalFile extends File {
         */
        function getTimestamp() {
                $this->load();
+
                return $this->timestamp;
        }
 
@@ -1754,15 +1815,17 @@ class LocalFile extends File {
         */
        function isCacheable() {
                $this->load();
+
                // If extra data (metadata) was not loaded then it must have been large
                return $this->extraDataLoaded
-                       && strlen( serialize( $this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN;
+               && strlen( serialize( $this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN;
        }
 
        /**
         * Start a transaction and lock the image for update
         * Increments a reference counter if the lock is already held
-        * @return boolean True if the image exists, false otherwise
+        * @throws MWException
+        * @return bool True if the image exists, false otherwise
         */
        function lock() {
                $dbw = $this->repo->getMasterDB();
@@ -1780,7 +1843,7 @@ class LocalFile extends File {
                        if ( !$cache->lock( $key, 60 ) ) {
                                throw new MWException( "Could not acquire lock for '{$this->getName()}.'" );
                        }
-                       $dbw->onTransactionIdle( function() use ( $cache, $key ) {
+                       $dbw->onTransactionIdle( function () use ( $cache, $key ) {
                                $cache->unlock( $key ); // release on commit
                        } );
                }
@@ -1830,19 +1893,31 @@ class LocalFile extends File {
  * @ingroup FileAbstraction
  */
 class LocalFileDeleteBatch {
+       /** @var LocalFile */
+       private $file;
 
-       /**
-        * @var LocalFile
-        */
-       var $file;
+       /** @var string */
+       private $reason;
+
+       /** @var array */
+       private $srcRels = array();
+
+       /** @var array */
+       private $archiveUrls = array();
+
+       /** @var array Items to be processed in the deletion batch */
+       private $deletionBatch;
+
+       /** @var bool Wether to suppress all suppressable fields when deleting */
+       private $suppress;
 
-       var $reason, $srcRels = array(), $archiveUrls = array(), $deletionBatch, $suppress;
-       var $status;
+       /** @var FileRepoStatus */
+       private $status;
 
        /**
-        * @param $file File
-        * @param $reason string
-        * @param $suppress bool
+        * @param File $file
+        * @param string $reason
+        * @param bool $suppress
         */
        function __construct( File $file, $reason = '', $suppress = false ) {
                $this->file = $file;
@@ -1856,7 +1931,7 @@ class LocalFileDeleteBatch {
        }
 
        /**
-        * @param $oldName string
+        * @param string $oldName
         */
        function addOld( $oldName ) {
                $this->srcRels[$oldName] = $this->file->getArchiveRel( $oldName );
@@ -1865,7 +1940,7 @@ class LocalFileDeleteBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return Array List of archive names from old versions
+        * @return array List of archive names from old versions
         */
        function addOlds() {
                $archiveNames = array();
@@ -1990,27 +2065,27 @@ class LocalFileDeleteBatch {
                        $dbw->insertSelect( 'filearchive', 'image',
                                array(
                                        'fa_storage_group' => $encGroup,
-                                       'fa_storage_key'   => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
-                                       'fa_deleted_user'      => $encUserId,
+                                       'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
+                                       'fa_deleted_user' => $encUserId,
                                        'fa_deleted_timestamp' => $encTimestamp,
-                                       'fa_deleted_reason'    => $encReason,
-                                       'fa_deleted'           => $this->suppress ? $bitfield : 0,
+                                       'fa_deleted_reason' => $encReason,
+                                       'fa_deleted' => $this->suppress ? $bitfield : 0,
 
-                                       'fa_name'         => 'img_name',
+                                       'fa_name' => 'img_name',
                                        'fa_archive_name' => 'NULL',
-                                       'fa_size'         => 'img_size',
-                                       'fa_width'        => 'img_width',
-                                       'fa_height'       => 'img_height',
-                                       'fa_metadata'     => 'img_metadata',
-                                       'fa_bits'         => 'img_bits',
-                                       'fa_media_type'   => 'img_media_type',
-                                       'fa_major_mime'   => 'img_major_mime',
-                                       'fa_minor_mime'   => 'img_minor_mime',
-                                       'fa_description'  => 'img_description',
-                                       'fa_user'         => 'img_user',
-                                       'fa_user_text'    => 'img_user_text',
-                                       'fa_timestamp'    => 'img_timestamp',
-                                       'fa_sha1'         => 'img_sha1',
+                                       'fa_size' => 'img_size',
+                                       'fa_width' => 'img_width',
+                                       'fa_height' => 'img_height',
+                                       'fa_metadata' => 'img_metadata',
+                                       'fa_bits' => 'img_bits',
+                                       'fa_media_type' => 'img_media_type',
+                                       'fa_major_mime' => 'img_major_mime',
+                                       'fa_minor_mime' => 'img_minor_mime',
+                                       'fa_description' => 'img_description',
+                                       'fa_user' => 'img_user',
+                                       'fa_user_text' => 'img_user_text',
+                                       'fa_timestamp' => 'img_timestamp',
+                                       'fa_sha1' => 'img_sha1',
                                ), $where, __METHOD__ );
                }
 
@@ -2022,27 +2097,27 @@ class LocalFileDeleteBatch {
                        $dbw->insertSelect( 'filearchive', 'oldimage',
                                array(
                                        'fa_storage_group' => $encGroup,
-                                       'fa_storage_key'   => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
-                                       'fa_deleted_user'      => $encUserId,
+                                       'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
+                                       'fa_deleted_user' => $encUserId,
                                        'fa_deleted_timestamp' => $encTimestamp,
-                                       'fa_deleted_reason'    => $encReason,
-                                       'fa_deleted'           => $this->suppress ? $bitfield : 'oi_deleted',
+                                       'fa_deleted_reason' => $encReason,
+                                       'fa_deleted' => $this->suppress ? $bitfield : 'oi_deleted',
 
-                                       'fa_name'         => 'oi_name',
+                                       'fa_name' => 'oi_name',
                                        'fa_archive_name' => 'oi_archive_name',
-                                       'fa_size'         => 'oi_size',
-                                       'fa_width'        => 'oi_width',
-                                       'fa_height'       => 'oi_height',
-                                       'fa_metadata'     => 'oi_metadata',
-                                       'fa_bits'         => 'oi_bits',
-                                       'fa_media_type'   => 'oi_media_type',
-                                       'fa_major_mime'   => 'oi_major_mime',
-                                       'fa_minor_mime'   => 'oi_minor_mime',
-                                       'fa_description'  => 'oi_description',
-                                       'fa_user'         => 'oi_user',
-                                       'fa_user_text'    => 'oi_user_text',
-                                       'fa_timestamp'    => 'oi_timestamp',
-                                       'fa_sha1'         => 'oi_sha1',
+                                       'fa_size' => 'oi_size',
+                                       'fa_width' => 'oi_width',
+                                       'fa_height' => 'oi_height',
+                                       'fa_metadata' => 'oi_metadata',
+                                       'fa_bits' => 'oi_bits',
+                                       'fa_media_type' => 'oi_media_type',
+                                       'fa_major_mime' => 'oi_major_mime',
+                                       'fa_minor_mime' => 'oi_minor_mime',
+                                       'fa_description' => 'oi_description',
+                                       'fa_user' => 'oi_user',
+                                       'fa_user_text' => 'oi_user_text',
+                                       'fa_timestamp' => 'oi_timestamp',
+                                       'fa_sha1' => 'oi_sha1',
                                ), $where, __METHOD__ );
                }
        }
@@ -2130,6 +2205,7 @@ class LocalFileDeleteBatch {
                        // TODO: delete the defunct filearchive rows if we are using a non-transactional DB
                        $this->file->unlockAndRollback();
                        wfProfileOut( __METHOD__ );
+
                        return $this->status;
                }
 
@@ -2175,16 +2251,24 @@ class LocalFileDeleteBatch {
  * @ingroup FileAbstraction
  */
 class LocalFileRestoreBatch {
-       /**
-        * @var LocalFile
-        */
-       var $file;
+       /** @var LocalFile */
+       private $file;
+
+       /** @var array List of file IDs to restore */
+       private $cleanupBatch;
+
+       /** @var array List of file IDs to restore */
+       private $ids;
 
-       var $cleanupBatch, $ids, $all, $unsuppress = false;
+       /** @var bool Add all revisions of the file  */
+       private $all;
+
+       /** @var bool Wether to remove all settings for suppressed fields  */
+       private $unsuppress = false;
 
        /**
-        * @param $file File
-        * @param $unsuppress bool
+        * @param File $file
+        * @param bool $unsuppress
         */
        function __construct( File $file, $unsuppress = false ) {
                $this->file = $file;
@@ -2274,7 +2358,8 @@ class LocalFileRestoreBatch {
                                continue;
                        }
 
-                       $deletedRel = $this->file->repo->getDeletedHashPath( $row->fa_storage_key ) . $row->fa_storage_key;
+                       $deletedRel = $this->file->repo->getDeletedHashPath( $row->fa_storage_key ) .
+                               $row->fa_storage_key;
                        $deletedUrl = $this->file->repo->getVirtualUrl() . '/deleted/' . $deletedRel;
 
                        if ( isset( $row->fa_sha1 ) ) {
@@ -2292,7 +2377,8 @@ class LocalFileRestoreBatch {
                        if ( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown'
                                || is_null( $row->fa_minor_mime ) || $row->fa_minor_mime == 'unknown'
                                || is_null( $row->fa_media_type ) || $row->fa_media_type == 'UNKNOWN'
-                               || is_null( $row->fa_metadata ) ) {
+                               || is_null( $row->fa_metadata )
+                       ) {
                                // Refresh our metadata
                                // Required for a new current revision; nice for older ones too. :)
                                $props = RepoGroup::singleton()->getFileProps( $deletedUrl );
@@ -2301,7 +2387,7 @@ class LocalFileRestoreBatch {
                                        'minor_mime' => $row->fa_minor_mime,
                                        'major_mime' => $row->fa_major_mime,
                                        'media_type' => $row->fa_media_type,
-                                       'metadata'   => $row->fa_metadata
+                                       'metadata' => $row->fa_metadata
                                );
                        }
 
@@ -2309,20 +2395,20 @@ class LocalFileRestoreBatch {
                                // This revision will be published as the new current version
                                $destRel = $this->file->getRel();
                                $insertCurrent = array(
-                                       'img_name'        => $row->fa_name,
-                                       'img_size'        => $row->fa_size,
-                                       'img_width'       => $row->fa_width,
-                                       'img_height'      => $row->fa_height,
-                                       'img_metadata'    => $props['metadata'],
-                                       'img_bits'        => $row->fa_bits,
-                                       'img_media_type'  => $props['media_type'],
-                                       'img_major_mime'  => $props['major_mime'],
-                                       'img_minor_mime'  => $props['minor_mime'],
+                                       'img_name' => $row->fa_name,
+                                       'img_size' => $row->fa_size,
+                                       'img_width' => $row->fa_width,
+                                       'img_height' => $row->fa_height,
+                                       'img_metadata' => $props['metadata'],
+                                       'img_bits' => $row->fa_bits,
+                                       'img_media_type' => $props['media_type'],
+                                       'img_major_mime' => $props['major_mime'],
+                                       'img_minor_mime' => $props['minor_mime'],
                                        'img_description' => $row->fa_description,
-                                       'img_user'        => $row->fa_user,
-                                       'img_user_text'   => $row->fa_user_text,
-                                       'img_timestamp'   => $row->fa_timestamp,
-                                       'img_sha1'        => $sha1
+                                       'img_user' => $row->fa_user,
+                                       'img_user_text' => $row->fa_user_text,
+                                       'img_timestamp' => $row->fa_timestamp,
+                                       'img_sha1' => $sha1
                                );
 
                                // The live (current) version cannot be hidden!
@@ -2348,22 +2434,22 @@ class LocalFileRestoreBatch {
                                $archiveNames[$archiveName] = true;
                                $destRel = $this->file->getArchiveRel( $archiveName );
                                $insertBatch[] = array(
-                                       'oi_name'         => $row->fa_name,
+                                       'oi_name' => $row->fa_name,
                                        'oi_archive_name' => $archiveName,
-                                       'oi_size'         => $row->fa_size,
-                                       'oi_width'        => $row->fa_width,
-                                       'oi_height'       => $row->fa_height,
-                                       'oi_bits'         => $row->fa_bits,
-                                       'oi_description'  => $row->fa_description,
-                                       'oi_user'         => $row->fa_user,
-                                       'oi_user_text'    => $row->fa_user_text,
-                                       'oi_timestamp'    => $row->fa_timestamp,
-                                       'oi_metadata'     => $props['metadata'],
-                                       'oi_media_type'   => $props['media_type'],
-                                       'oi_major_mime'   => $props['major_mime'],
-                                       'oi_minor_mime'   => $props['minor_mime'],
-                                       'oi_deleted'      => $this->unsuppress ? 0 : $row->fa_deleted,
-                                       'oi_sha1'         => $sha1 );
+                                       'oi_size' => $row->fa_size,
+                                       'oi_width' => $row->fa_width,
+                                       'oi_height' => $row->fa_height,
+                                       'oi_bits' => $row->fa_bits,
+                                       'oi_description' => $row->fa_description,
+                                       'oi_user' => $row->fa_user,
+                                       'oi_user_text' => $row->fa_user_text,
+                                       'oi_timestamp' => $row->fa_timestamp,
+                                       'oi_metadata' => $props['metadata'],
+                                       'oi_media_type' => $props['media_type'],
+                                       'oi_major_mime' => $props['major_mime'],
+                                       'oi_minor_mime' => $props['minor_mime'],
+                                       'oi_deleted' => $this->unsuppress ? 0 : $row->fa_deleted,
+                                       'oi_sha1' => $sha1 );
                        }
 
                        $deleteIds[] = $row->fa_id;
@@ -2448,7 +2534,7 @@ class LocalFileRestoreBatch {
 
        /**
         * Removes non-existent files from a store batch.
-        * @param $triplets array
+        * @param array $triplets
         * @return array
         */
        function removeNonexistentFiles( $triplets ) {
@@ -2470,7 +2556,7 @@ class LocalFileRestoreBatch {
 
        /**
         * Removes non-existent files from a cleanup batch.
-        * @param $batch array
+        * @param array $batch
         * @return array
         */
        function removeNonexistentFromCleanup( $batch ) {
@@ -2539,23 +2625,26 @@ class LocalFileRestoreBatch {
  * @ingroup FileAbstraction
  */
 class LocalFileMoveBatch {
+       /** @var LocalFile */
+       protected $file;
 
-       /**
-        * @var LocalFile
-        */
-       var $file;
+       /** @var Title */
+       protected $target;
 
-       /**
-        * @var Title
-        */
-       var $target;
+       /** @var   */
+       protected $cur;
 
-       var $cur, $olds, $oldCount, $archive;
+       /** @var   */
+       protected $olds;
 
-       /**
-        * @var DatabaseBase
-        */
-       var $db;
+       /** @var   */
+       protected $oldCount;
+
+       /** @var   */
+       protected $archive;
+
+       /** @var DatabaseBase */
+       protected $db;
 
        /**
         * @param File $file
@@ -2582,7 +2671,7 @@ class LocalFileMoveBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return Array List of archive names from old versions
+        * @return array List of archive names from old versions
         */
        function addOlds() {
                $archiveBase = 'archive';
@@ -2650,21 +2739,25 @@ class LocalFileMoveBatch {
                if ( !$statusDb->isGood() ) {
                        $this->file->unlockAndRollback();
                        $statusDb->ok = false;
+
                        return $statusDb;
                }
-               wfDebugLog( 'imagemove', "Renamed {$this->file->getName()} in database: {$statusDb->successCount} successes, {$statusDb->failCount} failures" );
+               wfDebugLog( 'imagemove', "Renamed {$this->file->getName()} in database: " .
+                       "{$statusDb->successCount} successes, {$statusDb->failCount} failures" );
 
                // Copy the files into their new location.
                // If a prior process fataled copying or cleaning up files we tolerate any
                // of the existing files if they are identical to the ones being stored.
                $statusMove = $repo->storeBatch( $triplets, FileRepo::OVERWRITE_SAME );
-               wfDebugLog( 'imagemove', "Moved files for {$this->file->getName()}: {$statusMove->successCount} successes, {$statusMove->failCount} failures" );
+               wfDebugLog( 'imagemove', "Moved files for {$this->file->getName()}: " .
+                       "{$statusMove->successCount} successes, {$statusMove->failCount} failures" );
                if ( !$statusMove->isGood() ) {
                        // Delete any files copied over (while the destination is still locked)
                        $this->cleanupTarget( $triplets );
                        $this->file->unlockAndRollback(); // unlocks the destination
                        wfDebugLog( 'imagemove', "Error in moving files: " . $statusMove->getWikiText() );
                        $statusMove->ok = false;
+
                        return $statusMove;
                }
                $this->file->unlock(); // done
@@ -2702,6 +2795,7 @@ class LocalFileMoveBatch {
                } else {
                        $status->failCount++;
                        $status->fatal( 'imageinvalidfilename' );
+
                        return $status;
                }
 
@@ -2743,7 +2837,10 @@ class LocalFileMoveBatch {
                        // $move: (oldRelativePath, newRelativePath)
                        $srcUrl = $this->file->repo->getVirtualUrl() . '/public/' . rawurlencode( $move[0] );
                        $triplets[] = array( $srcUrl, 'public', $move[1] );
-                       wfDebugLog( 'imagemove', "Generated move triplet for {$this->file->getName()}: {$srcUrl} :: public :: {$move[1]}" );
+                       wfDebugLog(
+                               'imagemove',
+                               "Generated move triplet for {$this->file->getName()}: {$srcUrl} :: public :: {$move[1]}"
+                       );
                }
 
                return $triplets;
@@ -2751,7 +2848,7 @@ class LocalFileMoveBatch {
 
        /**
         * Removes non-existent files from move batch.
-        * @param $triplets array
+        * @param array $triplets
         * @return array
         */
        function removeNonexistentFiles( $triplets ) {