Remove tofu detection logging
Change-Id: I2b808bae2ee19062c16d8aaff2bdf0b2986e8ad0
This commit is contained in:
@@ -82,7 +82,6 @@ $wgResourceModules['ext.uls.eventlogger'] = array(
|
|||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
'mediawiki.user',
|
'mediawiki.user',
|
||||||
'schema.UniversalLanguageSelector',
|
'schema.UniversalLanguageSelector',
|
||||||
'schema.UniversalLanguageSelector-tofu',
|
|
||||||
),
|
),
|
||||||
) + $resourcePaths;
|
) + $resourcePaths;
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$wgULSPosition, $wgULSNoWebfontsSelectors,
|
$wgULSPosition, $wgULSNoWebfontsSelectors,
|
||||||
$wgULSAnonCanChangeLanguage,
|
$wgULSAnonCanChangeLanguage,
|
||||||
$wgULSEventLogging,
|
$wgULSEventLogging,
|
||||||
$wgULSTofuLoggingChance, $wgULSTofuLoggingMaxTime,
|
|
||||||
$wgULSImeSelectors, $wgULSNoImeSelectors,
|
$wgULSImeSelectors, $wgULSNoImeSelectors,
|
||||||
$wgULSFontRepositoryBasePath,
|
$wgULSFontRepositoryBasePath,
|
||||||
$wgExtensionAssetsPath;
|
$wgExtensionAssetsPath;
|
||||||
@@ -290,8 +289,6 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$vars['wgULSPosition'] = $wgULSPosition;
|
$vars['wgULSPosition'] = $wgULSPosition;
|
||||||
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
|
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
|
||||||
$vars['wgULSEventLogging'] = $wgULSEventLogging;
|
$vars['wgULSEventLogging'] = $wgULSEventLogging;
|
||||||
$vars['wgULSTofuLoggingChance'] = $wgULSTofuLoggingChance;
|
|
||||||
$vars['wgULSTofuLoggingMaxTime'] = $wgULSTofuLoggingMaxTime;
|
|
||||||
$vars['wgULSImeSelectors'] = $wgULSImeSelectors;
|
$vars['wgULSImeSelectors'] = $wgULSImeSelectors;
|
||||||
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors;
|
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors;
|
||||||
$vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors;
|
$vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors;
|
||||||
|
|||||||
@@ -136,25 +136,6 @@ $GLOBALS['wgULSPosition'] = 'personal';
|
|||||||
*/
|
*/
|
||||||
$GLOBALS['wgULSEventLogging'] = false;
|
$GLOBALS['wgULSEventLogging'] = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* How frequently to run tofu detection for all languages and to log them.
|
|
||||||
* This must be a number between 0 and 100, which signifies the percentage
|
|
||||||
* of pages for which this will be done. If it's 100, then it will be
|
|
||||||
* done for all pages. If it's 20, then it will be done on 20% of pages.
|
|
||||||
* The default is not to do it on any pages.
|
|
||||||
* @since 2014.04
|
|
||||||
*/
|
|
||||||
$GLOBALS['wgULSTofuLoggingChance'] = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If tofu detection for all languages is enabled, and this value is non-zero
|
|
||||||
* this specifies the maximum time in milliseconds that the tofu detection
|
|
||||||
* is allowed to run before it's forced to stop.
|
|
||||||
* The default is 0 - not to force it to stop.
|
|
||||||
* @since 2014.04
|
|
||||||
*/
|
|
||||||
$GLOBALS['wgULSTofuLoggingMaxTime'] = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of jQuery selectors of elements on which IME should be enabled.
|
* Array of jQuery selectors of elements on which IME should be enabled.
|
||||||
*
|
*
|
||||||
@@ -261,13 +242,6 @@ $GLOBALS['wgExtensionFunctions'][] = function () {
|
|||||||
'schema' => 'UniversalLanguageSelector',
|
'schema' => 'UniversalLanguageSelector',
|
||||||
'revision' => 7327441,
|
'revision' => 7327441,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector-tofu
|
|
||||||
$wgResourceModules['schema.UniversalLanguageSelector-tofu'] = array(
|
|
||||||
'class' => 'ResourceLoaderSchemaModule',
|
|
||||||
'schema' => 'UniversalLanguageSelector-tofu',
|
|
||||||
'revision' => 7629564,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, '
|
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, '
|
||||||
. 'but the extension is not available. Disabling wgULSEventLogging.' );
|
. 'but the extension is not available. Disabling wgULSEventLogging.' );
|
||||||
|
|||||||
@@ -42,11 +42,6 @@
|
|||||||
interfaceLanguage: mw.config.get( 'wgUserLanguage' )
|
interfaceLanguage: mw.config.get( 'wgUserLanguage' )
|
||||||
} );
|
} );
|
||||||
|
|
||||||
mw.eventLog.setDefaults( 'UniversalLanguageSelector-tofu', {
|
|
||||||
version: 1,
|
|
||||||
token: mw.user.id()
|
|
||||||
} );
|
|
||||||
|
|
||||||
eventLogger.logEventQueue.fire();
|
eventLogger.logEventQueue.fire();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -92,7 +87,6 @@
|
|||||||
mw.hook( 'mw.uls.font.change' ).add( $.proxy( this.fontChange, this ) );
|
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.enable' ).add( $.proxy( this.enableWebfonts, this ) );
|
||||||
mw.hook( 'mw.uls.webfonts.disable' ).add( $.proxy( this.disableWebfonts, 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',
|
$( 'body' ).on( 'noresults.uls', '.uls-menu .languagefilter',
|
||||||
$.proxy( this.noSearchResults, this )
|
$.proxy( this.noSearchResults, this )
|
||||||
@@ -235,17 +229,6 @@
|
|||||||
this.log( { action: 'webfonts-enable', context: context } );
|
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.
|
* Log search strings which produce no search results.
|
||||||
* @param {jQuery.event} event The orignal event
|
* @param {jQuery.event} event The orignal event
|
||||||
|
|||||||
@@ -224,70 +224,11 @@
|
|||||||
|
|
||||||
$( document ).ready( function () {
|
$( document ).ready( function () {
|
||||||
mw.uls.init( function () {
|
mw.uls.init( function () {
|
||||||
var tofuStartTime, tofuEndTime, tofuTime;
|
|
||||||
|
|
||||||
mw.webfonts.preferences.load();
|
mw.webfonts.preferences.load();
|
||||||
|
|
||||||
if ( mw.webfonts.preferences.isEnabled() ) {
|
if ( mw.webfonts.preferences.isEnabled() ) {
|
||||||
mw.loader.using( 'ext.uls.webfonts.fonts', mw.webfonts.setup );
|
mw.loader.using( 'ext.uls.webfonts.fonts', mw.webfonts.setup );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If event logging is enabled and this page "wins" the tofu logging lottery
|
|
||||||
// try to detect tofu
|
|
||||||
if ( !mw.config.get( 'wgULSEventLogging' ) ||
|
|
||||||
mw.config.get( 'wgULSTofuLoggingChance' ) < mw.config.get( 'wgArticleId' ) % 100
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout( function () {
|
|
||||||
var i, lang, text,
|
|
||||||
$langElements, $element,
|
|
||||||
maxTime = mw.config.get( 'wgULSTofuLoggingMaxTime' );
|
|
||||||
|
|
||||||
tofuStartTime = ( new Date() ).getTime();
|
|
||||||
|
|
||||||
// Check all elements that have the lang attribute,
|
|
||||||
// except the root <html> - it has lang,
|
|
||||||
// but its text is not useful for testing.
|
|
||||||
// mw-content-text also always has lang,
|
|
||||||
// and its text is more relevant.
|
|
||||||
$langElements = $( 'body [lang]' );
|
|
||||||
|
|
||||||
for ( i = 0; i < $langElements.length; i++ ) {
|
|
||||||
$element = $( $langElements[ i ] );
|
|
||||||
lang = $element.prop( 'lang' );
|
|
||||||
|
|
||||||
// Skip if this languages was already tested
|
|
||||||
if ( tofuLanguages[lang] !== undefined ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
text = $.trim( $element.text() ).substr( 0, 4 );
|
|
||||||
|
|
||||||
// Skip if the text only has basic ASCII and Latin
|
|
||||||
if ( !text.match( /[^\u0009-\u0200]/ ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tofuLanguages[lang] = detectTofu( text );
|
|
||||||
|
|
||||||
if ( tofuLanguages[lang] ) {
|
|
||||||
mw.log( 'tofu detected for ' + lang );
|
|
||||||
mw.hook( 'mw.uls.webfonts.tofudetected' ).fire( lang );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force to break the detection loop if it's taking too long
|
|
||||||
if ( maxTime && ( new Date() ).getTime() - tofuStartTime > maxTime ) {
|
|
||||||
mw.log( 'tofu detection max time reached. last lang: ' + lang );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tofuEndTime = ( new Date() ).getTime();
|
|
||||||
tofuTime = ( tofuEndTime - tofuStartTime ) / 1000;
|
|
||||||
mw.log( 'tofu detection took ' + tofuTime + ' seconds' );
|
|
||||||
}, 1000 );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}( jQuery, mediaWiki ) );
|
}( jQuery, mediaWiki ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user