Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / user / User.php
index f7dcb93..7c2f038 100644 (file)
@@ -243,10 +243,19 @@ class User implements IDBAccessObject, UserIdentity {
                return (string)$this->getName();
        }
 
-       public function __get( $name ) {
+       public function &__get( $name ) {
                // A shortcut for $mRights deprecation phase
                if ( $name === 'mRights' ) {
-                       return $this->getRights();
+                       $copy = $this->getRights();
+                       return $copy;
+               } elseif ( !property_exists( $this, $name ) ) {
+                       // T227688 - do not break $u->foo['bar'] = 1
+                       wfLogWarning( 'tried to get non-existent property' );
+                       $this->$name = null;
+                       return $this->$name;
+               } else {
+                       wfLogWarning( 'tried to get non-visible property' );
+                       return null;
                }
        }
 
@@ -258,6 +267,10 @@ class User implements IDBAccessObject, UserIdentity {
                                $this,
                                is_null( $value ) ? [] : $value
                        );
+               } elseif ( !property_exists( $this, $name ) ) {
+                       $this->$name = $value;
+               } else {
+                       wfLogWarning( 'tried to set non-visible property' );
                }
        }
 
@@ -419,12 +432,12 @@ class User implements IDBAccessObject, UserIdentity {
 
        /**
         * @since 1.27
-        * @param string $wikiId
+        * @param string $dbDomain
         * @param int $userId
         */
-       public static function purge( $wikiId, $userId ) {
+       public static function purge( $dbDomain, $userId ) {
                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
-               $key = $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId );
+               $key = $cache->makeGlobalKey( 'user', 'id', $dbDomain, $userId );
                $cache->delete( $key );
        }
 
@@ -608,16 +621,16 @@ class User implements IDBAccessObject, UserIdentity {
         * @param int|null $userId User ID, if known
         * @param string|null $userName User name, if known
         * @param int|null $actorId Actor ID, if known
-        * @param bool|string $wikiId remote wiki to which the User/Actor ID applies, or false if none
+        * @param bool|string $dbDomain remote wiki to which the User/Actor ID applies, or false if none
         * @return User
         */
-       public static function newFromAnyId( $userId, $userName, $actorId, $wikiId = false ) {
+       public static function newFromAnyId( $userId, $userName, $actorId, $dbDomain = false ) {
                global $wgActorTableSchemaMigrationStage;
 
                // Stop-gap solution for the problem described in T222212.
                // Force the User ID and Actor ID to zero for users loaded from the database
                // of another wiki, to prevent subtle data corruption and confusing failure modes.
-               if ( $wikiId !== false ) {
+               if ( $dbDomain !== false ) {
                        $userId = 0;
                        $actorId = 0;
                }
@@ -2571,7 +2584,7 @@ class User implements IDBAccessObject, UserIdentity {
                if ( $mode === 'refresh' ) {
                        $cache->delete( $key, 1 ); // low tombstone/"hold-off" TTL
                } else {
-                       $lb->getConnection( DB_MASTER )->onTransactionPreCommitOrIdle(
+                       $lb->getConnectionRef( DB_MASTER )->onTransactionPreCommitOrIdle(
                                function () use ( $cache, $key ) {
                                        $cache->delete( $key );
                                },
@@ -3463,7 +3476,7 @@ class User implements IDBAccessObject, UserIdentity {
 
                        if ( $count === null ) {
                                // it has not been initialized. do so.
-                               $count = $this->initEditCountInternal();
+                               $count = $this->initEditCountInternal( $dbr );
                        }
                        $this->mEditCount = $count;
                }
@@ -5023,14 +5036,13 @@ class User implements IDBAccessObject, UserIdentity {
        /**
         * Initialize user_editcount from data out of the revision table
         *
-        * This method should not be called outside User/UserEditCountUpdate
-        *
+        * @internal This method should not be called outside User/UserEditCountUpdate
+        * @param IDatabase $dbr Replica database
         * @return int Number of edits
         */
-       public function initEditCountInternal() {
+       public function initEditCountInternal( IDatabase $dbr ) {
                // Pull from a replica DB to be less cruel to servers
                // Accuracy isn't the point anyway here
-               $dbr = wfGetDB( DB_REPLICA );
                $actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $this );
                $count = (int)$dbr->selectField(
                        [ 'revision' ] + $actorWhere['tables'],