2013-05-07 23:27:46 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-06 16:11:17 +00:00
|
|
|
use MediaWiki\Extension\EventLogging\EventLogging;
|
2021-06-29 06:10:07 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
|
2013-05-07 23:27:46 +00:00
|
|
|
/**
|
|
|
|
* Static class for handling all kinds of event logging
|
2021-06-29 06:10:07 +00:00
|
|
|
*
|
|
|
|
* TODO: consider making this a service with dependencies injected
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
|
|
|
class MWEchoEventLogging {
|
|
|
|
|
2021-07-27 18:54:39 +00:00
|
|
|
/** @var array */
|
2018-07-26 18:48:32 +00:00
|
|
|
private static $revisionIds = [
|
2021-07-27 18:54:39 +00:00
|
|
|
// Keep in sync with extension.json
|
|
|
|
'EchoMail' => '/analytics/legacy/echomail/1.0.0',
|
|
|
|
'EchoInteraction' => '/analytics/legacy/echointeraction/1.0.0'
|
2018-07-26 18:48:32 +00:00
|
|
|
];
|
|
|
|
|
2013-05-07 23:27:46 +00:00
|
|
|
/**
|
|
|
|
* This is the only function that interacts with EventLogging
|
2016-08-19 01:07:29 +00:00
|
|
|
*
|
2016-08-22 20:33:34 +00:00
|
|
|
* Adds common fields, and logs if logging is enabled for the given $schema.
|
2016-08-19 01:07:29 +00:00
|
|
|
*
|
2016-08-16 12:59:15 +00:00
|
|
|
* @param string $schema
|
|
|
|
* @param array $data
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
2016-08-19 01:07:29 +00:00
|
|
|
protected static function logEvent( $schema, array $data ) {
|
2016-12-01 16:50:18 +00:00
|
|
|
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
|
2013-05-07 23:27:46 +00:00
|
|
|
|
2016-12-01 16:50:18 +00:00
|
|
|
$schemaConfig = $wgEchoEventLoggingSchemas[$schema];
|
2018-07-26 18:48:32 +00:00
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' )
|
|
|
|
|| !$schemaConfig['enabled']
|
|
|
|
) {
|
2016-08-19 01:07:29 +00:00
|
|
|
// If logging for this schema is disabled, it's a no-op.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-26 18:48:32 +00:00
|
|
|
$revision = self::$revisionIds[$schema];
|
2016-12-01 16:50:18 +00:00
|
|
|
$data['version'] = $wgEchoEventLoggingVersion;
|
2016-08-22 20:33:34 +00:00
|
|
|
|
2018-07-26 18:48:32 +00:00
|
|
|
EventLogging::logEvent( $schema, $revision, $data );
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-16 21:14:26 +00:00
|
|
|
* Function for logging the event for Schema:EchoEmail
|
2021-06-29 06:10:07 +00:00
|
|
|
* @param UserIdentity $userIdentity
|
2016-08-16 12:59:15 +00:00
|
|
|
* @param string $emailDeliveryMode 'single' (default), 'daily_digest', or 'weekly_digest'
|
2013-05-07 23:27:46 +00:00
|
|
|
*/
|
2021-06-29 06:10:07 +00:00
|
|
|
public static function logSchemaEchoMail( UserIdentity $userIdentity, $emailDeliveryMode = 'single' ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$data = [
|
2021-06-29 06:10:07 +00:00
|
|
|
'recipientUserId' => $userIdentity->getId(),
|
2013-05-07 23:27:46 +00:00
|
|
|
'emailDeliveryMode' => $emailDeliveryMode
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2013-05-07 23:27:46 +00:00
|
|
|
|
2016-08-19 01:07:29 +00:00
|
|
|
self::logEvent( 'EchoMail', $data );
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 10:59:07 +00:00
|
|
|
/**
|
2021-06-29 06:10:07 +00:00
|
|
|
* @param UserIdentity $userIdentity
|
2016-08-16 10:59:07 +00:00
|
|
|
* @param string $skinName
|
|
|
|
*/
|
2021-06-29 06:10:07 +00:00
|
|
|
public static function logSpecialPageVisit( UserIdentity $userIdentity, $skinName ) {
|
|
|
|
$userEditCount = (int)MediaWikiServices::getInstance()
|
|
|
|
->getUserEditTracker()
|
|
|
|
->getUserEditCount( $userIdentity );
|
2016-08-19 01:07:29 +00:00
|
|
|
self::logEvent(
|
2016-08-16 10:59:07 +00:00
|
|
|
'EchoInteraction',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-08-16 10:59:07 +00:00
|
|
|
'context' => 'archive',
|
|
|
|
'action' => 'special-page-visit',
|
2021-06-29 06:10:07 +00:00
|
|
|
'userId' => $userIdentity->getId(),
|
|
|
|
'editCount' => $userEditCount,
|
2021-12-21 00:47:31 +00:00
|
|
|
'notifWiki' => WikiMap::getCurrentWikiId(),
|
2016-08-16 10:59:07 +00:00
|
|
|
// Hack: Figure out if we are in the mobile skin
|
|
|
|
'mobile' => $skinName === 'minerva',
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-08-16 10:59:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:27:46 +00:00
|
|
|
}
|