Pass $user to LocalFileDeleteBatch
authorumherirrender <umherirrender_de.wp@web.de>
Tue, 6 May 2014 19:03:45 +0000 (21:03 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Tue, 6 May 2014 19:31:29 +0000 (21:31 +0200)
This avoids the use of $wgUser

Change-Id: I60cab27e0708a818c77791cc89194b6dd726da0b

includes/FileDeleteForm.php
includes/filerepo/file/LocalFile.php

index 44aaeb4..642c49e 100644 (file)
@@ -149,7 +149,7 @@ class FileDeleteForm {
 
                if ( $oldimage ) {
                        $page = null;
-                       $status = $file->deleteOld( $oldimage, $reason, $suppress );
+                       $status = $file->deleteOld( $oldimage, $reason, $suppress, $user );
                        if ( $status->ok ) {
                                // Need to do a log item
                                $logComment = wfMessage( 'deletedrevision', $oldimage )->inContentLanguage()->text();
@@ -180,7 +180,7 @@ class FileDeleteForm {
                                // doDeleteArticleReal() returns a non-fatal error status if the page
                                // or revision is missing, so check for isOK() rather than isGood()
                                if ( $deleteStatus->isOK() ) {
-                                       $status = $file->delete( $reason, $suppress );
+                                       $status = $file->delete( $reason, $suppress, $user );
                                        if ( $status->isOK() ) {
                                                $dbw->commit( __METHOD__ );
                                        } else {
index b3d5d5d..7fb85b9 100644 (file)
@@ -1599,14 +1599,15 @@ class LocalFile extends File {
         *
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         * @return FileRepoStatus
         */
-       function delete( $reason, $suppress = false ) {
+       function delete( $reason, $suppress = false, $user = null ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
 
-               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
+               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
 
                $this->lock(); // begin
                $batch->addCurrent();
@@ -1656,16 +1657,17 @@ class LocalFile extends File {
         * @param string $archiveName
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         * @throws MWException Exception on database or file store failure
         * @return FileRepoStatus
         */
-       function deleteOld( $archiveName, $reason, $suppress = false ) {
+       function deleteOld( $archiveName, $reason, $suppress = false, $user = null ) {
                global $wgUseSquid;
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
 
-               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
+               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
 
                $this->lock(); // begin
                $batch->addOld( $archiveName );
@@ -1964,15 +1966,25 @@ class LocalFileDeleteBatch {
        /** @var FileRepoStatus */
        private $status;
 
+       /** @var User */
+       private $user;
+
        /**
         * @param File $file
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         */
-       function __construct( File $file, $reason = '', $suppress = false ) {
+       function __construct( File $file, $reason = '', $suppress = false, $user = null ) {
                $this->file = $file;
                $this->reason = $reason;
                $this->suppress = $suppress;
+               if ( $user ) {
+                       $this->user = $user;
+               } else {
+                       global $wgUser;
+                       $this->user = $wgUser;
+               }
                $this->status = $file->repo->newGood();
        }
 
@@ -2086,11 +2098,9 @@ class LocalFileDeleteBatch {
        }
 
        function doDBInserts() {
-               global $wgUser;
-
                $dbw = $this->file->repo->getMasterDB();
                $encTimestamp = $dbw->addQuotes( $dbw->timestamp() );
-               $encUserId = $dbw->addQuotes( $wgUser->getId() );
+               $encUserId = $dbw->addQuotes( $this->user->getId() );
                $encReason = $dbw->addQuotes( $this->reason );
                $encGroup = $dbw->addQuotes( 'deleted' );
                $ext = $this->file->getExtension();