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
|
2016-08-19 01:07:29 +00:00
|
|
|
*
|
2016-08-22 20:33:34 +00:00
|
|
|
* Adds common fields, and logs if logging is enabled for the given $schema.
|
2016-08-19 01:07:29 +00:00
|
|
|
*
|
2016-08-16 12:59:15 +00:00
|
|
|
* @param string $schema
|
|
|
|
* @param array $data
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
2016-08-19 01:07:29 +00:00
|
|
|
protected static function logEvent( $schema, array $data ) {
|
2016-12-01 16:50:18 +00:00
|
|
|
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
|
2013-05-07 23:27:46 +00:00
|
|
|
|
2016-12-01 16:50:18 +00:00
|
|
|
$schemaConfig = $wgEchoEventLoggingSchemas[$schema];
|
2016-08-19 01:07:29 +00:00
|
|
|
if ( !$schemaConfig['enabled'] ) {
|
|
|
|
// If logging for this schema is disabled, it's a no-op.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:50:18 +00:00
|
|
|
$data['version'] = $wgEchoEventLoggingVersion;
|
2016-08-22 20:33:34 +00:00
|
|
|
|
2016-08-19 01:07:29 +00:00
|
|
|
EventLogging::logEvent( $schema, $schemaConfig['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
|
2016-08-16 12:59:15 +00:00
|
|
|
* @param User $user User being notified.
|
|
|
|
* @param EchoEvent $event Event to log detail about.
|
|
|
|
* @param string $deliveryMethod 'web' or 'email'
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
2013-05-16 21:14:26 +00:00
|
|
|
public static function logSchemaEcho( User $user, EchoEvent $event, $deliveryMethod ) {
|
2016-08-22 20:33:34 +00:00
|
|
|
global $wgEchoNotifications;
|
2013-05-07 23:27:46 +00:00
|
|
|
|
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';
|
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$data = [
|
2015-10-21 18:08:31 +00:00
|
|
|
'eventId' => (int)$event->getId(),
|
2013-05-07 23:27:46 +00:00
|
|
|
'notificationType' => $event->getType(),
|
|
|
|
'notificationGroup' => $group,
|
|
|
|
'sender' => (string)$sender,
|
|
|
|
'recipientUserId' => $user->getId(),
|
|
|
|
'recipientEditCount' => (int)$user->getEditCount()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2013-05-07 23:27:46 +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'];
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
if ( $deliveryMethod == 'email' ) {
|
2013-05-07 23:27:46 +00:00
|
|
|
$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
|
|
|
|
2016-08-19 01:07:29 +00:00
|
|
|
self::logEvent( 'Echo', $data );
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-16 21:14:26 +00:00
|
|
|
* Function for logging the event for Schema:EchoEmail
|
2016-08-16 12:59:15 +00:00
|
|
|
* @param User $user
|
|
|
|
* @param string $emailDeliveryMode 'single' (default), 'daily_digest', or 'weekly_digest'
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
2013-05-16 21:14:26 +00:00
|
|
|
public static function logSchemaEchoMail( User $user, $emailDeliveryMode = 'single' ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$data = [
|
2013-05-07 23:27:46 +00:00
|
|
|
'recipientUserId' => $user->getId(),
|
|
|
|
'emailDeliveryMode' => $emailDeliveryMode
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2013-05-07 23:27:46 +00:00
|
|
|
|
2016-08-19 01:07:29 +00:00
|
|
|
self::logEvent( 'EchoMail', $data );
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 10:59:07 +00:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param string $skinName
|
|
|
|
*/
|
2016-08-22 20:33:34 +00:00
|
|
|
public static function logSpecialPageVisit( User $user, $skinName ) {
|
2016-08-19 01:07:29 +00:00
|
|
|
self::logEvent(
|
2016-08-16 10:59:07 +00:00
|
|
|
'EchoInteraction',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-08-16 10:59:07 +00:00
|
|
|
'context' => 'archive',
|
|
|
|
'action' => 'special-page-visit',
|
|
|
|
'userId' => (int)$user->getId(),
|
|
|
|
'editCount' => (int)$user->getEditCount(),
|
|
|
|
'notifWiki' => wfWikiID(),
|
|
|
|
// Hack: Figure out if we are in the mobile skin
|
|
|
|
'mobile' => $skinName === 'minerva',
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-08-16 10:59:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|