Add user preference to enable ULS
Adds an option, 'enable-uls' for users to enable ULS. By default it is enabled. Wikis can use $wgHiddenPrefs to prevent users from disabling ULS. Bug: 46306 Change-Id: I71b70d8ee7c3cad7f49b32e5dc494ef4fc1bdb2f
This commit is contained in:
@@ -27,6 +27,7 @@ class UniversalLanguageSelectorHooks {
|
||||
*/
|
||||
public static function isToolbarEnabled( $user ) {
|
||||
global $wgULSEnable, $wgULSEnableAnon;
|
||||
|
||||
if ( !$wgULSEnable ) {
|
||||
return false;
|
||||
}
|
||||
@@ -34,7 +35,7 @@ class UniversalLanguageSelectorHooks {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $user->getBoolOption( 'uls-enable' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,11 @@ class UniversalLanguageSelectorHooks {
|
||||
public static function addModules( $out, $skin ) {
|
||||
global $wgULSGeoService, $wgULSEventLogging;
|
||||
|
||||
$user = $out->getUser();
|
||||
if ( !$user->getBoolOption( 'uls-enable') ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load the style for users without JS, to hide the useless links
|
||||
$out->addModuleStyles( 'ext.uls.nojs' );
|
||||
|
||||
@@ -65,7 +71,7 @@ class UniversalLanguageSelectorHooks {
|
||||
$out->addModules( 'ext.uls.geoclient' );
|
||||
}
|
||||
|
||||
if ( self::isToolbarEnabled( $out->getUser() ) ) {
|
||||
if ( self::isToolbarEnabled( $user ) ) {
|
||||
// Enable UI language selection for the user.
|
||||
$out->addModules( 'ext.uls.interface' );
|
||||
}
|
||||
@@ -299,6 +305,12 @@ class UniversalLanguageSelectorHooks {
|
||||
}
|
||||
|
||||
public static function onGetPreferences( $user, &$preferences ) {
|
||||
$preferences['uls-enable'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'uls-preference',
|
||||
'section' => 'personal/i18n',
|
||||
);
|
||||
|
||||
$preferences['uls-preferences'] = array(
|
||||
'type' => 'api',
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ $messages = array();
|
||||
* @author santhosh
|
||||
* @author Amire80
|
||||
* @author Nike
|
||||
* @author Kunal Mehta
|
||||
*/
|
||||
$messages['en'] = array(
|
||||
'UniversalLanguageSelector' => 'Universal Language Selector',
|
||||
@@ -32,11 +33,13 @@ $messages['en'] = array(
|
||||
|
||||
'uls-plang-title-languages' => 'Languages',
|
||||
'uls-ime-helppage' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Extension:UniversalLanguageSelector/Input_methods/$1',
|
||||
'uls-preference' => 'Enable the [https://www.mediawiki.org/wiki/Special:MyLanguage/Universal_Language_Selector Universal Language Selector]',
|
||||
);
|
||||
|
||||
/** Message documentation (Message documentation)
|
||||
* @author Amire80
|
||||
* @author Shirayuki
|
||||
* @author Kunal Mehta
|
||||
*/
|
||||
$messages['qqq'] = array(
|
||||
'UniversalLanguageSelector' => 'Extension name',
|
||||
@@ -46,6 +49,7 @@ This title is shown when there are no interlanguage links there, but an icon tha
|
||||
{{Identical|Language}}',
|
||||
'uls-ime-helppage' => 'Target page for ime helps. Parameters:
|
||||
* $1 - ime id. Intended for wiki local customization. e.g. cyrl-palochka',
|
||||
'uls-preference' => 'Label for checkbox to enable the Universal Language Selector on Special:Preferences',
|
||||
);
|
||||
|
||||
/** Arabic (العربية)
|
||||
|
||||
@@ -195,6 +195,7 @@ $GLOBALS['wgHooks']['SkinTemplateOutputPageBeforeExec'][] =
|
||||
$GLOBALS['wgHooks']['EnterMobileMode'][] = 'UniversalLanguageSelectorHooks::onEnterMobileMode';
|
||||
|
||||
$GLOBALS['wgDefaultUserOptions']['uls-preferences'] = '';
|
||||
$GLOBALS['wgDefaultUserOptions']['uls-enable'] = '';
|
||||
$GLOBALS['wgHooks']['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
|
||||
|
||||
$GLOBALS['wgExtensionFunctions'][] = function () {
|
||||
|
||||
Reference in New Issue
Block a user