Hard-deprecate password handling in User
[lhc/web/wiklou.git] / includes / user / User.php
index 7bebe80..12623e8 100644 (file)
@@ -27,6 +27,7 @@ use MediaWiki\Auth\AuthManager;
 use MediaWiki\Auth\AuthenticationResponse;
 use MediaWiki\Auth\AuthenticationRequest;
 use MediaWiki\User\UserIdentity;
+use MediaWiki\Logger\LoggerFactory;
 use Wikimedia\IPSet;
 use Wikimedia\ScopedCallback;
 use Wikimedia\Rdbms\Database;
@@ -1010,10 +1011,10 @@ class User implements IDBAccessObject, UserIdentity {
                // Should these be merged into the title char list?
                $unicodeBlacklist = '/[' .
                        '\x{0080}-\x{009f}' . # iso-8859-1 control chars
-                       '\x{00a0}' .          # non-breaking space
+                       '\x{00a0}' . # non-breaking space
                        '\x{2000}-\x{200f}' . # various whitespace
                        '\x{2028}-\x{202f}' . # breaks and control chars
-                       '\x{3000}' .          # ideographic space
+                       '\x{3000}' . # ideographic space
                        '\x{e000}-\x{f8ff}' . # private use
                        ']/u';
                if ( preg_match( $unicodeBlacklist, $name ) ) {
@@ -1050,7 +1051,7 @@ class User implements IDBAccessObject, UserIdentity {
                // Certain names may be reserved for batch processes.
                foreach ( $reservedUsernames as $reserved ) {
                        if ( substr( $reserved, 0, 4 ) == 'msg:' ) {
-                               $reserved = wfMessage( substr( $reserved, 4 ) )->inContentLanguage()->text();
+                               $reserved = wfMessage( substr( $reserved, 4 ) )->inContentLanguage()->plain();
                        }
                        if ( $reserved == $name ) {
                                return false;
@@ -2165,10 +2166,6 @@ class User implements IDBAccessObject, UserIdentity {
                        if ( isset( $limits['user'] ) ) {
                                $userLimit = $limits['user'];
                        }
-                       // limits for newbie logged-in users
-                       if ( $isNewbie && isset( $limits['newbie'] ) ) {
-                               $keys[$cache->makeKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
-                       }
                }
 
                // limits for anons and for newbie logged-in users
@@ -2200,6 +2197,11 @@ class User implements IDBAccessObject, UserIdentity {
                        }
                }
 
+               // limits for newbie logged-in users (override all the normal user limits)
+               if ( $id !== 0 && $isNewbie && isset( $limits['newbie'] ) ) {
+                       $userLimit = $limits['newbie'];
+               }
+
                // Set the user limit key
                if ( $userLimit !== false ) {
                        list( $max, $period ) = $userLimit;
@@ -2874,6 +2876,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool
         */
        public function setPassword( $str ) {
+               wfDeprecated( __METHOD__, '1.27' );
                return $this->setPasswordInternal( $str );
        }
 
@@ -2886,6 +2889,7 @@ class User implements IDBAccessObject, UserIdentity {
         *  through the web interface.
         */
        public function setInternalPassword( $str ) {
+               wfDeprecated( __METHOD__, '1.27' );
                $this->setPasswordInternal( $str );
        }
 
@@ -3538,6 +3542,7 @@ class User implements IDBAccessObject, UserIdentity {
                                }
                        }
 
+                       Hooks::run( 'UserGetRightsRemove', [ $this, &$this->mRights ] );
                        // Force reindexation of rights when a hook has unset one of them
                        $this->mRights = array_values( array_unique( $this->mRights ) );
 
@@ -4208,9 +4213,12 @@ class User implements IDBAccessObject, UserIdentity {
                                $this->clearSharedCache( 'refresh' );
                                // User was changed in the meantime or loaded with stale data
                                $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'replica';
-                               throw new MWException(
-                                       "CAS update failed on user_touched for user ID '{$this->mId}' (read from $from);" .
-                                       " the version of the user to be saved is older than the current version."
+                               LoggerFactory::getInstance( 'preferences' )->warning(
+                                       "CAS update failed on user_touched for user ID '{user_id}' ({db_flag} read)",
+                                       [ 'user_id' => $this->mId, 'db_flag' => $from ]
+                               );
+                               throw new MWException( "CAS update failed on user_touched. " .
+                                       "The version of the user to be saved is older than the current version."
                                );
                        }
 
@@ -4384,7 +4392,7 @@ class User implements IDBAccessObject, UserIdentity {
                                        'user',
                                        'user_id',
                                        [ 'user_name' => $this->mName ],
-                                       __METHOD__,
+                                       $fname,
                                        [ 'LOCK IN SHARE MODE' ]
                                );
                                $loaded = false;
@@ -4394,7 +4402,7 @@ class User implements IDBAccessObject, UserIdentity {
                                        }
                                }
                                if ( !$loaded ) {
-                                       throw new MWException( __METHOD__ . ": hit a key conflict attempting " .
+                                       throw new MWException( $fname . ": hit a key conflict attempting " .
                                                "to insert user '{$this->mName}' row, but it was not present in select!" );
                                }
                                return Status::newFatal( 'userexists' );
@@ -4540,6 +4548,8 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool True if the given password is correct, otherwise False
         */
        public function checkPassword( $password ) {
+               wfDeprecated( __METHOD__, '1.27' );
+
                $manager = AuthManager::singleton();
                $reqs = AuthenticationRequest::loadRequestsFromSubmission(
                        $manager->getAuthenticationRequests( AuthManager::ACTION_LOGIN ),
@@ -4573,6 +4583,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool True if matches, false otherwise
         */
        public function checkTemporaryPassword( $plaintext ) {
+               wfDeprecated( __METHOD__, '1.27' );
                // Can't check the temporary password individually.
                return $this->checkPassword( $plaintext );
        }