MediaWiki r21898 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r21897‎ | r21898 (on ViewVC)‎ | r21899 >
Date:12:44, 5 May 2007
Author:river
Status:old
Tags:
Comment:
allow enotif mails to be sent via job queue
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/UserMailer.php
===================================================================
--- trunk/phase3/includes/UserMailer.php	(revision 21897)
+++ trunk/phase3/includes/UserMailer.php	(revision 21898)
@@ -479,8 +479,7 @@
 			$wgLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
 			$body);
 
-		$error = userMailer( $to, $this->from, $this->subject, $body, $this->replyto );
-		return ($error == '');
+		return $this->send_or_queue_mail($to, $this->from, $this->subject, $body, $this->replyto);
 	}
 
 	/**
@@ -503,9 +502,34 @@
 				array(	wfMsgForContent('enotif_impersonal_salutation'),
 					$wgLang->timeanddate($this->timestamp, true, false, false)),
 				$this->body);
-		$error = userMailer($to, $this->from, $this->subject, $body, $this->replyto);
-		return $error == '';
+		
+		return $this->send_or_queue_mail($to, $this->from, $this->subject, $body, $this->replyto);
 	}
 
+	/**
+	 * Either send an email or add it to the job queue to be sent later.
+	 */
+	function send_or_queue_mail($to, $from, $subj, $body, $replyto) {
+		global $wgEnotifUseJobQ, $wgEnotifMaxRecips;
+
+		if (!$wgEnotifUseJobQ)
+			return '' != userMailer($to, $from, $subj, $body, $replyto);
+
+		if (!is_array($to))
+			$to = array($to);
+
+		$chunks = array_chunk($to, $wgEnotifMaxRecips);
+		foreach ($chunks as $chunk) {
+			$job = new EmaillingJob(array(
+						'to' => $chunk,
+						'from' => $from,
+						'subj' => $subj,
+						'body' => $body,
+						'replyto' => $replyto));
+			$job->insert();
+		}
+
+		return true;
+	}
 } # end of class EmailNotification
 ?>
Index: trunk/phase3/includes/JobQueue.php
===================================================================
--- trunk/phase3/includes/JobQueue.php	(revision 21897)
+++ trunk/phase3/includes/JobQueue.php	(revision 21898)
@@ -4,6 +4,8 @@
 	die( "This file is part of MediaWiki, it is not a valid entry point\n" );
 }
 
+require_once('UserMailer.php');
+
 /**
  * Class to both describe a background job and handle jobs.
  */
@@ -134,6 +136,8 @@
 			case 'htmlCacheUpdate':
 			case 'html_cache_update': # BC
 				return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id );
+			case 'sendMail':
+				return new EmaillingJob($params);
 			default:
 				throw new MWException( "Invalid job command \"$command\"" );
 		}
@@ -291,4 +295,15 @@
 	}
 }
 
+class EmaillingJob extends Job {
+	function __construct($params) {
+		parent::__construct('sendMail', Title::newMainPage(), $params);
+	}
+
+	function run() {
+		userMailer($this->params['to'], $this->params['from'], $this->params['subj'],
+				$this->params['body'], $this->params['replyto']);
+	}
+}
+
 ?>
Index: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php	(revision 21897)
+++ trunk/phase3/includes/AutoLoader.php	(revision 21898)
@@ -247,6 +247,7 @@
 		'Xml' => 'includes/Xml.php',
 		'ZhClient' => 'includes/ZhClient.php',
 		'memcached' => 'includes/memcached-client.php',
+		'EmaillingJob' => 'includes/JobQueue.php',
 
 		# Media
 		'BitmapHandler' => 'includes/media/Bitmap.php',
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 21897)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 21898)
@@ -1186,6 +1186,9 @@
 # match the limit on your mail server.
 $wgEnotifMaxRecips = 500;
 
+# Send mails via the job queue.
+$wgEnotifUseJobQ = false;
+
 /** 
  * Array of usernames who will be sent a notification email for every change which occurs on a wiki
  */
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox