+ /*
+ * Try to set a user's email address.
+ * This does *not* try to validate the address.
+ * @param $user User
+ * @param $newaddr string New email address
+ * @return Array (true on success or Status on failure, info string)
+ */
+ public static function trySetUserEmail( User $user, $newaddr ) {
+ global $wgEnableEmail, $wgEmailAuthentication;
+ $info = ''; // none
+
+ if ( $wgEnableEmail ) {
+ $oldaddr = $user->getEmail();
+ if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
+ # The user has supplied a new email address on the login page
+ # new behaviour: set this new emailaddr from login-page into user database record
+ $user->setEmail( $newaddr );
+ # But flag as "dirty" = unauthenticated
+ $user->invalidateEmail();
+ if ( $wgEmailAuthentication ) {
+ # Mail a temporary password to the dirty address.
+ # User can come back through the confirmation URL to re-enable email.
+ $type = $oldaddr != '' ? 'changed' : 'set';
+ $result = $user->sendConfirmationMail( $type );
+ if ( !$result->isGood() ) {
+ return array( $result, 'mailerror' );
+ }
+ $info = 'eauth';
+ }
+ } else {
+ $user->setEmail( $newaddr );
+ }
+ if ( $oldaddr != $newaddr ) {
+ wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
+ }
+ }
+
+ return array( true, $info );
+ }
+
+ /**
+ * @param $user User
+ * @return array
+ */