r77715 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77714‎ | r77715 | r77716 >
Date:13:39, 4 December 2010
Author:ialex
Status:ok
Tags:
Comment:
Stylise UserMailer.php ; added some "public" to public functions
Modified paths:
  • /trunk/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UserMailer.php
@@ -36,7 +36,7 @@
3737 * @param $realName String: human-readable real name if a string address is given
3838 */
3939 function __construct( $address, $name = null, $realName = null ) {
40 - if( is_object( $address ) && $address instanceof User ) {
 40+ if ( is_object( $address ) && $address instanceof User ) {
4141 $this->address = $address->getEmail();
4242 $this->name = $address->getName();
4343 $this->realName = $address->getRealName();
@@ -55,11 +55,11 @@
5656 # PHP's mail() implementation under Windows is somewhat shite, and
5757 # can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
5858 # so don't bother generating them
59 - if( $this->name != '' && !wfIsWindows() ) {
 59+ if ( $this->name != '' && !wfIsWindows() ) {
6060 global $wgEnotifUseRealName;
6161 $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
6262 $quoted = wfQuotedPrintable( $name );
63 - if( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
 63+ if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
6464 $quoted = '"' . $quoted . '"';
6565 }
6666 return "$quoted <{$this->address}>";
@@ -79,16 +79,15 @@
8080 */
8181 class UserMailer {
8282 static $mErrorString;
83 -
 83+
8484 /**
8585 * Send mail using a PEAR mailer
8686 */
87 - protected static function sendWithPear($mailer, $dest, $headers, $body)
88 - {
89 - $mailResult = $mailer->send($dest, $headers, $body);
 87+ protected static function sendWithPear( $mailer, $dest, $headers, $body ) {
 88+ $mailResult = $mailer->send( $dest, $headers, $body );
9089
9190 # Based on the result return an error string,
92 - if( PEAR::isError( $mailResult ) ) {
 91+ if ( PEAR::isError( $mailResult ) ) {
9392 wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
9493 return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
9594 } else {
@@ -110,23 +109,23 @@
111110 * @param $contentType String: optional custom Content-Type
112111 * @return Status object
113112 */
114 - static function send( $to, $from, $subject, $body, $replyto=null, $contentType=null ) {
 113+ public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = null ) {
115114 global $wgSMTP, $wgOutputEncoding, $wgEnotifImpersonal;
116115 global $wgEnotifMaxRecips, $wgAdditionalMailParams;
117116
118117 if ( is_array( $to ) ) {
119118 // This wouldn't be necessary if implode() worked on arrays of
120119 // objects using __toString(). http://bugs.php.net/bug.php?id=36612
121 - foreach( $to as $t ) {
 120+ foreach ( $to as $t ) {
122121 $emails .= $t->toString() . ",";
123122 }
124123 $emails = rtrim( $emails, ',' );
125 - wfDebug( __METHOD__.': sending mail to ' . $emails . "\n" );
 124+ wfDebug( __METHOD__ . ': sending mail to ' . $emails . "\n" );
126125 } else {
127 - wfDebug( __METHOD__.': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
 126+ wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
128127 }
129128
130 - if (is_array( $wgSMTP )) {
 129+ if ( is_array( $wgSMTP ) ) {
131130 $found = false;
132131 $pathArray = explode( PATH_SEPARATOR, get_include_path() );
133132 foreach ( $pathArray as $path ) {
@@ -140,20 +139,20 @@
141140 }
142141 require_once( 'Mail.php' );
143142
144 - $msgid = str_replace(" ", "_", microtime());
145 - if (function_exists('posix_getpid'))
 143+ $msgid = str_replace( " ", "_", microtime() );
 144+ if ( function_exists( 'posix_getpid' ) )
146145 $msgid .= '.' . posix_getpid();
147146
148 - if (is_array($to)) {
 147+ if ( is_array( $to ) ) {
149148 $dest = array();
150 - foreach ($to as $u)
 149+ foreach ( $to as $u )
151150 $dest[] = $u->address;
152151 } else
153152 $dest = $to->address;
154153
155154 $headers['From'] = $from->toString();
156155
157 - if ($wgEnotifImpersonal) {
 156+ if ( $wgEnotifImpersonal ) {
158157 $headers['To'] = 'undisclosed-recipients:;';
159158 }
160159 else {
@@ -166,8 +165,8 @@
167166 $headers['Subject'] = wfQuotedPrintable( $subject );
168167 $headers['Date'] = date( 'r' );
169168 $headers['MIME-Version'] = '1.0';
170 - $headers['Content-type'] = (is_null($contentType) ?
171 - 'text/plain; charset='.$wgOutputEncoding : $contentType);
 169+ $headers['Content-type'] = ( is_null( $contentType ) ?
 170+ 'text/plain; charset=' . $wgOutputEncoding : $contentType );
172171 $headers['Content-transfer-encoding'] = '8bit';
173172 $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME
174173 $headers['X-Mailer'] = 'MediaWiki mailer';
@@ -175,8 +174,8 @@
176175 wfSuppressWarnings();
177176
178177 // Create the mail object using the Mail::factory method
179 - $mail_object =& Mail::factory('smtp', $wgSMTP);
180 - if( PEAR::isError( $mail_object ) ) {
 178+ $mail_object =& Mail::factory( 'smtp', $wgSMTP );
 179+ if ( PEAR::isError( $mail_object ) ) {
181180 wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
182181 wfRestoreWarnings();
183182 return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
@@ -184,9 +183,9 @@
185184
186185 wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
187186 $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
188 - foreach ($chunks as $chunk) {
189 - $status = self::sendWithPear($mail_object, $chunk, $headers, $body);
190 - if( !$status->isOK() ) {
 187+ foreach ( $chunks as $chunk ) {
 188+ $status = self::sendWithPear( $mail_object, $chunk, $headers, $body );
 189+ if ( !$status->isOK() ) {
191190 wfRestoreWarnings();
192191 return $status;
193192 }
@@ -205,27 +204,27 @@
206205 } else {
207206 $endl = "\n";
208207 }
209 - $ctype = (is_null($contentType) ?
210 - 'text/plain; charset='.$wgOutputEncoding : $contentType);
 208+ $ctype = ( is_null( $contentType ) ?
 209+ 'text/plain; charset=' . $wgOutputEncoding : $contentType );
211210 $headers =
212211 "MIME-Version: 1.0$endl" .
213212 "Content-type: $ctype$endl" .
214213 "Content-Transfer-Encoding: 8bit$endl" .
215 - "X-Mailer: MediaWiki mailer$endl".
 214+ "X-Mailer: MediaWiki mailer$endl" .
216215 'From: ' . $from->toString();
217 - if ($replyto) {
 216+ if ( $replyto ) {
218217 $headers .= "{$endl}Reply-To: " . $replyto->toString();
219218 }
220219
221220 wfDebug( "Sending mail via internal mail() function\n" );
222 -
 221+
223222 self::$mErrorString = '';
224223 $html_errors = ini_get( 'html_errors' );
225224 ini_set( 'html_errors', '0' );
226225 set_error_handler( array( 'UserMailer', 'errorHandler' ) );
227226
228 - if (is_array($to)) {
229 - foreach ($to as $recip) {
 227+ if ( is_array( $to ) ) {
 228+ foreach ( $to as $recip ) {
230229 $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
231230 }
232231 } else {
@@ -238,8 +237,8 @@
239238 if ( self::$mErrorString ) {
240239 wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
241240 return Status::newFatal( 'php-mail-error', self::$mErrorString );
242 - } elseif (! $sent ) {
243 - //mail function only tells if there's an error
 241+ } elseif ( ! $sent ) {
 242+ // mail function only tells if there's an error
244243 wfDebug( "Error sending mail\n" );
245244 return Status::newFatal( 'php-mail-error-unknown' );
246245 } else {
@@ -261,7 +260,7 @@
262261 /**
263262 * Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
264263 */
265 - static function rfc822Phrase( $phrase ) {
 264+ public static function rfc822Phrase( $phrase ) {
266265 $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
267266 return '"' . $phrase . '"';
268267 }
@@ -305,15 +304,15 @@
306305 * @param $minorEdit
307306 * @param $oldid (default: false)
308307 */
309 - function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) {
 308+ public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
310309 global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
311310
312 - if ($title->getNamespace() < 0)
 311+ if ( $title->getNamespace() < 0 )
313312 return;
314313
315314 // Build a list of users to notfiy
316315 $watchers = array();
317 - if ($wgEnotifWatchlist || $wgShowUpdatedMarker) {
 316+ if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
318317 $dbw = wfGetDB( DB_MASTER );
319318 $res = $dbw->select( array( 'watchlist' ),
320319 array( 'wl_user' ),
@@ -327,7 +326,7 @@
328327 foreach ( $res as $row ) {
329328 $watchers[] = intval( $row->wl_user );
330329 }
331 - if ($watchers) {
 330+ if ( $watchers ) {
332331 // Update wl_notificationtimestamp for all watching users except
333332 // the editor
334333 $dbw->begin();
@@ -344,7 +343,7 @@
345344 }
346345 }
347346
348 - if ($wgEnotifUseJobQ) {
 347+ if ( $wgEnotifUseJobQ ) {
349348 $params = array(
350349 "editor" => $editor->getName(),
351350 "editorID" => $editor->getID(),
@@ -352,7 +351,7 @@
353352 "summary" => $summary,
354353 "minorEdit" => $minorEdit,
355354 "oldid" => $oldid,
356 - "watchers" => $watchers);
 355+ "watchers" => $watchers );
357356 $job = new EnotifNotifyJob( $title, $params );
358357 $job->insert();
359358 } else {
@@ -375,7 +374,7 @@
376375 * @param $oldid int Revision ID
377376 * @param $watchers array of user IDs
378377 */
379 - function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers) {
 378+ public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
380379 # we use $wgPasswordSender as sender's address
381380 global $wgEnotifWatchlist;
382381 global $wgEnotifMinorEdits, $wgEnotifUserTalk;
@@ -386,7 +385,7 @@
387386 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
388387 # 2. minor edits (changes) are only regarded if the global flag indicates so
389388
390 - $isUserTalkPage = ($title->getNamespace() == NS_USER_TALK);
 389+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
391390
392391 $this->title = $title;
393392 $this->timestamp = $timestamp;
@@ -398,23 +397,23 @@
399398
400399 $userTalkId = false;
401400
402 - if ( !$minorEdit || ($wgEnotifMinorEdits && !$editor->isAllowed('nominornewtalk') ) ) {
 401+ if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
403402 if ( $wgEnotifUserTalk && $isUserTalkPage ) {
404403 $targetUser = User::newFromName( $title->getText() );
405404 if ( !$targetUser || $targetUser->isAnon() ) {
406 - wfDebug( __METHOD__.": user talk page edited, but user does not exist\n" );
 405+ wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
407406 } elseif ( $targetUser->getId() == $editor->getId() ) {
408 - wfDebug( __METHOD__.": user edited their own talk page, no notification sent\n" );
409 - } elseif( $targetUser->getOption( 'enotifusertalkpages' ) ) {
410 - if( $targetUser->isEmailConfirmed() ) {
411 - wfDebug( __METHOD__.": sending talk page update notification\n" );
 407+ wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
 408+ } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) ) {
 409+ if ( $targetUser->isEmailConfirmed() ) {
 410+ wfDebug( __METHOD__ . ": sending talk page update notification\n" );
412411 $this->compose( $targetUser );
413412 $userTalkId = $targetUser->getId();
414413 } else {
415 - wfDebug( __METHOD__.": talk page owner doesn't have validated email\n" );
 414+ wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
416415 }
417416 } else {
418 - wfDebug( __METHOD__.": talk page owner doesn't want notifications\n" );
 417+ wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
419418 }
420419 }
421420
@@ -423,7 +422,7 @@
424423 $userArray = UserArray::newFromIDs( $watchers );
425424 foreach ( $userArray as $watchingUser ) {
426425 if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
427 - ( !$minorEdit || $watchingUser->getOption('enotifminoredits') ) &&
 426+ ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) ) &&
428427 $watchingUser->isEmailConfirmed() &&
429428 $watchingUser->getID() != $userTalkId )
430429 {
@@ -453,8 +452,8 @@
454453
455454 $this->composed_common = true;
456455
457 - $summary = ($this->summary == '') ? ' - ' : $this->summary;
458 - $medit = ($this->minorEdit) ? wfMsgForContent( 'minoredit' ) : '';
 456+ $summary = ( $this->summary == '' ) ? ' - ' : $this->summary;
 457+ $medit = ( $this->minorEdit ) ? wfMsgForContent( 'minoredit' ) : '';
459458
460459 # You as the WikiAdmin and Sysops can make use of plenty of
461460 # named variables when composing your notification emails while
@@ -466,7 +465,7 @@
467466 $replyto = ''; /* fail safe */
468467 $keys = array();
469468
470 - if( $this->oldid ) {
 469+ if ( $this->oldid ) {
471470 $difflink = $this->title->getFullUrl( 'diff=0&oldid=' . $this->oldid );
472471 $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
473472 $keys['$OLDID'] = $this->oldid;
@@ -478,13 +477,13 @@
479478 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
480479 }
481480
482 - if ($wgEnotifImpersonal && $this->oldid) {
 481+ if ( $wgEnotifImpersonal && $this->oldid ) {
483482 /*
484483 * For impersonal mail, show a diff link to the last
485484 * revision.
486485 */
487 - $keys['$NEWPAGE'] = wfMsgForContent('enotif_lastdiff',
488 - $this->title->getFullURL("oldid={$this->oldid}&diff=next"));
 486+ $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
 487+ $this->title->getFullURL( "oldid={$this->oldid}&diff=next" ) );
489488 }
490489
491490 $body = strtr( $body, $keys );
@@ -505,10 +504,10 @@
506505 $name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
507506 $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
508507 $editorAddress = new MailAddress( $editor );
509 - if( $wgEnotifRevealEditorAddress
 508+ if ( $wgEnotifRevealEditorAddress
510509 && ( $editor->getEmail() != '' )
511510 && $editor->getOption( 'enotifrevealaddr' ) ) {
512 - if( $wgEnotifFromEditor ) {
 511+ if ( $wgEnotifFromEditor ) {
513512 $from = $editorAddress;
514513 } else {
515514 $from = $adminAddress;
@@ -519,14 +518,14 @@
520519 $replyto = new MailAddress( $wgNoReplyAddress );
521520 }
522521
523 - if( $editor->isIP( $name ) ) {
524 - #real anon (user:xxx.xxx.xxx.xxx)
525 - $utext = wfMsgForContent('enotif_anon_editor', $name);
526 - $subject = str_replace('$PAGEEDITOR', $utext, $subject);
 522+ if ( $editor->isIP( $name ) ) {
 523+ # real anon (user:xxx.xxx.xxx.xxx)
 524+ $utext = wfMsgForContent( 'enotif_anon_editor', $name );
 525+ $subject = str_replace( '$PAGEEDITOR', $utext, $subject );
527526 $keys['$PAGEEDITOR'] = $utext;
528527 $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
529528 } else {
530 - $subject = str_replace('$PAGEEDITOR', $name, $subject);
 529+ $subject = str_replace( '$PAGEEDITOR', $name, $subject );
531530 $keys['$PAGEEDITOR'] = $name;
532531 $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
533532 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
@@ -588,7 +587,7 @@
589588 // The mail command will not parse this properly while talking with the MTA.
590589 $to = new MailAddress( $watchingUser );
591590 $name = $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName();
592 - $body = str_replace( '$WATCHINGUSERNAME', $name , $this->body );
 591+ $body = str_replace( '$WATCHINGUSERNAME', $name, $this->body );
593592
594593 $timecorrection = $watchingUser->getOption( 'timecorrection' );
595594
@@ -596,15 +595,15 @@
597596 # expressed in terms of individual local time of the notification
598597 # recipient, i.e. watching user
599598 $body = str_replace(
600 - array( '$PAGEEDITDATEANDTIME',
 599+ array( '$PAGEEDITDATEANDTIME',
601600 '$PAGEEDITDATE',
602601 '$PAGEEDITTIME' ),
603 - array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
 602+ array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
604603 $wgContLang->date( $this->timestamp, true, false, $timecorrection ),
605604 $wgContLang->time( $this->timestamp, true, false, $timecorrection ) ),
606 - $body);
 605+ $body );
607606
608 - return UserMailer::send($to, $this->from, $this->subject, $body, $this->replyto);
 607+ return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
609608 }
610609
611610 /**
@@ -614,17 +613,17 @@
615614 function sendImpersonal( $addresses ) {
616615 global $wgContLang;
617616
618 - if (empty($addresses))
 617+ if ( empty( $addresses ) )
619618 return;
620619
621620 $body = str_replace(
622 - array( '$WATCHINGUSERNAME',
623 - '$PAGEEDITDATE'),
624 - array( wfMsgForContent('enotif_impersonal_salutation'),
625 - $wgContLang->timeanddate($this->timestamp, true, false, false)),
626 - $this->body);
 621+ array( '$WATCHINGUSERNAME',
 622+ '$PAGEEDITDATE' ),
 623+ array( wfMsgForContent( 'enotif_impersonal_salutation' ),
 624+ $wgContLang->timeanddate( $this->timestamp, true, false, false ) ),
 625+ $this->body );
627626
628 - return UserMailer::send($addresses, $this->from, $this->subject, $body, $this->replyto);
 627+ return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
629628 }
630629
631630 } # end of class EmailNotification
@@ -639,7 +638,7 @@
640639 return UserMailer::rfc822Phrase( $s );
641640 }
642641
643 -function userMailer( $to, $from, $subject, $body, $replyto=null ) {
 642+function userMailer( $to, $from, $subject, $body, $replyto = null ) {
644643 wfDeprecated( __FUNCTION__ );
645644 return UserMailer::send( $to, $from, $subject, $body, $replyto );
646645 }

Status & tagging log