From: Roan Kattouw Date: Wed, 27 Feb 2019 02:16:49 +0000 (-0800) Subject: Add UserSendConfirmationMail hook X-Git-Tag: 1.34.0-rc.0~2688^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=10f7497eab3fab4b5018f6e3995c0ecb7a4e35bf;hp=04179d3a5ce90f3f967d0e004fdf68bd45b04541;p=lhc%2Fweb%2Fwiklou.git Add UserSendConfirmationMail hook Allow extensions to modify the confirmation email. Bug: T215665 Change-Id: I4bcf76699a5114292fc19085fe441de8b898a8d3 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 8b5e4d7a70..e52914d92c 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -3837,6 +3837,23 @@ the database) have been saved. Compare to the UserSaveOptions hook, which is called before. $user: The User for which the options have been saved +'UserSendConfirmationMail': Called just before a confirmation email is sent to +a user. Hook handlers can modify the email that will be sent. +$user: The User for which the confirmation email is going to be sent +&$mail: Associative array describing the email, with the following keys: + - subject: Subject line of the email + - body: Email body. Can be a string, or an array with keys 'text' and 'html' + - from: User object, or null meaning $wgPasswordSender will be used + - replyTo: MailAddress object or null +$info: Associative array with additional information: + - type: 'created' if the user's account was just created; 'set' if the user + set an email address when they previously didn't have one; 'changed' if + the user had an email address and changed it + - ip: The IP address from which the user set/changed their email address + - confirmURL: URL the user should visit to confirm their email + - invalidateURL: URL the user should visit to invalidate confirmURL + - expiration: time and date when confirmURL expires + 'UserSetCookies': DEPRECATED since 1.27! If you're trying to replace core session cookie handling, you want to create a subclass of MediaWiki\Session\CookieSessionProvider instead. Otherwise, you can no longer diff --git a/includes/user/User.php b/includes/user/User.php index 8173f5db8c..904a934308 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -4724,22 +4724,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 +4766,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 ) {