'Xml' => 'includes/Xml.php',
'ZhClient' => 'includes/ZhClient.php',
'memcached' => 'includes/memcached-client.php',
+ 'EmaillingJob' => 'includes/JobQueue.php',
# Media
'BitmapHandler' => 'includes/media/Bitmap.php',
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.
*/
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\"" );
}
}
}
+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']);
+ }
+}
+
?>
$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);
}
/**
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
?>