3 * Classes used to send e-mails
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author <brion@pobox.com>
22 * @author <mail@tgries.de>
23 * @author Tim Starling
24 * @author Luke Welling lwelling@wikimedia.org
28 * Stores a single person's name and email address.
29 * These are passed in via the constructor, and will be returned in SMTP
30 * header format when requested.
34 * @param string|User $address string with an email address, or a User object
35 * @param string $name human-readable name if a string address is given
36 * @param string $realName human-readable real name if a string address is given
38 function __construct( $address, $name = null, $realName = null ) {
39 if ( is_object( $address ) && $address instanceof User
) {
40 $this->address
= $address->getEmail();
41 $this->name
= $address->getName();
42 $this->realName
= $address->getRealName();
44 $this->address
= strval( $address );
45 $this->name
= strval( $name );
46 $this->realName
= strval( $realName );
51 * Return formatted and quoted address to insert into SMTP headers
55 # PHP's mail() implementation under Windows is somewhat shite, and
56 # can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
57 # so don't bother generating them
58 if ( $this->address
) {
59 if ( $this->name
!= '' && !wfIsWindows() ) {
60 global $wgEnotifUseRealName;
61 $name = ( $wgEnotifUseRealName && $this->realName
) ?
$this->realName
: $this->name
;
62 $quoted = UserMailer
::quotedPrintable( $name );
63 if ( strpos( $quoted, '.' ) !== false ||
strpos( $quoted, ',' ) !== false ) {
64 $quoted = '"' . $quoted . '"';
66 return "$quoted <{$this->address}>";
68 return $this->address
;
75 function __toString() {
76 return $this->toString();
81 * Collection of static functions for sending mail
87 * Send mail using a PEAR mailer
96 protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
97 $mailResult = $mailer->send( $dest, $headers, $body );
99 # Based on the result return an error string,
100 if ( PEAR
::isError( $mailResult ) ) {
101 wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
102 return Status
::newFatal( 'pear-mail-error', $mailResult->getMessage() );
104 return Status
::newGood();
109 * Creates a single string from an associative array
111 * @param array $headers Associative Array: keys are header field names,
112 * values are ... values.
113 * @param string $endl The end of line character. Defaults to "\n"
115 * Note RFC2822 says newlines must be CRLF (\r\n)
116 * but php mail naively "corrects" it and requires \n for the "correction" to work
120 static function arrayToHeaderString( $headers, $endl = "\n" ) {
122 foreach ( $headers as $name => $value ) {
123 // Prevent header injection by stripping newlines from value
124 $value = self
::sanitizeHeaderValue( $value );
125 $strings[] = "$name: $value";
127 return implode( $endl, $strings );
131 * Create a value suitable for the MessageId Header
135 static function makeMsgId() {
136 global $wgSMTP, $wgServer;
138 $msgid = uniqid( wfWikiID() . ".", true ); /* true required for cygwin */
139 if ( is_array( $wgSMTP ) && isset( $wgSMTP['IDHost'] ) && $wgSMTP['IDHost'] ) {
140 $domain = $wgSMTP['IDHost'];
142 $url = wfParseUrl( $wgServer );
143 $domain = $url['host'];
145 return "<$msgid@$domain>";
149 * This function will perform a direct (authenticated) login to
150 * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
151 * array of parameters. It requires PEAR:Mail to do that.
152 * Otherwise it just uses the standard PHP 'mail' function.
154 * @param $to MailAddress: recipient's email (or an array of them)
155 * @param $from MailAddress: sender's email
156 * @param string $subject email's subject.
157 * @param string $body email's text or Array of two strings to be the text and html bodies
158 * @param $replyto MailAddress: optional reply-to email (default: null).
159 * @param string $contentType optional custom Content-Type (default: text/plain; charset=UTF-8)
160 * @throws MWException
161 * @return Status object
163 public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) {
164 global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail;
166 if ( !is_array( $to ) ) {
170 // mail body must have some content
172 // arbitrary but longer than Array or Object to detect casting error
174 // body must either be a string or an array with text and body
177 !is_array( $body ) &&
178 strlen( $body ) >= $minBodyLen
183 isset( $body['text'] ) &&
184 isset( $body['html'] ) &&
185 strlen( $body['text'] ) >= $minBodyLen &&
186 strlen( $body['html'] ) >= $minBodyLen
189 // if it is neither we have a problem
190 return Status
::newFatal( 'user-mail-no-body' );
193 if ( !$wgAllowHTMLEmail && is_array( $body ) ) {
194 // HTML not wanted. Dump it.
195 $body = $body['text'];
198 wfDebug( __METHOD__
. ': sending mail to ' . implode( ', ', $to ) . "\n" );
200 # Make sure we have at least one address
201 $has_address = false;
202 foreach ( $to as $u ) {
208 if ( !$has_address ) {
209 return Status
::newFatal( 'user-mail-no-addy' );
212 # Forge email headers
213 # -------------------
217 # DO NOT add To: or Subject: headers at this step. They need to be
218 # handled differently depending upon the mailer we are going to use.
221 # PHP mail() first argument is the mail receiver. The argument is
222 # used as a recipient destination and as a To header.
224 # PEAR mailer has a recipient argument which is only used to
225 # send the mail. If no To header is given, PEAR will set it to
226 # to 'undisclosed-recipients:'.
228 # NOTE: To: is for presentation, the actual recipient is specified
229 # by the mailer using the Rcpt-To: header.
232 # PHP mail() second argument to pass the subject, passing a Subject
233 # as an additional header will result in a duplicate header.
235 # PEAR mailer should be passed a Subject header.
239 $headers['From'] = $from->toString();
240 $headers['Return-Path'] = $from->address
;
243 $headers['Reply-To'] = $replyto->toString();
246 $headers['Date'] = MWTimestamp
::getLocalInstance()->format( 'r' );
247 $headers['Message-ID'] = self
::makeMsgId();
248 $headers['X-Mailer'] = 'MediaWiki mailer';
250 # Line endings need to be different on Unix and Windows due to
251 # the bug described at http://trac.wordpress.org/ticket/2603
252 if ( wfIsWindows() ) {
258 if ( is_array( $body ) ) {
259 // we are sending a multipart message
260 wfDebug( "Assembling multipart mime email\n" );
261 if ( !stream_resolve_include_path( 'Mail/mime.php' ) ) {
262 wfDebug( "PEAR Mail_Mime package is not installed. Falling back to text email.\n" );
263 // remove the html body for text email fall back
264 $body = $body['text'];
266 require_once 'Mail/mime.php';
267 if ( wfIsWindows() ) {
268 $body['text'] = str_replace( "\n", "\r\n", $body['text'] );
269 $body['html'] = str_replace( "\n", "\r\n", $body['html'] );
271 $mime = new Mail_mime( array( 'eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8' ) );
272 $mime->setTXTBody( $body['text'] );
273 $mime->setHTMLBody( $body['html'] );
274 $body = $mime->get(); // must call get() before headers()
275 $headers = $mime->headers( $headers );
278 if ( $mime === null ) {
279 // sending text only, either deliberately or as a fallback
280 if ( wfIsWindows() ) {
281 $body = str_replace( "\n", "\r\n", $body );
283 $headers['MIME-Version'] = '1.0';
284 $headers['Content-type'] = ( is_null( $contentType ) ?
285 'text/plain; charset=UTF-8' : $contentType );
286 $headers['Content-transfer-encoding'] = '8bit';
289 $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) );
290 if ( $ret === false ) {
291 // the hook implementation will return false to skip regular mail sending
292 return Status
::newGood();
293 } elseif ( $ret !== true ) {
294 // the hook implementation will return a string to pass an error message
295 return Status
::newFatal( 'php-mail-error', $ret );
298 if ( is_array( $wgSMTP ) ) {
303 if ( !stream_resolve_include_path( 'Mail.php' ) ) {
304 throw new MWException( 'PEAR mail package is not installed' );
306 require_once 'Mail.php';
308 wfSuppressWarnings();
310 // Create the mail object using the Mail::factory method
311 $mail_object =& Mail
::factory( 'smtp', $wgSMTP );
312 if ( PEAR
::isError( $mail_object ) ) {
313 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
315 return Status
::newFatal( 'pear-mail-error', $mail_object->getMessage() );
318 wfDebug( "Sending mail via PEAR::Mail\n" );
320 $headers['Subject'] = self
::quotedPrintable( $subject );
322 # When sending only to one recipient, shows it its email using To:
323 if ( count( $to ) == 1 ) {
324 $headers['To'] = $to[0]->toString();
327 # Split jobs since SMTP servers tends to limit the maximum
328 # number of possible recipients.
329 $chunks = array_chunk( $to, $wgEnotifMaxRecips );
330 foreach ( $chunks as $chunk ) {
331 $status = self
::sendWithPear( $mail_object, $chunk, $headers, $body );
332 # FIXME : some chunks might be sent while others are not!
333 if ( !$status->isOK() ) {
339 return Status
::newGood();
344 if ( count( $to ) > 1 ) {
345 $headers['To'] = 'undisclosed-recipients:;';
347 $headers = self
::arrayToHeaderString( $headers, $endl );
349 wfDebug( "Sending mail via internal mail() function\n" );
351 self
::$mErrorString = '';
352 $html_errors = ini_get( 'html_errors' );
353 ini_set( 'html_errors', '0' );
354 set_error_handler( 'UserMailer::errorHandler' );
357 $safeMode = wfIniGetBool( 'safe_mode' );
359 foreach ( $to as $recip ) {
361 $sent = mail( $recip, self
::quotedPrintable( $subject ), $body, $headers );
363 $sent = mail( $recip, self
::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
366 } catch ( Exception
$e ) {
367 restore_error_handler();
371 restore_error_handler();
372 ini_set( 'html_errors', $html_errors );
374 if ( self
::$mErrorString ) {
375 wfDebug( "Error sending mail: " . self
::$mErrorString . "\n" );
376 return Status
::newFatal( 'php-mail-error', self
::$mErrorString );
377 } elseif ( ! $sent ) {
378 // mail function only tells if there's an error
379 wfDebug( "Unknown error sending mail\n" );
380 return Status
::newFatal( 'php-mail-error-unknown' );
382 return Status
::newGood();
388 * Set the mail error message in self::$mErrorString
390 * @param $code Integer: error number
391 * @param string $string error message
393 static function errorHandler( $code, $string ) {
394 self
::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
398 * Strips bad characters from a header value to prevent PHP mail header injection attacks
399 * @param string $val String to be santizied
402 public static function sanitizeHeaderValue( $val ) {
403 return strtr( $val, array( "\r" => '', "\n" => '' ) );
407 * Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
408 * @param $phrase string
411 public static function rfc822Phrase( $phrase ) {
412 // Remove line breaks
413 $phrase = self
::sanitizeHeaderValue( $phrase );
415 $phrase = str_replace( '"', '', $phrase );
416 return '"' . $phrase . '"';
420 * Converts a string into quoted-printable format
423 * From PHP5.3 there is a built in function quoted_printable_encode()
424 * This method does not duplicate that.
425 * This method is doing Q encoding inside encoded-words as defined by RFC 2047
426 * This is for email headers.
427 * The built in quoted_printable_encode() is for email bodies
430 public static function quotedPrintable( $string, $charset = '' ) {
431 # Probably incomplete; see RFC 2045
432 if ( empty( $charset ) ) {
435 $charset = strtoupper( $charset );
436 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
438 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
439 $replace = $illegal . '\t ?_';
440 if ( !preg_match( "/[$illegal]/", $string ) ) {
443 $out = "=?$charset?Q?";
444 $out .= preg_replace_callback( "/([$replace])/",
445 array( __CLASS__
, 'quotedPrintableCallback' ), $string );
450 protected static function quotedPrintableCallback( $matches ) {
451 return sprintf( "=%02X", ord( $matches[1] ) );
456 * This module processes the email notifications when the current page is
457 * changed. It looks up the table watchlist to find out which users are watching
460 * The current implementation sends independent emails to each watching user for
461 * the following reason:
463 * - Each watching user will be notified about the page edit time expressed in
464 * his/her local time (UTC is shown additionally). To achieve this, we need to
465 * find the individual timeoffset of each watching user from the preferences..
467 * Suggested improvement to slack down the number of sent emails: We could think
468 * of sending out bulk mails (bcc:user1,user2...) for all these users having the
469 * same timeoffset in their preferences.
471 * Visit the documentation pages under http://meta.wikipedia.com/Enotif
475 class EmailNotification
{
476 protected $subject, $body, $replyto, $from;
477 protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus;
478 protected $mailTargets = array();
491 * Send emails corresponding to the user $editor editing the page $title.
492 * Also updates wl_notificationtimestamp.
494 * May be deferred via the job queue.
496 * @param $editor User object
497 * @param $title Title object
501 * @param $oldid (default: false)
502 * @param $pageStatus (default: 'changed')
504 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $pageStatus = 'changed' ) {
505 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
506 $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
508 if ( $title->getNamespace() < 0 ) {
512 // Build a list of users to notify
514 if ( $wgEnotifWatchlist ||
$wgShowUpdatedMarker ) {
515 $dbw = wfGetDB( DB_MASTER
);
516 $res = $dbw->select( array( 'watchlist' ),
519 'wl_user != ' . intval( $editor->getID() ),
520 'wl_namespace' => $title->getNamespace(),
521 'wl_title' => $title->getDBkey(),
522 'wl_notificationtimestamp IS NULL',
525 foreach ( $res as $row ) {
526 $watchers[] = intval( $row->wl_user
);
529 // Update wl_notificationtimestamp for all watching users except the editor
531 $dbw->onTransactionIdle(
532 function() use ( $dbw, $timestamp, $watchers, $title, $fname ) {
533 $dbw->begin( $fname );
534 $dbw->update( 'watchlist',
536 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
537 ), array( /* WHERE */
538 'wl_user' => $watchers,
539 'wl_namespace' => $title->getNamespace(),
540 'wl_title' => $title->getDBkey(),
543 $dbw->commit( $fname );
550 // If nobody is watching the page, and there are no users notified on all changes
551 // don't bother creating a job/trying to send emails
552 // $watchers deals with $wgEnotifWatchlist
553 if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
555 // Only send notification for non minor edits, unless $wgEnotifMinorEdits
556 if ( !$minorEdit ||
( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
557 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK
);
558 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
567 if ( $wgEnotifUseJobQ ) {
569 'editor' => $editor->getName(),
570 'editorID' => $editor->getID(),
571 'timestamp' => $timestamp,
572 'summary' => $summary,
573 'minorEdit' => $minorEdit,
575 'watchers' => $watchers,
576 'pageStatus' => $pageStatus
578 $job = new EnotifNotifyJob( $title, $params );
579 JobQueueGroup
::singleton()->push( $job );
581 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus );
586 * Immediate version of notifyOnPageChange().
588 * Send emails corresponding to the user $editor editing the page $title.
589 * Also updates wl_notificationtimestamp.
591 * @param $editor User object
592 * @param $title Title object
593 * @param string $timestamp Edit timestamp
594 * @param string $summary Edit summary
595 * @param $minorEdit bool
596 * @param int $oldid Revision ID
597 * @param array $watchers of user IDs
598 * @param string $pageStatus
599 * @throws MWException
601 public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit,
602 $oldid, $watchers, $pageStatus = 'changed' ) {
603 # we use $wgPasswordSender as sender's address
604 global $wgEnotifWatchlist;
605 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
607 wfProfileIn( __METHOD__
);
609 # The following code is only run, if several conditions are met:
610 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
611 # 2. minor edits (changes) are only regarded if the global flag indicates so
613 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK
);
615 $this->title
= $title;
616 $this->timestamp
= $timestamp;
617 $this->summary
= $summary;
618 $this->minorEdit
= $minorEdit;
619 $this->oldid
= $oldid;
620 $this->editor
= $editor;
621 $this->composed_common
= false;
622 $this->pageStatus
= $pageStatus;
624 $formattedPageStatus = array( 'deleted', 'created', 'moved', 'restored', 'changed' );
626 wfRunHooks( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) );
627 if ( !in_array( $this->pageStatus
, $formattedPageStatus ) ) {
628 wfProfileOut( __METHOD__
);
629 throw new MWException( 'Not a valid page status!' );
634 if ( !$minorEdit ||
( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
636 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
637 $targetUser = User
::newFromName( $title->getText() );
638 $this->compose( $targetUser );
639 $userTalkId = $targetUser->getId();
642 if ( $wgEnotifWatchlist ) {
643 // Send updates to watchers other than the current editor
644 $userArray = UserArray
::newFromIDs( $watchers );
645 foreach ( $userArray as $watchingUser ) {
646 if ( $watchingUser->getOption( 'enotifwatchlistpages' )
647 && ( !$minorEdit ||
$watchingUser->getOption( 'enotifminoredits' ) )
648 && $watchingUser->isEmailConfirmed()
649 && $watchingUser->getID() != $userTalkId
651 if ( wfRunHooks( 'SendWatchlistEmailNotification', array( $watchingUser, $title, $this ) ) ) {
652 $this->compose( $watchingUser );
659 global $wgUsersNotifiedOnAllChanges;
660 foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
661 if ( $editor->getName() == $name ) {
662 // No point notifying the user that actually made the change!
665 $user = User
::newFromName( $name );
666 $this->compose( $user );
670 wfProfileOut( __METHOD__
);
674 * @param $editor User
675 * @param $title Title bool
679 private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
680 global $wgEnotifUserTalk;
681 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK
);
683 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
684 $targetUser = User
::newFromName( $title->getText() );
686 if ( !$targetUser ||
$targetUser->isAnon() ) {
687 wfDebug( __METHOD__
. ": user talk page edited, but user does not exist\n" );
688 } elseif ( $targetUser->getId() == $editor->getId() ) {
689 wfDebug( __METHOD__
. ": user edited their own talk page, no notification sent\n" );
690 } elseif ( $targetUser->getOption( 'enotifusertalkpages' )
691 && ( !$minorEdit ||
$targetUser->getOption( 'enotifminoredits' ) )
693 if ( !$targetUser->isEmailConfirmed() ) {
694 wfDebug( __METHOD__
. ": talk page owner doesn't have validated email\n" );
695 } elseif ( !wfRunHooks( 'AbortTalkPageEmailNotification', array( $targetUser, $title ) ) ) {
696 wfDebug( __METHOD__
. ": talk page update notification is aborted for this user\n" );
698 wfDebug( __METHOD__
. ": sending talk page update notification\n" );
702 wfDebug( __METHOD__
. ": talk page owner doesn't want notifications\n" );
709 * Generate the generic "this page has been changed" e-mail text.
711 private function composeCommonMailtext() {
712 global $wgPasswordSender, $wgNoReplyAddress;
713 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
714 global $wgEnotifImpersonal, $wgEnotifUseRealName;
716 $this->composed_common
= true;
718 # You as the WikiAdmin and Sysops can make use of plenty of
719 # named variables when composing your notification emails while
720 # simply editing the Meta pages
723 $postTransformKeys = array();
724 $pageTitleUrl = $this->title
->getCanonicalURL();
725 $pageTitle = $this->title
->getPrefixedText();
727 if ( $this->oldid
) {
728 // Always show a link to the diff which triggered the mail. See bug 32210.
729 $keys['$NEWPAGE'] = "\n\n" . wfMessage( 'enotif_lastdiff',
730 $this->title
->getCanonicalURL( array( 'diff' => 'next', 'oldid' => $this->oldid
) ) )
731 ->inContentLanguage()->text();
733 if ( !$wgEnotifImpersonal ) {
734 // For personal mail, also show a link to the diff of all changes
735 // since last visited.
736 $keys['$NEWPAGE'] .= "\n\n" . wfMessage( 'enotif_lastvisited',
737 $this->title
->getCanonicalURL( array( 'diff' => '0', 'oldid' => $this->oldid
) ) )
738 ->inContentLanguage()->text();
740 $keys['$OLDID'] = $this->oldid
;
741 // @deprecated Remove in MediaWiki 1.23.
742 $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
744 # clear $OLDID placeholder in the message template
745 $keys['$OLDID'] = '';
746 $keys['$NEWPAGE'] = '';
747 // @deprecated Remove in MediaWiki 1.23.
748 $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
751 $keys['$PAGETITLE'] = $this->title
->getPrefixedText();
752 $keys['$PAGETITLE_URL'] = $this->title
->getCanonicalURL();
753 $keys['$PAGEMINOREDIT'] = $this->minorEdit ?
754 wfMessage( 'minoredit' )->inContentLanguage()->text() : '';
755 $keys['$UNWATCHURL'] = $this->title
->getCanonicalURL( 'action=unwatch' );
757 if ( $this->editor
->isAnon() ) {
758 # real anon (user:xxx.xxx.xxx.xxx)
759 $keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor
->getName() )
760 ->inContentLanguage()->text();
761 $keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
764 $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ?
$this->editor
->getRealName() : $this->editor
->getName();
765 $emailPage = SpecialPage
::getSafeTitleFor( 'Emailuser', $this->editor
->getName() );
766 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL();
769 $keys['$PAGEEDITOR_WIKI'] = $this->editor
->getUserPage()->getCanonicalURL();
771 # Replace this after transforming the message, bug 35019
772 $postTransformKeys['$PAGESUMMARY'] = $this->summary
== '' ?
' - ' : $this->summary
;
774 // Now build message's subject and body
777 // enotif_subject_deleted, enotif_subject_created, enotif_subject_moved,
778 // enotif_subject_restored, enotif_subject_changed
779 $this->subject
= wfMessage( 'enotif_subject_' . $this->pageStatus
)->inContentLanguage()
780 ->params( $pageTitle, $keys['$PAGEEDITOR'] )->text();
783 // enotif_body_intro_deleted, enotif_body_intro_created, enotif_body_intro_moved,
784 // enotif_body_intro_restored, enotif_body_intro_changed
785 $keys['$PAGEINTRO'] = wfMessage( 'enotif_body_intro_' . $this->pageStatus
)
786 ->inContentLanguage()->params( $pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl )
789 $body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
790 $body = strtr( $body, $keys );
791 $body = MessageCache
::singleton()->transform( $body, false, null, $this->title
);
792 $this->body
= wordwrap( strtr( $body, $postTransformKeys ), 72 );
794 # Reveal the page editor's address as REPLY-TO address only if
795 # the user has not opted-out and the option is enabled at the
796 # global configuration level.
797 $adminAddress = new MailAddress( $wgPasswordSender,
798 wfMessage( 'emailsender' )->inContentLanguage()->text() );
799 if ( $wgEnotifRevealEditorAddress
800 && ( $this->editor
->getEmail() != '' )
801 && $this->editor
->getOption( 'enotifrevealaddr' )
803 $editorAddress = new MailAddress( $this->editor
);
804 if ( $wgEnotifFromEditor ) {
805 $this->from
= $editorAddress;
807 $this->from
= $adminAddress;
808 $this->replyto
= $editorAddress;
811 $this->from
= $adminAddress;
812 $this->replyto
= new MailAddress( $wgNoReplyAddress );
817 * Compose a mail to a given user and either queue it for sending, or send it now,
818 * depending on settings.
820 * Call sendMails() to send any mails that were queued.
823 function compose( $user ) {
824 global $wgEnotifImpersonal;
826 if ( !$this->composed_common
) {
827 $this->composeCommonMailtext();
830 if ( $wgEnotifImpersonal ) {
831 $this->mailTargets
[] = new MailAddress( $user );
833 $this->sendPersonalised( $user );
838 * Send any queued mails
840 function sendMails() {
841 global $wgEnotifImpersonal;
842 if ( $wgEnotifImpersonal ) {
843 $this->sendImpersonal( $this->mailTargets
);
848 * Does the per-user customizations to a notification e-mail (name,
849 * timestamp in proper timezone, etc) and sends it out.
850 * Returns true if the mail was sent successfully.
852 * @param $watchingUser User object
856 function sendPersonalised( $watchingUser ) {
857 global $wgContLang, $wgEnotifUseRealName;
858 // From the PHP manual:
859 // Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
860 // The mail command will not parse this properly while talking with the MTA.
861 $to = new MailAddress( $watchingUser );
863 # $PAGEEDITDATE is the time and date of the page change
864 # expressed in terms of individual local time of the notification
865 # recipient, i.e. watching user
867 array( '$WATCHINGUSERNAME',
870 array( $wgEnotifUseRealName ?
$watchingUser->getRealName() : $watchingUser->getName(),
871 $wgContLang->userDate( $this->timestamp
, $watchingUser ),
872 $wgContLang->userTime( $this->timestamp
, $watchingUser ) ),
875 return UserMailer
::send( $to, $this->from
, $this->subject
, $body, $this->replyto
);
879 * Same as sendPersonalised but does impersonal mail suitable for bulk
880 * mailing. Takes an array of MailAddress objects.
881 * @param $addresses array
882 * @return Status|null
884 function sendImpersonal( $addresses ) {
887 if ( empty( $addresses ) ) {
892 array( '$WATCHINGUSERNAME',
895 array( wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
896 $wgContLang->date( $this->timestamp
, false, false ),
897 $wgContLang->time( $this->timestamp
, false, false ) ),
900 return UserMailer
::send( $addresses, $this->from
, $this->subject
, $body, $this->replyto
);
903 } # end of class EmailNotification