Avoid master queries on image history view
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 10 Sep 2015 22:47:54 +0000 (15:47 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 16 Sep 2015 17:41:12 +0000 (10:41 -0700)
* The path that needs READ_LATEST already calls load() as needed first

Bug: T92357
Change-Id: Ia06bba6c2853823add2e527bb1b013b64d3f020a

includes/page/ImagePage.php
includes/upload/UploadBase.php

index 62dd1e3..d7bd568 100644 (file)
@@ -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(),
index b06b91e..30a85ae 100644 (file)
@@ -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' );
        }