jenkins-bot has submitted this change and it was merged.

Change subject: Revert "Clean up user handling in UploadStash"
......................................................................


Revert "Clean up user handling in UploadStash"

This reverts commit 58713d2b1611e55fcd0cf7647af8d96ebc1e88bf.

Bug: T145228
Change-Id: Ic62f19109f98fab9dd029acccecd6518b649e34b
---
M includes/upload/UploadStash.php
M maintenance/cleanupUploadStash.php
M tests/phpunit/includes/upload/UploadStashTest.php
3 files changed, 21 insertions(+), 9 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php
index 1c3e13b..c171ded 100644
--- a/includes/upload/UploadStash.php
+++ b/includes/upload/UploadStash.php
@@ -73,8 +73,8 @@
        // fileprops cache
        protected $fileProps = [];
 
-       // current user info
-       protected $userId, $isLoggedIn;
+       // current user
+       protected $user, $userId, $isLoggedIn;
 
        /**
         * Represents a temporary filestore, with metadata in the database.
@@ -82,15 +82,25 @@
         * (should replace it eventually).
         *
         * @param FileRepo $repo
-        * @param User $user
+        * @param User $user (default null)
         */
-       public function __construct( FileRepo $repo, User $user ) {
+       public function __construct( FileRepo $repo, $user = null ) {
                // this might change based on wiki's configuration.
                $this->repo = $repo;
 
-               // We only need the logged in status and user id.
-               $this->userId = $user->getId();
-               $this->isLoggedIn = $user->isLoggedIn();
+               // if a user was passed, use it. otherwise, attempt to use the 
global.
+               // this keeps FileRepo from breaking when it creates an 
UploadStash object
+               if ( $user ) {
+                       $this->user = $user;
+               } else {
+                       global $wgUser;
+                       $this->user = $wgUser;
+               }
+
+               if ( is_object( $this->user ) ) {
+                       $this->userId = $this->user->getId();
+                       $this->isLoggedIn = $this->user->isLoggedIn();
+               }
        }
 
        /**
diff --git a/maintenance/cleanupUploadStash.php 
b/maintenance/cleanupUploadStash.php
index 3c768d8..cd7a842 100644
--- a/maintenance/cleanupUploadStash.php
+++ b/maintenance/cleanupUploadStash.php
@@ -74,7 +74,7 @@
                        // this could be done some other, more direct/efficient 
way, but using
                        // UploadStash's own methods means it's less likely to 
fall accidentally
                        // out-of-date someday
-                       $stash = new UploadStash( $repo, new User() );
+                       $stash = new UploadStash( $repo );
 
                        $i = 0;
                        foreach ( $keys as $key ) {
diff --git a/tests/phpunit/includes/upload/UploadStashTest.php 
b/tests/phpunit/includes/upload/UploadStashTest.php
index e1db084..9b25505 100644
--- a/tests/phpunit/includes/upload/UploadStashTest.php
+++ b/tests/phpunit/includes/upload/UploadStashTest.php
@@ -55,8 +55,10 @@
         * @todo give this test a real name explaining what is being tested here
         */
        public function testBug29408() {
+               $this->setMwGlobals( 'wgUser', 
self::$users['uploader']->getUser() );
+
                $repo = RepoGroup::singleton()->getLocalRepo();
-               $stash = new UploadStash( $repo, 
self::$users['uploader']->getUser() );
+               $stash = new UploadStash( $repo );
 
                // Throws exception caught by PHPUnit on failure
                $file = $stash->stashFile( $this->bug29408File );

-- 
To view, visit https://gerrit.wikimedia.org/r/309736
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic62f19109f98fab9dd029acccecd6518b649e34b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to