MediaWiki  REL1_20
UserMailer.php
Go to the documentation of this file.
00001 <?php
00032 class MailAddress {
00038         function __construct( $address, $name = null, $realName = null ) {
00039                 if ( is_object( $address ) && $address instanceof User ) {
00040                         $this->address = $address->getEmail();
00041                         $this->name = $address->getName();
00042                         $this->realName = $address->getRealName();
00043                 } else {
00044                         $this->address = strval( $address );
00045                         $this->name = strval( $name );
00046                         $this->realName = strval( $realName );
00047                 }
00048         }
00049 
00054         function toString() {
00055                 # PHP's mail() implementation under Windows is somewhat shite, and
00056                 # can't handle "Joe Bloggs <[email protected]>" format email addresses,
00057                 # so don't bother generating them
00058                 if ( $this->address ) {
00059                         if ( $this->name != '' && !wfIsWindows() ) {
00060                                 global $wgEnotifUseRealName;
00061                                 $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
00062                                 $quoted = UserMailer::quotedPrintable( $name );
00063                                 if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
00064                                         $quoted = '"' . $quoted . '"';
00065                                 }
00066                                 return "$quoted <{$this->address}>";
00067                         } else {
00068                                 return $this->address;
00069                         }
00070                 } else {
00071                         return "";
00072                 }
00073         }
00074 
00075         function __toString() {
00076                 return $this->toString();
00077         }
00078 }
00079 
00080 
00084 class UserMailer {
00085         static $mErrorString;
00086 
00097         protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
00098                 $mailResult = $mailer->send( $dest, $headers, $body );
00099 
00100                 # Based on the result return an error string,
00101                 if ( PEAR::isError( $mailResult ) ) {
00102                         wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
00103                         return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
00104                 } else {
00105                         return Status::newGood();
00106                 }
00107         }
00108 
00117         static function arrayToHeaderString( $headers, $endl = "\n" ) {
00118                 $strings = array();
00119                 foreach( $headers as $name => $value ) {
00120                         $strings[] = "$name: $value";
00121                 }
00122                 return implode( $endl, $strings );
00123         }
00124 
00130         static function makeMsgId() {
00131                 global $wgSMTP, $wgServer;
00132 
00133                 $msgid = uniqid( wfWikiID() . ".", true ); /* true required for cygwin */
00134                 if ( is_array($wgSMTP) && isset($wgSMTP['IDHost']) && $wgSMTP['IDHost'] ) {
00135                         $domain = $wgSMTP['IDHost'];
00136                 } else {
00137                         $url = wfParseUrl($wgServer);
00138                         $domain = $url['host'];
00139                 }
00140                 return "<$msgid@$domain>";
00141         }
00142 
00157         public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) {
00158                 global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams;
00159 
00160                 if ( !is_array( $to ) ) {
00161                         $to = array( $to );
00162                 }
00163 
00164                 wfDebug( __METHOD__ . ': sending mail to ' . implode( ', ', $to ) . "\n" );
00165 
00166                 # Make sure we have at least one address
00167                 $has_address = false;
00168                 foreach ( $to as $u ) {
00169                         if ( $u->address ) {
00170                                 $has_address = true;
00171                                 break;
00172                         }
00173                 }
00174                 if ( !$has_address ) {
00175                         return Status::newFatal( 'user-mail-no-addy' );
00176                 }
00177 
00178                 # Forge email headers
00179                 # -------------------
00180                 #
00181                 # WARNING
00182                 #
00183                 # DO NOT add To: or Subject: headers at this step. They need to be
00184                 # handled differently depending upon the mailer we are going to use.
00185                 #
00186                 # To:
00187                 #  PHP mail() first argument is the mail receiver. The argument is
00188                 #  used as a recipient destination and as a To header.
00189                 #
00190                 #  PEAR mailer has a recipient argument which is only used to
00191                 #  send the mail. If no To header is given, PEAR will set it to
00192                 #  to 'undisclosed-recipients:'.
00193                 #
00194                 #  NOTE: To: is for presentation, the actual recipient is specified
00195                 #  by the mailer using the Rcpt-To: header.
00196                 #
00197                 # Subject: 
00198                 #  PHP mail() second argument to pass the subject, passing a Subject
00199                 #  as an additional header will result in a duplicate header.
00200                 #
00201                 #  PEAR mailer should be passed a Subject header.
00202                 #
00203                 # -- hashar 20120218
00204 
00205                 $headers['From'] = $from->toString();
00206                 $headers['Return-Path'] = $from->address;
00207 
00208                 if ( $replyto ) {
00209                         $headers['Reply-To'] = $replyto->toString();
00210                 }
00211 
00212                 $headers['Date'] = date( 'r' );
00213                 $headers['MIME-Version'] = '1.0';
00214                 $headers['Content-type'] = ( is_null( $contentType ) ?
00215                         'text/plain; charset=UTF-8' : $contentType );
00216                 $headers['Content-transfer-encoding'] = '8bit';
00217 
00218                 $headers['Message-ID'] = self::makeMsgId();
00219                 $headers['X-Mailer'] = 'MediaWiki mailer';
00220 
00221                 $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) );
00222                 if ( $ret === false ) {
00223                         return Status::newGood();
00224                 } elseif ( $ret !== true ) {
00225                         return Status::newFatal( 'php-mail-error', $ret );
00226                 }
00227 
00228                 if ( is_array( $wgSMTP ) ) {
00229                         #
00230                         # PEAR MAILER
00231                         # 
00232 
00233                         if ( function_exists( 'stream_resolve_include_path' ) ) {
00234                                 $found = stream_resolve_include_path( 'Mail.php' );
00235                         } else {
00236                                 $found = Fallback::stream_resolve_include_path( 'Mail.php' );
00237                         }
00238                         if ( !$found ) {
00239                                 throw new MWException( 'PEAR mail package is not installed' );
00240                         }
00241                         require_once( 'Mail.php' );
00242 
00243                         wfSuppressWarnings();
00244 
00245                         // Create the mail object using the Mail::factory method
00246                         $mail_object =& Mail::factory( 'smtp', $wgSMTP );
00247                         if ( PEAR::isError( $mail_object ) ) {
00248                                 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
00249                                 wfRestoreWarnings();
00250                                 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
00251                         }
00252 
00253                         wfDebug( "Sending mail via PEAR::Mail\n" );
00254 
00255                         $headers['Subject'] = self::quotedPrintable( $subject );
00256 
00257                         # When sending only to one recipient, shows it its email using To:
00258                         if ( count( $to ) == 1 ) {
00259                                 $headers['To'] = $to[0]->toString();
00260                         }
00261 
00262                         # Split jobs since SMTP servers tends to limit the maximum
00263                         # number of possible recipients.        
00264                         $chunks = array_chunk( $to, $wgEnotifMaxRecips );
00265                         foreach ( $chunks as $chunk ) {
00266                                 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
00267                                 # FIXME : some chunks might be sent while others are not!
00268                                 if ( !$status->isOK() ) {
00269                                         wfRestoreWarnings();
00270                                         return $status;
00271                                 }
00272                         }
00273                         wfRestoreWarnings();
00274                         return Status::newGood();
00275                 } else  {
00276                         # 
00277                         # PHP mail()
00278                         #
00279 
00280                         # Line endings need to be different on Unix and Windows due to
00281                         # the bug described at http://trac.wordpress.org/ticket/2603
00282                         if ( wfIsWindows() ) {
00283                                 $body = str_replace( "\n", "\r\n", $body );
00284                                 $endl = "\r\n";
00285                         } else {
00286                                 $endl = "\n";
00287                         }
00288 
00289                         if( count($to) > 1 ) {
00290                                 $headers['To'] = 'undisclosed-recipients:;';
00291                         }
00292                         $headers = self::arrayToHeaderString( $headers, $endl );
00293 
00294                         wfDebug( "Sending mail via internal mail() function\n" );
00295 
00296                         self::$mErrorString = '';
00297                         $html_errors = ini_get( 'html_errors' );
00298                         ini_set( 'html_errors', '0' );
00299                         set_error_handler( 'UserMailer::errorHandler' );
00300 
00301                         $safeMode = wfIniGetBool( 'safe_mode' );
00302                         foreach ( $to as $recip ) {
00303                                 if ( $safeMode ) {
00304                                         $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
00305                                 } else {
00306                                         $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
00307                                 }
00308                         }
00309 
00310                         restore_error_handler();
00311                         ini_set( 'html_errors', $html_errors );
00312 
00313                         if ( self::$mErrorString ) {
00314                                 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
00315                                 return Status::newFatal( 'php-mail-error', self::$mErrorString );
00316                         } elseif ( ! $sent ) {
00317                                 // mail function only tells if there's an error
00318                                 wfDebug( "Unknown error sending mail\n" );
00319                                 return Status::newFatal( 'php-mail-error-unknown' );
00320                         } else {
00321                                 return Status::newGood();
00322                         }
00323                 }
00324         }
00325 
00332         static function errorHandler( $code, $string ) {
00333                 self::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
00334         }
00335 
00341         public static function rfc822Phrase( $phrase ) {
00342                 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
00343                 return '"' . $phrase . '"';
00344         }
00345 
00351         public static function quotedPrintable( $string, $charset = '' ) {
00352                 # Probably incomplete; see RFC 2045
00353                 if( empty( $charset ) ) {
00354                         $charset = 'UTF-8';
00355                 }
00356                 $charset = strtoupper( $charset );
00357                 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
00358 
00359                 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
00360                 $replace = $illegal . '\t ?_';
00361                 if( !preg_match( "/[$illegal]/", $string ) ) {
00362                         return $string;
00363                 }
00364                 $out = "=?$charset?Q?";
00365                 $out .= preg_replace_callback( "/([$replace])/",
00366                         array( __CLASS__, 'quotedPrintableCallback' ), $string );
00367                 $out .= '?=';
00368                 return $out;
00369         }
00370 
00371         protected static function quotedPrintableCallback( $matches ) {
00372                 return sprintf( "=%02X", ord( $matches[1] ) );
00373         }
00374 }
00375 
00396 class EmailNotification {
00397         protected $subject, $body, $replyto, $from;
00398         protected $timestamp, $summary, $minorEdit, $oldid, $composed_common;
00399         protected $mailTargets = array();
00400 
00404         protected $title;
00405 
00409         protected $editor;
00410 
00424         public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
00425                 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
00426                         $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
00427 
00428                 if ( $title->getNamespace() < 0 ) {
00429                         return;
00430                 }
00431 
00432                 // Build a list of users to notfiy
00433                 $watchers = array();
00434                 if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
00435                         $dbw = wfGetDB( DB_MASTER );
00436                         $res = $dbw->select( array( 'watchlist' ),
00437                                 array( 'wl_user' ),
00438                                 array(
00439                                         'wl_user != ' . intval( $editor->getID() ),
00440                                         'wl_namespace' => $title->getNamespace(),
00441                                         'wl_title' => $title->getDBkey(),
00442                                         'wl_notificationtimestamp IS NULL',
00443                                 ), __METHOD__
00444                         );
00445                         foreach ( $res as $row ) {
00446                                 $watchers[] = intval( $row->wl_user );
00447                         }
00448                         if ( $watchers ) {
00449                                 // Update wl_notificationtimestamp for all watching users except
00450                                 // the editor
00451                                 $dbw->begin( __METHOD__ );
00452                                 $dbw->update( 'watchlist',
00453                                         array( /* SET */
00454                                                 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
00455                                         ), array( /* WHERE */
00456                                                 'wl_user' => $watchers,
00457                                                 'wl_namespace' => $title->getNamespace(),
00458                                                 'wl_title' => $title->getDBkey(),
00459                                         ), __METHOD__
00460                                 );
00461                                 $dbw->commit( __METHOD__ );
00462                         }
00463                 }
00464 
00465                 $sendEmail = true;
00466                 // If nobody is watching the page, and there are no users notified on all changes
00467                 // don't bother creating a job/trying to send emails
00468                 // $watchers deals with $wgEnotifWatchlist
00469                 if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
00470                         $sendEmail = false;
00471                         // Only send notification for non minor edits, unless $wgEnotifMinorEdits
00472                         if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
00473                                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00474                                 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
00475                                         $sendEmail = true;
00476                                 }
00477                         }
00478                 }
00479 
00480                 if ( !$sendEmail ) {
00481                         return;
00482                 }
00483                 if ( $wgEnotifUseJobQ ) {
00484                         $params = array(
00485                                 'editor' => $editor->getName(),
00486                                 'editorID' => $editor->getID(),
00487                                 'timestamp' => $timestamp,
00488                                 'summary' => $summary,
00489                                 'minorEdit' => $minorEdit,
00490                                 'oldid' => $oldid,
00491                                 'watchers' => $watchers
00492                         );
00493                         $job = new EnotifNotifyJob( $title, $params );
00494                         $job->insert();
00495                 } else {
00496                         $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
00497                 }
00498         }
00499 
00514         public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
00515                 # we use $wgPasswordSender as sender's address
00516                 global $wgEnotifWatchlist;
00517                 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
00518 
00519                 wfProfileIn( __METHOD__ );
00520 
00521                 # The following code is only run, if several conditions are met:
00522                 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
00523                 # 2. minor edits (changes) are only regarded if the global flag indicates so
00524 
00525                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00526 
00527                 $this->title = $title;
00528                 $this->timestamp = $timestamp;
00529                 $this->summary = $summary;
00530                 $this->minorEdit = $minorEdit;
00531                 $this->oldid = $oldid;
00532                 $this->editor = $editor;
00533                 $this->composed_common = false;
00534 
00535                 $userTalkId = false;
00536 
00537                 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
00538 
00539                         if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
00540                                 $targetUser = User::newFromName( $title->getText() );
00541                                 $this->compose( $targetUser );
00542                                 $userTalkId = $targetUser->getId();
00543                         }
00544 
00545                         if ( $wgEnotifWatchlist ) {
00546                                 // Send updates to watchers other than the current editor
00547                                 $userArray = UserArray::newFromIDs( $watchers );
00548                                 foreach ( $userArray as $watchingUser ) {
00549                                         if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
00550                                                 ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) &&
00551                                                 $watchingUser->isEmailConfirmed() &&
00552                                                 $watchingUser->getID() != $userTalkId )
00553                                         {
00554                                                 $this->compose( $watchingUser );
00555                                         }
00556                                 }
00557                         }
00558                 }
00559 
00560                 global $wgUsersNotifiedOnAllChanges;
00561                 foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
00562                         if ( $editor->getName() == $name ) {
00563                                 // No point notifying the user that actually made the change!
00564                                 continue;
00565                         }
00566                         $user = User::newFromName( $name );
00567                         $this->compose( $user );
00568                 }
00569 
00570                 $this->sendMails();
00571                 wfProfileOut( __METHOD__ );
00572         }
00573 
00580         private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
00581                 global $wgEnotifUserTalk;
00582                 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
00583 
00584                 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
00585                         $targetUser = User::newFromName( $title->getText() );
00586 
00587                         if ( !$targetUser || $targetUser->isAnon() ) {
00588                                 wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
00589                         } elseif ( $targetUser->getId() == $editor->getId() ) {
00590                                 wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
00591                         } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
00592                                 ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
00593                         {
00594                                 if ( $targetUser->isEmailConfirmed() ) {
00595                                         wfDebug( __METHOD__ . ": sending talk page update notification\n" );
00596                                         return true;
00597                                 } else {
00598                                         wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
00599                                 }
00600                         } else {
00601                                 wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
00602                         }
00603                 }
00604                 return false;
00605         }
00606 
00610         private function composeCommonMailtext() {
00611                 global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
00612                 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
00613                 global $wgEnotifImpersonal, $wgEnotifUseRealName;
00614 
00615                 $this->composed_common = true;
00616 
00617                 # You as the WikiAdmin and Sysops can make use of plenty of
00618                 # named variables when composing your notification emails while
00619                 # simply editing the Meta pages
00620 
00621                 $keys = array();
00622                 $postTransformKeys = array();
00623 
00624                 if ( $this->oldid ) {
00625                         // Always show a link to the diff which triggered the mail. See bug 32210.
00626                         $keys['$NEWPAGE'] = wfMessage( 'enotif_lastdiff',
00627                                 $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) )
00628                                 ->inContentLanguage()->text();
00629                         if ( !$wgEnotifImpersonal ) {
00630                                 // For personal mail, also show a link to the diff of all changes
00631                                 // since last visited.
00632                                 $keys['$NEWPAGE'] .= " \n" . wfMessage( 'enotif_lastvisited',
00633                                         $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) )
00634                                         ->inContentLanguage()->text();
00635                         }
00636                         $keys['$OLDID']   = $this->oldid;
00637                         $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
00638                 } else {
00639                         $keys['$NEWPAGE'] = wfMessage( 'enotif_newpagetext' )->inContentLanguage()->text();
00640                         # clear $OLDID placeholder in the message template
00641                         $keys['$OLDID']   = '';
00642                         $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
00643                 }
00644 
00645                 $keys['$PAGETITLE'] = $this->title->getPrefixedText();
00646                 $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
00647                 $keys['$PAGEMINOREDIT'] = $this->minorEdit ?
00648                         wfMessage( 'minoredit' )->inContentLanguage()->text() : '';
00649                 $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
00650 
00651                 if ( $this->editor->isAnon() ) {
00652                         # real anon (user:xxx.xxx.xxx.xxx)
00653                         $keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
00654                                 ->inContentLanguage()->text();
00655                         $keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
00656                 } else {
00657                         $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
00658                         $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
00659                         $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
00660                 }
00661 
00662                 $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalUrl();
00663 
00664                 # Replace this after transforming the message, bug 35019
00665                 $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
00666 
00667                 # Now build message's subject and body
00668 
00669                 $subject = wfMessage( 'enotif_subject' )->inContentLanguage()->plain();
00670                 $subject = strtr( $subject, $keys );
00671                 $subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
00672                 $this->subject = strtr( $subject, $postTransformKeys );
00673 
00674                 $body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
00675                 $body = strtr( $body, $keys );
00676                 $body = MessageCache::singleton()->transform( $body, false, null, $this->title );
00677                 $this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 );
00678 
00679                 # Reveal the page editor's address as REPLY-TO address only if
00680                 # the user has not opted-out and the option is enabled at the
00681                 # global configuration level.
00682                 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
00683                 if ( $wgEnotifRevealEditorAddress
00684                         && ( $this->editor->getEmail() != '' )
00685                         && $this->editor->getOption( 'enotifrevealaddr' ) )
00686                 {
00687                         $editorAddress = new MailAddress( $this->editor );
00688                         if ( $wgEnotifFromEditor ) {
00689                                 $this->from    = $editorAddress;
00690                         } else {
00691                                 $this->from    = $adminAddress;
00692                                 $this->replyto = $editorAddress;
00693                         }
00694                 } else {
00695                         $this->from    = $adminAddress;
00696                         $this->replyto = new MailAddress( $wgNoReplyAddress );
00697                 }
00698         }
00699 
00707         function compose( $user ) {
00708                 global $wgEnotifImpersonal;
00709 
00710                 if ( !$this->composed_common )
00711                         $this->composeCommonMailtext();
00712 
00713                 if ( $wgEnotifImpersonal ) {
00714                         $this->mailTargets[] = new MailAddress( $user );
00715                 } else {
00716                         $this->sendPersonalised( $user );
00717                 }
00718         }
00719 
00723         function sendMails() {
00724                 global $wgEnotifImpersonal;
00725                 if ( $wgEnotifImpersonal ) {
00726                         $this->sendImpersonal( $this->mailTargets );
00727                 }
00728         }
00729 
00739         function sendPersonalised( $watchingUser ) {
00740                 global $wgContLang, $wgEnotifUseRealName;
00741                 // From the PHP manual:
00742                 //     Note:  The to parameter cannot be an address in the form of "Something <[email protected]>".
00743                 //     The mail command will not parse this properly while talking with the MTA.
00744                 $to = new MailAddress( $watchingUser );
00745 
00746                 # $PAGEEDITDATE is the time and date of the page change
00747                 # expressed in terms of individual local time of the notification
00748                 # recipient, i.e. watching user
00749                 $body = str_replace(
00750                         array( '$WATCHINGUSERNAME',
00751                                 '$PAGEEDITDATE',
00752                                 '$PAGEEDITTIME' ),
00753                         array( $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName(),
00754                                 $wgContLang->userDate( $this->timestamp, $watchingUser ),
00755                                 $wgContLang->userTime( $this->timestamp, $watchingUser ) ),
00756                         $this->body );
00757 
00758                 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
00759         }
00760 
00766         function sendImpersonal( $addresses ) {
00767                 global $wgContLang;
00768 
00769                 if ( empty( $addresses ) )
00770                         return;
00771 
00772                 $body = str_replace(
00773                                 array( '$WATCHINGUSERNAME',
00774                                         '$PAGEEDITDATE',
00775                                         '$PAGEEDITTIME' ),
00776                                 array( wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
00777                                         $wgContLang->date( $this->timestamp, false, false ),
00778                                         $wgContLang->time( $this->timestamp, false, false ) ),
00779                                 $this->body );
00780 
00781                 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
00782         }
00783 
00784 } # end of class EmailNotification