Split up $wgEchoConfig

$wgEchoConfig is a deeply nested structure that ExtensionRegistry can't handle well.
It also combined different things, and the version number was used for two
separate purposes.

Split this out into $wgEchoCacheVersion, $wgEchoEventLoggingVersion
and $wgEchoEventLoggingSchemas.

Change-Id: I2f9d5d111f7925fb057d423a3e7064bff5040205
This commit is contained in:
Roan Kattouw 2016-12-01 08:50:18 -08:00
parent 53d3e99744
commit 49974544ba
5 changed files with 48 additions and 49 deletions

View file

@ -560,30 +560,31 @@ $wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
$wgDefaultUserOptions['echo-subscriptions-web-mention-failure'] = false;
$wgDefaultUserOptions['echo-subscriptions-web-mention-success'] = false;
// Echo cache version
$wgEchoCacheVersion = '1.12';
// Echo Configuration for EventLogging
$wgEchoConfig = array(
'version' => '1.12',
'eventlogging' => array(
/**
* Properties:
* - 'enabled': Whether it should be used
* - 'revision': revision id of the schema
* - 'client': whether the schema is needed client-side
*/
'Echo' => array(
'enabled' => false,
'revision' => 7731316,
'client' => false,
),
'EchoMail' => array(
'enabled' => false,
'revision' => 5467650,
'client' => false,
),
'EchoInteraction' => array(
'enabled' => false,
'revision' => 15823738,
'client' => true,
),
)
$wgEchoEventLoggingVersion = '1.12';
$wgEchoEventLoggingSchemas = array(
/**
* Properties:
* - 'enabled': Whether it should be used
* - 'revision': revision id of the schema
* - 'client': whether the schema is needed client-side
*/
'Echo' => array(
'enabled' => false,
'revision' => 7731316,
'client' => false,
),
'EchoMail' => array(
'enabled' => false,
'revision' => 5467650,
'client' => false,
),
'EchoInteraction' => array(
'enabled' => false,
'revision' => 15823738,
'client' => true,
),
);

View file

@ -10,7 +10,7 @@ class EchoHooks {
*/
public static function initEchoExtension() {
global $wgEchoNotifications, $wgEchoNotificationCategories, $wgEchoNotificationIcons,
$wgEchoConfig, $wgEchoMentionStatusNotifications;
$wgEchoEventLoggingSchemas, $wgEchoMentionStatusNotifications;
// allow extensions to define their own event
Hooks::run( 'BeforeCreateEchoEvent', array( &$wgEchoNotifications, &$wgEchoNotificationCategories, &$wgEchoNotificationIcons ) );
@ -23,9 +23,9 @@ class EchoHooks {
// turn schema off if eventLogging is not enabled
if ( !class_exists( 'EventLogging' ) ) {
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
foreach ( $wgEchoEventLoggingSchemas as $schema => $property ) {
if ( $property['enabled'] ) {
$wgEchoConfig['eventlogging'][$schema]['enabled'] = false;
$wgEchoEventLoggingSchemas[$schema]['enabled'] = false;
}
}
}
@ -84,8 +84,8 @@ class EchoHooks {
}
public static function onEventLoggingRegisterSchemas( array &$schemas ) {
global $wgEchoConfig;
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
global $wgEchoEventLoggingSchemas;
foreach ( $wgEchoEventLoggingSchemas as $schema => $property ) {
if ( $property['enabled'] && $property['client'] ) {
$schemas[$schema] = $property['revision'];
}
@ -96,7 +96,7 @@ class EchoHooks {
* Handler for ResourceLoaderRegisterModules hook
*/
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
global $wgEchoConfig;
global $wgEchoEventLoggingSchemas;
// ext.echo.logger is used by mobile notifications as well, so be sure not to add any
// dependencies that do not target mobile.
@ -114,7 +114,7 @@ class EchoHooks {
);
$hasSchemas = false;
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
foreach ( $wgEchoEventLoggingSchemas as $schema => $property ) {
if ( $property['enabled'] && $property['client'] ) {
$definition['dependencies'][] = 'schema.' . $schema;
$hasSchemas = true;
@ -1022,23 +1022,22 @@ class EchoHooks {
* @return bool true in all cases
*/
public static function makeGlobalVariablesScript( &$vars, OutputPage $outputPage ) {
global $wgEchoConfig;
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
$user = $outputPage->getUser();
// Provide info for the Overlay
if ( $user->isLoggedIn() ) {
$vars['wgEchoConfig'] = $wgEchoConfig;
$vars['wgEchoEventLoggingSchemas'] = $wgEchoEventLoggingSchemas;
$vars['wgEchoEventLoggingVersion'] = $wgEchoEventLoggingVersion;
} elseif (
$outputPage->getTitle()->equals( SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit' ) ) ||
// Also if running from /plain or /export
$outputPage->getTitle()->isSubpageOf( SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit' ) )
) {
// For testing purposes
$vars['wgEchoConfig'] = array(
'eventlogging' => array(
'EchoInteraction' => array(),
),
$vars['wgEchoEventLoggingSchemas'] = array(
'EchoInteraction' => array(),
);
}

View file

@ -14,15 +14,15 @@ class MWEchoEventLogging {
* @param array $data
*/
protected static function logEvent( $schema, array $data ) {
global $wgEchoConfig;
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
$schemaConfig = $wgEchoConfig['eventlogging'][$schema];
$schemaConfig = $wgEchoEventLoggingSchemas[$schema];
if ( !$schemaConfig['enabled'] ) {
// If logging for this schema is disabled, it's a no-op.
return;
}
$data['version'] = $wgEchoConfig['version'];
$data['version'] = $wgEchoEventLoggingVersion;
EventLogging::logEvent( $schema, $schemaConfig['revision'], $data );
}

View file

@ -147,8 +147,8 @@ class MWEchoNotifUser {
* Memcache key for talk notification
*/
public function getTalkNotificationCacheKey() {
global $wgEchoConfig;
return wfMemcKey( 'echo-new-talk-notification', $this->mUser->getId(), $wgEchoConfig['version'] );
global $wgEchoCacheVersion;
return wfMemcKey( 'echo-new-talk-notification', $this->mUser->getId(), $wgEchoCacheVersion );
}
/**
@ -654,9 +654,9 @@ class MWEchoNotifUser {
* @return string|false Memcached key, or false if one could not be generated
*/
protected function getMemcKey( $key, $global = false ) {
global $wgEchoConfig;
global $wgEchoCacheVersion;
if ( !$global ) {
return wfMemcKey( $key, $this->mUser->getId(), $wgEchoConfig['version'] );
return wfMemcKey( $key, $this->mUser->getId(), $wgEchoCacheVersion );
}
$lookup = CentralIdLookup::factory();
@ -664,7 +664,7 @@ class MWEchoNotifUser {
if ( !$globalId ) {
return false;
}
return wfGlobalCacheKey( $key, $globalId, $wgEchoConfig['version'] );
return wfGlobalCacheKey( $key, $globalId, $wgEchoCacheVersion );
}

View file

@ -19,7 +19,7 @@
// This should usually already be loaded, but not always
this.deferred = mw.loader.using( 'ext.eventLogging', function () {
mw.eventLog.setDefaults( 'EchoInteraction', {
version: mw.config.get( 'wgEchoConfig' ).version,
version: mw.config.get( 'wgEchoEventLoggingVersion' ),
userId: +mw.config.get( 'wgUserId' ),
editCount: +mw.config.get( 'wgUserEditCount' )
} );
@ -41,8 +41,7 @@
* @property {boolean}
*/
mw.echo.Logger.static.clickThroughEnabled = OO.getProp(
mw.config.get( 'wgEchoConfig' ),
'eventlogging',
mw.config.get( 'wgEchoEventLoggingSchemas' ),
'EchoInteraction',
'enabled'
);