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:
Kunal Mehta
2013-10-29 12:16:59 -07:00
committed by Ori Livneh
parent 4b3f2a9f10
commit ad9caf32be
3 changed files with 19 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ class UniversalLanguageSelectorHooks {
*/ */
public static function isToolbarEnabled( $user ) { public static function isToolbarEnabled( $user ) {
global $wgULSEnable, $wgULSEnableAnon; global $wgULSEnable, $wgULSEnableAnon;
if ( !$wgULSEnable ) { if ( !$wgULSEnable ) {
return false; return false;
} }
@@ -34,7 +35,7 @@ class UniversalLanguageSelectorHooks {
return false; return false;
} }
return true; return $user->getBoolOption( 'uls-enable' );
} }
/** /**
@@ -46,6 +47,11 @@ class UniversalLanguageSelectorHooks {
public static function addModules( $out, $skin ) { public static function addModules( $out, $skin ) {
global $wgULSGeoService, $wgULSEventLogging; 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 // Load the style for users without JS, to hide the useless links
$out->addModuleStyles( 'ext.uls.nojs' ); $out->addModuleStyles( 'ext.uls.nojs' );
@@ -65,7 +71,7 @@ class UniversalLanguageSelectorHooks {
$out->addModules( 'ext.uls.geoclient' ); $out->addModules( 'ext.uls.geoclient' );
} }
if ( self::isToolbarEnabled( $out->getUser() ) ) { if ( self::isToolbarEnabled( $user ) ) {
// Enable UI language selection for the user. // Enable UI language selection for the user.
$out->addModules( 'ext.uls.interface' ); $out->addModules( 'ext.uls.interface' );
} }
@@ -299,6 +305,12 @@ class UniversalLanguageSelectorHooks {
} }
public static function onGetPreferences( $user, &$preferences ) { public static function onGetPreferences( $user, &$preferences ) {
$preferences['uls-enable'] = array(
'type' => 'toggle',
'label-message' => 'uls-preference',
'section' => 'personal/i18n',
);
$preferences['uls-preferences'] = array( $preferences['uls-preferences'] = array(
'type' => 'api', 'type' => 'api',
); );

View File

@@ -25,6 +25,7 @@ $messages = array();
* @author santhosh * @author santhosh
* @author Amire80 * @author Amire80
* @author Nike * @author Nike
* @author Kunal Mehta
*/ */
$messages['en'] = array( $messages['en'] = array(
'UniversalLanguageSelector' => 'Universal Language Selector', 'UniversalLanguageSelector' => 'Universal Language Selector',
@@ -32,11 +33,13 @@ $messages['en'] = array(
'uls-plang-title-languages' => 'Languages', 'uls-plang-title-languages' => 'Languages',
'uls-ime-helppage' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Extension:UniversalLanguageSelector/Input_methods/$1', '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) /** Message documentation (Message documentation)
* @author Amire80 * @author Amire80
* @author Shirayuki * @author Shirayuki
* @author Kunal Mehta
*/ */
$messages['qqq'] = array( $messages['qqq'] = array(
'UniversalLanguageSelector' => 'Extension name', 'UniversalLanguageSelector' => 'Extension name',
@@ -46,6 +49,7 @@ This title is shown when there are no interlanguage links there, but an icon tha
{{Identical|Language}}', {{Identical|Language}}',
'uls-ime-helppage' => 'Target page for ime helps. Parameters: 'uls-ime-helppage' => 'Target page for ime helps. Parameters:
* $1 - ime id. Intended for wiki local customization. e.g. cyrl-palochka', * $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 (العربية) /** Arabic (العربية)

View File

@@ -195,6 +195,7 @@ $GLOBALS['wgHooks']['SkinTemplateOutputPageBeforeExec'][] =
$GLOBALS['wgHooks']['EnterMobileMode'][] = 'UniversalLanguageSelectorHooks::onEnterMobileMode'; $GLOBALS['wgHooks']['EnterMobileMode'][] = 'UniversalLanguageSelectorHooks::onEnterMobileMode';
$GLOBALS['wgDefaultUserOptions']['uls-preferences'] = ''; $GLOBALS['wgDefaultUserOptions']['uls-preferences'] = '';
$GLOBALS['wgDefaultUserOptions']['uls-enable'] = '';
$GLOBALS['wgHooks']['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences'; $GLOBALS['wgHooks']['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
$GLOBALS['wgExtensionFunctions'][] = function () { $GLOBALS['wgExtensionFunctions'][] = function () {