Merge "watcheditem: Remove unused import/use statement"
[lhc/web/wiklou.git] / includes / user / User.php
index 40511cf..22fe44c 100644 (file)
@@ -55,17 +55,10 @@ 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.
         */
-       const VERSION = 12;
+       const VERSION = 13;
 
        /**
         * Exclude user options that are set to their default value.
@@ -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;
@@ -1151,8 +1144,8 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool
         */
        public function isValidPassword( $password ) {
-               // simple boolean wrapper for getPasswordValidity
-               return $this->getPasswordValidity( $password ) === true;
+               // simple boolean wrapper for checkPasswordValidity
+               return $this->checkPasswordValidity( $password )->isGood();
        }
 
        /**
@@ -1160,8 +1153,11 @@ class User implements IDBAccessObject, UserIdentity {
         *
         * @param string $password Desired password
         * @return bool|string|array True on success, string or array of error message on failure
+        * @deprecated since 1.33, use checkPasswordValidity
         */
        public function getPasswordValidity( $password ) {
+               wfDeprecated( __METHOD__, '1.33' );
+
                $result = $this->checkPasswordValidity( $password );
                if ( $result->isGood() ) {
                        return true;
@@ -1831,7 +1827,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;
                }
 
@@ -2311,9 +2307,10 @@ class User implements IDBAccessObject, UserIdentity {
                                        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 );
+                                               // If the block is partial, ignore 'editownusertalk' unless
+                                               // there is a restriction on the user talk namespace.
+                                               // TODO: To be implemented with Namespace restrictions
+                                               $blocked = $block->appliesToTitle( $title );
                                        }
                                } else {
                                        $blocked = $block->appliesToTitle( $title );
@@ -2547,8 +2544,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()}"
@@ -3598,7 +3601,8 @@ class User implements IDBAccessObject, UserIdentity {
        /**
         * Get the list of explicit group memberships this user has.
         * The implicit * and user groups are not included.
-        * @return array Array of String internal group names
+        *
+        * @return string[] Array of internal group names (sorted since 1.33)
         */
        public function getGroups() {
                $this->load();
@@ -4116,7 +4120,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;
                }
 
@@ -4210,7 +4214,7 @@ class User implements IDBAccessObject, UserIdentity {
                }
 
                $this->load();
-               if ( 0 == $this->mId ) {
+               if ( $this->mId == 0 ) {
                        return; // anon
                }