r99646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99645‎ | r99646 | r99647 >
Date:19:11, 12 October 2011
Author:reedy
Status:ok
Tags:
Comment:
MFT r97810
Modified paths:
  • /branches/wmf/1.18wmf1 (modified) (history)
  • /branches/wmf/1.18wmf1/includes (modified) (history)
  • /branches/wmf/1.18wmf1/includes/UserMailer.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/job/EnotifNotifyJob.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/includes/UserMailer.php
@@ -345,7 +345,8 @@
346346 * @param $oldid (default: false)
347347 */
348348 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
349 - global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
 349+ global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
 350+ $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
350351
351352 if ( $title->getNamespace() < 0 ) {
352353 return;
@@ -384,6 +385,24 @@
385386 }
386387 }
387388
 389+ $sendEmail = true;
 390+ // If nobody is watching the page, and there are no users notified on all changes
 391+ // don't bother creating a job/trying to send emails
 392+ // $watchers deals with $wgEnotifWatchlist
 393+ if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
 394+ $sendEmail = false;
 395+ // Only send notification for non minor edits, unless $wgEnotifMinorEdits
 396+ if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
 397+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
 398+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
 399+ $sendEmail = true;
 400+ }
 401+ }
 402+ }
 403+
 404+ if ( !$sendEmail ) {
 405+ return;
 406+ }
388407 if ( $wgEnotifUseJobQ ) {
389408 $params = array(
390409 "editor" => $editor->getName(),
@@ -398,7 +417,6 @@
399418 } else {
400419 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
401420 }
402 -
403421 }
404422
405423 /**
@@ -439,25 +457,11 @@
440458 $userTalkId = false;
441459
442460 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
443 - if ( $wgEnotifUserTalk && $isUserTalkPage ) {
 461+
 462+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
444463 $targetUser = User::newFromName( $title->getText() );
445 - if ( !$targetUser || $targetUser->isAnon() ) {
446 - wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
447 - } elseif ( $targetUser->getId() == $editor->getId() ) {
448 - wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
449 - } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
450 - ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
451 - {
452 - if ( $targetUser->isEmailConfirmed() ) {
453 - wfDebug( __METHOD__ . ": sending talk page update notification\n" );
454 - $this->compose( $targetUser );
455 - $userTalkId = $targetUser->getId();
456 - } else {
457 - wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
458 - }
459 - } else {
460 - wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
461 - }
 464+ $this->compose( $targetUser );
 465+ $userTalkId = $targetUser->getId();
462466 }
463467
464468 if ( $wgEnotifWatchlist ) {
@@ -486,6 +490,39 @@
487491 }
488492
489493 /**
 494+ * @param $editor User
 495+ * @param $title Title bool
 496+ * @param $minorEdit
 497+ * @return bool
 498+ */
 499+ private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
 500+ global $wgEnotifUserTalk;
 501+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
 502+
 503+ if ( $wgEnotifUserTalk && $isUserTalkPage ) {
 504+ $targetUser = User::newFromName( $title->getText() );
 505+
 506+ if ( !$targetUser || $targetUser->isAnon() ) {
 507+ wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
 508+ } elseif ( $targetUser->getId() == $editor->getId() ) {
 509+ wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
 510+ } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
 511+ ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
 512+ {
 513+ if ( $targetUser->isEmailConfirmed() ) {
 514+ wfDebug( __METHOD__ . ": sending talk page update notification\n" );
 515+ return true;
 516+ } else {
 517+ wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
 518+ }
 519+ } else {
 520+ wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
 521+ }
 522+ }
 523+ return false;
 524+ }
 525+
 526+ /**
490527 * Generate the generic "this page has been changed" e-mail text.
491528 */
492529 private function composeCommonMailtext() {
Index: branches/wmf/1.18wmf1/includes/job/EnotifNotifyJob.php
@@ -20,7 +20,7 @@
2121 function run() {
2222 $enotif = new EmailNotification();
2323 // Get the user from ID (rename safe). Anons are 0, so defer to name.
24 - if( isset($this->params['editorID']) && $this->params['editorID'] ) {
 24+ if( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
2525 $editor = User::newFromId( $this->params['editorID'] );
2626 // B/C, only the name might be given.
2727 } else {
Property changes on: branches/wmf/1.18wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
2828 Merged /trunk/phase3/includes:r97810
Property changes on: branches/wmf/1.18wmf1
___________________________________________________________________
Modified: svn:mergeinfo
2929 Merged /trunk/phase3:r97810

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97810* (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued...reedy12:14, 22 September 2011

Status & tagging log