Bsitu has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51610
Change subject: Add first version of EventLogging schema to Echo
......................................................................
Add first version of EventLogging schema to Echo
Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
---
M Echo.php
M Hooks.php
M Notifier.php
M model/Notification.php
4 files changed, 96 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/10/51610/1
diff --git a/Echo.php b/Echo.php
index 50ece45..7e576ea 100644
--- a/Echo.php
+++ b/Echo.php
@@ -87,6 +87,7 @@
$wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
$wgHooks['MakeGlobalVariablesScript'][] =
'EchoHooks::makeGlobalVariablesScript';
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
+$wgHooks['ResourceLoaderRegisterModules'][] =
'EchoHooks::onResourceLoaderRegisterModules';
// Extension initialization
$wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
@@ -244,23 +245,28 @@
$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',
),
);
@@ -366,3 +372,14 @@
// 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
+ )
+ )
+);
diff --git a/Hooks.php b/Hooks.php
index 8fccccd..f7ce92d 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -16,6 +16,49 @@
}
/**
+ * 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 (
+ !function_exists( 'efLogServerSideEvent' )
+ || !isset( $wgEchoConfig['eventlogging'][$schema] )
+ || !$wgEchoConfig['eventlogging'][$schema]['enabled']
+ ) {
+ return;
+ }
+
+ efLogServerSideEvent( $schema,
$wgEchoConfig['eventlogging'][$schema]['revision'], $data );
+ }
+
+ /**
* @param $updater DatabaseUpdater object
* @return bool true in all cases
*/
diff --git a/Notifier.php b/Notifier.php
index 57836c8..d58a46a 100644
--- a/Notifier.php
+++ b/Notifier.php
@@ -10,7 +10,34 @@
* @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 );
}
diff --git a/model/Notification.php b/model/Notification.php
index d1bdea5..c947d77 100644
--- a/model/Notification.php
+++ b/model/Notification.php
@@ -66,4 +66,12 @@
$wgEchoBackend->createNotification( $row );
}
+
+ public function getEvent() {
+ return $this->event;
+ }
+
+ public function getUser() {
+ return $this->user;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/51610
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits