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