From 592a6e7d2e4f750c79b278ec18a4af6d001ef122 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 10 Sep 2015 15:47:54 -0700 Subject: [PATCH] Avoid master queries on image history view * The path that needs READ_LATEST already calls load() as needed first Bug: T92357 Change-Id: Ia06bba6c2853823add2e527bb1b013b64d3f020a --- includes/page/ImagePage.php | 2 +- includes/upload/UploadBase.php | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 62dd1e32ae..d7bd568486 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -712,7 +712,7 @@ EOT $canUpload = $this->getTitle()->userCan( 'upload', $this->getContext()->getUser() ); if ( $canUpload && UploadBase::userCanReUpload( $this->getContext()->getUser(), - $this->mPage->getFile()->name ) + $this->mPage->getFile() ) ) { $ulink = Linker::makeExternalLink( $this->getUploadUrl(), diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index b06b91e4a7..30a85aec14 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1706,24 +1706,21 @@ abstract class UploadBase { * Check if a user is the last uploader * * @param User $user - * @param string $img Image name + * @param File $img * @return bool */ - public static function userCanReUpload( User $user, $img ) { + public static function userCanReUpload( User $user, File $img ) { if ( $user->isAllowed( 'reupload' ) ) { return true; // non-conditional - } - if ( !$user->isAllowed( 'reupload-own' ) ) { + } elseif ( !$user->isAllowed( 'reupload-own' ) ) { return false; } - if ( is_string( $img ) ) { - $img = wfLocalFile( $img ); - } + if ( !( $img instanceof LocalFile ) ) { return false; } - $img->load( File::READ_LATEST ); + $img->load(); return $user->getId() == $img->getUser( 'id' ); } -- 2.20.1