2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// @todo Fill in
|
|
|
|
class EchoNotifier {
|
|
|
|
/**
|
2013-01-14 23:52:46 +00:00
|
|
|
* Record an EchoNotification for an EchoEvent
|
|
|
|
* Currently used for web-based notifications.
|
2012-04-27 15:14:24 +00:00
|
|
|
*
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $user User to notify.
|
|
|
|
* @param $event EchoEvent to notify about.
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
public static function notifyWithNotification( $user, $event ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoConfig, $wgEchoNotifications;
|
2013-03-01 00:26:59 +00:00
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
2013-03-01 00:26:59 +00:00
|
|
|
|
|
|
|
// Attempt event logging if Echo schema is enabled
|
|
|
|
if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
$agent = $event->getAgent();
|
|
|
|
// Typically an event should always have an agent, but agent could be
|
|
|
|
// null if the data is corrupted
|
|
|
|
if ( $agent ) {
|
|
|
|
$sender = $agent->isAnon() ? $agent->getName() : $agent->getId();
|
|
|
|
} else {
|
|
|
|
$sender = 0;
|
|
|
|
}
|
2013-03-01 00:26:59 +00:00
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
if ( isset( $wgEchoNotifications[$event->getType()]['group'] ) ) {
|
|
|
|
$group = $wgEchoNotifications[$event->getType()]['group'];
|
2013-03-01 00:26:59 +00:00
|
|
|
} else {
|
|
|
|
$group = 'neutral';
|
|
|
|
}
|
|
|
|
$data = array (
|
|
|
|
'version' => $wgEchoConfig['version'],
|
|
|
|
'eventId' => $event->getId(),
|
|
|
|
'notificationType' => $event->getType(),
|
|
|
|
'notificationGroup' => $group,
|
2013-02-16 02:20:34 +00:00
|
|
|
'sender' => (string)$sender,
|
2013-03-01 00:26:59 +00:00
|
|
|
'recipientUserId' => $user->getId(),
|
|
|
|
'recipientEditCount' => (int)$user->getEditCount()
|
|
|
|
);
|
2013-03-20 20:55:21 +00:00
|
|
|
// Add the source if it exists. (This is mostly for the Thanks extension.)
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( isset( $extra['source'] ) ) {
|
|
|
|
$data['eventSource'] = (string)$extra['source'];
|
|
|
|
}
|
2013-03-01 00:26:59 +00:00
|
|
|
EchoHooks::logEvent( 'Echo', $data );
|
|
|
|
}
|
|
|
|
|
2012-12-19 02:16:52 +00:00
|
|
|
EchoNotificationController::resetNotificationCount( $user, DB_MASTER );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Notification to a user by email
|
|
|
|
*
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $user User to notify.
|
|
|
|
* @param $event EchoEvent to notify about.
|
|
|
|
* @return bool
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
|
|
|
public static function notifyWithEmail( $user, $event ) {
|
2012-08-31 21:50:46 +00:00
|
|
|
if ( !$user->isEmailConfirmed() ) {
|
2012-05-17 15:36:18 +00:00
|
|
|
// No valid email address
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-07 18:32:29 +00:00
|
|
|
// See if the user wants to receive emails for this category of event
|
2013-03-09 00:32:28 +00:00
|
|
|
if ( $user->getOption( 'echo-subscriptions-email-' . $event->getCategory() ) ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoEnableEmailBatch, $wgPasswordSender, $wgPasswordSenderName;
|
2012-11-16 21:03:57 +00:00
|
|
|
|
|
|
|
// batched email notification
|
|
|
|
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
$priority = EchoNotificationController::getNotificationPriority( $event->getType() );
|
2012-11-16 21:03:57 +00:00
|
|
|
MWEchoEmailBatch::addToQueue( $user->getId(), $event->getId(), $priority );
|
|
|
|
return true;
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
2012-11-16 21:03:57 +00:00
|
|
|
// 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 );
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 09:30:38 +00:00
|
|
|
return true;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|