Add hook that could be the solution for Bug #28026 (“Enable e-mail
[lhc/web/wiklou.git] / includes / UserMailer.php
1 <?php
2 /**
3 * Classes used to send e-mails
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author <brion@pobox.com>
22 * @author <mail@tgries.de>
23 * @author Tim Starling
24 */
25
26
27 /**
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.
31 */
32 class MailAddress {
33 /**
34 * @param $address string|User string with an email address, or a User object
35 * @param $name String: human-readable name if a string address is given
36 * @param $realName String: human-readable real name if a string address is given
37 */
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();
43 } else {
44 $this->address = strval( $address );
45 $this->name = strval( $name );
46 $this->realName = strval( $realName );
47 }
48 }
49
50 /**
51 * Return formatted and quoted address to insert into SMTP headers
52 * @return string
53 */
54 function toString() {
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 . '"';
65 }
66 return "$quoted <{$this->address}>";
67 } else {
68 return $this->address;
69 }
70 } else {
71 return "";
72 }
73 }
74
75 function __toString() {
76 return $this->toString();
77 }
78 }
79
80
81 /**
82 * Collection of static functions for sending mail
83 */
84 class UserMailer {
85 static $mErrorString;
86
87 /**
88 * Send mail using a PEAR mailer
89 *
90 * @param $mailer
91 * @param $dest
92 * @param $headers
93 * @param $body
94 *
95 * @return Status
96 */
97 protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
98 $mailResult = $mailer->send( $dest, $headers, $body );
99
100 # Based on the result return an error string,
101 if ( PEAR::isError( $mailResult ) ) {
102 wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
103 return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
104 } else {
105 return Status::newGood();
106 }
107 }
108
109 /**
110 * Creates a single string from an associative array
111 *
112 * @param $header Associative Array: keys are header field names,
113 * values are ... values.
114 * @param $endl String: The end of line character. Defaults to "\n"
115 * @return String
116 */
117 static function arrayToHeaderString( $headers, $endl = "\n" ) {
118 foreach( $headers as $name => $value ) {
119 $string[] = "$name: $value";
120 }
121 return implode( $endl, $string );
122 }
123
124 /**
125 * This function will perform a direct (authenticated) login to
126 * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
127 * array of parameters. It requires PEAR:Mail to do that.
128 * Otherwise it just uses the standard PHP 'mail' function.
129 *
130 * @param $to MailAddress: recipient's email (or an array of them)
131 * @param $from MailAddress: sender's email
132 * @param $subject String: email's subject.
133 * @param $body String: email's text.
134 * @param $replyto MailAddress: optional reply-to email (default: null).
135 * @param $contentType String: optional custom Content-Type (default: text/plain; charset=UTF-8)
136 * @return Status object
137 */
138 public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) {
139 global $wgSMTP, $wgEnotifImpersonal;
140 global $wgEnotifMaxRecips, $wgAdditionalMailParams;
141
142 $emails = '';
143 wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
144
145 $headers['From'] = $from->toString();
146 $headers['Return-Path'] = $from->toString();
147
148 $dest = array();
149 if ( is_array( $to ) ) {
150 foreach ( $to as $u ) {
151 if ( $u->address ) {
152 $dest[] = $u->address;
153 }
154 }
155 } else if( $to->address ) {
156 $dest[] = $to->address;
157 }
158 if ( count( $dest ) == 0 ) {
159 return Status::newFatal( 'user-mail-no-addy' );
160 }
161
162 if ( $wgEnotifImpersonal ) {
163 $headers['To'] = 'undisclosed-recipients:;';
164 }
165 else {
166 $headers['To'] = implode( ", ", $dest );
167 }
168
169 if ( $replyto ) {
170 $headers['Reply-To'] = $replyto->toString();
171 }
172 $headers['Subject'] = self::quotedPrintable( $subject );
173 $headers['Date'] = date( 'r' );
174 $headers['MIME-Version'] = '1.0';
175 $headers['Content-type'] = ( is_null( $contentType ) ?
176 'text/plain; charset=UTF-8' : $contentType );
177 $headers['Content-transfer-encoding'] = '8bit';
178 // @todo FIXME
179 $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>';
180 $headers['X-Mailer'] = 'MediaWiki mailer';
181 $headers['From'] = $from->toString();
182
183 $ret = wfRunHooks( 'AlternateUserMailer', array( $this, $headers, $to, $from, $subject, $body, $replyto, $contentType ) ) ) {
184 if ( $ret === false ) {
185 return Status::newGood();
186 } else if ( $ret != true ) {
187 return Status::newFatal( 'php-mail-error', $ret );
188 }
189
190 if ( is_array( $wgSMTP ) ) {
191 if ( function_exists( 'stream_resolve_include_path' ) ) {
192 $found = stream_resolve_include_path( 'Mail.php' );
193 } else {
194 $found = Fallback::stream_resolve_include_path( 'Mail.php' );
195 }
196 if ( !$found ) {
197 throw new MWException( 'PEAR mail package is not installed' );
198 }
199 require_once( 'Mail.php' );
200
201 $msgid = str_replace( " ", "_", microtime() );
202 if ( function_exists( 'posix_getpid' ) ) {
203 $msgid .= '.' . posix_getpid();
204 }
205
206 wfSuppressWarnings();
207
208 // Create the mail object using the Mail::factory method
209 $mail_object =& Mail::factory( 'smtp', $wgSMTP );
210 if ( PEAR::isError( $mail_object ) ) {
211 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
212 wfRestoreWarnings();
213 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
214 }
215
216 wfDebug( "Sending mail via PEAR::Mail\n" );
217 $chunks = array_chunk( $dest, $wgEnotifMaxRecips );
218 foreach ( $chunks as $chunk ) {
219 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
220 if ( !$status->isOK() ) {
221 wfRestoreWarnings();
222 return $status;
223 }
224 }
225 wfRestoreWarnings();
226 return Status::newGood();
227 } else {
228 # Line endings need to be different on Unix and Windows due to
229 # the bug described at http://trac.wordpress.org/ticket/2603
230 if ( wfIsWindows() ) {
231 $body = str_replace( "\n", "\r\n", $body );
232 $endl = "\r\n";
233 } else {
234 $endl = "\n";
235 }
236
237 $headers = self::arrayToHeaderString( $headers, $endl );
238
239 wfDebug( "Sending mail via internal mail() function\n" );
240
241 self::$mErrorString = '';
242 $html_errors = ini_get( 'html_errors' );
243 ini_set( 'html_errors', '0' );
244 set_error_handler( 'UserMailer::errorHandler' );
245
246 foreach ( $dest as $recip ) {
247 $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
248 }
249
250 restore_error_handler();
251 ini_set( 'html_errors', $html_errors );
252
253 if ( self::$mErrorString ) {
254 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
255 return Status::newFatal( 'php-mail-error', self::$mErrorString );
256 } elseif ( ! $sent ) {
257 // mail function only tells if there's an error
258 wfDebug( "Unknown error sending mail\n" );
259 return Status::newFatal( 'php-mail-error-unknown' );
260 } else {
261 return Status::newGood();
262 }
263 }
264 }
265
266 /**
267 * Set the mail error message in self::$mErrorString
268 *
269 * @param $code Integer: error number
270 * @param $string String: error message
271 */
272 static function errorHandler( $code, $string ) {
273 self::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
274 }
275
276 /**
277 * Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
278 * @param $phrase string
279 * @return string
280 */
281 public static function rfc822Phrase( $phrase ) {
282 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
283 return '"' . $phrase . '"';
284 }
285
286 /**
287 * Converts a string into quoted-printable format
288 * @since 1.17
289 */
290 public static function quotedPrintable( $string, $charset = '' ) {
291 # Probably incomplete; see RFC 2045
292 if( empty( $charset ) ) {
293 $charset = 'UTF-8';
294 }
295 $charset = strtoupper( $charset );
296 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
297
298 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
299 $replace = $illegal . '\t ?_';
300 if( !preg_match( "/[$illegal]/", $string ) ) {
301 return $string;
302 }
303 $out = "=?$charset?Q?";
304 $out .= preg_replace_callback( "/([$replace])/",
305 array( __CLASS__, 'quotedPrintableCallback' ), $string );
306 $out .= '?=';
307 return $out;
308 }
309
310 protected static function quotedPrintableCallback( $matches ) {
311 return sprintf( "=%02X", ord( $matches[1] ) );
312 }
313 }
314
315 /**
316 * This module processes the email notifications when the current page is
317 * changed. It looks up the table watchlist to find out which users are watching
318 * that page.
319 *
320 * The current implementation sends independent emails to each watching user for
321 * the following reason:
322 *
323 * - Each watching user will be notified about the page edit time expressed in
324 * his/her local time (UTC is shown additionally). To achieve this, we need to
325 * find the individual timeoffset of each watching user from the preferences..
326 *
327 * Suggested improvement to slack down the number of sent emails: We could think
328 * of sending out bulk mails (bcc:user1,user2...) for all these users having the
329 * same timeoffset in their preferences.
330 *
331 * Visit the documentation pages under http://meta.wikipedia.com/Enotif
332 *
333 *
334 */
335 class EmailNotification {
336 protected $to, $subject, $body, $replyto, $from;
337 protected $user, $title, $timestamp, $summary, $minorEdit, $oldid, $composed_common, $editor;
338 protected $mailTargets = array();
339
340 /**
341 * Send emails corresponding to the user $editor editing the page $title.
342 * Also updates wl_notificationtimestamp.
343 *
344 * May be deferred via the job queue.
345 *
346 * @param $editor User object
347 * @param $title Title object
348 * @param $timestamp
349 * @param $summary
350 * @param $minorEdit
351 * @param $oldid (default: false)
352 */
353 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
354 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
355
356 if ( $title->getNamespace() < 0 ) {
357 return;
358 }
359
360 // Build a list of users to notfiy
361 $watchers = array();
362 if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
363 $dbw = wfGetDB( DB_MASTER );
364 $res = $dbw->select( array( 'watchlist' ),
365 array( 'wl_user' ),
366 array(
367 'wl_title' => $title->getDBkey(),
368 'wl_namespace' => $title->getNamespace(),
369 'wl_user != ' . intval( $editor->getID() ),
370 'wl_notificationtimestamp IS NULL',
371 ), __METHOD__
372 );
373 foreach ( $res as $row ) {
374 $watchers[] = intval( $row->wl_user );
375 }
376 if ( $watchers ) {
377 // Update wl_notificationtimestamp for all watching users except
378 // the editor
379 $dbw->begin();
380 $dbw->update( 'watchlist',
381 array( /* SET */
382 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
383 ), array( /* WHERE */
384 'wl_title' => $title->getDBkey(),
385 'wl_namespace' => $title->getNamespace(),
386 'wl_user' => $watchers
387 ), __METHOD__
388 );
389 $dbw->commit();
390 }
391 }
392
393 if ( $wgEnotifUseJobQ ) {
394 $params = array(
395 'editor' => $editor->getName(),
396 'editorID' => $editor->getID(),
397 'timestamp' => $timestamp,
398 'summary' => $summary,
399 'minorEdit' => $minorEdit,
400 'oldid' => $oldid,
401 'watchers' => $watchers
402 );
403 $job = new EnotifNotifyJob( $title, $params );
404 $job->insert();
405 } else {
406 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
407 }
408
409 }
410
411 /**
412 * Immediate version of notifyOnPageChange().
413 *
414 * Send emails corresponding to the user $editor editing the page $title.
415 * Also updates wl_notificationtimestamp.
416 *
417 * @param $editor User object
418 * @param $title Title object
419 * @param $timestamp string Edit timestamp
420 * @param $summary string Edit summary
421 * @param $minorEdit bool
422 * @param $oldid int Revision ID
423 * @param $watchers array of user IDs
424 */
425 public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
426 # we use $wgPasswordSender as sender's address
427 global $wgEnotifWatchlist;
428 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
429
430 wfProfileIn( __METHOD__ );
431
432 # The following code is only run, if several conditions are met:
433 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
434 # 2. minor edits (changes) are only regarded if the global flag indicates so
435
436 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
437
438 $this->title = $title;
439 $this->timestamp = $timestamp;
440 $this->summary = $summary;
441 $this->minorEdit = $minorEdit;
442 $this->oldid = $oldid;
443 $this->editor = $editor;
444 $this->composed_common = false;
445
446 $userTalkId = false;
447
448 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
449 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
450 $targetUser = User::newFromName( $title->getText() );
451 if ( !$targetUser || $targetUser->isAnon() ) {
452 wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
453 } elseif ( $targetUser->getId() == $editor->getId() ) {
454 wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
455 } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
456 ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
457 {
458 if ( $targetUser->isEmailConfirmed() ) {
459 wfDebug( __METHOD__ . ": sending talk page update notification\n" );
460 $this->compose( $targetUser );
461 $userTalkId = $targetUser->getId();
462 } else {
463 wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
464 }
465 } else {
466 wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
467 }
468 }
469
470 if ( $wgEnotifWatchlist ) {
471 // Send updates to watchers other than the current editor
472 $userArray = UserArray::newFromIDs( $watchers );
473 foreach ( $userArray as $watchingUser ) {
474 if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
475 ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) &&
476 $watchingUser->isEmailConfirmed() &&
477 $watchingUser->getID() != $userTalkId )
478 {
479 $this->compose( $watchingUser );
480 }
481 }
482 }
483 }
484
485 global $wgUsersNotifiedOnAllChanges;
486 foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
487 $user = User::newFromName( $name );
488 $this->compose( $user );
489 }
490
491 $this->sendMails();
492 wfProfileOut( __METHOD__ );
493 }
494
495 /**
496 * Generate the generic "this page has been changed" e-mail text.
497 */
498 private function composeCommonMailtext() {
499 global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
500 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
501 global $wgEnotifImpersonal, $wgEnotifUseRealName;
502
503 $this->composed_common = true;
504
505 $summary = ( $this->summary == '' ) ? ' - ' : $this->summary;
506 $medit = ( $this->minorEdit ) ? wfMsgForContent( 'minoredit' ) : '';
507
508 # You as the WikiAdmin and Sysops can make use of plenty of
509 # named variables when composing your notification emails while
510 # simply editing the Meta pages
511
512 $subject = wfMsgForContent( 'enotif_subject' );
513 $body = wfMsgForContent( 'enotif_body' );
514 $from = ''; /* fail safe */
515 $replyto = ''; /* fail safe */
516 $keys = array();
517
518 if ( $this->oldid ) {
519 $difflink = $this->title->getFullUrl( 'diff=0&oldid=' . $this->oldid );
520 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
521 $keys['$OLDID'] = $this->oldid;
522 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
523 } else {
524 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' );
525 # clear $OLDID placeholder in the message template
526 $keys['$OLDID'] = '';
527 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
528 }
529
530 if ( $wgEnotifImpersonal && $this->oldid ) {
531 /**
532 * For impersonal mail, show a diff link to the last
533 * revision.
534 */
535 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
536 $this->title->getFullURL( "oldid={$this->oldid}&diff=next" ) );
537 }
538
539 $body = strtr( $body, $keys );
540 $pagetitle = $this->title->getPrefixedText();
541 $keys['$PAGETITLE'] = $pagetitle;
542 $keys['$PAGETITLE_URL'] = $this->title->getFullUrl();
543
544 $keys['$PAGEMINOREDIT'] = $medit;
545 $keys['$PAGESUMMARY'] = $summary;
546 $keys['$UNWATCHURL'] = $this->title->getFullUrl( 'action=unwatch' );
547
548 $subject = strtr( $subject, $keys );
549
550 # Reveal the page editor's address as REPLY-TO address only if
551 # the user has not opted-out and the option is enabled at the
552 # global configuration level.
553 $editor = $this->editor;
554 $name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
555 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
556 $editorAddress = new MailAddress( $editor );
557 if ( $wgEnotifRevealEditorAddress
558 && ( $editor->getEmail() != '' )
559 && $editor->getOption( 'enotifrevealaddr' ) ) {
560 if ( $wgEnotifFromEditor ) {
561 $from = $editorAddress;
562 } else {
563 $from = $adminAddress;
564 $replyto = $editorAddress;
565 }
566 } else {
567 $from = $adminAddress;
568 $replyto = new MailAddress( $wgNoReplyAddress );
569 }
570
571 if ( $editor->isAnon() ) {
572 # real anon (user:xxx.xxx.xxx.xxx)
573 $utext = wfMsgForContent( 'enotif_anon_editor', $name );
574 $subject = str_replace( '$PAGEEDITOR', $utext, $subject );
575 $keys['$PAGEEDITOR'] = $utext;
576 $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
577 } else {
578 $subject = str_replace( '$PAGEEDITOR', $name, $subject );
579 $keys['$PAGEEDITOR'] = $name;
580 $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
581 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
582 }
583 $userPage = $editor->getUserPage();
584 $keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl();
585 $body = strtr( $body, $keys );
586 $body = wordwrap( $body, 72 );
587
588 # now save this as the constant user-independent part of the message
589 $this->from = $from;
590 $this->replyto = $replyto;
591 $this->subject = $subject;
592 $this->body = $body;
593 }
594
595 /**
596 * Compose a mail to a given user and either queue it for sending, or send it now,
597 * depending on settings.
598 *
599 * Call sendMails() to send any mails that were queued.
600 */
601 function compose( $user ) {
602 global $wgEnotifImpersonal;
603
604 if ( !$this->composed_common )
605 $this->composeCommonMailtext();
606
607 if ( $wgEnotifImpersonal ) {
608 $this->mailTargets[] = new MailAddress( $user );
609 } else {
610 $this->sendPersonalised( $user );
611 }
612 }
613
614 /**
615 * Send any queued mails
616 */
617 function sendMails() {
618 global $wgEnotifImpersonal;
619 if ( $wgEnotifImpersonal ) {
620 $this->sendImpersonal( $this->mailTargets );
621 }
622 }
623
624 /**
625 * Does the per-user customizations to a notification e-mail (name,
626 * timestamp in proper timezone, etc) and sends it out.
627 * Returns true if the mail was sent successfully.
628 *
629 * @param $watchingUser User object
630 * @return Boolean
631 * @private
632 */
633 function sendPersonalised( $watchingUser ) {
634 global $wgContLang, $wgEnotifUseRealName;
635 // From the PHP manual:
636 // Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
637 // The mail command will not parse this properly while talking with the MTA.
638 $to = new MailAddress( $watchingUser );
639 $name = $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName();
640 $body = str_replace( '$WATCHINGUSERNAME', $name, $this->body );
641
642 $timecorrection = $watchingUser->getOption( 'timecorrection' );
643
644 # $PAGEEDITDATE is the time and date of the page change
645 # expressed in terms of individual local time of the notification
646 # recipient, i.e. watching user
647 $body = str_replace(
648 array( '$PAGEEDITDATEANDTIME',
649 '$PAGEEDITDATE',
650 '$PAGEEDITTIME' ),
651 array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
652 $wgContLang->date( $this->timestamp, true, false, $timecorrection ),
653 $wgContLang->time( $this->timestamp, true, false, $timecorrection ) ),
654 $body );
655
656 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
657 }
658
659 /**
660 * Same as sendPersonalised but does impersonal mail suitable for bulk
661 * mailing. Takes an array of MailAddress objects.
662 */
663 function sendImpersonal( $addresses ) {
664 global $wgContLang;
665
666 if ( empty( $addresses ) )
667 return;
668
669 $body = str_replace(
670 array( '$WATCHINGUSERNAME',
671 '$PAGEEDITDATE',
672 '$PAGEEDITTIME' ),
673 array( wfMsgForContent( 'enotif_impersonal_salutation' ),
674 $wgContLang->date( $this->timestamp, true, false, false ),
675 $wgContLang->time( $this->timestamp, true, false, false ) ),
676 $this->body );
677
678 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
679 }
680
681 } # end of class EmailNotification