Merge "Fix WatchedItemStore last-seen stashing logic"
[lhc/web/wiklou.git] / includes / user / User.php
index 8173f5d..277731a 100644 (file)
@@ -1191,6 +1191,8 @@ class User implements IDBAccessObject, UserIdentity {
         * - forceChange (bool): if set to true, the user should not be
         *   allowed to log with this password unless they change it during
         *   the login process (see ResetPasswordSecondaryAuthenticationProvider).
+        * - suggestChangeOnLogin (bool): if set to true, the user should be prompted for
+        *   a password change on login.
         *
         * @param string $password Desired password
         * @return Status
@@ -1258,10 +1260,7 @@ class User implements IDBAccessObject, UserIdentity {
                        return false;
                }
 
-               // Reject various classes of invalid names
-               $name = AuthManager::callLegacyAuthPlugin(
-                       'getCanonicalName', [ $t->getText() ], $t->getText()
-               );
+               $name = $t->getText();
 
                switch ( $validate ) {
                        case false:
@@ -1667,7 +1666,6 @@ class User implements IDBAccessObject, UserIdentity {
 
                // update groups in external authentication database
                Hooks::run( 'UserGroupsChanged', [ $this, $toPromote, [], false, false, $oldUGMs, $newUGMs ] );
-               AuthManager::callLegacyAuthPlugin( 'updateExternalDBGroups', [ $this, $toPromote ] );
 
                $logEntry = new ManualLogEntry( 'rights', 'autopromote' );
                $logEntry->setPerformer( $this );
@@ -2407,10 +2405,8 @@ class User implements IDBAccessObject, UserIdentity {
                if ( $this->mLocked !== null ) {
                        return $this->mLocked;
                }
-               // Avoid PHP 7.1 warning of passing $this by reference
-               $user = $this;
-               $authUser = AuthManager::callLegacyAuthPlugin( 'getUserInstance', [ &$user ], null );
-               $this->mLocked = $authUser && $authUser->isLocked();
+               // Reset for hook
+               $this->mLocked = false;
                Hooks::run( 'UserIsLocked', [ $this, &$this->mLocked ] );
                return $this->mLocked;
        }
@@ -2426,10 +2422,8 @@ class User implements IDBAccessObject, UserIdentity {
                }
                $this->getBlockedStatus();
                if ( !$this->mHideName ) {
-                       // Avoid PHP 7.1 warning of passing $this by reference
-                       $user = $this;
-                       $authUser = AuthManager::callLegacyAuthPlugin( 'getUserInstance', [ &$user ], null );
-                       $this->mHideName = $authUser && $authUser->isHidden();
+                       // Reset for hook
+                       $this->mHideName = false;
                        Hooks::run( 'UserIsHidden', [ $this, &$this->mHideName ] );
                }
                return (bool)$this->mHideName;
@@ -4274,7 +4268,7 @@ class User implements IDBAccessObject, UserIdentity {
 
                Hooks::run( 'UserSaveSettings', [ $this ] );
                $this->clearSharedCache();
-               $this->getUserPage()->invalidateCache();
+               $this->getUserPage()->purgeSquid();
        }
 
        /**
@@ -4724,22 +4718,38 @@ class User implements IDBAccessObject, UserIdentity {
 
                if ( $type == 'created' || $type === false ) {
                        $message = 'confirmemail_body';
+                       $type = 'created';
                } elseif ( $type === true ) {
                        $message = 'confirmemail_body_changed';
+                       $type = 'changed';
                } else {
                        // Messages: confirmemail_body_changed, confirmemail_body_set
                        $message = 'confirmemail_body_' . $type;
                }
 
-               return $this->sendMail( wfMessage( 'confirmemail_subject' )->text(),
-                       wfMessage( $message,
+               $mail = [
+                       'subject' => wfMessage( 'confirmemail_subject' )->text(),
+                       'body' => wfMessage( $message,
                                $this->getRequest()->getIP(),
                                $this->getName(),
                                $url,
                                $wgLang->userTimeAndDate( $expiration, $this ),
                                $invalidateURL,
                                $wgLang->userDate( $expiration, $this ),
-                               $wgLang->userTime( $expiration, $this ) )->text() );
+                               $wgLang->userTime( $expiration, $this ) )->text(),
+                       'from' => null,
+                       'replyTo' => null,
+               ];
+               $info = [
+                       'type' => $type,
+                       'ip' => $this->getRequest()->getIP(),
+                       'confirmURL' => $url,
+                       'invalidateURL' => $invalidateURL,
+                       'expiration' => $expiration
+               ];
+
+               Hooks::run( 'UserSendConfirmationMail', [ $this, &$mail, $info ] );
+               return $this->sendMail( $mail['subject'], $mail['body'], $mail['from'], $mail['replyTo'] );
        }
 
        /**
@@ -4750,7 +4760,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @param string $body Message body
         * @param User|null $from Optional sending user; if unspecified, default
         *   $wgPasswordSender will be used.
-        * @param string|null $replyto Reply-To address
+        * @param MailAddress|null $replyto Reply-To address
         * @return Status
         */
        public function sendMail( $subject, $body, $from = null, $replyto = null ) {
@@ -4966,6 +4976,28 @@ class User implements IDBAccessObject, UserIdentity {
         *  non-existent/anonymous user accounts.
         */
        public function getFirstEditTimestamp() {
+               return $this->getEditTimestamp( true );
+       }
+
+       /**
+        * Get the timestamp of the latest edit
+        *
+        * @since 1.33
+        * @return string|bool Timestamp of first edit, or false for
+        *  non-existent/anonymous user accounts.
+        */
+       public function getLatestEditTimestamp() {
+               return $this->getEditTimestamp( false );
+       }
+
+       /**
+        * Get the timestamp of the first or latest edit
+        *
+        * @param bool $first True for the first edit, false for the latest one
+        * @return string|bool Timestamp of first or latest edit, or false for
+        *  non-existent/anonymous user accounts.
+        */
+       private function getEditTimestamp( $first ) {
                if ( $this->getId() == 0 ) {
                        return false; // anons
                }
@@ -4973,12 +5005,13 @@ class User implements IDBAccessObject, UserIdentity {
                $actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $this );
                $tsField = isset( $actorWhere['tables']['temp_rev_user'] )
                        ? 'revactor_timestamp' : 'rev_timestamp';
+               $sortOrder = $first ? 'ASC' : 'DESC';
                $time = $dbr->selectField(
                        [ 'revision' ] + $actorWhere['tables'],
                        $tsField,
                        [ $actorWhere['conds'] ],
                        __METHOD__,
-                       [ 'ORDER BY' => "$tsField ASC" ],
+                       [ 'ORDER BY' => "$tsField $sortOrder" ],
                        $actorWhere['joins']
                );
                if ( !$time ) {