jenkins-bot has submitted this change and it was merged.

Change subject: Always try to set an email in 
CentralAuthUser::attemptAutoMigration
......................................................................


Always try to set an email in CentralAuthUser::attemptAutoMigration

Sometimes the home wiki might not have an email address, but
a password confirmed account has.
Use that to prevent creating global accounts without emails set.

Tries to use authenticated emails, but falls back to non-authenticated
if that's not possible.

Change-Id: I0d8e95b9fff6a2da68992e792759cb6c117c4d27
---
M includes/CentralAuthUser.php
1 file changed, 35 insertions(+), 6 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index ab617cd..d0c3494 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -794,8 +794,9 @@
                                // Matches the pre-authenticated password, yay!
                                $method = 'password';
                        } elseif ( $local['emailAuthenticated'] && isset( 
$passingMail[$local['email']] ) ) {
-                               // Same email addresss as primary means we know 
they could
-                               // reset their password, so we give them the 
account.
+                               // Same email address as the primary account, 
or the same email address as another
+                               // password confirmed account, means we know 
they could reset their password, so we
+                               // give them the account.
                                // Authenticated email addresses only to 
prevent merges with malicious users
                                $method = 'mail';
                        } else {
@@ -908,6 +909,28 @@
        }
 
        /**
+        * Choose an email address to use from an array as obtained via 
self::queryUnattached.
+        *
+        * @param array[] $wikisToAttach
+        */
+       private function chooseEmail( array $wikisToAttach ) {
+               if ( $this->mEmail ) {
+                       return;
+               }
+
+               foreach ( $wikisToAttach as $attachWiki ) {
+                       if ( $attachWiki['email'] ) {
+                               $this->mEmail = $attachWiki['email'];
+                               $this->mEmailAuthenticated = 
$attachWiki['emailAuthenticated'];
+                               if ( $attachWiki['emailAuthenticated'] ) {
+                                       // If the email is authenticated, stop 
searching
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       /**
         * Pick a winning master account and try to auto-merge as many as 
possible.
         * @fixme add some locking or something
         *
@@ -955,14 +978,20 @@
                        return false;
                }
 
+               $wikisToAttach = array_intersect_key( $migrationSet, $attach );
+
+               // The home wiki might not have an email set, but maybe an 
other account has one?
+               $this->chooseEmail( $wikisToAttach );
+
                // storeGlobalData clears $this->mHomeWiki
                $homeWiki = $this->mHomeWiki;
                // Actually do the migration
                $ok = $this->storeGlobalData(
-                               $home['id'],
-                               $home['password'],
-                               $home['email'],
-                               $home['emailAuthenticated'] );
+                       $home['id'],
+                       $home['password'],
+                       $this->mEmail,
+                       $this->mEmailAuthenticated
+               );
 
                if ( !$ok ) {
                        wfDebugLog( 'CentralAuth',

-- 
To view, visit https://gerrit.wikimedia.org/r/181401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0d8e95b9fff6a2da68992e792759cb6c117c4d27
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to