2013-05-07 23:27:46 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-13 07:53:42 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications;
|
|
|
|
|
|
|
|
use ExtensionRegistry;
|
|
|
|
use MediaWiki\Extension\EventLogging\EventLogging as EventLoggingExt;
|
2021-06-29 06:10:07 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\User\UserIdentity;
|
2023-04-25 09:53:21 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2021-06-29 06:10:07 +00:00
|
|
|
|
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
|
|
|
*/
|
2022-11-13 07:53:42 +00:00
|
|
|
class EventLogging {
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:50:18 +00:00
|
|
|
$data['version'] = $wgEchoEventLoggingVersion;
|
2016-08-22 20:33:34 +00:00
|
|
|
|
2022-09-23 11:15:12 +00:00
|
|
|
// 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.
|
2022-11-13 07:53:42 +00:00
|
|
|
EventLoggingExt::logEvent( $schema, -1, $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
|
|
|
}
|