Merge "Add first version of EventLogging schema to Echo"

This commit is contained in:
jenkins-bot 2013-03-03 03:45:46 +00:00 committed by Gerrit Code Review
commit 95f1d50c18
4 changed files with 98 additions and 1 deletions

View file

@ -87,6 +87,7 @@ $wgHooks['PersonalUrls'][] = 'EchoHooks::onPersonalUrls';
$wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
$wgHooks['MakeGlobalVariablesScript'][] = 'EchoHooks::makeGlobalVariablesScript';
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
$wgHooks['ResourceLoaderRegisterModules'][] = 'EchoHooks::onResourceLoaderRegisterModules';
// Extension initialization
$wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
@ -247,23 +248,28 @@ $wgEchoEnabledEvents = array(
$wgEchoEventDetails = array(
'welcome' => array(
'nodismiss' => array( 'web', 'email' ),
'group' => 'positive',
),
'edit-user-talk' => array(
'category' => 'edit-user-talk',
'priority' => 1,
'nodismiss' => array( 'web' ),
'group' => 'interactive',
),
'reverted' => array(
'category' => 'edit-revert',
'priority' => 9,
'group' => 'negative',
),
'article-linked' => array(
'category' => 'cross-reference',
'priority' => 5,
'group' => 'positive',
),
'mention' => array(
'category' => 'mention',
'priority' => 4,
'group' => 'interactive',
),
);
@ -369,3 +375,14 @@ foreach ( $wgEchoEnabledEvents as $wgEchoEnabledEvent ) {
// unset default email for reverted, article-linked (change them to opt-in)
$wgDefaultUserOptions['echo-email-notificationsreverted'] = false;
$wgDefaultUserOptions['echo-email-notificationsarticle-linked'] = false;
// Echo Configuration
$wgEchoConfig = array(
'version' => '1.0',
'eventlogging' => array (
'Echo' => array (
'enabled' => true,
'revision' => 5285750
)
)
);

View file

@ -15,6 +15,43 @@ class EchoHooks {
$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
* @return bool true in all cases

View file

@ -10,7 +10,34 @@ class EchoNotifier {
* @param $event EchoEvent to notify about.
*/
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 );
}

View file

@ -66,4 +66,20 @@ class EchoNotification {
$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;
}
}