Merge "Revert "Clean up user handling in UploadStash""
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sun, 11 Sep 2016 00:35:32 +0000 (00:35 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 11 Sep 2016 00:35:32 +0000 (00:35 +0000)
1  2 
includes/upload/UploadStash.php

@@@ -73,8 -73,8 +73,8 @@@ class UploadStash 
        // 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.
         * (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();
+               }
        }
  
        /**
         * Helper function: do the actual database query to fetch file metadata.
         *
         * @param string $key
 -       * @param int $readFromDB Constant (default: DB_SLAVE)
 +       * @param int $readFromDB Constant (default: DB_REPLICA)
         * @return bool
         */
 -      protected function fetchFileMetadata( $key, $readFromDB = DB_SLAVE ) {
 +      protected function fetchFileMetadata( $key, $readFromDB = DB_REPLICA ) {
                // populate $fileMetadata[$key]
                $dbr = null;
                if ( $readFromDB === DB_MASTER ) {