From 5085a4b5cfa32ef693dc3a23c5c6d128156f7018 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 5 Mar 2015 12:13:28 -0800 Subject: [PATCH] Made wfFindFile/wfLocalFile callers use explicit "latest" flags * Callers that should not use caches won't * Aliased the old "bypassCache" param to "latest" bug: T89184 Change-Id: I9f79e5942ced4ae13ba4de0b4c62908cc746e777 --- includes/Import.php | 1 + includes/MovePage.php | 3 +++ includes/Title.php | 6 +++++- includes/api/ApiImageRotate.php | 2 +- includes/filerepo/FileRepo.php | 7 +++++-- includes/filerepo/RepoGroup.php | 6 +++++- includes/jobqueue/jobs/ThumbnailRenderJob.php | 3 ++- includes/specials/SpecialMovepage.php | 1 + includes/specials/SpecialUndelete.php | 1 + includes/upload/UploadBase.php | 7 ++++++- includes/upload/UploadFromChunks.php | 14 -------------- 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index 3ba4306c65..de453b5a5f 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -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(); diff --git a/includes/MovePage.php b/includes/MovePage.php index 01c25d397a..de7da3f939 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -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() ) { diff --git a/includes/Title.php b/includes/Title.php index 2ef4ee43d2..36237ed5bf 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php index aba6921a1c..6fd79f4fbd 100644 --- a/includes/api/ApiImageRotate.php +++ b/includes/api/ApiImageRotate.php @@ -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'; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 01495a4032..5b42c2c628 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -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 ) { diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 6ac00dec24..050c429054 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -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(); } diff --git a/includes/jobqueue/jobs/ThumbnailRenderJob.php b/includes/jobqueue/jobs/ThumbnailRenderJob.php index 4b5189d975..ab381388a5 100644 --- a/includes/jobqueue/jobs/ThumbnailRenderJob.php +++ b/includes/jobqueue/jobs/ThumbnailRenderJob.php @@ -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__ ); diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index d488253a57..a519bd0770 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -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 ); } diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index c88c2f1154..205e2f416b 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -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; diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index fccb5e1a3a..a79526e0fb 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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' ); } diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 3c249ce9ee..cc9f5c85fc 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -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 -- 2.20.1