Made wfFindFile/wfLocalFile callers use explicit "latest" flags
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 5 Mar 2015 20:13:28 +0000 (12:13 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 6 Mar 2015 04:18:50 +0000 (04:18 +0000)
* Callers that should not use caches won't
* Aliased the old "bypassCache" param to "latest"

bug: T89184
Change-Id: I9f79e5942ced4ae13ba4de0b4c62908cc746e777

includes/Import.php
includes/MovePage.php
includes/Title.php
includes/api/ApiImageRotate.php
includes/filerepo/FileRepo.php
includes/filerepo/RepoGroup.php
includes/jobqueue/jobs/ThumbnailRenderJob.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialUndelete.php
includes/upload/UploadBase.php
includes/upload/UploadFromChunks.php

index 3ba4306..de453b5 100644 (file)
@@ -1670,6 +1670,7 @@ class WikiRevision {
                                RepoGroup::singleton()->getLocalRepo(), $archiveName );
                } else {
                        $file = wfLocalFile( $this->getTitle() );
+                       $file->load( File::READ_LATEST );
                        wfDebug( __METHOD__ . 'Importing new file as ' . $file->getName() . "\n" );
                        if ( $file->exists() && $file->getTimestamp() > $this->getTimestamp() ) {
                                $archiveName = $file->getTimestamp() . '!' . $file->getName();
index 01c25d3..de7da3f 100644 (file)
@@ -159,6 +159,7 @@ class MovePage {
        protected function isValidFileMove() {
                $status = new Status();
                $file = wfLocalFile( $this->oldTitle );
+               $file->load( File::READ_LATEST );
                if ( $file->exists() ) {
                        if ( $this->newTitle->getText() != wfStripIllegalFilenameChars( $this->newTitle->getText() ) ) {
                                $status->fatal( 'imageinvalidfilename' );
@@ -186,6 +187,7 @@ class MovePage {
                # Is it an existing file?
                if ( $this->newTitle->inNamespace( NS_FILE ) ) {
                        $file = wfLocalFile( $this->newTitle );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                wfDebug( __METHOD__ . ": file exists\n" );
                                return false;
@@ -238,6 +240,7 @@ class MovePage {
                $dbw = wfGetDB( DB_MASTER );
                if ( $this->oldTitle->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $this->oldTitle );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                $status = $file->move( $this->newTitle );
                                if ( !$status->isOk() ) {
index 2ef4ee4..36237ed 100644 (file)
@@ -3631,7 +3631,10 @@ class Title {
                $errors = array();
 
                $destFile = wfLocalFile( $nt );
-               if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destFile->exists() && wfFindFile( $nt ) ) {
+               $destFile->load( File::READ_LATEST );
+               if ( !$wgUser->isAllowed( 'reupload-shared' )
+                       && !$destFile->exists() && wfFindFile( $nt )
+               ) {
                        $errors[] = array( 'file-exists-sharedrepo' );
                }
 
@@ -3806,6 +3809,7 @@ class Title {
                # Is it an existing file?
                if ( $nt->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $nt );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                wfDebug( __METHOD__ . ": file exists\n" );
                                return false;
index aba6921..6fd79f4 100644 (file)
@@ -73,7 +73,7 @@ class ApiImageRotate extends ApiBase {
                                $r['missing'] = '';
                        }
 
-                       $file = wfFindFile( $title );
+                       $file = wfFindFile( $title, array( 'latest' => true ) );
                        if ( !$file ) {
                                $r['result'] = 'Failure';
                                $r['errormessage'] = 'File does not exist';
index 01495a4..5b42c2c 100644 (file)
@@ -406,7 +406,7 @@ class FileRepo {
         *   private:        If true, return restricted (deleted) files if the current
         *                   user is allowed to view them. Otherwise, such files will not
         *                   be found. If a User object, use that user instead of the current.
-        *   bypassCache:    If true, do not use the process/persistent cache of File objects
+        *   latest:         If true, load from the latest available data into File objects
         * @return File|bool False on failure
         */
        public function findFile( $title, $options = array() ) {
@@ -414,8 +414,11 @@ class FileRepo {
                if ( !$title ) {
                        return false;
                }
+               if ( isset( $options['bypassCache'] ) ) {
+                       $options['latest'] = $options['bypassCache']; // b/c
+               }
                $time = isset( $options['time'] ) ? $options['time'] : false;
-               $flags = !empty( $options['bypassCache'] ) ? File::READ_LATEST : 0;
+               $flags = !empty( $options['latest'] ) ? File::READ_LATEST : 0;
                # First try the current version of the file to see if it precedes the timestamp
                $img = $this->newFile( $title );
                if ( !$img ) {
index 6ac00de..050c429 100644 (file)
@@ -114,7 +114,7 @@ class RepoGroup {
         *   private:        If true, return restricted (deleted) files if the current
         *                   user is allowed to view them. Otherwise, such files will not
         *                   be found.
-        *   bypassCache:    If true, do not use the process/persistent cache of File objects
+        *   latest:         If true, load from the latest available data into File objects
         * @return File|bool False if title is not found
         */
        function findFile( $title, $options = array() ) {
@@ -122,6 +122,10 @@ class RepoGroup {
                        // MW 1.15 compat
                        $options = array( 'time' => $options );
                }
+               if ( isset( $options['bypassCache'] ) ) {
+                       $options['latest'] = $options['bypassCache']; // b/c
+               }
+
                if ( !$this->reposInitialised ) {
                        $this->initialiseRepos();
                }
index 4b5189d..ab38138 100644 (file)
@@ -37,6 +37,7 @@ class ThumbnailRenderJob extends Job {
                $transformParams = $this->params['transformParams'];
 
                $file = wfLocalFile( $this->title );
+               $file->load( File::READ_LATEST );
 
                if ( $file && $file->exists() ) {
                        if ( $wgUploadThumbnailRenderMethod === 'jobqueue' ) {
@@ -92,7 +93,7 @@ class ThumbnailRenderJob extends Job {
 
                wfDebug( __METHOD__ . ": hitting url {$thumbUrl}\n" );
 
-               $request = MWHttpRequest::factory( $thumbUrl, 
+               $request = MWHttpRequest::factory( $thumbUrl,
                        array( 'method' => 'HEAD', 'followRedirects' => true ),
                        __METHOD__
                );
index d488253..a519bd0 100644 (file)
@@ -537,6 +537,7 @@ class MovePageForm extends UnlistedSpecialPage {
                        // Delete an associated image if there is
                        if ( $nt->getNamespace() == NS_FILE ) {
                                $file = wfLocalFile( $nt );
+                               $file->load( File::READ_LATEST );
                                if ( $file->exists() ) {
                                        $file->delete( $reason, false, $user );
                                }
index c88c2f1..205e2f4 100644 (file)
@@ -370,6 +370,7 @@ class PageArchive {
 
                if ( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
                        $img = wfLocalFile( $this->title );
+                       $img->load( File::READ_LATEST );
                        $this->fileStatus = $img->restore( $fileVersions, $unsuppress );
                        if ( !$this->fileStatus->isOK() ) {
                                return false;
index fccb5e1..a79526e 100644 (file)
@@ -622,6 +622,7 @@ abstract class UploadBase {
                $warnings = array();
 
                $localFile = $this->getLocalFile();
+               $localFile->load( File::READ_LATEST );
                $filename = $localFile->getName();
 
                /**
@@ -701,6 +702,7 @@ abstract class UploadBase {
         * @return Status Indicating the whether the upload succeeded.
         */
        public function performUpload( $comment, $pageText, $watch, $user ) {
+               $this->getLocalFile()->load( File::READ_LATEST );
 
                $status = $this->getLocalFile()->upload(
                        $this->mTempPath,
@@ -1699,6 +1701,7 @@ abstract class UploadBase {
        private function checkOverwrite( $user ) {
                // First check whether the local file can be overwritten
                $file = $this->getLocalFile();
+               $file->load( File::READ_LATEST );
                if ( $file->exists() ) {
                        if ( !self::userCanReUpload( $user, $file ) ) {
                                return array( 'fileexists-forbidden', $file->getName() );
@@ -1710,7 +1713,7 @@ abstract class UploadBase {
                /* Check shared conflicts: if the local file does not exist, but
                 * wfFindFile finds a file, it exists in a shared repository.
                 */
-               $file = wfFindFile( $this->getTitle() );
+               $file = wfFindFile( $this->getTitle(), array( 'latest' => true ) );
                if ( $file && !$user->isAllowed( 'reupload-shared' ) ) {
                        return array( 'fileexists-shared-forbidden', $file->getName() );
                }
@@ -1739,6 +1742,8 @@ abstract class UploadBase {
                        return false;
                }
 
+               $img->load( File::READ_LATEST );
+
                return $user->getId() == $img->getUser( 'id' );
        }
 
index 3c249ce..cc9f5c8 100644 (file)
@@ -170,20 +170,6 @@ class UploadFromChunks extends UploadFromFile {
                return $status;
        }
 
-       /**
-        * Perform the upload, then remove the temp copy afterward
-        * @param string $comment
-        * @param string $pageText
-        * @param bool $watch
-        * @param User $user
-        * @return Status
-        */
-       public function performUpload( $comment, $pageText, $watch, $user ) {
-               $rv = parent::performUpload( $comment, $pageText, $watch, $user );
-
-               return $rv;
-       }
-
        /**
         * Returns the virtual chunk location:
         * @param int $index