Log tofu detection event

This only works if webfonts enabled (the checkbox is checked).

Change-Id: Ibbedc6a34dacb983f156d8a33afa5ab625e32f5f
This commit is contained in:
Amir E. Aharoni
2014-02-17 23:12:02 +02:00
parent 4f27c6769b
commit 261542d738
4 changed files with 48 additions and 11 deletions

View File

@@ -79,7 +79,10 @@ $wgResourceModules['ext.uls.init'] = array(
$wgResourceModules['ext.uls.eventlogger'] = array(
'scripts' => 'resources/js/ext.uls.eventlogger.js',
'dependencies' => 'schema.UniversalLanguageSelector',
'dependencies' => array(
'schema.UniversalLanguageSelector',
'schema.UniversalLanguageSelector-tofu',
),
) + $resourcePaths;
$wgResourceModules['ext.uls.i18n'] = array(

View File

@@ -216,20 +216,29 @@ $GLOBALS['wgExtensionFunctions'][] = function () {
};
}
// If EventLogging integration is enabled, first ensure that the
// EventLogging extension is present, then declare schema module.
// 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' ) ) {
// NB: When updating the schema, remember also to update the version
// in the schema default in the JavaScript library.
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
$wgResourceModules['schema.UniversalLanguageSelector'] = array(
'class' => 'ResourceLoaderSchemaModule',
'schema' => 'UniversalLanguageSelector',
'revision' => 7327441,
);
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector-tofu
$wgResourceModules['schema.UniversalLanguageSelector-tofu'] = array(
'class' => 'ResourceLoaderSchemaModule',
'schema' => 'UniversalLanguageSelector-tofu',
'revision' => 7629564,
);
} else {
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, but '
. 'the extension is is not available. Disabling wgULSEventLogging.' );
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, '
. 'but the extension is not available. Disabling wgULSEventLogging.' );
$wgULSEventLogging = false;
}
}

View File

@@ -35,7 +35,6 @@
init: function () {
var eventLogger = this;
// Set event defaults and make the
mw.eventLog.setDefaults( 'UniversalLanguageSelector', {
version: 1,
token: mw.user.id(),
@@ -43,6 +42,11 @@
interfaceLanguage: mw.config.get( 'wgUserLanguage' )
} );
mw.eventLog.setDefaults( 'UniversalLanguageSelector-tofu', {
version: 1,
token: mw.user.id()
} );
eventLogger.logEventQueue.fire();
},
@@ -50,17 +54,20 @@
* Local wrapper for 'mw.eventLog.logEvent'
*
* @param {Object} event Event action and optional fields
* @param {String} schema The schema; 'UniversalLanguageSelector' is the default
* @return {jQuery.Promise} jQuery Promise object for the logging call
*/
log: function ( event ) {
log: function ( event, schema ) {
// We need to create our own deferred for two reasons:
// - logEvent might not be executed immediately
// - we cannot reject a promise returned by it
// So we proxy the original promises status updates.
var deferred = $.Deferred();
schema = schema || 'UniversalLanguageSelector';
this.logEventQueue.add( function () {
mw.eventLog.logEvent( 'UniversalLanguageSelector', event )
mw.eventLog.logEvent( schema, event )
.done( deferred.resolve )
.fail( deferred.reject );
} );
@@ -85,6 +92,7 @@
mw.hook( 'mw.uls.font.change' ).add( $.proxy( this.fontChange, this ) );
mw.hook( 'mw.uls.webfonts.enable' ).add( $.proxy( this.enableWebfonts, this ) );
mw.hook( 'mw.uls.webfonts.disable' ).add( $.proxy( this.disableWebfonts, this ) );
mw.hook( 'mw.uls.webfonts.tofudetected' ).add( $.proxy( this.tofuDetected, this ) );
$( 'body' ).on( 'noresults.uls', '.uls-menu .languagefilter',
$.proxy( this.noSearchResults, this )
@@ -227,6 +235,17 @@
this.log( { action: 'webfonts-enable', context: context } );
},
/**
* Log tofu detection
* @param {string} language Code of the element in which tofu was detected
*/
tofuDetected: function ( language ) {
this.log( {
tofuElementLanguage: language,
webfontsEnabled: mw.webfonts.preferences.isEnabled()
}, 'UniversalLanguageSelector-tofu' );
},
/**
* Log search strings which produce no search results.
* @param {jQuery.event} event The orignal event

View File

@@ -168,9 +168,15 @@
detectTofu( $.uls.data.getAutonym( language ) );
if ( tofu ) {
mw.log( 'tofu detected for ' + language );
// Cache the languages with tofu
tofuLanguages[language] = true;
// Log the tofu detection only once per page per language
if ( !tofuLanguages[language] ) {
mw.log( 'tofu detected for ' + language );
mw.hook( 'mw.uls.webfonts.tofudetected' ).fire( language );
// Cache the languages with tofu
tofuLanguages[language] = true;
}
font = autonym ? 'Autonym' : defaultFont;
} else {
// No tofu and no font preference. Use system font.