r22110 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22109‎ | r22110 | r22111 >
Date:16:42, 11 May 2007
Author:river
Status:old
Tags:
Comment:
instead of storing every mail as a job, have a job to send enotif updates for the whole mail at once.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/JobQueue.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/RecentChange.php
@@ -195,10 +195,11 @@
196196 global $wgUseEnotif;
197197 if( $wgUseEnotif ) {
198198 # this would be better as an extension hook
 199+ global $wgUser;
199200 include_once( "UserMailer.php" );
200201 $enotif = new EmailNotification();
201202 $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
202 - $enotif->notifyOnPageChange( $title,
 203+ $enotif->notifyOnPageChange( $wgUser, $title,
203204 $this->mAttribs['rc_timestamp'],
204205 $this->mAttribs['rc_comment'],
205206 $this->mAttribs['rc_minor'],
Index: trunk/phase3/includes/UserMailer.php
@@ -101,13 +101,15 @@
102102 * @param $replyto String: optional reply-to email (default: null).
103103 */
104104 function userMailer( $to, $from, $subject, $body, $replyto=null ) {
105 - global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal;
 105+ global $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal;
106106 global $wgEnotifMaxRecips;
107107
108108 if (is_array( $wgSMTP )) {
109109 require_once( 'Mail.php' );
110110
111 - $timestamp = time();
 111+ $msgid = str_replace(" ", "_", microtime());
 112+ if (function_exists('posix_getpid'))
 113+ $msgid .= '.' . posix_getpid();
112114
113115 if (is_array($to)) {
114116 $dest = array();
@@ -131,7 +133,7 @@
132134 $headers['MIME-Version'] = '1.0';
133135 $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
134136 $headers['Content-transfer-encoding'] = '8bit';
135 - $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>'; // FIXME
 137+ $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME
136138 $headers['X-Mailer'] = 'MediaWiki mailer';
137139
138140 // Create the mail object using the Mail::factory method
@@ -234,6 +236,25 @@
235237
236238 /**@}}*/
237239
 240+ function notifyOnPageChange($editor, &$title, $timestamp, $summary, $minorEdit, $oldid = false) {
 241+ global $wgEnotifUseJobQ;
 242+ global $wgEnotifWatchlist, $wgShowUpdatedMarker;
 243+
 244+ if ($wgEnotifUseJobQ) {
 245+ $params = array(
 246+ "editor" => $editor->getName(),
 247+ "timestamp" => $timestamp,
 248+ "summary" => $summary,
 249+ "minorEdit" => $minorEdit,
 250+ "oldid" => $oldid);
 251+ $job = new EnotifNotifyJob($title, $params);
 252+ $job->insert();
 253+ } else {
 254+ $this->actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid);
 255+ }
 256+
 257+ }
 258+
238259 /**
239260 * @todo document
240261 * @param $title Title object
@@ -242,10 +263,10 @@
243264 * @param $minorEdit
244265 * @param $oldid (default: false)
245266 */
246 - function notifyOnPageChange(&$title, $timestamp, $summary, $minorEdit, $oldid=false) {
 267+ function actuallyNotifyOnPageChange($editor, &$title, $timestamp, $summary, $minorEdit, $oldid=false) {
247268
248269 # we use $wgEmergencyContact as sender's address
249 - global $wgUser, $wgEnotifWatchlist;
 270+ global $wgEnotifWatchlist;
250271 global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
251272 global $wgEnotifImpersonal;
252273
@@ -265,20 +286,20 @@
266287 $this->summary = $summary;
267288 $this->minorEdit = $minorEdit;
268289 $this->oldid = $oldid;
269 - $this->composeCommonMailtext();
 290+ $this->composeCommonMailtext($editor);
270291
271292 $impersonals = array();
272293
273294 if ( (!$minorEdit || $wgEnotifMinorEdits) ) {
274295 if( $wgEnotifWatchlist ) {
275296 // Send updates to watchers other than the current editor
276 - $userCondition = 'wl_user <> ' . intval( $wgUser->getId() );
 297+ $userCondition = 'wl_user <> ' . intval( $editor->getId() );
277298 } elseif( $wgEnotifUserTalk && $title->getNamespace() == NS_USER_TALK ) {
278299 $targetUser = User::newFromName( $title->getText() );
279300 if( is_null( $targetUser ) ) {
280301 wfDebug( "$fname: user-talk-only mode; no such user\n" );
281302 $userCondition = false;
282 - } elseif( $targetUser->getId() == $wgUser->getId() ) {
 303+ } elseif( $targetUser->getId() == $editor->getId() ) {
283304 wfDebug( "$fname: user-talk-only mode; editor is target user\n" );
284305 $userCondition = false;
285306 } else {
@@ -356,14 +377,15 @@
357378 );
358379 # FIXME what do we do on failure ?
359380 }
 381+
360382 wfProfileOut( $fname );
361383 } # function NotifyOnChange
362384
363385 /**
364386 * @private
365387 */
366 - function composeCommonMailtext() {
367 - global $wgUser, $wgEmergencyContact, $wgNoReplyAddress;
 388+ function composeCommonMailtext($editor) {
 389+ global $wgEmergencyContact, $wgNoReplyAddress;
368390 global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
369391 global $wgEnotifImpersonal;
370392
@@ -416,12 +438,12 @@
417439 # Reveal the page editor's address as REPLY-TO address only if
418440 # the user has not opted-out and the option is enabled at the
419441 # global configuration level.
420 - $name = $wgUser->getName();
 442+ $name = $editor->getName();
421443 $adminAddress = new MailAddress( $wgEmergencyContact, 'WikiAdmin' );
422 - $editorAddress = new MailAddress( $wgUser );
 444+ $editorAddress = new MailAddress( $editor );
423445 if( $wgEnotifRevealEditorAddress
424 - && ( $wgUser->getEmail() != '' )
425 - && $wgUser->getOption( 'enotifrevealaddr' ) ) {
 446+ && ( $editor->getEmail() != '' )
 447+ && $editor->getOption( 'enotifrevealaddr' ) ) {
426448 if( $wgEnotifFromEditor ) {
427449 $from = $editorAddress;
428450 } else {
@@ -433,9 +455,9 @@
434456 $replyto = new MailAddress( $wgNoReplyAddress );
435457 }
436458
437 - if( $wgUser->isIP( $name ) ) {
438 - $utext = wfMsgForContent('enotif_anon_editor', $name);
 459+ if( $editor->isIP( $name ) ) {
439460 #real anon (user:xxx.xxx.xxx.xxx)
 461+ $utext = wfMsgForContent('enotif_anon_editor', $name);
440462 $subject = str_replace('$PAGEEDITOR', $utext, $subject);
441463 $keys['$PAGEEDITOR'] = $utext;
442464 $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
@@ -445,7 +467,7 @@
446468 $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name );
447469 $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
448470 }
449 - $userPage = $wgUser->getUserPage();
 471+ $userPage = $editor->getUserPage();
450472 $keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl();
451473 $body = strtr( $body, $keys );
452474 $body = wordwrap( $body, 72 );
@@ -484,7 +506,7 @@
485507 $wgLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
486508 $body);
487509
488 - return $this->send_or_queue_mail($to, $this->from, $this->subject, $body, $this->replyto);
 510+ return userMailer($to, $this->from, $this->subject, $body, $this->replyto);
489511 }
490512
491513 /**
@@ -508,33 +530,8 @@
509531 $wgLang->timeanddate($this->timestamp, true, false, false)),
510532 $this->body);
511533
512 - return $this->send_or_queue_mail($to, $this->from, $this->subject, $body, $this->replyto);
 534+ return userMailer($to, $this->from, $this->subject, $body, $this->replyto);
513535 }
514536
515 - /**
516 - * Either send an email or add it to the job queue to be sent later.
517 - */
518 - function send_or_queue_mail($to, $from, $subj, $body, $replyto) {
519 - global $wgEnotifUseJobQ, $wgEnotifMaxRecips;
520 -
521 - if (!$wgEnotifUseJobQ)
522 - return '' != userMailer($to, $from, $subj, $body, $replyto);
523 -
524 - if (!is_array($to))
525 - $to = array($to);
526 -
527 - $chunks = array_chunk($to, $wgEnotifMaxRecips);
528 - foreach ($chunks as $chunk) {
529 - $job = new EmaillingJob(array(
530 - 'to' => $chunk,
531 - 'from' => $from,
532 - 'subj' => $subj,
533 - 'body' => $body,
534 - 'replyto' => $replyto));
535 - $job->insert();
536 - }
537 -
538 - return true;
539 - }
540537 } # end of class EmailNotification
541538 ?>
Index: trunk/phase3/includes/JobQueue.php
@@ -178,6 +178,8 @@
179179 return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id );
180180 case 'sendMail':
181181 return new EmaillingJob($params);
 182+ case 'enotifNotify':
 183+ return new EnotifNotifyJob($title, $params);
182184 default:
183185 throw new MWException( "Invalid job command \"$command\"" );
184186 }
@@ -346,4 +348,19 @@
347349 }
348350 }
349351
 352+class EnotifNotifyJob extends Job {
 353+ function __construct($title, $params) {
 354+ parent::__construct('enotifNotify', $title, $params);
 355+ }
 356+
 357+ function run() {
 358+ $enotif = new EmailNotification();
 359+ $enotif->actuallyNotifyOnPageChange( User::newFromName($this->params['editor'], false),
 360+ $this->title, $this->params['timestamp'],
 361+ $this->params['summary'], $this->params['minorEdit'],
 362+ $this->params['oldid']);
 363+ }
 364+}
 365+
 366+
350367 ?>
Index: trunk/phase3/includes/AutoLoader.php
@@ -94,6 +94,7 @@
9595 'HistoryBlobCurStub' => 'includes/HistoryBlob.php',
9696 'HTMLCacheUpdate' => 'includes/HTMLCacheUpdate.php',
9797 'HTMLCacheUpdateJob' => 'includes/HTMLCacheUpdate.php',
 98+ 'EnotifNotifyJob' => 'includes/JobQueue.php',
9899 'Http' => 'includes/HttpFunctions.php',
99100 'Image' => 'includes/Image.php',
100101 'ArchivedFile' => 'includes/Image.php',