BryanDavis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/222204

Change subject: Add support for the 'TrackEvent' hook
......................................................................

Add support for the 'TrackEvent' hook

Add a new $wgEventLoggingTrackedEvents global and a listener to process
'TrackEvent' hook callbacks as EventLogging::logEvent calls.
$wgEventLoggingTrackedEvents is an associative array of 'TrackEvent'
$topic => array() values that describe which event topics are of
interest and how to map them to an EventLogging schema.

Requires: Ie77a3f03f04967e0072877a32fcc86bcb15dfb3a
Bug: T95356
Change-Id: Iac7358080577e16c354a2992725170bd33dfe8fd
---
M EventLogging.php
M includes/EventLoggingHooks.php
2 files changed, 45 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging 
refs/changes/04/222204/1

diff --git a/EventLogging.php b/EventLogging.php
index 553b1eb..c791f66 100644
--- a/EventLogging.php
+++ b/EventLogging.php
@@ -95,6 +95,21 @@
  */
 $wgEventLoggingSchemas = isset( $wgEventLoggingSchemas ) ? 
$wgEventLoggingSchemas : array();
 
+/**
+ * @var array: Associative array of 'TrackEvent' hook topics to record as
+ * events.
+ *
+ * Array keys are 'TrackEvent' $topic values. Values are associative arrays to
+ * be used to submit the event to EventLogging::logEvent:
+ * - 'schema': string Schema name (optional: default is $topic)
+ * - 'revision': int Revision ID of schema
+ * - 'data': array Data to merge with data from hook (optional: default 
array())
+ * - 'options': int logEvent options bitmask (optional: default 0)
+ *
+ * @example array: array( 'PageSave' => array( 'revision' => 12345 ) );
+ */
+$wgEventLoggingTrackedEvents = array();
+
 // Helpers
 
 /**
@@ -212,6 +227,7 @@
 $wgHooks[ 'ResourceLoaderGetConfigVars' ][] = 
'EventLoggingHooks::onResourceLoaderGetConfigVars';
 $wgHooks[ 'ResourceLoaderTestModules' ][] = 
'EventLoggingHooks::onResourceLoaderTestModules';
 $wgHooks[ 'ResourceLoaderRegisterModules' ][] = 
'EventLoggingHooks::onResourceLoaderRegisterModules';
+$wgHooks[ 'TrackEvent' ][] = 'EventLoggingHooks::onTrackEvent';
 
 // Registers hook and content handlers for JSON schema content iff
 // running on the MediaWiki instance housing the schemas.
diff --git a/includes/EventLoggingHooks.php b/includes/EventLoggingHooks.php
index df8fc10..ace0931 100644
--- a/includes/EventLoggingHooks.php
+++ b/includes/EventLoggingHooks.php
@@ -27,7 +27,8 @@
                        'wgEventLoggingBaseUri',
                        'wgEventLoggingDBname',
                        'wgEventLoggingFile',
-                       'wgEventLoggingSchemaApiUri'
+                       'wgEventLoggingSchemaApiUri',
+                       'wgEventLoggingTrackedEvents',
                ) as $configVar ) {
                        if ( !isset( $GLOBALS[ $configVar ] ) || $GLOBALS[ 
$configVar ] === false ) {
                                wfDebugLog( 'EventLogging', "$configVar has not 
been configured." );
@@ -105,4 +106,31 @@
                );
                return true;
        }
+
+       /**
+        * Log events recieved from the 'TrackEvent' hook that have been
+        * registered in $wgEventLoggingTrackedEvents.
+        *
+        * @param string $topic Event topic
+        * @param array $data Event data
+        */
+       public static function onTrackEvent( $topic, $data ) {
+               global $wgEventLoggingTrackedEvents;
+               if ( isset( $wgEventLoggingTrackedEvents[$topic] ) &&
+                       isset( $wgEventLoggingTrackedEvents[$topic]['revision'] 
)
+               ) {
+                       $cfg = $wgEventLoggingTrackedEvents[$topic] + array(
+                               'schema' => $topic,
+                               'data' => array(),
+                               'options' => 0,
+                       );
+
+                       EventLogging::logEvent(
+                               $cfg['schema'],
+                               $cfg['revision'],
+                               $data + $cfg['data'],
+                               $cfg['options']
+                       );
+               }
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/222204
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac7358080577e16c354a2992725170bd33dfe8fd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to