Merge "Prepare ULS for EventLogging"
This commit is contained in:
@@ -43,11 +43,16 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* Hook: BeforePageDisplay
|
* Hook: BeforePageDisplay
|
||||||
*/
|
*/
|
||||||
public static function addModules( $out, $skin ) {
|
public static function addModules( $out, $skin ) {
|
||||||
global $wgULSGeoService;
|
global $wgULSGeoService, $wgULSEventLogging;
|
||||||
|
|
||||||
// Load the style for users without JS, to hide the useless links
|
// Load the style for users without JS, to hide the useless links
|
||||||
$out->addModuleStyles( 'ext.uls.nojs' );
|
$out->addModuleStyles( 'ext.uls.nojs' );
|
||||||
|
|
||||||
|
// If EventLogging integration is enabled, load the schema module.
|
||||||
|
if ( $wgULSEventLogging ) {
|
||||||
|
$out->addModules( 'schema.UniversalLanguageSelector' );
|
||||||
|
}
|
||||||
|
|
||||||
// If the extension is enabled, basic features (API, language data) available.
|
// If the extension is enabled, basic features (API, language data) available.
|
||||||
$out->addModules( 'ext.uls.init' );
|
$out->addModules( 'ext.uls.init' );
|
||||||
|
|
||||||
@@ -240,7 +245,7 @@ class UniversalLanguageSelectorHooks {
|
|||||||
*/
|
*/
|
||||||
public static function addConfig( &$vars ) {
|
public static function addConfig( &$vars ) {
|
||||||
global $wgULSGeoService, $wgULSIMEEnabled, $wgULSPosition,
|
global $wgULSGeoService, $wgULSIMEEnabled, $wgULSPosition,
|
||||||
$wgULSAnonCanChangeLanguage;
|
$wgULSAnonCanChangeLanguage, $wgULSEventLogging;
|
||||||
|
|
||||||
// Place constant stuff here (not depending on request context)
|
// Place constant stuff here (not depending on request context)
|
||||||
if ( is_string( $wgULSGeoService ) ) {
|
if ( is_string( $wgULSGeoService ) ) {
|
||||||
@@ -249,6 +254,7 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$vars['wgULSIMEEnabled'] = $wgULSIMEEnabled;
|
$vars['wgULSIMEEnabled'] = $wgULSIMEEnabled;
|
||||||
$vars['wgULSPosition'] = $wgULSPosition;
|
$vars['wgULSPosition'] = $wgULSPosition;
|
||||||
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
|
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
|
||||||
|
$vars['wgULSEventLogging'] = $wgULSEventLogging;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,13 @@ $wgULSIMEEnabled = true;
|
|||||||
*/
|
*/
|
||||||
$wgULSPosition = 'personal';
|
$wgULSPosition = 'personal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use EventLogging. The EventLogging extension must be installed
|
||||||
|
* if this option is enabled.
|
||||||
|
* @since 2013.06
|
||||||
|
*/
|
||||||
|
$wgULSEventLogging = false;
|
||||||
|
|
||||||
$dir = __DIR__;
|
$dir = __DIR__;
|
||||||
|
|
||||||
// Internationalization
|
// Internationalization
|
||||||
@@ -139,11 +146,12 @@ $wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLangua
|
|||||||
$wgHooks['SkinTemplateOutputPageBeforeExec'][] =
|
$wgHooks['SkinTemplateOutputPageBeforeExec'][] =
|
||||||
'UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec';
|
'UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec';
|
||||||
|
|
||||||
|
|
||||||
$wgDefaultUserOptions['uls-preferences'] = '';
|
$wgDefaultUserOptions['uls-preferences'] = '';
|
||||||
$wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
|
$wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
|
||||||
|
|
||||||
$wgExtensionFunctions[] = function() {
|
$wgExtensionFunctions[] = function() {
|
||||||
global $wgHooks, $wgULSGeoService;
|
global $wgHooks, $wgResourceModules, $wgULSEventLogging, $wgULSGeoService;
|
||||||
|
|
||||||
if ( $wgULSGeoService === true ) {
|
if ( $wgULSGeoService === true ) {
|
||||||
$wgHooks['BeforePageDisplay'][] = function( &$out ) {
|
$wgHooks['BeforePageDisplay'][] = function( &$out ) {
|
||||||
@@ -153,6 +161,24 @@ $wgExtensionFunctions[] = function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If EventLogging integration is enabled, first ensure that the
|
||||||
|
// EventLogging extension is present, then declare schema module.
|
||||||
|
// If it is not present, emit a warning and disable logging.
|
||||||
|
if ( $wgULSEventLogging ) {
|
||||||
|
if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
|
||||||
|
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
|
||||||
|
$wgResourceModules['schema.UniversalLanguageSelector'] = array(
|
||||||
|
'class' => 'ResourceLoaderSchemaModule',
|
||||||
|
'schema' => 'UniversalLanguageSelector',
|
||||||
|
'revision' => 5573536,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, but '
|
||||||
|
. 'the extension is is not available. Disabling wgULSEventLogging.' );
|
||||||
|
$wgULSEventLogging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,33 @@
|
|||||||
return !/MSIE [67]/i.test( navigator.userAgent );
|
return !/MSIE [67]/i.test( navigator.userAgent );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local wrapper for 'mw.eventLog.logEvent' which handles default params
|
||||||
|
* and ensures the correct schema is loaded.
|
||||||
|
*
|
||||||
|
* @param {Object} data Event action and optional fields
|
||||||
|
* @since 2013.07
|
||||||
|
* @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
|
||||||
|
*/
|
||||||
|
mw.uls.logEvent = $.noop;
|
||||||
|
|
||||||
|
// If EventLogging integration is enabled, set event defaults and make the
|
||||||
|
// the function call event logging with correct schema.
|
||||||
|
if ( mw.config.get( 'wgULSEventLogging' ) ) {
|
||||||
|
mw.loader.using( 'schema.UniversalLanguageSelector', function () {
|
||||||
|
mw.eventLog.setDefaults( 'UniversalLanguageSelector', {
|
||||||
|
version: 1,
|
||||||
|
token: mw.user.id(),
|
||||||
|
contentLanguage: mw.config.get( 'wgContentLanguage' ),
|
||||||
|
interfaceLanguage: currentLang
|
||||||
|
} );
|
||||||
|
|
||||||
|
mw.uls.logEvent = function ( event ) {
|
||||||
|
mw.eventLog.logEvent( 'UniversalLanguageSelector', event );
|
||||||
|
};
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* i18n initialization
|
* i18n initialization
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user