mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Add first version of EventLogging schema to Echo
Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
This commit is contained in:
parent
3e30543b8b
commit
fc5c341692
17
Echo.php
17
Echo.php
|
@ -87,6 +87,7 @@ $wgHooks['PersonalUrls'][] = 'EchoHooks::onPersonalUrls';
|
||||||
$wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
|
$wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
|
||||||
$wgHooks['MakeGlobalVariablesScript'][] = 'EchoHooks::makeGlobalVariablesScript';
|
$wgHooks['MakeGlobalVariablesScript'][] = 'EchoHooks::makeGlobalVariablesScript';
|
||||||
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
|
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
|
||||||
|
$wgHooks['ResourceLoaderRegisterModules'][] = 'EchoHooks::onResourceLoaderRegisterModules';
|
||||||
|
|
||||||
// Extension initialization
|
// Extension initialization
|
||||||
$wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
|
$wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
|
||||||
|
@ -244,23 +245,28 @@ $wgEchoEnabledEvents = array(
|
||||||
$wgEchoEventDetails = array(
|
$wgEchoEventDetails = array(
|
||||||
'welcome' => array(
|
'welcome' => array(
|
||||||
'nodismiss' => array( 'web', 'email' ),
|
'nodismiss' => array( 'web', 'email' ),
|
||||||
|
'group' => 'positive',
|
||||||
),
|
),
|
||||||
'edit-user-talk' => array(
|
'edit-user-talk' => array(
|
||||||
'category' => 'edit-user-talk',
|
'category' => 'edit-user-talk',
|
||||||
'priority' => 1,
|
'priority' => 1,
|
||||||
'nodismiss' => array( 'web' ),
|
'nodismiss' => array( 'web' ),
|
||||||
|
'group' => 'interactive',
|
||||||
),
|
),
|
||||||
'reverted' => array(
|
'reverted' => array(
|
||||||
'category' => 'edit-revert',
|
'category' => 'edit-revert',
|
||||||
'priority' => 9,
|
'priority' => 9,
|
||||||
|
'group' => 'negative',
|
||||||
),
|
),
|
||||||
'article-linked' => array(
|
'article-linked' => array(
|
||||||
'category' => 'cross-reference',
|
'category' => 'cross-reference',
|
||||||
'priority' => 5,
|
'priority' => 5,
|
||||||
|
'group' => 'positive',
|
||||||
),
|
),
|
||||||
'mention' => array(
|
'mention' => array(
|
||||||
'category' => 'mention',
|
'category' => 'mention',
|
||||||
'priority' => 4,
|
'priority' => 4,
|
||||||
|
'group' => 'interactive',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -366,3 +372,14 @@ foreach ( $wgEchoEnabledEvents as $wgEchoEnabledEvent ) {
|
||||||
// unset default email for reverted, article-linked (change them to opt-in)
|
// unset default email for reverted, article-linked (change them to opt-in)
|
||||||
$wgDefaultUserOptions['echo-email-notificationsreverted'] = false;
|
$wgDefaultUserOptions['echo-email-notificationsreverted'] = false;
|
||||||
$wgDefaultUserOptions['echo-email-notificationsarticle-linked'] = false;
|
$wgDefaultUserOptions['echo-email-notificationsarticle-linked'] = false;
|
||||||
|
|
||||||
|
// Echo Configuration
|
||||||
|
$wgEchoConfig = array(
|
||||||
|
'version' => '1.0',
|
||||||
|
'eventlogging' => array (
|
||||||
|
'Echo' => array (
|
||||||
|
'enabled' => true,
|
||||||
|
'revision' => 5285750
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
37
Hooks.php
37
Hooks.php
|
@ -15,6 +15,43 @@ class EchoHooks {
|
||||||
$wgEchoBackend = MWEchoBackend::factory( $wgEchoBackendName );
|
$wgEchoBackend = MWEchoBackend::factory( $wgEchoBackendName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for ResourceLoaderRegisterModules hook
|
||||||
|
*/
|
||||||
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
||||||
|
global $wgResourceModules, $wgEchoConfig;
|
||||||
|
|
||||||
|
$eventLogEnabled = function_exists( 'efLogServerSideEvent' );
|
||||||
|
|
||||||
|
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
|
||||||
|
if ( $eventLogEnabled && $property['enabled'] ) {
|
||||||
|
$wgResourceModules[ 'schema.' . $schema ] = array(
|
||||||
|
'class' => 'ResourceLoaderSchemaModule',
|
||||||
|
'schema' => $schema,
|
||||||
|
'revision' => $property['revision'],
|
||||||
|
);
|
||||||
|
$wgResourceModules['ext.echo.base']['dependencies'][] = 'schema.' . $schema;
|
||||||
|
} else {
|
||||||
|
$wgEchoConfig['eventlogging'][$schema]['enabled'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to log the event
|
||||||
|
* @param $schema string
|
||||||
|
* @param $data array
|
||||||
|
*/
|
||||||
|
public static function logEvent( $schema, $data ) {
|
||||||
|
global $wgEchoConfig;
|
||||||
|
|
||||||
|
if ( !empty( $wgEchoConfig['eventlogging'][$schema]['enabled'] ) ) {
|
||||||
|
efLogServerSideEvent( $schema, $wgEchoConfig['eventlogging'][$schema]['revision'], $data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $updater DatabaseUpdater object
|
* @param $updater DatabaseUpdater object
|
||||||
* @return bool true in all cases
|
* @return bool true in all cases
|
||||||
|
|
29
Notifier.php
29
Notifier.php
|
@ -10,7 +10,34 @@ class EchoNotifier {
|
||||||
* @param $event EchoEvent to notify about.
|
* @param $event EchoEvent to notify about.
|
||||||
*/
|
*/
|
||||||
public static function notifyWithNotification( $user, $event ) {
|
public static function notifyWithNotification( $user, $event ) {
|
||||||
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
global $wgEchoConfig, $wgEchoEventDetails;
|
||||||
|
|
||||||
|
$notif = EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
||||||
|
|
||||||
|
// Attempt event logging if Echo schema is enabled
|
||||||
|
if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) {
|
||||||
|
$event = $notif->getEvent();
|
||||||
|
$sender = $event->getAgent();
|
||||||
|
$user = $notif->getUser();
|
||||||
|
|
||||||
|
if ( isset( $wgEchoEventDetails[$event->getType()]['group'] ) ) {
|
||||||
|
$group = $wgEchoEventDetails[$event->getType()]['group'];
|
||||||
|
} else {
|
||||||
|
$group = 'neutral';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array (
|
||||||
|
'version' => $wgEchoConfig['version'],
|
||||||
|
'eventId' => $event->getId(),
|
||||||
|
'notificationType' => $event->getType(),
|
||||||
|
'notificationGroup' => $group,
|
||||||
|
'sender' => (string)( $sender->isAnon() ? $sender->getName() : $sender->getId() ),
|
||||||
|
'recipientUserId' => $user->getId(),
|
||||||
|
'recipientEditCount' => (int)$user->getEditCount()
|
||||||
|
);
|
||||||
|
EchoHooks::logEvent( 'Echo', $data );
|
||||||
|
}
|
||||||
|
|
||||||
EchoNotificationController::resetNotificationCount( $user, DB_MASTER );
|
EchoNotificationController::resetNotificationCount( $user, DB_MASTER );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,4 +66,20 @@ class EchoNotification {
|
||||||
|
|
||||||
$wgEchoBackend->createNotification( $row );
|
$wgEchoBackend->createNotification( $row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter method
|
||||||
|
* @return EchoEvent The event for this notification
|
||||||
|
*/
|
||||||
|
public function getEvent() {
|
||||||
|
return $this->event;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter method
|
||||||
|
* @return User The recipient of this notification
|
||||||
|
*/
|
||||||
|
public function getUser() {
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue