From 1603fd97a83818808ffff9979cf8522a5dd9c05c Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Mon, 8 Jul 2013 12:17:29 -0700 Subject: [PATCH] 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 --- resources/js/ext.uls.init.js | 38 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/resources/js/ext.uls.init.js b/resources/js/ext.uls.init.js index 02421849..f722caa1 100644 --- a/resources/js/ext.uls.init.js +++ b/resources/js/ext.uls.init.js @@ -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,