mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-15 03:35:01 +00:00
844a64ff9a
EventLogging::logEvent() overwrides the $revId parameter when the schema has been migrated to the Event Platform. Add a note and use a $revId of -1 to make this consistent with other calls to EventLogging::logEvent() for schemas that have been migrated to the Event Platform [0]. [0] https://codesearch.wmcloud.org/search/?q=%3A%3AlogEvent%5C(%20%27%5Cw%2B%27%2C%20-1 Bug: T318263 Change-Id: I5fa515d853326307619b044d25c2f672bcb6de63
78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\EventLogging\EventLogging;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
/**
|
|
* Static class for handling all kinds of event logging
|
|
*
|
|
* TODO: consider making this a service with dependencies injected
|
|
*/
|
|
class MWEchoEventLogging {
|
|
|
|
/**
|
|
* This is the only function that interacts with EventLogging
|
|
*
|
|
* Adds common fields, and logs if logging is enabled for the given $schema.
|
|
*
|
|
* @param string $schema
|
|
* @param array $data
|
|
*/
|
|
protected static function logEvent( $schema, array $data ) {
|
|
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
|
|
|
|
$schemaConfig = $wgEchoEventLoggingSchemas[$schema];
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' )
|
|
|| !$schemaConfig['enabled']
|
|
) {
|
|
// If logging for this schema is disabled, it's a no-op.
|
|
return;
|
|
}
|
|
|
|
$data['version'] = $wgEchoEventLoggingVersion;
|
|
|
|
// NOTE: The 'EchoMail' and 'EchoInteraction' events were migrated to the Event Platform
|
|
// and are no longer using the legacy EventLogging schema from metawiki. $revId is actually
|
|
// overridden by the EventLoggingSchemas extension attribute in extension.json.
|
|
EventLogging::logEvent( $schema, -1, $data );
|
|
}
|
|
|
|
/**
|
|
* Function for logging the event for Schema:EchoEmail
|
|
* @param UserIdentity $userIdentity
|
|
* @param string $emailDeliveryMode 'single' (default), 'daily_digest', or 'weekly_digest'
|
|
*/
|
|
public static function logSchemaEchoMail( UserIdentity $userIdentity, $emailDeliveryMode = 'single' ) {
|
|
$data = [
|
|
'recipientUserId' => $userIdentity->getId(),
|
|
'emailDeliveryMode' => $emailDeliveryMode
|
|
];
|
|
|
|
self::logEvent( 'EchoMail', $data );
|
|
}
|
|
|
|
/**
|
|
* @param UserIdentity $userIdentity
|
|
* @param string $skinName
|
|
*/
|
|
public static function logSpecialPageVisit( UserIdentity $userIdentity, $skinName ) {
|
|
$userEditCount = (int)MediaWikiServices::getInstance()
|
|
->getUserEditTracker()
|
|
->getUserEditCount( $userIdentity );
|
|
self::logEvent(
|
|
'EchoInteraction',
|
|
[
|
|
'context' => 'archive',
|
|
'action' => 'special-page-visit',
|
|
'userId' => $userIdentity->getId(),
|
|
'editCount' => $userEditCount,
|
|
'notifWiki' => WikiMap::getCurrentWikiId(),
|
|
// Hack: Figure out if we are in the mobile skin
|
|
'mobile' => $skinName === 'minerva',
|
|
]
|
|
);
|
|
}
|
|
|
|
}
|