Index: trunk/phase3/includes/RecentChange.php |
— | — | @@ -195,10 +195,11 @@ |
196 | 196 | global $wgUseEnotif; |
197 | 197 | if( $wgUseEnotif ) { |
198 | 198 | # this would be better as an extension hook |
| 199 | + global $wgUser; |
199 | 200 | include_once( "UserMailer.php" ); |
200 | 201 | $enotif = new EmailNotification(); |
201 | 202 | $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] ); |
202 | | - $enotif->notifyOnPageChange( $title, |
| 203 | + $enotif->notifyOnPageChange( $wgUser, $title, |
203 | 204 | $this->mAttribs['rc_timestamp'], |
204 | 205 | $this->mAttribs['rc_comment'], |
205 | 206 | $this->mAttribs['rc_minor'], |
Index: trunk/phase3/includes/UserMailer.php |
— | — | @@ -101,13 +101,15 @@ |
102 | 102 | * @param $replyto String: optional reply-to email (default: null). |
103 | 103 | */ |
104 | 104 | function userMailer( $to, $from, $subject, $body, $replyto=null ) { |
105 | | - global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal; |
| 105 | + global $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal; |
106 | 106 | global $wgEnotifMaxRecips; |
107 | 107 | |
108 | 108 | if (is_array( $wgSMTP )) { |
109 | 109 | require_once( 'Mail.php' ); |
110 | 110 | |
111 | | - $timestamp = time(); |
| 111 | + $msgid = str_replace(" ", "_", microtime()); |
| 112 | + if (function_exists('posix_getpid')) |
| 113 | + $msgid .= '.' . posix_getpid(); |
112 | 114 | |
113 | 115 | if (is_array($to)) { |
114 | 116 | $dest = array(); |
— | — | @@ -131,7 +133,7 @@ |
132 | 134 | $headers['MIME-Version'] = '1.0'; |
133 | 135 | $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding; |
134 | 136 | $headers['Content-transfer-encoding'] = '8bit'; |
135 | | - $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>'; // FIXME |
| 137 | + $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME |
136 | 138 | $headers['X-Mailer'] = 'MediaWiki mailer'; |
137 | 139 | |
138 | 140 | // Create the mail object using the Mail::factory method |
— | — | @@ -234,6 +236,25 @@ |
235 | 237 | |
236 | 238 | /**@}}*/ |
237 | 239 | |
| 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 | + |
238 | 259 | /** |
239 | 260 | * @todo document |
240 | 261 | * @param $title Title object |
— | — | @@ -242,10 +263,10 @@ |
243 | 264 | * @param $minorEdit |
244 | 265 | * @param $oldid (default: false) |
245 | 266 | */ |
246 | | - function notifyOnPageChange(&$title, $timestamp, $summary, $minorEdit, $oldid=false) { |
| 267 | + function actuallyNotifyOnPageChange($editor, &$title, $timestamp, $summary, $minorEdit, $oldid=false) { |
247 | 268 | |
248 | 269 | # we use $wgEmergencyContact as sender's address |
249 | | - global $wgUser, $wgEnotifWatchlist; |
| 270 | + global $wgEnotifWatchlist; |
250 | 271 | global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker; |
251 | 272 | global $wgEnotifImpersonal; |
252 | 273 | |
— | — | @@ -265,20 +286,20 @@ |
266 | 287 | $this->summary = $summary; |
267 | 288 | $this->minorEdit = $minorEdit; |
268 | 289 | $this->oldid = $oldid; |
269 | | - $this->composeCommonMailtext(); |
| 290 | + $this->composeCommonMailtext($editor); |
270 | 291 | |
271 | 292 | $impersonals = array(); |
272 | 293 | |
273 | 294 | if ( (!$minorEdit || $wgEnotifMinorEdits) ) { |
274 | 295 | if( $wgEnotifWatchlist ) { |
275 | 296 | // Send updates to watchers other than the current editor |
276 | | - $userCondition = 'wl_user <> ' . intval( $wgUser->getId() ); |
| 297 | + $userCondition = 'wl_user <> ' . intval( $editor->getId() ); |
277 | 298 | } elseif( $wgEnotifUserTalk && $title->getNamespace() == NS_USER_TALK ) { |
278 | 299 | $targetUser = User::newFromName( $title->getText() ); |
279 | 300 | if( is_null( $targetUser ) ) { |
280 | 301 | wfDebug( "$fname: user-talk-only mode; no such user\n" ); |
281 | 302 | $userCondition = false; |
282 | | - } elseif( $targetUser->getId() == $wgUser->getId() ) { |
| 303 | + } elseif( $targetUser->getId() == $editor->getId() ) { |
283 | 304 | wfDebug( "$fname: user-talk-only mode; editor is target user\n" ); |
284 | 305 | $userCondition = false; |
285 | 306 | } else { |
— | — | @@ -356,14 +377,15 @@ |
357 | 378 | ); |
358 | 379 | # FIXME what do we do on failure ? |
359 | 380 | } |
| 381 | + |
360 | 382 | wfProfileOut( $fname ); |
361 | 383 | } # function NotifyOnChange |
362 | 384 | |
363 | 385 | /** |
364 | 386 | * @private |
365 | 387 | */ |
366 | | - function composeCommonMailtext() { |
367 | | - global $wgUser, $wgEmergencyContact, $wgNoReplyAddress; |
| 388 | + function composeCommonMailtext($editor) { |
| 389 | + global $wgEmergencyContact, $wgNoReplyAddress; |
368 | 390 | global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress; |
369 | 391 | global $wgEnotifImpersonal; |
370 | 392 | |
— | — | @@ -416,12 +438,12 @@ |
417 | 439 | # Reveal the page editor's address as REPLY-TO address only if |
418 | 440 | # the user has not opted-out and the option is enabled at the |
419 | 441 | # global configuration level. |
420 | | - $name = $wgUser->getName(); |
| 442 | + $name = $editor->getName(); |
421 | 443 | $adminAddress = new MailAddress( $wgEmergencyContact, 'WikiAdmin' ); |
422 | | - $editorAddress = new MailAddress( $wgUser ); |
| 444 | + $editorAddress = new MailAddress( $editor ); |
423 | 445 | if( $wgEnotifRevealEditorAddress |
424 | | - && ( $wgUser->getEmail() != '' ) |
425 | | - && $wgUser->getOption( 'enotifrevealaddr' ) ) { |
| 446 | + && ( $editor->getEmail() != '' ) |
| 447 | + && $editor->getOption( 'enotifrevealaddr' ) ) { |
426 | 448 | if( $wgEnotifFromEditor ) { |
427 | 449 | $from = $editorAddress; |
428 | 450 | } else { |
— | — | @@ -433,9 +455,9 @@ |
434 | 456 | $replyto = new MailAddress( $wgNoReplyAddress ); |
435 | 457 | } |
436 | 458 | |
437 | | - if( $wgUser->isIP( $name ) ) { |
438 | | - $utext = wfMsgForContent('enotif_anon_editor', $name); |
| 459 | + if( $editor->isIP( $name ) ) { |
439 | 460 | #real anon (user:xxx.xxx.xxx.xxx) |
| 461 | + $utext = wfMsgForContent('enotif_anon_editor', $name); |
440 | 462 | $subject = str_replace('$PAGEEDITOR', $utext, $subject); |
441 | 463 | $keys['$PAGEEDITOR'] = $utext; |
442 | 464 | $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' ); |
— | — | @@ -445,7 +467,7 @@ |
446 | 468 | $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $name ); |
447 | 469 | $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl(); |
448 | 470 | } |
449 | | - $userPage = $wgUser->getUserPage(); |
| 471 | + $userPage = $editor->getUserPage(); |
450 | 472 | $keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl(); |
451 | 473 | $body = strtr( $body, $keys ); |
452 | 474 | $body = wordwrap( $body, 72 ); |
— | — | @@ -484,7 +506,7 @@ |
485 | 507 | $wgLang->timeanddate( $this->timestamp, true, false, $timecorrection ), |
486 | 508 | $body); |
487 | 509 | |
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); |
489 | 511 | } |
490 | 512 | |
491 | 513 | /** |
— | — | @@ -508,33 +530,8 @@ |
509 | 531 | $wgLang->timeanddate($this->timestamp, true, false, false)), |
510 | 532 | $this->body); |
511 | 533 | |
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); |
513 | 535 | } |
514 | 536 | |
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 | | - } |
540 | 537 | } # end of class EmailNotification |
541 | 538 | ?> |
Index: trunk/phase3/includes/JobQueue.php |
— | — | @@ -178,6 +178,8 @@ |
179 | 179 | return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id ); |
180 | 180 | case 'sendMail': |
181 | 181 | return new EmaillingJob($params); |
| 182 | + case 'enotifNotify': |
| 183 | + return new EnotifNotifyJob($title, $params); |
182 | 184 | default: |
183 | 185 | throw new MWException( "Invalid job command \"$command\"" ); |
184 | 186 | } |
— | — | @@ -346,4 +348,19 @@ |
347 | 349 | } |
348 | 350 | } |
349 | 351 | |
| 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 | + |
350 | 367 | ?> |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -94,6 +94,7 @@ |
95 | 95 | 'HistoryBlobCurStub' => 'includes/HistoryBlob.php', |
96 | 96 | 'HTMLCacheUpdate' => 'includes/HTMLCacheUpdate.php', |
97 | 97 | 'HTMLCacheUpdateJob' => 'includes/HTMLCacheUpdate.php', |
| 98 | + 'EnotifNotifyJob' => 'includes/JobQueue.php', |
98 | 99 | 'Http' => 'includes/HttpFunctions.php', |
99 | 100 | 'Image' => 'includes/Image.php', |
100 | 101 | 'ArchivedFile' => 'includes/Image.php', |