MediaWiki
REL1_22
|
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 00083 class UserMailer { 00084 static $mErrorString; 00085 00096 protected static function sendWithPear( $mailer, $dest, $headers, $body ) { 00097 $mailResult = $mailer->send( $dest, $headers, $body ); 00098 00099 # Based on the result return an error string, 00100 if ( PEAR::isError( $mailResult ) ) { 00101 wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" ); 00102 return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() ); 00103 } else { 00104 return Status::newGood(); 00105 } 00106 } 00107 00120 static function arrayToHeaderString( $headers, $endl = "\n" ) { 00121 $strings = array(); 00122 foreach ( $headers as $name => $value ) { 00123 $strings[] = "$name: $value"; 00124 } 00125 return implode( $endl, $strings ); 00126 } 00127 00133 static function makeMsgId() { 00134 global $wgSMTP, $wgServer; 00135 00136 $msgid = uniqid( wfWikiID() . ".", true ); /* true required for cygwin */ 00137 if ( is_array( $wgSMTP ) && isset( $wgSMTP['IDHost'] ) && $wgSMTP['IDHost'] ) { 00138 $domain = $wgSMTP['IDHost']; 00139 } else { 00140 $url = wfParseUrl( $wgServer ); 00141 $domain = $url['host']; 00142 } 00143 return "<$msgid@$domain>"; 00144 } 00145 00161 public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) { 00162 global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail; 00163 $mime = null; 00164 if ( !is_array( $to ) ) { 00165 $to = array( $to ); 00166 } 00167 00168 // mail body must have some content 00169 $minBodyLen = 10; 00170 // arbitrary but longer than Array or Object to detect casting error 00171 00172 // body must either be a string or an array with text and body 00173 if ( 00174 !( 00175 !is_array( $body ) && 00176 strlen( $body ) >= $minBodyLen 00177 ) 00178 && 00179 !( 00180 is_array( $body ) && 00181 isset( $body['text'] ) && 00182 isset( $body['html'] ) && 00183 strlen( $body['text'] ) >= $minBodyLen && 00184 strlen( $body['html'] ) >= $minBodyLen 00185 ) 00186 ) { 00187 // if it is neither we have a problem 00188 return Status::newFatal( 'user-mail-no-body' ); 00189 } 00190 00191 if ( !$wgAllowHTMLEmail && is_array( $body ) ) { 00192 // HTML not wanted. Dump it. 00193 $body = $body['text']; 00194 } 00195 00196 wfDebug( __METHOD__ . ': sending mail to ' . implode( ', ', $to ) . "\n" ); 00197 00198 # Make sure we have at least one address 00199 $has_address = false; 00200 foreach ( $to as $u ) { 00201 if ( $u->address ) { 00202 $has_address = true; 00203 break; 00204 } 00205 } 00206 if ( !$has_address ) { 00207 return Status::newFatal( 'user-mail-no-addy' ); 00208 } 00209 00210 # Forge email headers 00211 # ------------------- 00212 # 00213 # WARNING 00214 # 00215 # DO NOT add To: or Subject: headers at this step. They need to be 00216 # handled differently depending upon the mailer we are going to use. 00217 # 00218 # To: 00219 # PHP mail() first argument is the mail receiver. The argument is 00220 # used as a recipient destination and as a To header. 00221 # 00222 # PEAR mailer has a recipient argument which is only used to 00223 # send the mail. If no To header is given, PEAR will set it to 00224 # to 'undisclosed-recipients:'. 00225 # 00226 # NOTE: To: is for presentation, the actual recipient is specified 00227 # by the mailer using the Rcpt-To: header. 00228 # 00229 # Subject: 00230 # PHP mail() second argument to pass the subject, passing a Subject 00231 # as an additional header will result in a duplicate header. 00232 # 00233 # PEAR mailer should be passed a Subject header. 00234 # 00235 # -- hashar 20120218 00236 00237 $headers['From'] = $from->toString(); 00238 $headers['Return-Path'] = $from->address; 00239 00240 if ( $replyto ) { 00241 $headers['Reply-To'] = $replyto->toString(); 00242 } 00243 00244 $headers['Date'] = MWTimestamp::getLocalInstance()->format( 'r' ); 00245 $headers['Message-ID'] = self::makeMsgId(); 00246 $headers['X-Mailer'] = 'MediaWiki mailer'; 00247 00248 # Line endings need to be different on Unix and Windows due to 00249 # the bug described at http://trac.wordpress.org/ticket/2603 00250 if ( wfIsWindows() ) { 00251 $endl = "\r\n"; 00252 } else { 00253 $endl = "\n"; 00254 } 00255 00256 if ( is_array( $body ) ) { 00257 // we are sending a multipart message 00258 wfDebug( "Assembling multipart mime email\n" ); 00259 if ( !stream_resolve_include_path( 'Mail/mime.php' ) ) { 00260 wfDebug( "PEAR Mail_Mime package is not installed. Falling back to text email.\n" ); 00261 // remove the html body for text email fall back 00262 $body = $body['text']; 00263 } 00264 else { 00265 require_once 'Mail/mime.php'; 00266 if ( wfIsWindows() ) { 00267 $body['text'] = str_replace( "\n", "\r\n", $body['text'] ); 00268 $body['html'] = str_replace( "\n", "\r\n", $body['html'] ); 00269 } 00270 $mime = new Mail_mime( array( 'eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8' ) ); 00271 $mime->setTXTBody( $body['text'] ); 00272 $mime->setHTMLBody( $body['html'] ); 00273 $body = $mime->get(); // must call get() before headers() 00274 $headers = $mime->headers( $headers ); 00275 } 00276 } 00277 if ( !isset( $mime ) ) { 00278 // sending text only, either deliberately or as a fallback 00279 if ( wfIsWindows() ) { 00280 $body = str_replace( "\n", "\r\n", $body ); 00281 } 00282 $headers['MIME-Version'] = '1.0'; 00283 $headers['Content-type'] = ( is_null( $contentType ) ? 00284 'text/plain; charset=UTF-8' : $contentType ); 00285 $headers['Content-transfer-encoding'] = '8bit'; 00286 } 00287 00288 $ret = wfRunHooks( 'AlternateUserMailer', array( $headers, $to, $from, $subject, $body ) ); 00289 if ( $ret === false ) { 00290 // the hook implementation will return false to skip regular mail sending 00291 return Status::newGood(); 00292 } elseif ( $ret !== true ) { 00293 // the hook implementation will return a string to pass an error message 00294 return Status::newFatal( 'php-mail-error', $ret ); 00295 } 00296 00297 if ( is_array( $wgSMTP ) ) { 00298 # 00299 # PEAR MAILER 00300 # 00301 00302 if ( !stream_resolve_include_path( 'Mail.php' ) ) { 00303 throw new MWException( 'PEAR mail package is not installed' ); 00304 } 00305 require_once 'Mail.php'; 00306 00307 wfSuppressWarnings(); 00308 00309 // Create the mail object using the Mail::factory method 00310 $mail_object =& Mail::factory( 'smtp', $wgSMTP ); 00311 if ( PEAR::isError( $mail_object ) ) { 00312 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" ); 00313 wfRestoreWarnings(); 00314 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() ); 00315 } 00316 00317 wfDebug( "Sending mail via PEAR::Mail\n" ); 00318 00319 $headers['Subject'] = self::quotedPrintable( $subject ); 00320 00321 # When sending only to one recipient, shows it its email using To: 00322 if ( count( $to ) == 1 ) { 00323 $headers['To'] = $to[0]->toString(); 00324 } 00325 00326 # Split jobs since SMTP servers tends to limit the maximum 00327 # number of possible recipients. 00328 $chunks = array_chunk( $to, $wgEnotifMaxRecips ); 00329 foreach ( $chunks as $chunk ) { 00330 $status = self::sendWithPear( $mail_object, $chunk, $headers, $body ); 00331 # FIXME : some chunks might be sent while others are not! 00332 if ( !$status->isOK() ) { 00333 wfRestoreWarnings(); 00334 return $status; 00335 } 00336 } 00337 wfRestoreWarnings(); 00338 return Status::newGood(); 00339 } else { 00340 # 00341 # PHP mail() 00342 # 00343 if ( count( $to ) > 1 ) { 00344 $headers['To'] = 'undisclosed-recipients:;'; 00345 } 00346 $headers = self::arrayToHeaderString( $headers, $endl ); 00347 00348 wfDebug( "Sending mail via internal mail() function\n" ); 00349 00350 self::$mErrorString = ''; 00351 $html_errors = ini_get( 'html_errors' ); 00352 ini_set( 'html_errors', '0' ); 00353 set_error_handler( 'UserMailer::errorHandler' ); 00354 00355 $safeMode = wfIniGetBool( 'safe_mode' ); 00356 00357 foreach ( $to as $recip ) { 00358 if ( $safeMode ) { 00359 $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers ); 00360 } else { 00361 $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); 00362 } 00363 } 00364 00365 restore_error_handler(); 00366 ini_set( 'html_errors', $html_errors ); 00367 00368 if ( self::$mErrorString ) { 00369 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" ); 00370 return Status::newFatal( 'php-mail-error', self::$mErrorString ); 00371 } elseif ( ! $sent ) { 00372 // mail function only tells if there's an error 00373 wfDebug( "Unknown error sending mail\n" ); 00374 return Status::newFatal( 'php-mail-error-unknown' ); 00375 } else { 00376 return Status::newGood(); 00377 } 00378 } 00379 } 00380 00387 static function errorHandler( $code, $string ) { 00388 self::$mErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string ); 00389 } 00390 00396 public static function rfc822Phrase( $phrase ) { 00397 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) ); 00398 return '"' . $phrase . '"'; 00399 } 00400 00412 public static function quotedPrintable( $string, $charset = '' ) { 00413 # Probably incomplete; see RFC 2045 00414 if ( empty( $charset ) ) { 00415 $charset = 'UTF-8'; 00416 } 00417 $charset = strtoupper( $charset ); 00418 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ? 00419 00420 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff='; 00421 $replace = $illegal . '\t ?_'; 00422 if ( !preg_match( "/[$illegal]/", $string ) ) { 00423 return $string; 00424 } 00425 $out = "=?$charset?Q?"; 00426 $out .= preg_replace_callback( "/([$replace])/", 00427 array( __CLASS__, 'quotedPrintableCallback' ), $string ); 00428 $out .= '?='; 00429 return $out; 00430 } 00431 00432 protected static function quotedPrintableCallback( $matches ) { 00433 return sprintf( "=%02X", ord( $matches[1] ) ); 00434 } 00435 } 00436 00457 class EmailNotification { 00458 protected $subject, $body, $replyto, $from; 00459 protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus; 00460 protected $mailTargets = array(); 00461 00465 protected $title; 00466 00470 protected $editor; 00471 00486 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $pageStatus = 'changed' ) { 00487 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits, 00488 $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk; 00489 00490 if ( $title->getNamespace() < 0 ) { 00491 return; 00492 } 00493 00494 // Build a list of users to notify 00495 $watchers = array(); 00496 if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) { 00497 $dbw = wfGetDB( DB_MASTER ); 00498 $res = $dbw->select( array( 'watchlist' ), 00499 array( 'wl_user' ), 00500 array( 00501 'wl_user != ' . intval( $editor->getID() ), 00502 'wl_namespace' => $title->getNamespace(), 00503 'wl_title' => $title->getDBkey(), 00504 'wl_notificationtimestamp IS NULL', 00505 ), __METHOD__ 00506 ); 00507 foreach ( $res as $row ) { 00508 $watchers[] = intval( $row->wl_user ); 00509 } 00510 if ( $watchers ) { 00511 // Update wl_notificationtimestamp for all watching users except the editor 00512 $fname = __METHOD__; 00513 $dbw->onTransactionIdle( 00514 function() use ( $dbw, $timestamp, $watchers, $title, $fname ) { 00515 $dbw->begin( $fname ); 00516 $dbw->update( 'watchlist', 00517 array( /* SET */ 00518 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) 00519 ), array( /* WHERE */ 00520 'wl_user' => $watchers, 00521 'wl_namespace' => $title->getNamespace(), 00522 'wl_title' => $title->getDBkey(), 00523 ), $fname 00524 ); 00525 $dbw->commit( $fname ); 00526 } 00527 ); 00528 } 00529 } 00530 00531 $sendEmail = true; 00532 // If nobody is watching the page, and there are no users notified on all changes 00533 // don't bother creating a job/trying to send emails 00534 // $watchers deals with $wgEnotifWatchlist 00535 if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) { 00536 $sendEmail = false; 00537 // Only send notification for non minor edits, unless $wgEnotifMinorEdits 00538 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) { 00539 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK ); 00540 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) { 00541 $sendEmail = true; 00542 } 00543 } 00544 } 00545 00546 if ( !$sendEmail ) { 00547 return; 00548 } 00549 if ( $wgEnotifUseJobQ ) { 00550 $params = array( 00551 'editor' => $editor->getName(), 00552 'editorID' => $editor->getID(), 00553 'timestamp' => $timestamp, 00554 'summary' => $summary, 00555 'minorEdit' => $minorEdit, 00556 'oldid' => $oldid, 00557 'watchers' => $watchers, 00558 'pageStatus' => $pageStatus 00559 ); 00560 $job = new EnotifNotifyJob( $title, $params ); 00561 JobQueueGroup::singleton()->push( $job ); 00562 } else { 00563 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus ); 00564 } 00565 } 00566 00583 public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, 00584 $oldid, $watchers, $pageStatus = 'changed' ) { 00585 # we use $wgPasswordSender as sender's address 00586 global $wgEnotifWatchlist; 00587 global $wgEnotifMinorEdits, $wgEnotifUserTalk; 00588 00589 wfProfileIn( __METHOD__ ); 00590 00591 # The following code is only run, if several conditions are met: 00592 # 1. EmailNotification for pages (other than user_talk pages) must be enabled 00593 # 2. minor edits (changes) are only regarded if the global flag indicates so 00594 00595 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK ); 00596 00597 $this->title = $title; 00598 $this->timestamp = $timestamp; 00599 $this->summary = $summary; 00600 $this->minorEdit = $minorEdit; 00601 $this->oldid = $oldid; 00602 $this->editor = $editor; 00603 $this->composed_common = false; 00604 $this->pageStatus = $pageStatus; 00605 00606 $formattedPageStatus = array( 'deleted', 'created', 'moved', 'restored', 'changed' ); 00607 00608 wfRunHooks( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) ); 00609 if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) { 00610 wfProfileOut( __METHOD__ ); 00611 throw new MWException( 'Not a valid page status!' ); 00612 } 00613 00614 $userTalkId = false; 00615 00616 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) { 00617 00618 if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) { 00619 $targetUser = User::newFromName( $title->getText() ); 00620 $this->compose( $targetUser ); 00621 $userTalkId = $targetUser->getId(); 00622 } 00623 00624 if ( $wgEnotifWatchlist ) { 00625 // Send updates to watchers other than the current editor 00626 $userArray = UserArray::newFromIDs( $watchers ); 00627 foreach ( $userArray as $watchingUser ) { 00628 if ( $watchingUser->getOption( 'enotifwatchlistpages' ) && 00629 ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) && 00630 $watchingUser->isEmailConfirmed() && 00631 $watchingUser->getID() != $userTalkId ) 00632 { 00633 $this->compose( $watchingUser ); 00634 } 00635 } 00636 } 00637 } 00638 00639 global $wgUsersNotifiedOnAllChanges; 00640 foreach ( $wgUsersNotifiedOnAllChanges as $name ) { 00641 if ( $editor->getName() == $name ) { 00642 // No point notifying the user that actually made the change! 00643 continue; 00644 } 00645 $user = User::newFromName( $name ); 00646 $this->compose( $user ); 00647 } 00648 00649 $this->sendMails(); 00650 wfProfileOut( __METHOD__ ); 00651 } 00652 00659 private function canSendUserTalkEmail( $editor, $title, $minorEdit ) { 00660 global $wgEnotifUserTalk; 00661 $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK ); 00662 00663 if ( $wgEnotifUserTalk && $isUserTalkPage ) { 00664 $targetUser = User::newFromName( $title->getText() ); 00665 00666 if ( !$targetUser || $targetUser->isAnon() ) { 00667 wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" ); 00668 } elseif ( $targetUser->getId() == $editor->getId() ) { 00669 wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" ); 00670 } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) && 00671 ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) ) 00672 { 00673 if ( !$targetUser->isEmailConfirmed() ) { 00674 wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" ); 00675 } elseif ( !wfRunHooks( 'AbortTalkPageEmailNotification', array( $targetUser, $title ) ) ) { 00676 wfDebug( __METHOD__ . ": talk page update notification is aborted for this user\n" ); 00677 } else { 00678 wfDebug( __METHOD__ . ": sending talk page update notification\n" ); 00679 return true; 00680 } 00681 } else { 00682 wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" ); 00683 } 00684 } 00685 return false; 00686 } 00687 00691 private function composeCommonMailtext() { 00692 global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress; 00693 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress; 00694 global $wgEnotifImpersonal, $wgEnotifUseRealName; 00695 00696 $this->composed_common = true; 00697 00698 # You as the WikiAdmin and Sysops can make use of plenty of 00699 # named variables when composing your notification emails while 00700 # simply editing the Meta pages 00701 00702 $keys = array(); 00703 $postTransformKeys = array(); 00704 $pageTitleUrl = $this->title->getCanonicalURL(); 00705 $pageTitle = $this->title->getPrefixedText(); 00706 00707 if ( $this->oldid ) { 00708 // Always show a link to the diff which triggered the mail. See bug 32210. 00709 $keys['$NEWPAGE'] = "\n\n" . wfMessage( 'enotif_lastdiff', 00710 $this->title->getCanonicalURL( array( 'diff' => 'next', 'oldid' => $this->oldid ) ) ) 00711 ->inContentLanguage()->text(); 00712 00713 if ( !$wgEnotifImpersonal ) { 00714 // For personal mail, also show a link to the diff of all changes 00715 // since last visited. 00716 $keys['$NEWPAGE'] .= "\n\n" . wfMessage( 'enotif_lastvisited', 00717 $this->title->getCanonicalURL( array( 'diff' => '0', 'oldid' => $this->oldid ) ) ) 00718 ->inContentLanguage()->text(); 00719 } 00720 $keys['$OLDID'] = $this->oldid; 00721 // @deprecated Remove in MediaWiki 1.23. 00722 $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text(); 00723 } else { 00724 # clear $OLDID placeholder in the message template 00725 $keys['$OLDID'] = ''; 00726 $keys['$NEWPAGE'] = ''; 00727 // @deprecated Remove in MediaWiki 1.23. 00728 $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text(); 00729 } 00730 00731 $keys['$PAGETITLE'] = $this->title->getPrefixedText(); 00732 $keys['$PAGETITLE_URL'] = $this->title->getCanonicalURL(); 00733 $keys['$PAGEMINOREDIT'] = $this->minorEdit ? 00734 wfMessage( 'minoredit' )->inContentLanguage()->text() : ''; 00735 $keys['$UNWATCHURL'] = $this->title->getCanonicalURL( 'action=unwatch' ); 00736 00737 if ( $this->editor->isAnon() ) { 00738 # real anon (user:xxx.xxx.xxx.xxx) 00739 $keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() ) 00740 ->inContentLanguage()->text(); 00741 $keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text(); 00742 00743 } else { 00744 $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName(); 00745 $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() ); 00746 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL(); 00747 } 00748 00749 $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL(); 00750 $keys['$HELPPAGE'] = wfExpandUrl( Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ) ); 00751 00752 # Replace this after transforming the message, bug 35019 00753 $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary; 00754 00755 // Now build message's subject and body 00756 00757 // Messages: 00758 // enotif_subject_deleted, enotif_subject_created, enotif_subject_moved, 00759 // enotif_subject_restored, enotif_subject_changed 00760 $this->subject = wfMessage( 'enotif_subject_' . $this->pageStatus )->inContentLanguage() 00761 ->params( $pageTitle, $keys['$PAGEEDITOR'] )->text(); 00762 00763 // Messages: 00764 // enotif_body_intro_deleted, enotif_body_intro_created, enotif_body_intro_moved, 00765 // enotif_body_intro_restored, enotif_body_intro_changed 00766 $keys['$PAGEINTRO'] = wfMessage( 'enotif_body_intro_' . $this->pageStatus ) 00767 ->inContentLanguage()->params( $pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl ) 00768 ->text(); 00769 00770 $body = wfMessage( 'enotif_body' )->inContentLanguage()->plain(); 00771 $body = strtr( $body, $keys ); 00772 $body = MessageCache::singleton()->transform( $body, false, null, $this->title ); 00773 $this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 ); 00774 00775 # Reveal the page editor's address as REPLY-TO address only if 00776 # the user has not opted-out and the option is enabled at the 00777 # global configuration level. 00778 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName ); 00779 if ( $wgEnotifRevealEditorAddress 00780 && ( $this->editor->getEmail() != '' ) 00781 && $this->editor->getOption( 'enotifrevealaddr' ) ) 00782 { 00783 $editorAddress = new MailAddress( $this->editor ); 00784 if ( $wgEnotifFromEditor ) { 00785 $this->from = $editorAddress; 00786 } else { 00787 $this->from = $adminAddress; 00788 $this->replyto = $editorAddress; 00789 } 00790 } else { 00791 $this->from = $adminAddress; 00792 $this->replyto = new MailAddress( $wgNoReplyAddress ); 00793 } 00794 } 00795 00803 function compose( $user ) { 00804 global $wgEnotifImpersonal; 00805 00806 if ( !$this->composed_common ) { 00807 $this->composeCommonMailtext(); 00808 } 00809 00810 if ( $wgEnotifImpersonal ) { 00811 $this->mailTargets[] = new MailAddress( $user ); 00812 } else { 00813 $this->sendPersonalised( $user ); 00814 } 00815 } 00816 00820 function sendMails() { 00821 global $wgEnotifImpersonal; 00822 if ( $wgEnotifImpersonal ) { 00823 $this->sendImpersonal( $this->mailTargets ); 00824 } 00825 } 00826 00836 function sendPersonalised( $watchingUser ) { 00837 global $wgContLang, $wgEnotifUseRealName; 00838 // From the PHP manual: 00839 // Note: The to parameter cannot be an address in the form of "Something <[email protected]>". 00840 // The mail command will not parse this properly while talking with the MTA. 00841 $to = new MailAddress( $watchingUser ); 00842 00843 # $PAGEEDITDATE is the time and date of the page change 00844 # expressed in terms of individual local time of the notification 00845 # recipient, i.e. watching user 00846 $body = str_replace( 00847 array( '$WATCHINGUSERNAME', 00848 '$PAGEEDITDATE', 00849 '$PAGEEDITTIME' ), 00850 array( $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName(), 00851 $wgContLang->userDate( $this->timestamp, $watchingUser ), 00852 $wgContLang->userTime( $this->timestamp, $watchingUser ) ), 00853 $this->body ); 00854 00855 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto ); 00856 } 00857 00864 function sendImpersonal( $addresses ) { 00865 global $wgContLang; 00866 00867 if ( empty( $addresses ) ) { 00868 return null; 00869 } 00870 00871 $body = str_replace( 00872 array( '$WATCHINGUSERNAME', 00873 '$PAGEEDITDATE', 00874 '$PAGEEDITTIME' ), 00875 array( wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(), 00876 $wgContLang->date( $this->timestamp, false, false ), 00877 $wgContLang->time( $this->timestamp, false, false ) ), 00878 $this->body ); 00879 00880 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto ); 00881 } 00882 00883 } # end of class EmailNotification