Merge "Fix unexpected return type of User::idFromName()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 3 Dec 2018 18:18:54 +0000 (18:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 3 Dec 2018 18:18:54 +0000 (18:18 +0000)
1  2 
includes/user/User.php

diff --combined includes/user/User.php
@@@ -935,7 -935,7 +935,7 @@@ class User implements IDBAccessObject, 
                if ( $s === false ) {
                        $result = null;
                } else {
-                       $result = $s->user_id;
+                       $result = (int)$s->user_id;
                }
  
                self::$idCacheByName[$name] = $result;
  
        /**
         * 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 ) {
                }
  
                // User/IP blocking
 -              $block = Block::newFromTarget( $this, $ip, !$bFromSlave );
 +              $block = Block::newFromTarget( $this, $ip, !$bFromReplica );
  
                // Cookie blocking
                if ( !$block instanceof Block ) {
                        $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
        /**
         * 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;
        }
  
         * 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 );
 +                              // 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 );
 +                              }
                        }
                }