mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
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:
parent
90b1f09ec5
commit
a3bfd725ea
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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' )
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue