Fixes LocalFile isMissing always returning true
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 789d7c5..aa04fae 100644 (file)
@@ -634,7 +634,6 @@ class LocalFile extends File {
                }
 
                $this->fileExists = true;
-               $this->maybeUpgradeRow();
        }
 
        /**
@@ -659,7 +658,7 @@ class LocalFile extends File {
        /**
         * Upgrade a row if it needs it
         */
-       function maybeUpgradeRow() {
+       protected function maybeUpgradeRow() {
                global $wgUpdateCompatibleMetadata;
 
                if ( wfReadOnly() || $this->upgrading ) {
@@ -797,11 +796,14 @@ class LocalFile extends File {
        /** isVisible inherited */
 
        /**
+        * Checks if this file exists in its parent repo, as referenced by its
+        * virtual URL.
+        *
         * @return bool
         */
        function isMissing() {
                if ( $this->missing === null ) {
-                       list( $fileExists ) = $this->repo->fileExists( $this->getVirtualUrl() );
+                       $fileExists = $this->repo->fileExists( $this->getVirtualUrl() );
                        $this->missing = !$fileExists;
                }
 
@@ -1028,6 +1030,7 @@ class LocalFile extends File {
         */
        function purgeCache( $options = [] ) {
                // Refresh metadata cache
+               $this->maybeUpgradeRow();
                $this->purgeMetadataCache();
 
                // Delete thumbnails
@@ -1303,12 +1306,13 @@ class LocalFile extends File {
         *   (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
+        * @param bool $revert If this file upload is a revert
         * @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 = [],
-               $createNullRevision = true
+               $createNullRevision = true, $revert = false
        ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
@@ -1366,7 +1370,8 @@ class LocalFile extends File {
                                $timestamp,
                                $user,
                                $tags,
-                               $createNullRevision
+                               $createNullRevision,
+                               $revert
                        );
                        if ( !$uploadStatus->isOK() ) {
                                if ( $uploadStatus->hasMessage( 'filenotfound' ) ) {
@@ -1425,11 +1430,12 @@ class LocalFile extends File {
         * @param string[] $tags
         * @param bool $createNullRevision Set to false to avoid creation of a null revision on file
         *   upload, see T193621
+        * @param bool $revert If this file upload is a revert
         * @return Status
         */
        function recordUpload2(
                $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [],
-               $createNullRevision = true
+               $createNullRevision = true, $revert = false
        ) {
                global $wgActorTableSchemaMigrationStage;
 
@@ -1602,8 +1608,16 @@ class LocalFile extends File {
                $wikiPage = new WikiFilePage( $descTitle );
                $wikiPage->setFile( $this );
 
+               // Determine log action. If reupload is done by reverting, use a special log_action.
+               if ( $revert === true ) {
+                       $logAction = 'revert';
+               } elseif ( $reupload === true ) {
+                       $logAction = 'overwrite';
+               } else {
+                       $logAction = 'upload';
+               }
                // Add the log entry...
-               $logEntry = new ManualLogEntry( 'upload', $reupload ? 'overwrite' : 'upload' );
+               $logEntry = new ManualLogEntry( 'upload', $logAction );
                $logEntry->setTimestamp( $this->timestamp );
                $logEntry->setPerformer( $user );
                $logEntry->setComment( $comment );
@@ -1827,8 +1841,13 @@ class LocalFile extends File {
 
                $this->lock();
 
-               $archiveName = wfTimestamp( TS_MW ) . '!' . $this->getName();
-               $archiveRel = $this->getArchiveRel( $archiveName );
+               if ( $this->isOld() ) {
+                       $archiveRel = $dstRel;
+                       $archiveName = basename( $archiveRel );
+               } else {
+                       $archiveName = wfTimestamp( TS_MW ) . '!' . $this->getName();
+                       $archiveRel = $this->getArchiveRel( $archiveName );
+               }
 
                if ( $repo->hasSha1Storage() ) {
                        $sha1 = FileRepo::isVirtualUrl( $srcPath )