Merge "No yoda conditions"
[lhc/web/wiklou.git] / includes / user / User.php
index f429ab5..419e23b 100644 (file)
@@ -55,13 +55,6 @@ class User implements IDBAccessObject, UserIdentity {
         */
        const INVALID_TOKEN = '*** INVALID ***';
 
-       /**
-        * Global constant made accessible as class constants so that autoloader
-        * magic can be used.
-        * @deprecated since 1.27, use \MediaWiki\Session\Token::SUFFIX
-        */
-       const EDIT_TOKEN_SUFFIX = Token::SUFFIX;
-
        /**
         * @const int Serialized record version.
         */
@@ -935,7 +928,7 @@ class User implements IDBAccessObject, UserIdentity {
                if ( $s === false ) {
                        $result = null;
                } else {
-                       $result = $s->user_id;
+                       $result = (int)$s->user_id;
                }
 
                self::$idCacheByName[$name] = $result;
@@ -1831,7 +1824,7 @@ class User implements IDBAccessObject, UserIdentity {
        private function getBlockedStatus( $bFromReplica = true ) {
                global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff, $wgSoftBlockRanges;
 
-               if ( -1 != $this->mBlockedby ) {
+               if ( $this->mBlockedby != -1 ) {
                        return;
                }
 
@@ -2304,7 +2297,20 @@ class User implements IDBAccessObject, UserIdentity {
                if ( !$blocked ) {
                        $block = $this->getBlock( $fromReplica );
                        if ( $block ) {
-                               $blocked = $block->preventsEdit( $title );
+                               // Special handling for a user's own talk page. The block is not aware
+                               // of the user, so this must be done here.
+                               if ( $title->equals( $this->getTalkPage() ) ) {
+                                       // If the block is sitewide, then whatever is set is what is honored.
+                                       if ( $block->isSitewide() ) {
+                                               $blocked = $block->prevents( 'editownusertalk' );
+                                       } else {
+                                               // If the block is partial, then only a true value is honored,
+                                               // otherwise fallback to the partial block settings.
+                                               $blocked = $block->prevents( 'editownusertalk' ) ?: $block->appliesToTitle( $title );
+                                       }
+                               } else {
+                                       $blocked = $block->appliesToTitle( $title );
+                               }
                        }
                }
 
@@ -2534,8 +2540,14 @@ class User implements IDBAccessObject, UserIdentity {
                                        $this->mActorId = (int)$dbw->insertId();
                                } else {
                                        // Outdated cache?
-                                       list( , $options ) = DBAccessObjectUtils::getDBOptions( $this->queryFlagsUsed );
-                                       $this->mActorId = (int)$dbw->selectField( 'actor', 'actor_id', $q, __METHOD__, $options );
+                                       // Use LOCK IN SHARE MODE to bypass any MySQL REPEATABLE-READ snapshot.
+                                       $this->mActorId = (int)$dbw->selectField(
+                                               'actor',
+                                               'actor_id',
+                                               $q,
+                                               __METHOD__,
+                                               [ 'LOCK IN SHARE MODE' ]
+                                       );
                                        if ( !$this->mActorId ) {
                                                throw new CannotCreateActorException(
                                                        "Cannot create actor ID for user_id={$this->getId()} user_name={$this->getName()}"
@@ -4103,7 +4115,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function setCookies( $request = null, $secure = null, $rememberMe = false ) {
                $this->load();
-               if ( 0 == $this->mId ) {
+               if ( $this->mId == 0 ) {
                        return;
                }
 
@@ -4197,7 +4209,7 @@ class User implements IDBAccessObject, UserIdentity {
                }
 
                $this->load();
-               if ( 0 == $this->mId ) {
+               if ( $this->mId == 0 ) {
                        return; // anon
                }