Merge "Use User::equals() where applicable in the class"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 18 Sep 2015 09:08:27 +0000 (09:08 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 18 Sep 2015 09:08:27 +0000 (09:08 +0000)
1  2 
includes/User.php

diff --combined includes/User.php
@@@ -1591,7 -1591,7 +1591,7 @@@ class User implements IDBAccessObject 
                # We only need to worry about passing the IP address to the Block generator if the
                # user is not immune to autoblocks/hardblocks, and they are the current user so we
                # know which IP address they're actually coming from
-               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
+               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->equals( $wgUser ) ) {
                        $ip = $this->getRequest()->getIP();
                } else {
                        $ip = null;
         */
        public function setInternalPassword( $str ) {
                $this->setToken();
 +              $this->setOption( 'watchlisttoken', false );
  
                $passwordFactory = self::getPasswordFactory();
                $this->mPassword = $passwordFactory->newFromPlaintext( $str );
         * @return string|bool User's current value for the option, or false if this option is disabled.
         * @see resetTokenFromOption()
         * @see getOption()
 +       * @deprecated 1.26 Applications should use the OAuth extension
         */
        public function getTokenFromOption( $oname ) {
                global $wgHiddenPrefs;
 -              if ( in_array( $oname, $wgHiddenPrefs ) ) {
 +
 +              $id = $this->getId();
 +              if ( !$id || in_array( $oname, $wgHiddenPrefs ) ) {
                        return false;
                }
  
                $token = $this->getOption( $oname );
                if ( !$token ) {
 -                      $token = $this->resetTokenFromOption( $oname );
 -                      if ( !wfReadOnly() ) {
 -                              $this->saveSettings();
 -                      }
 +                      // Default to a value based on the user token to avoid space
 +                      // wasted on storing tokens for all users. When this option
 +                      // is set manually by the user, only then is it stored.
 +                      $token = hash_hmac( 'sha1', "$oname:$id", $this->getToken() );
                }
 +
                return $token;
        }
  
        /**
         * Check if user is allowed to access a feature / make an action
         *
 -       * @param string $permissions,... Permissions to test
 +       * @param string ... Permissions to test
         * @return bool True if user is allowed to perform *any* of the given actions
         */
 -      public function isAllowedAny( /*...*/ ) {
 +      public function isAllowedAny() {
                $permissions = func_get_args();
                foreach ( $permissions as $permission ) {
                        if ( $this->isAllowed( $permission ) ) {
  
        /**
         *
 -       * @param string $permissions,... Permissions to test
 +       * @param string ... Permissions to test
         * @return bool True if the user is allowed to perform *all* of the given actions
         */
 -      public function isAllowedAll( /*...*/ ) {
 +      public function isAllowedAll() {
                $permissions = func_get_args();
                foreach ( $permissions as $permission ) {
                        if ( !$this->isAllowed( $permission ) ) {
                Hooks::run( 'UserSaveSettings', array( $this ) );
                $this->clearSharedCache();
                $this->getUserPage()->invalidateCache();
 -
 -              // T95839: clear the cache again post-commit to reduce race conditions
 -              // where stale values are written back to the cache by other threads.
 -              // Note: this *still* doesn't deal with REPEATABLE-READ snapshot lag...
 -              $that = $this;
 -              $dbw->onTransactionIdle( function() use ( $that ) {
 -                      $that->clearSharedCache();
 -              } );
        }
  
        /**