Bundle logger-related config vars with ext.echo.logger module

There's no real reason for these to be in MakeGlobalVariablesScript
because they don't really depend on the request context: they were being
omitted if the user was not logged in, but we can just check the user's
logged-in status in JS instead.

Bug: T221151
Change-Id: I2df6d7e061545d342bc3068dccd5ce2f6e85fe78
This commit is contained in:
Roan Kattouw 2019-07-20 00:07:05 -07:00 committed by Catrope
parent 90b1f09ec5
commit a3bfd725ea
3 changed files with 20 additions and 27 deletions

View file

@ -52,11 +52,16 @@
},
"ResourceModules": {
"ext.echo.logger": {
"scripts": [
"logger/mw.echo.Logger.js"
"packageFiles": [
"logger/mw.echo.Logger.js",
{
"name": "logger/config.json",
"callback": "EchoHooks::getLoggerConfigVars"
}
],
"dependencies": [
"oojs"
"oojs",
"mediawiki.user"
],
"targets": [
"desktop",
@ -386,7 +391,6 @@
"GetPreferences": "EchoHooks::getPreferences",
"PersonalUrls": "EchoHooks::onPersonalUrls",
"BeforePageDisplay": "EchoHooks::beforePageDisplay",
"MakeGlobalVariablesScript": "EchoHooks::makeGlobalVariablesScript",
"ResourceLoaderRegisterModules": "EchoHooks::onResourceLoaderRegisterModules",
"ResourceLoaderTestModules": "EchoHooks::onResourceLoaderTestModules",
"UserGroupsChanged": "EchoHooks::onUserGroupsChanged",

View file

@ -1110,27 +1110,6 @@ class EchoHooks {
return true;
}
/**
* Handler for MakeGlobalVariablesScript hook.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
* @param array &$vars Variables to be added into the output
* @param OutputPage $outputPage OutputPage instance calling the hook
* @return bool true in all cases
*/
public static function makeGlobalVariablesScript( &$vars, OutputPage $outputPage ) {
global $wgEchoEventLoggingSchemas, $wgEchoEventLoggingVersion;
$user = $outputPage->getUser();
// Provide info for ext.echo.logger
if ( $user->isLoggedIn() ) {
$vars['wgEchoInteractionLogging'] = $wgEchoEventLoggingSchemas['EchoInteraction']['enabled']
&& ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' );
$vars['wgEchoEventLoggingVersion'] = $wgEchoEventLoggingVersion;
}
return true;
}
public static function onOutputPageCheckLastModified( array &$modifiedTimes, OutputPage $out ) {
$user = $out->getUser();
if ( $user->isLoggedIn() ) {
@ -1484,6 +1463,15 @@ class EchoHooks {
];
}
public static function getLoggerConfigVars( ResourceLoaderContext $context, Config $config ) {
$schemas = $config->get( 'EchoEventLoggingSchemas' );
return [
'EchoInteractionLogging' => $schemas['EchoInteraction']['enabled'] &&
ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ),
'EchoEventLoggingVersion' => $config->get( 'EchoEventLoggingVersion' )
];
}
/**
* @param WikiPage &$article
* @param User &$user

View file

@ -1,4 +1,5 @@
( function () {
var configVars = require( './config.json' );
mw.echo = mw.echo || {};
/**
@ -28,7 +29,7 @@
* @static
* @property {boolean}
*/
mw.echo.Logger.static.clickThroughEnabled = !!mw.config.get( 'wgEchoInteractionLogging' );
mw.echo.Logger.static.clickThroughEnabled = !!configVars.EchoInteractionLogging && !mw.user.isAnon();
/**
* Context definitions.
@ -84,7 +85,7 @@
myEvt = {
action: action,
version: mw.config.get( 'wgEchoEventLoggingVersion' ),
version: configVars.EchoEventLoggingVersion,
userId: +mw.config.get( 'wgUserId' ),
editCount: +mw.config.get( 'wgUserEditCount' )
};