r107920 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107919‎ | r107920 | r107921 >
Date:18:38, 3 January 2012
Author:ialex
Status:ok
Tags:
Comment:
Per request of Reedy, MFT r99942 and r99950
Modified paths:
  • /branches/REL1_18/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/includes/UserMailer.php
@@ -119,22 +119,14 @@
120120 * @return Status object
121121 */
122122 public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8') {
123 - global $wgSMTP, $wgEnotifImpersonal;
124 - global $wgEnotifMaxRecips, $wgAdditionalMailParams;
 123+ global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams;
125124
126 - if ( is_array( $to ) ) {
127 - $emails = '';
128 - // This wouldn't be necessary if implode() worked on arrays of
129 - // objects using __toString(). http://bugs.php.net/bug.php?id=36612
130 - foreach ( $to as $t ) {
131 - $emails .= $t->toString() . ",";
132 - }
133 - $emails = rtrim( $emails, ',' );
134 - wfDebug( __METHOD__ . ': sending mail to ' . $emails . "\n" );
135 - } else {
136 - wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
 125+ if ( !is_array( $to ) ) {
 126+ $to = array( $to );
137127 }
138128
 129+ wfDebug( __METHOD__ . ': sending mail to ' . implode( ', ', $to ) . "\n" );
 130+
139131 if ( is_array( $wgSMTP ) ) {
140132 if ( function_exists( 'stream_resolve_include_path' ) ) {
141133 $found = stream_resolve_include_path( 'Mail.php' );
@@ -161,13 +153,13 @@
162154 }
163155
164156 $headers['From'] = $from->toString();
165 - $headers['Return-Path'] = $from->toString();
 157+ $headers['Return-Path'] = $from->address;
166158
167 - if ( $wgEnotifImpersonal ) {
 159+ if ( count( $to ) > 1 ) {
168160 $headers['To'] = 'undisclosed-recipients:;';
169161 }
170162 else {
171 - $headers['To'] = implode( ", ", (array )$dest );
 163+ $headers['To'] = $to[0]->toString();
172164 }
173165
174166 if ( $replyto ) {
@@ -177,7 +169,7 @@
178170 $headers['Date'] = date( 'r' );
179171 $headers['MIME-Version'] = '1.0';
180172 $headers['Content-type'] = ( is_null( $contentType ) ?
181 - 'text/plain; charset=UTF-8' : $contentType );
 173+ 'text/plain; charset=UTF-8' : $contentType );
182174 $headers['Content-transfer-encoding'] = '8bit';
183175 // @todo FIXME
184176 $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>';
@@ -495,18 +487,11 @@
496488
497489 $this->composed_common = true;
498490
499 - $summary = ( $this->summary == '' ) ? ' - ' : $this->summary;
500 - $medit = ( $this->minorEdit ) ? wfMsgForContent( 'minoredit' ) : '';
501 -
502491 # You as the WikiAdmin and Sysops can make use of plenty of
503492 # named variables when composing your notification emails while
504493 # simply editing the Meta pages
505494
506 - $subject = wfMsgForContent( 'enotif_subject' );
507 - $body = wfMsgForContent( 'enotif_body' );
508 - $from = ''; /* fail safe */
509 - $replyto = ''; /* fail safe */
510 - $keys = array();
 495+ $keys = array();
511496
512497 if ( $this->oldid ) {
513498 $difflink = $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid );
@@ -520,69 +505,54 @@
521506 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
522507 }
523508
524 - if ( $wgEnotifImpersonal && $this->oldid ) {
525 - /**
526 - * For impersonal mail, show a diff link to the last
527 - * revision.
528 - */
529 - $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
530 - $this->title->getCanonicalUrl( "oldid={$this->oldid}&diff=next" ) );
 509+ $keys['$PAGETITLE'] = $this->title->getPrefixedText();
 510+ $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
 511+ $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMsgForContent( 'minoredit' ) : '';
 512+ $keys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
 513+ $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
 514+
 515+ if ( $this->editor->isAnon() ) {
 516+ # real anon (user:xxx.xxx.xxx.xxx)
 517+ $keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $this->editor->getName() );
 518+ $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
 519+ } else {
 520+ $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
 521+ $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
 522+ $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
531523 }
532524
533 - $body = strtr( $body, $keys );
534 - $pagetitle = $this->title->getPrefixedText();
535 - $keys['$PAGETITLE'] = $pagetitle;
536 - $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
 525+ $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalUrl();
537526
538 - $keys['$PAGEMINOREDIT'] = $medit;
539 - $keys['$PAGESUMMARY'] = $summary;
540 - $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
 527+ # Now build message's subject and body
541528
 529+ $subject = wfMsgExt( 'enotif_subject', 'content' );
542530 $subject = strtr( $subject, $keys );
 531+ $this->subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
543532
 533+ $body = wfMsgExt( 'enotif_body', 'content' );
 534+ $body = strtr( $body, $keys );
 535+ $body = MessageCache::singleton()->transform( $body, false, null, $this->title );
 536+ $this->body = wordwrap( $body, 72 );
 537+
544538 # Reveal the page editor's address as REPLY-TO address only if
545539 # the user has not opted-out and the option is enabled at the
546540 # global configuration level.
547 - $editor = $this->editor;
548 - $name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
549541 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
550 - $editorAddress = new MailAddress( $editor );
551542 if ( $wgEnotifRevealEditorAddress
552 - && ( $editor->getEmail() != '' )
553 - && $editor->getOption( 'enotifrevealaddr' ) ) {
 543+ && ( $this->editor->getEmail() != '' )
 544+ && $this->editor->getOption( 'enotifrevealaddr' ) )
 545+ {
 546+ $editorAddress = new MailAddress( $this->editor );
554547 if ( $wgEnotifFromEditor ) {
555 - $from = $editorAddress;
 548+ $this->from = $editorAddress;
556549 } else {
557 - $from = $adminAddress;
558 - $replyto = $editorAddress;
 550+ $this->from = $adminAddress;
 551+ $this->replyto = $editorAddress;
559552 }
560553 } else {
561 - $from = $adminAddress;
562 - $replyto = new MailAddress( $wgNoReplyAddress );
 554+ $this->from = $adminAddress;
 555+ $this->replyto = new MailAddress( $wgNoReplyAddress );
563556 }
564 -
565 - if ( $editor->isAnon() ) {
566 - # real anon (user:xxx.xxx.xxx.xxx)
567 - $utext = wfMsgForContent( 'enotif_anon_editor', $name );
568 - $subject = str_replace( '$PAGEEDITOR', $utext, $subject );
569 - $keys['$PAGEEDITOR'] = $utext;
570 - $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
571 - } else {
572 - $subject = str_replace( '$PAGEEDITOR', $name, $subject );
573 - $keys['$PAGEEDITOR'] = $name;
574 - $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
575 - $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
576 - }
577 - $userPage = $editor->getUserPage();
578 - $keys['$PAGEEDITOR_WIKI'] = $userPage->getCanonicalUrl();
579 - $body = strtr( $body, $keys );
580 - $body = wordwrap( $body, 72 );
581 -
582 - # now save this as the constant user-independent part of the message
583 - $this->from = $from;
584 - $this->replyto = $replyto;
585 - $this->subject = $subject;
586 - $this->body = $body;
587557 }
588558
589559 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r107948Merge r107920, so essentially merging r99942, r99950reedy22:06, 3 January 2012
r111538Note about fixing mail sent to exchange server...hashar14:26, 15 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99942* Do magic word parsing after parameter replacement in MediaWiki:Enotif_body ...ialex09:53, 16 October 2011
r99950* Send "undisclosed-recipients" in "To" header when sending the mail to more ...ialex12:39, 16 October 2011

Status & tagging log