mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
f897c02385
Patch set 16: * change some of the message rendering from plain() to escaped() Change-Id: I9b971bd11171e73cd4d0c4ea10f817f4e19024f2
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
// @todo Fill in
|
|
class EchoNotifier {
|
|
/**
|
|
* Record an EchoNotification for an EchoEvent.
|
|
*
|
|
* @param $user User to notify.
|
|
* @param $event EchoEvent to notify about.
|
|
*/
|
|
public static function notifyWithNotification( $user, $event ) {
|
|
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
|
EchoNotificationController::resetNotificationCount( $user );
|
|
}
|
|
|
|
/**
|
|
* Send a Notification to a user by email
|
|
*
|
|
* @param $user User to notify.
|
|
* @param $event EchoEvent to notify about.
|
|
* @return bool
|
|
*/
|
|
public static function notifyWithEmail( $user, $event ) {
|
|
if ( !$user->isEmailConfirmed() ) {
|
|
// No valid email address
|
|
return false;
|
|
}
|
|
// See if the user wants to receive emails for this type of event
|
|
if ( $user->getOption( 'echo-email-notifications' . $event->getType() ) ) {
|
|
global $wgEchoEnableEmailBatch, $wgEchoEventDetails, $wgPasswordSender, $wgPasswordSenderName;
|
|
|
|
// batched email notification
|
|
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
|
|
// default priority is 10
|
|
$priority = 10;
|
|
if ( isset( $wgEchoEventDetails[$event->getType()]['priority'] ) ) {
|
|
$priority = $wgEchoEventDetails[$event->getType()]['priority'];
|
|
}
|
|
MWEchoEmailBatch::addToQueue( $user->getId(), $event->getId(), $priority );
|
|
return true;
|
|
}
|
|
// no email notification
|
|
if ( $user->getOption( 'echo-email-frequency' ) < 0 ) {
|
|
return false;
|
|
}
|
|
|
|
// instant email notification
|
|
$adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
|
|
$address = new MailAddress( $user );
|
|
$email = EchoNotificationController::formatNotification( $event, $user, 'email' );
|
|
$subject = $email['subject'];
|
|
$body = $email['body'];
|
|
|
|
UserMailer::send( $address, $adminAddress, $subject, $body );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|