Use $.Callbacks to queue events until EL has loaded

This patch provides a workaround for bug 50746. It modifies mw.uls.eventLog so
that it does not directly attempt to log events but instead adds them to a
$.Callbacks('memory once') queue. If EventLogging is not enabled, the Callbacks
object never fires. If EventLogging is enabled, it is requested via
mw.loader.using, but only after $(document).ready. This prevents ResourceLoader
from attempting to inject it via document.write. The mw.loader.using callback
sets the schema defaults and calls .fire on the Callbacks object, causing the
EventLogging event queue to be processed. Tested on Opera 12 and Chrome 30 on
OS X.

Bug: 50746
Change-Id: I89cf06990ee85e70698149b4812d7900218e4fb4
This commit is contained in:
Ori Livneh
2013-07-08 12:17:29 -07:00
committed by Ori.livneh
parent b95b7d75d5
commit 1603fd97a8

View File

@@ -34,7 +34,8 @@
var MWMessageStore,
jsonLoader,
initialized = false,
currentLang = mw.config.get( 'wgUserLanguage' );
currentLang = mw.config.get( 'wgUserLanguage' ),
logEventQueue = $.Callbacks( 'memory once' );
mw.uls = mw.uls || {};
mw.uls.previousLanguagesCookie = 'uls-previous-languages';
@@ -156,24 +157,11 @@
* @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 );
};
mw.uls.logEvent = function ( event ) {
logEventQueue.add( function () {
mw.eventLog.logEvent( 'UniversalLanguageSelector', event );
} );
}
};
/**
* jquery.i18n message store for MediaWiki
@@ -239,6 +227,20 @@
return;
}
// 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
} );
logEventQueue.fire();
} );
}
/*
* The 'als' is used in a non-standard way in MediaWiki -
* it may be used to represent the Allemanic language,