Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 0464f07..e86f292 100644 (file)
@@ -141,7 +141,7 @@ class LocalFile extends File {
         * @param FileRepo $repo
         * @param null $unused
         *
-        * @return LocalFile
+        * @return self
         */
        static function newFromTitle( $title, $repo, $unused = null ) {
                return new self( $title, $repo );
@@ -154,7 +154,7 @@ class LocalFile extends File {
         * @param stdClass $row
         * @param FileRepo $repo
         *
-        * @return LocalFile
+        * @return self
         */
        static function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_FILE, $row->img_name );
@@ -195,7 +195,7 @@ class LocalFile extends File {
        /**
         * Fields in the image table
         * @deprecated since 1.31, use self::getQueryInfo() instead.
-        * @return array
+        * @return string[]
         */
        static function selectFields() {
                global $wgActorTableSchemaMigrationStage;
@@ -226,7 +226,7 @@ class LocalFile extends File {
                        'img_actor' => $wgActorTableSchemaMigrationStage > MIGRATION_OLD ? 'img_actor' : null,
                        'img_timestamp',
                        'img_sha1',
-               ] + CommentStore::getStore()->getFields( 'img_description' );
+               ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'img_description' );
        }
 
        /**
@@ -235,13 +235,13 @@ class LocalFile extends File {
         * @since 1.31
         * @param string[] $options
         *   - omit-lazy: Omit fields that are lazily cached.
-        * @return array With three keys:
+        * @return array[] With three keys:
         *   - tables: (string[]) to include in the `$table` to `IDatabase->select()`
         *   - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public static function getQueryInfo( array $options = [] ) {
-               $commentQuery = CommentStore::getStore()->getJoin( 'img_description' );
+               $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'img_description' );
                $actorQuery = ActorMigration::newMigration()->getJoin( 'img_user' );
                $ret = [
                        'tables' => [ 'image' ] + $commentQuery['tables'] + $actorQuery['tables'],
@@ -323,7 +323,7 @@ class LocalFile extends File {
                        return;
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $cachedValues = $cache->getWithSetCallback(
                        $key,
                        $cache::TTL_WEEK,
@@ -388,7 +388,7 @@ class LocalFile extends File {
 
                $this->repo->getMasterDB()->onTransactionPreCommitOrIdle(
                        function () use ( $key ) {
-                               ObjectCache::getMainWANInstance()->delete( $key );
+                               MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
                        },
                        __METHOD__
                );
@@ -405,7 +405,7 @@ class LocalFile extends File {
        /**
         * Returns the list of object properties that are included as-is in the cache.
         * @param string $prefix Must be the empty string
-        * @return array
+        * @return string[]
         * @since 1.31 No longer accepts a non-empty $prefix
         */
        protected function getCacheFields( $prefix = 'img_' ) {
@@ -427,7 +427,7 @@ class LocalFile extends File {
         * Returns the list of object properties that are included as-is in the
         * cache, only when they're not too big, and are lazily loaded by self::loadExtraFromDB().
         * @param string $prefix Must be the empty string
-        * @return array
+        * @return string[]
         * @since 1.31 No longer accepts a non-empty $prefix
         */
        protected function getLazyCacheFields( $prefix = 'img_' ) {
@@ -500,7 +500,7 @@ class LocalFile extends File {
        /**
         * @param IDatabase $dbr
         * @param string $fname
-        * @return array|bool
+        * @return string[]|bool
         */
        private function loadExtraFieldsWithTimestamp( $dbr, $fname ) {
                $fieldMap = false;
@@ -579,13 +579,13 @@ class LocalFile extends File {
        function decodeRow( $row, $prefix = 'img_' ) {
                $decoded = $this->unprefixRow( $row, $prefix );
 
-               $decoded['description'] = CommentStore::getStore()
+               $decoded['description'] = MediaWikiServices::getInstance()->getCommentStore()
                        ->getComment( 'description', (object)$decoded )->text;
 
                $decoded['user'] = User::newFromAnyId(
-                       isset( $decoded['user'] ) ? $decoded['user'] : null,
-                       isset( $decoded['user_text'] ) ? $decoded['user_text'] : null,
-                       isset( $decoded['actor'] ) ? $decoded['actor'] : null
+                       $decoded['user'] ?? null,
+                       $decoded['user_text'] ?? null,
+                       $decoded['actor'] ?? null
                );
                unset( $decoded['user_text'], $decoded['actor'] );
 
@@ -772,9 +772,9 @@ class LocalFile extends File {
 
                if ( isset( $info['user'] ) || isset( $info['user_text'] ) || isset( $info['actor'] ) ) {
                        $this->user = User::newFromAnyId(
-                               isset( $info['user'] ) ? $info['user'] : null,
-                               isset( $info['user_text'] ) ? $info['user_text'] : null,
-                               isset( $info['actor'] ) ? $info['actor'] : null
+                               $info['user'] ?? null,
+                               $info['user_text'] ?? null,
+                               $info['actor'] ?? null
                        );
                }
 
@@ -1160,9 +1160,9 @@ class LocalFile extends File {
        /** purgeEverything inherited */
 
        /**
-        * @param int $limit Optional: Limit to number of results
-        * @param int $start Optional: Timestamp, start from
-        * @param int $end Optional: Timestamp, end at
+        * @param int|null $limit Optional: Limit to number of results
+        * @param string|int|null $start Optional: Timestamp, start from
+        * @param string|int|null $end Optional: Timestamp, end at
         * @param bool $inc
         * @return OldLocalFile[]
         */
@@ -1300,11 +1300,14 @@ class LocalFile extends File {
         * @param User|null $user User object or null to use $wgUser
         * @param string[] $tags Change tags to add to the log entry and page revision.
         *   (This doesn't check $user's permissions.)
+        * @param bool $createNullRevision Set to false to avoid creation of a null revision on file
+        *   upload, see T193621
         * @return Status On success, the value member contains the
         *     archive name, or an empty string if it was a new file.
         */
        function upload( $src, $comment, $pageText, $flags = 0, $props = false,
-               $timestamp = false, $user = null, $tags = []
+               $timestamp = false, $user = null, $tags = [],
+               $createNullRevision = true
        ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
@@ -1321,7 +1324,7 @@ class LocalFile extends File {
                        ) {
                                $props = $this->repo->getFileProps( $srcPath );
                        } else {
-                               $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
+                               $mwProps = new MWFileProps( MediaWikiServices::getInstance()->getMimeAnalyzer() );
                                $props = $mwProps->getPropsFromPath( $srcPath, true );
                        }
                }
@@ -1361,7 +1364,8 @@ class LocalFile extends File {
                                $props,
                                $timestamp,
                                $user,
-                               $tags
+                               $tags,
+                               $createNullRevision
                        );
                        if ( !$uploadStatus->isOK() ) {
                                if ( $uploadStatus->hasMessage( 'filenotfound' ) ) {
@@ -1419,10 +1423,13 @@ class LocalFile extends File {
         * @param string|bool $timestamp
         * @param null|User $user
         * @param string[] $tags
+        * @param bool $createNullRevision Set to false to avoid creation of a null revision on file
+        *   upload, see T193621
         * @return Status
         */
        function recordUpload2(
-               $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = []
+               $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [],
+               $createNullRevision = true
        ) {
                global $wgCommentTableSchemaMigrationStage, $wgActorTableSchemaMigrationStage;
 
@@ -1462,7 +1469,7 @@ class LocalFile extends File {
                # Test to see if the row exists using INSERT IGNORE
                # This avoids race conditions by locking the row until the commit, and also
                # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                list( $commentFields, $commentCallback ) =
                        $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
                $actorMigration = ActorMigration::newMigration();
@@ -1662,7 +1669,7 @@ class LocalFile extends File {
                        $formatter->setContext( RequestContext::newExtraneousContext( $descTitle ) );
                        $editSummary = $formatter->getPlainActionText();
 
-                       $nullRevision = Revision::newNullRevision(
+                       $nullRevision = $createNullRevision === false ? null : Revision::newNullRevision(
                                $dbw,
                                $descId,
                                $editSummary,
@@ -2105,8 +2112,8 @@ class LocalFile extends File {
         * This is not used by ImagePage for local files, since (among other things)
         * it skips the parser cache.
         *
-        * @param Language $lang What language to get description in (Optional)
-        * @return bool|mixed
+        * @param Language|null $lang What language to get description in (Optional)
+        * @return string|false
         */
        function getDescriptionText( $lang = null ) {
                $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
@@ -2124,7 +2131,7 @@ class LocalFile extends File {
 
        /**
         * @param int $audience
-        * @param User $user
+        * @param User|null $user
         * @return string
         */
        function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
@@ -2201,7 +2208,7 @@ class LocalFile extends File {
 
                // 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;
        }
 
        /**
@@ -2209,9 +2216,9 @@ class LocalFile extends File {
         * @since 1.28
         */
        public function acquireFileLock() {
-               return $this->getRepo()->getBackend()->lockFiles(
+               return Status::wrap( $this->getRepo()->getBackend()->lockFiles(
                        [ $this->getPath() ], LockManager::LOCK_EX, 10
-               );
+               ) );
        }
 
        /**
@@ -2219,9 +2226,9 @@ class LocalFile extends File {
         * @since 1.28
         */
        public function releaseFileLock() {
-               return $this->getRepo()->getBackend()->unlockFiles(
+               return Status::wrap( $this->getRepo()->getBackend()->unlockFiles(
                        [ $this->getPath() ], LockManager::LOCK_EX
-               );
+               ) );
        }
 
        /**
@@ -2369,7 +2376,7 @@ class LocalFileDeleteBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return array List of archive names from old versions
+        * @return string[] List of archive names from old versions
         */
        public function addOlds() {
                $archiveNames = [];
@@ -2470,7 +2477,7 @@ class LocalFileDeleteBatch {
                $now = time();
                $dbw = $this->file->repo->getMasterDB();
 
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                $actorMigration = ActorMigration::newMigration();
 
                $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
@@ -2762,10 +2769,10 @@ class LocalFileRestoreBatch {
        /** @var LocalFile */
        private $file;
 
-       /** @var array List of file IDs to restore */
+       /** @var string[] List of file IDs to restore */
        private $cleanupBatch;
 
-       /** @var array List of file IDs to restore */
+       /** @var string[] List of file IDs to restore */
        private $ids;
 
        /** @var bool Add all revisions of the file */
@@ -2780,7 +2787,7 @@ class LocalFileRestoreBatch {
         */
        function __construct( File $file, $unsuppress = false ) {
                $this->file = $file;
-               $this->cleanupBatch = $this->ids = [];
+               $this->cleanupBatch = [];
                $this->ids = [];
                $this->unsuppress = $unsuppress;
        }
@@ -2830,7 +2837,7 @@ class LocalFileRestoreBatch {
 
                $dbw = $this->file->repo->getMasterDB();
 
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                $actorMigration = ActorMigration::newMigration();
 
                $status = $this->file->repo->newGood();
@@ -3097,8 +3104,8 @@ class LocalFileRestoreBatch {
 
        /**
         * Removes non-existent files from a cleanup batch.
-        * @param array $batch
-        * @return array
+        * @param string[] $batch
+        * @return string[]
         */
        protected function removeNonexistentFromCleanup( $batch ) {
                $files = $newBatch = [];
@@ -3142,7 +3149,7 @@ class LocalFileRestoreBatch {
         * rollback by removing all items that were succesfully copied.
         *
         * @param Status $storeStatus
-        * @param array $storeBatch
+        * @param array[] $storeBatch
         */
        protected function cleanupFailedBatch( $storeStatus, $storeBatch ) {
                $cleanupBatch = [];
@@ -3208,7 +3215,7 @@ class LocalFileMoveBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return array List of archive names from old versions
+        * @return string[] List of archive names from old versions
         */
        public function addOlds() {
                $archiveBase = 'archive';
@@ -3409,7 +3416,7 @@ class LocalFileMoveBatch {
 
        /**
         * Generate triplets for FileRepo::storeBatch().
-        * @return array
+        * @return array[]
         */
        protected function getMoveTriplets() {
                $moves = array_merge( [ $this->cur ], $this->olds );
@@ -3461,7 +3468,7 @@ class LocalFileMoveBatch {
        /**
         * Cleanup a partially moved array of triplets by deleting the target
         * files. Called if something went wrong half way.
-        * @param array $triplets
+        * @param array[] $triplets
         */
        protected function cleanupTarget( $triplets ) {
                // Create dest pairs from the triplets
@@ -3477,7 +3484,7 @@ class LocalFileMoveBatch {
        /**
         * Cleanup a fully moved array of triplets by deleting the source files.
         * Called at the end of the move process if everything else went ok.
-        * @param array $triplets
+        * @param array[] $triplets
         */
        protected function cleanupSource( $triplets ) {
                // Create source file names from the triplets