2013-05-07 23:27:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static class for handling all kinds of event logging
|
|
|
|
*/
|
|
|
|
class MWEchoEventLogging {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the only function that interacts with EventLogging
|
|
|
|
* @param $schema string
|
|
|
|
* @param $data array
|
|
|
|
*/
|
|
|
|
public static function actuallyLogTheEvent( $schema, $data ) {
|
|
|
|
global $wgEchoConfig;
|
|
|
|
|
2013-05-16 21:14:26 +00:00
|
|
|
efLogServerSideEvent( $schema, $wgEchoConfig['eventlogging'][$schema]['revision'], $data );
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-16 21:14:26 +00:00
|
|
|
* Function for logging the event for Schema:Echo
|
2013-05-07 23:27:46 +00:00
|
|
|
* @param $user User being notified.
|
|
|
|
* @param $event EchoEvent to log detail about.
|
|
|
|
* @param $deliveryMethod string containing either 'web' or 'email'
|
|
|
|
*/
|
2013-05-16 21:14:26 +00:00
|
|
|
public static function logSchemaEcho( User $user, EchoEvent $event, $deliveryMethod ) {
|
2013-05-07 23:27:46 +00:00
|
|
|
global $wgEchoConfig, $wgEchoNotifications;
|
|
|
|
if ( !$wgEchoConfig['eventlogging']['Echo']['enabled'] ) {
|
|
|
|
// Only attempt event logging if Echo schema is enabled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:26:57 +00:00
|
|
|
// Notifications under system category should have -1 as sender id
|
|
|
|
if ( $event->getCategory() === 'system' ) {
|
2013-05-07 23:27:46 +00:00
|
|
|
$sender = -1;
|
2013-06-13 02:26:57 +00:00
|
|
|
} else {
|
|
|
|
$agent = $event->getAgent();
|
|
|
|
if ( $agent ) {
|
|
|
|
$sender = $agent->isAnon() ? $agent->getName() : $agent->getId();
|
|
|
|
} else {
|
|
|
|
$sender = -1;
|
|
|
|
}
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $wgEchoNotifications[$event->getType()]['group'] ) ) {
|
|
|
|
$group = $wgEchoNotifications[$event->getType()]['group'];
|
|
|
|
} else {
|
|
|
|
$group = 'neutral';
|
|
|
|
}
|
|
|
|
$data = array (
|
|
|
|
'version' => $wgEchoConfig['version'],
|
|
|
|
'eventId' => $event->getId(),
|
|
|
|
'notificationType' => $event->getType(),
|
|
|
|
'notificationGroup' => $group,
|
|
|
|
'sender' => (string)$sender,
|
|
|
|
'recipientUserId' => $user->getId(),
|
|
|
|
'recipientEditCount' => (int)$user->getEditCount()
|
|
|
|
);
|
|
|
|
// 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'];
|
|
|
|
}
|
|
|
|
if( $deliveryMethod == 'email' ) {
|
|
|
|
$data['deliveryMethod'] = 'email';
|
|
|
|
} else {
|
|
|
|
// whitelist valid delivery methods so it is always valid
|
|
|
|
$data['deliveryMethod'] = 'web';
|
|
|
|
}
|
2013-10-18 06:51:43 +00:00
|
|
|
// Add revision ID if it exists
|
|
|
|
$rev = $event->getRevision();
|
|
|
|
if ( $rev ) {
|
2013-11-04 18:42:48 +00:00
|
|
|
$data['revisionId'] = $rev->getId();
|
2013-10-18 06:51:43 +00:00
|
|
|
}
|
2013-05-07 23:27:46 +00:00
|
|
|
|
|
|
|
self::actuallyLogTheEvent( 'Echo', $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-16 21:14:26 +00:00
|
|
|
* Function for logging the event for Schema:EchoEmail
|
2013-05-07 23:27:46 +00:00
|
|
|
* @param $user User
|
|
|
|
* @param $emailDeliveryMode string
|
|
|
|
*/
|
2013-05-16 21:14:26 +00:00
|
|
|
public static function logSchemaEchoMail( User $user, $emailDeliveryMode = 'single' ) {
|
2013-05-07 23:27:46 +00:00
|
|
|
global $wgEchoConfig;
|
|
|
|
|
|
|
|
if ( !$wgEchoConfig['eventlogging']['EchoMail']['enabled'] ) {
|
|
|
|
// Only attempt event logging if EchoMail schema is enabled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array (
|
|
|
|
'version' => $wgEchoConfig['version'],
|
|
|
|
'recipientUserId' => $user->getId(),
|
|
|
|
'emailDeliveryMode' => $emailDeliveryMode
|
|
|
|
);
|
|
|
|
|
|
|
|
self::actuallyLogTheEvent( 'EchoMail', $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|