Merge "Wrap the "bytes changed" indication on Special:Contributions with CSS"
[lhc/web/wiklou.git] / includes / user / User.php
index 11cfd49..f429ab5 100644 (file)
@@ -909,6 +909,8 @@ class User implements IDBAccessObject, UserIdentity {
         * @return int|null The corresponding user's ID, or null if user is nonexistent
         */
        public static function idFromName( $name, $flags = self::READ_NORMAL ) {
+               // Don't explode on self::$idCacheByName[$name] if $name is not a string but e.g. a User object
+               $name = (string)$name;
                $nt = Title::makeTitleSafe( NS_USER, $name );
                if ( is_null( $nt ) ) {
                        // Illegal name
@@ -1822,11 +1824,11 @@ class User implements IDBAccessObject, UserIdentity {
 
        /**
         * Get blocking information
-        * @param bool $bFromSlave Whether to check the replica DB first.
+        * @param bool $bFromReplica Whether to check the replica DB first.
         *   To improve performance, non-critical checks are done against replica DBs.
         *   Check when actually saving should be done against master.
         */
-       private function getBlockedStatus( $bFromSlave = true ) {
+       private function getBlockedStatus( $bFromReplica = true ) {
                global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff, $wgSoftBlockRanges;
 
                if ( -1 != $this->mBlockedby ) {
@@ -1858,7 +1860,7 @@ class User implements IDBAccessObject, UserIdentity {
                }
 
                // User/IP blocking
-               $block = Block::newFromTarget( $this, $ip, !$bFromSlave );
+               $block = Block::newFromTarget( $this, $ip, !$bFromReplica );
 
                // Cookie blocking
                if ( !$block instanceof Block ) {
@@ -1894,7 +1896,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $xff = $this->getRequest()->getHeader( 'X-Forwarded-For' );
                        $xff = array_map( 'trim', explode( ',', $xff ) );
                        $xff = array_diff( $xff, [ $ip ] );
-                       $xffblocks = Block::getBlocksForIPList( $xff, $this->isAnon(), !$bFromSlave );
+                       $xffblocks = Block::getBlocksForIPList( $xff, $this->isAnon(), !$bFromReplica );
                        $block = Block::chooseBlock( $xffblocks, $xff );
                        if ( $block instanceof Block ) {
                                # Mangle the reason to alert the user that the block
@@ -2270,22 +2272,22 @@ class User implements IDBAccessObject, UserIdentity {
        /**
         * Check if user is blocked
         *
-        * @param bool $bFromSlave Whether to check the replica DB instead of
+        * @param bool $bFromReplica Whether to check the replica DB instead of
         *   the master. Hacked from false due to horrible probs on site.
         * @return bool True if blocked, false otherwise
         */
-       public function isBlocked( $bFromSlave = true ) {
-               return $this->getBlock( $bFromSlave ) instanceof Block && $this->getBlock()->prevents( 'edit' );
+       public function isBlocked( $bFromReplica = true ) {
+               return $this->getBlock( $bFromReplica ) instanceof Block && $this->getBlock()->prevents( 'edit' );
        }
 
        /**
         * Get the block affecting the user, or null if the user is not blocked
         *
-        * @param bool $bFromSlave Whether to check the replica DB instead of the master
+        * @param bool $bFromReplica Whether to check the replica DB instead of the master
         * @return Block|null
         */
-       public function getBlock( $bFromSlave = true ) {
-               $this->getBlockedStatus( $bFromSlave );
+       public function getBlock( $bFromReplica = true ) {
+               $this->getBlockedStatus( $bFromReplica );
                return $this->mBlock instanceof Block ? $this->mBlock : null;
        }
 
@@ -2293,14 +2295,14 @@ class User implements IDBAccessObject, UserIdentity {
         * Check if user is blocked from editing a particular article
         *
         * @param Title $title Title to check
-        * @param bool $fromSlave Whether to check the replica DB instead of the master
+        * @param bool $fromReplica Whether to check the replica DB instead of the master
         * @return bool
         */
-       public function isBlockedFrom( $title, $fromSlave = false ) {
+       public function isBlockedFrom( $title, $fromReplica = false ) {
                $blocked = $this->isHidden();
 
                if ( !$blocked ) {
-                       $block = $this->getBlock( $fromSlave );
+                       $block = $this->getBlock( $fromReplica );
                        if ( $block ) {
                                $blocked = $block->preventsEdit( $title );
                        }
@@ -4948,12 +4950,14 @@ class User implements IDBAccessObject, UserIdentity {
                }
                $dbr = wfGetDB( DB_REPLICA );
                $actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $this );
+               $tsField = isset( $actorWhere['tables']['temp_rev_user'] )
+                       ? 'revactor_timestamp' : 'rev_timestamp';
                $time = $dbr->selectField(
                        [ 'revision' ] + $actorWhere['tables'],
-                       'rev_timestamp',
+                       $tsField,
                        [ $actorWhere['conds'] ],
                        __METHOD__,
-                       [ 'ORDER BY' => 'rev_timestamp ASC' ],
+                       [ 'ORDER BY' => "$tsField ASC" ],
                        $actorWhere['joins']
                );
                if ( !$time ) {