http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97810
Revision: 97810
Author: reedy
Date: 2011-09-22 12:14:21 +0000 (Thu, 22 Sep 2011)
Log Message:
-----------
* (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued
Do some of the cheap checks before spawning attempting to send emails via any
method
Modified Paths:
--------------
trunk/phase3/RELEASE-NOTES-1.19
trunk/phase3/includes/UserMailer.php
trunk/phase3/includes/job/EnotifNotifyJob.php
Modified: trunk/phase3/RELEASE-NOTES-1.19
===================================================================
--- trunk/phase3/RELEASE-NOTES-1.19 2011-09-22 11:52:44 UTC (rev 97809)
+++ trunk/phase3/RELEASE-NOTES-1.19 2011-09-22 12:14:21 UTC (rev 97810)
@@ -96,6 +96,7 @@
really small, and somewhat inconsistent with each other.
* Per page edit-notices now work in namespaces without subpages enabled.
* (bug 30245) Use the correct way to construct a log page title
+* (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued
=== API changes in 1.19 ===
* (bug 19838) siprop=interwikimap can now use the interwiki cache.
Modified: trunk/phase3/includes/UserMailer.php
===================================================================
--- trunk/phase3/includes/UserMailer.php 2011-09-22 11:52:44 UTC (rev
97809)
+++ trunk/phase3/includes/UserMailer.php 2011-09-22 12:14:21 UTC (rev
97810)
@@ -364,7 +364,8 @@
* @param $oldid (default: false)
*/
public function notifyOnPageChange( $editor, $title, $timestamp,
$summary, $minorEdit, $oldid = false ) {
- global $wgEnotifUseJobQ, $wgEnotifWatchlist,
$wgShowUpdatedMarker;
+ global $wgEnotifUseJobQ, $wgEnotifWatchlist,
$wgShowUpdatedMarker, $wgEnotifMinorEdits,
+ $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
if ( $title->getNamespace() < 0 ) {
return;
@@ -403,6 +404,24 @@
}
}
+ $sendEmail = true;
+ // If nobody is watching the page, and there are no users
notified on all changes
+ // don't bother creating a job/trying to send emails
+ // $watchers deals with $wgEnotifWatchlist
+ if ( !count( $watchers ) && !count(
$wgUsersNotifiedOnAllChanges ) ) {
+ $sendEmail = false;
+ // Only send notification for non minor edits, unless
$wgEnotifMinorEdits
+ if ( !$minorEdit || ( $wgEnotifMinorEdits &&
!$editor->isAllowed( 'nominornewtalk' ) ) ) {
+ $isUserTalkPage = ( $title->getNamespace() ==
NS_USER_TALK );
+ if ( $wgEnotifUserTalk && $isUserTalkPage &&
$this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
+ $sendEmail = true;
+ }
+ }
+ }
+
+ if ( !$sendEmail ) {
+ return;
+ }
if ( $wgEnotifUseJobQ ) {
$params = array(
'editor' => $editor->getName(),
@@ -418,7 +437,6 @@
} else {
$this->actuallyNotifyOnPageChange( $editor, $title,
$timestamp, $summary, $minorEdit, $oldid, $watchers );
}
-
}
/**
@@ -459,25 +477,11 @@
$userTalkId = false;
if ( !$minorEdit || ( $wgEnotifMinorEdits &&
!$editor->isAllowed( 'nominornewtalk' ) ) ) {
- if ( $wgEnotifUserTalk && $isUserTalkPage ) {
+
+ if ( $wgEnotifUserTalk && $isUserTalkPage &&
$this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
$targetUser = User::newFromName(
$title->getText() );
- if ( !$targetUser || $targetUser->isAnon() ) {
- wfDebug( __METHOD__ . ": user talk page
edited, but user does not exist\n" );
- } elseif ( $targetUser->getId() ==
$editor->getId() ) {
- wfDebug( __METHOD__ . ": user edited
their own talk page, no notification sent\n" );
- } elseif ( $targetUser->getOption(
'enotifusertalkpages' ) &&
- ( !$minorEdit ||
$targetUser->getOption( 'enotifminoredits' ) ) )
- {
- if ( $targetUser->isEmailConfirmed() ) {
- wfDebug( __METHOD__ . ":
sending talk page update notification\n" );
- $this->compose( $targetUser );
- $userTalkId =
$targetUser->getId();
- } else {
- wfDebug( __METHOD__ . ": talk
page owner doesn't have validated email\n" );
- }
- } else {
- wfDebug( __METHOD__ . ": talk page
owner doesn't want notifications\n" );
- }
+ $this->compose( $targetUser );
+ $userTalkId = $targetUser->getId();
}
if ( $wgEnotifWatchlist ) {
@@ -506,6 +510,39 @@
}
/**
+ * @param $editor User
+ * @param $title Title bool
+ * @param $minorEdit
+ * @return bool
+ */
+ private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
+ global $wgEnotifUserTalk;
+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
+
+ if ( $wgEnotifUserTalk && $isUserTalkPage ) {
+ $targetUser = User::newFromName( $title->getText() );
+
+ if ( !$targetUser || $targetUser->isAnon() ) {
+ wfDebug( __METHOD__ . ": user talk page edited,
but user does not exist\n" );
+ } elseif ( $targetUser->getId() == $editor->getId() ) {
+ wfDebug( __METHOD__ . ": user edited their own
talk page, no notification sent\n" );
+ } elseif ( $targetUser->getOption(
'enotifusertalkpages' ) &&
+ ( !$minorEdit || $targetUser->getOption(
'enotifminoredits' ) ) )
+ {
+ if ( $targetUser->isEmailConfirmed() ) {
+ wfDebug( __METHOD__ . ": sending talk
page update notification\n" );
+ return true;
+ } else {
+ wfDebug( __METHOD__ . ": talk page
owner doesn't have validated email\n" );
+ }
+ } else {
+ wfDebug( __METHOD__ . ": talk page owner
doesn't want notifications\n" );
+ }
+ }
+ return false;
+ }
+
+ /**
* Generate the generic "this page has been changed" e-mail text.
*/
private function composeCommonMailtext() {
Modified: trunk/phase3/includes/job/EnotifNotifyJob.php
===================================================================
--- trunk/phase3/includes/job/EnotifNotifyJob.php 2011-09-22 11:52:44 UTC
(rev 97809)
+++ trunk/phase3/includes/job/EnotifNotifyJob.php 2011-09-22 12:14:21 UTC
(rev 97810)
@@ -20,7 +20,7 @@
function run() {
$enotif = new EmailNotification();
// Get the user from ID (rename safe). Anons are 0, so defer to
name.
- if( isset($this->params['editorID']) &&
$this->params['editorID'] ) {
+ if( isset( $this->params['editorID'] ) &&
$this->params['editorID'] ) {
$editor = User::newFromId( $this->params['editorID'] );
// B/C, only the name might be given.
} else {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs