MediaWiki master
NotificationEmailSender.php
Go to the documentation of this file.
1<?php
2
4
12use StatusValue;
14
22
23 public const CONSTRUCTOR_OPTIONS = [
26 ];
27
28 public function __construct(
29 private readonly ServiceOptions $options,
30 private readonly IEmailer $emailer,
31 private readonly BagOStuff $cache,
32 private readonly UrlUtils $urlUtils
33 ) {
34 $this->options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
35 }
36
46 public function sendNotificationMail(
47 IContextSource $ctx,
48 User $recipientUser,
49 string $change,
50 string $newEmail = ''
51 ): StatusValue {
52 $allowHtml = $this->options->get( MainConfigNames::AllowHTMLEmail );
53
54 if ( $allowHtml ) {
55 $builder = new HTMLNotificationEmailBuilder( $ctx, $this->cache, $this->urlUtils );
56 if ( $change === 'changed' ) {
57 $emailContent = $builder->buildNotificationEmailChanged( $recipientUser->getName(), $newEmail );
58 } else {
59 $emailContent = $builder->buildNotificationEmailRemoved( $recipientUser->getName() );
60 }
61
62 return $this->sendEmail(
63 $recipientUser,
64 $ctx,
65 $emailContent['subject'],
66 $emailContent['body']['text'],
67 $emailContent['body']['html']
68 );
69 }
70
71 $subject = $ctx->msg( 'notificationemail_subject_' . $change )->text();
72 $bodyText = $ctx->msg(
73 'notificationemail_body_' . $change,
74 $ctx->getRequest()->getIP(),
75 $recipientUser->getName(),
76 $newEmail
77 )->text();
78
79 return $this->sendEmail( $recipientUser, $ctx, $subject, $bodyText );
80 }
81
82 private function sendEmail(
83 User $recipientUser,
84 IContextSource $ctx,
85 string $subject,
86 string $bodyText,
87 ?string $bodyHtml = null
88 ): StatusValue {
89 $sender = new MailAddress(
90 $this->options->get( MainConfigNames::PasswordSender ),
91 $ctx->msg( 'emailsender' )->inContentLanguage()->text()
92 );
93
94 return $this->emailer->send(
95 [ MailAddress::newFromUser( $recipientUser ) ],
96 $sender,
97 $subject,
98 $bodyText,
99 $bodyHtml
100 );
101 }
102}
A class for passing options to services.
Represent and format a single name and email address pair for SMTP.
static newFromUser(UserEmailContact $user)
Builds HTML notification emails when a user changes or removes their email.
Sends notification emails to the old address when a user changes or removes their email.
sendNotificationMail(IContextSource $ctx, User $recipientUser, string $change, string $newEmail='')
Send an email to the old address notifying about the email change.
__construct(private readonly ServiceOptions $options, private readonly IEmailer $emailer, private readonly BagOStuff $cache, private readonly UrlUtils $urlUtils)
A class containing constants representing the names of configuration variables.
const AllowHTMLEmail
Name constant for the AllowHTMLEmail setting, for use with Config::get()
const PasswordSender
Name constant for the PasswordSender setting, for use with Config::get()
User class for the MediaWiki software.
Definition User.php:130
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:1524
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Abstract class for any ephemeral data store.
Definition BagOStuff.php:73
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.
Interface for sending arbitrary emails.
Definition IEmailer.php:20