. * * @file * @ingroup extensions */ namespace Popups\EventLogging; use Config; use ExtensionRegistry; class MWEventLogger implements EventLogger { /** * @var Config */ private $config; /** * @var ExtensionRegistry */ private $registry; /** * Module constructor. * @param Config $config MediaWiki configuration */ public function __construct( Config $config, ExtensionRegistry $registry ) { $this->config = $config; $this->registry = $registry; } /** * @return bool */ public function shouldLog() { // 1 fully enabled, 0 disabled $samplingRate = $this->config->get( 'PopupsSchemaSamplingRate' ); if ( $samplingRate == 0 ) { return false; } return (float)wfRandom() <= (float)$samplingRate; } public function log( array $event ) { if ( !$this->shouldLog() ) { return false; } $eventLoggingSchemas = $this->registry->getAttribute( 'EventLoggingSchemas' ); \EventLogging::logEvent( self::PREVIEWS_SCHEMA_NAME, $eventLoggingSchemas[ self::PREVIEWS_SCHEMA_NAME ], $event ); } }