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