Revert r113650 and reapply r113619 and r113649 with one modification: User::createNew...
[lhc/web/wiklou.git] / includes / User.php
index 0940766..fd17f24 100644 (file)
@@ -166,7 +166,7 @@ class User {
        var $mId, $mName, $mRealName, $mPassword, $mNewpassword, $mNewpassTime,
                $mEmail, $mTouched, $mToken, $mEmailAuthenticated,
                $mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups, $mOptionOverrides,
-               $mCookiePassword, $mEditCount, $mAllowUsertalk;
+               $mEditCount, $mAllowUsertalk;
        //@}
 
        /**
@@ -197,7 +197,7 @@ class User {
         */
        var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mRights,
                $mBlockreason, $mEffectiveGroups, $mImplicitGroups, $mFormerGroups, $mBlockedGlobally,
-               $mLocked, $mHideName, $mOptions, $mDisplayName;
+               $mLocked, $mHideName, $mOptions;
 
        /**
         * @var WebRequest
@@ -445,7 +445,7 @@ class User {
        /**
         * Get the username corresponding to a given user ID
         * @param $id Int User ID
-        * @return String|false The corresponding username
+        * @return String|bool The corresponding username
         */
        public static function whoIs( $id ) {
                $dbr = wfGetDB( DB_SLAVE );
@@ -456,7 +456,7 @@ class User {
         * Get the real name of a user given their user ID
         *
         * @param $id Int User ID
-        * @return String|false The corresponding user's real name
+        * @return String|bool The corresponding user's real name
         */
        public static function whoIsReal( $id ) {
                $dbr = wfGetDB( DB_SLAVE );
@@ -475,6 +475,11 @@ class User {
                        return null;
                }
 
+               if ( User::isIP( $name ) ) {
+                       # Cannot exist
+                       return null;
+               }
+
                if ( isset( self::$idCacheByName[$name] ) ) {
                        return self::$idCacheByName[$name];
                }
@@ -1191,7 +1196,6 @@ class User {
                $this->mEffectiveGroups = null;
                $this->mImplicitGroups = null;
                $this->mOptions = null;
-               $this->mDisplayName = null;
 
                if ( $reloadFrom ) {
                        $this->mLoadedItems = array();
@@ -2046,16 +2050,6 @@ class User {
                }
        }
 
-       /**
-        * Set the cookie password
-        *
-        * @param $str String New cookie password
-        */
-       private function setCookiePassword( $str ) {
-               $this->load();
-               $this->mCookiePassword = md5( $str );
-       }
-
        /**
         * Set the password for a password reminder or new account email
         *
@@ -2140,32 +2134,6 @@ class User {
                $this->mRealName = $str;
        }
 
-       /**
-        * Return the name of this user we should used to display in the user interface
-        * @return String The user's display name
-        */
-       public function getDisplayName() {
-               global $wgRealNameInInterface;
-               if ( is_null( $this->mDisplayName ) ) {
-                       $displayName = null;
-
-                       // Allow hooks to set a display name
-                       wfRunHooks( 'UserDisplayName', array( $this, &$displayName ) );
-
-                       if ( is_null( $displayName ) && $wgRealNameInInterface && $this->getRealName() ) {
-                               // If $wgRealNameInInterface is true use the real name as the display name if it's set
-                               $displayName = $this->getRealName();
-                       }
-
-                       if ( is_null( $displayName ) ) {
-                               $displayName = $this->getName();
-                       }
-
-                       $this->mDisplayName = $displayName;
-               }
-               return $this->mDisplayName;
-       }
-
        /**
         * Get the user's current setting for a given option.
         *
@@ -2628,14 +2596,6 @@ class User {
                $this->invalidateCache();
        }
 
-       /**
-        * Cleans up watchlist by removing invalid entries from it
-        */
-       public function cleanupWatchlist() {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->delete( 'watchlist', array( 'wl_namespace < 0', 'wl_user' => $this->getId() ), __METHOD__ );
-       }
-
        /**
         * Clear the user's notification timestamp for the given title.
         * If e-notif e-mails are on, they will receive notification mails on
@@ -2670,28 +2630,15 @@ class User {
                // The query to find out if it is watched is cached both in memcached and per-invocation,
                // and when it does have to be executed, it can be on a slave
                // If this is the user's newtalk page, we always update the timestamp
-               if( $title->getNamespace() == NS_USER_TALK &&
+               $force = '';
+               if ( $title->getNamespace() == NS_USER_TALK &&
                        $title->getText() == $this->getName() )
                {
-                       $watched = true;
-               } else {
-                       $watched = $this->isWatched( $title );
+                       $force = 'force';
                }
 
-               // If the page is watched by the user (or may be watched), update the timestamp on any
-               // any matching rows
-               if ( $watched ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->update( 'watchlist',
-                                       array( /* SET */
-                                               'wl_notificationtimestamp' => null
-                                       ), array( /* WHERE */
-                                               'wl_title' => $title->getDBkey(),
-                                               'wl_namespace' => $title->getNamespace(),
-                                               'wl_user' => $this->getID()
-                                       ), __METHOD__
-                       );
-               }
+               $wi = WatchedItem::fromUserTitle( $this, $title );
+               $wi->resetNotificationTimestamp( $force );
        }
 
        /**
@@ -2780,6 +2727,14 @@ class User {
 
                $this->load();
                if ( 0 == $this->mId ) return;
+               if ( !$this->mToken ) {
+                       // When token is empty or NULL generate a new one and then save it to the database
+                       // This allows a wiki to re-secure itself after a leak of it's user table or $wgSecretKey
+                       // Simply by setting every cell in the user_token column to NULL and letting them be
+                       // regenerated as users log back into the wiki.
+                       $this->setToken();
+                       $this->saveSettings();
+               }
                $session = array(
                        'wsUserID' => $this->mId,
                        'wsToken' => $this->mToken,
@@ -2925,6 +2880,7 @@ class User {
                        'user_token' => $user->mToken,
                        'user_registration' => $dbw->timestamp( $user->mRegistration ),
                        'user_editcount' => 0,
+                       'user_touched' => $dbw->timestamp( self::newTouchedTimestamp() ),
                );
                foreach ( $params as $name => $value ) {
                        $fields["user_$name"] = $value;
@@ -2943,6 +2899,9 @@ class User {
         */
        public function addToDatabase() {
                $this->load();
+
+               $this->mTouched = self::newTouchedTimestamp();
+
                $dbw = wfGetDB( DB_MASTER );
                $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
                $dbw->insert( 'user',
@@ -2958,6 +2917,7 @@ class User {
                                'user_token' => $this->mToken,
                                'user_registration' => $dbw->timestamp( $this->mRegistration ),
                                'user_editcount' => 0,
+                               'user_touched' => $dbw->timestamp( $this->mTouched ),
                        ), __METHOD__
                );
                $this->mId = $dbw->insertId();
@@ -3186,14 +3146,14 @@ class User {
 
        /**
         * Alias for getEditToken.
-        * @deprecated since 1.19, use getEditToken instead. Warnings in 1.21.
+        * @deprecated since 1.19, use getEditToken instead.
         *
         * @param $salt String|Array of Strings Optional function-specific data for hashing
         * @param $request WebRequest object to use or null to use $wgRequest
         * @return String The new edit token
         */
        public function editToken( $salt = '', $request = null ) {
-               wfDeprecated( __METHOD__, '1.19' );
+               wfDeprecated( __METHOD__, '1.19' );
                return $this->getEditToken( $salt, $request );
        }
 
@@ -3395,7 +3355,7 @@ class User {
         *
         * @note Call saveSettings() after calling this function to commit the change.
         *
-        * @return true
+        * @return bool
         */
        public function confirmEmail() {
                $this->setEmailAuthenticationTimestamp( wfTimestampNow() );
@@ -3408,7 +3368,7 @@ class User {
         * address if it was already confirmed.
         *
         * @note Call saveSettings() after calling this function to commit the change.
-        * @return true
+        * @return bool Returns true
         */
        function invalidateEmail() {
                $this->load();
@@ -3937,7 +3897,7 @@ class User {
        }
 
        /**
-        * Add a newuser log entry for this user
+        * Add a newuser log entry for this user. Before 1.19 the return value was always true.
         *
         * @param $byEmail Boolean: account made by email?
         * @param $reason String: user supplied reason
@@ -3976,7 +3936,7 @@ class User {
         * Add an autocreate newuser log entry for this user
         * Used by things like CentralAuth and perhaps other authplugins.
         *
-        * @return true
+        * @return bool
         */
        public function addNewUserLogEntryAutoCreate() {
                global $wgNewUserLog;
@@ -4016,6 +3976,7 @@ class User {
                                __METHOD__
                        );
 
+                       $this->mOptionOverrides = array();
                        foreach ( $res as $row ) {
                                $this->mOptionOverrides[$row->up_property] = $row->up_value;
                                $this->mOptions[$row->up_property] = $row->up_value;