Add a MediaWiki preference for enabling ULS IME

Bug: 47240
Change-Id: I957d9f409b0c29f956bcf8a49187cdf27c4f42f8
This commit is contained in:
Amir E. Aharoni
2013-05-01 14:15:57 +03:00
parent 24ebaff9e9
commit 6ae0fe3e44
4 changed files with 63 additions and 6 deletions

View File

@@ -295,10 +295,20 @@ class UniversalLanguageSelectorHooks {
}
public static function onGetPreferences( $user, &$preferences ) {
// The detailed preferences for different layouts.
// Saved as JSON and modifiable through the ULS screens.
$preferences['uls-preferences'] = array(
'type' => 'api',
);
// A checkbox in the general MediaWiki preferences screen
// to enable or disable IME in ULS
$preferences['uls-ime-enable'] = array(
'type' => 'toggle',
'label-message' => 'uls-ime-enable-preferences-label',
'section' => 'editing/advancedediting', // under 'Advanced options' section of 'Editing' tab
);
return true;
}

View File

@@ -30,6 +30,7 @@ $messages['en'] = array(
'uls-desc' => 'Gives the user several ways to select a language and to adjust language settings',
'uls-plang-title-languages' => 'Languages',
'uls-ime-enable-preferences-label' => 'Enable input methods',
);
/** Message documentation (Message documentation)
@@ -42,6 +43,10 @@ $messages['qqq'] = array(
'uls-plang-title-languages' => 'A title for the are in the sidebar in which the interlanguage links are supposed to appear.
This title is shown when there are no interlanguage links there, but an icon that enables the ULS is shown.
{{Identical|Language}}',
'uls-ime-enable-preferences-label' => 'A label for a user preference.',
'uls-select-content-language' => 'Main heading in the language selector popup.
{{Identical|Select language}}',
);
/** Arabic (العربية)

View File

@@ -137,6 +137,7 @@ $wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLangua
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec';
$wgDefaultUserOptions['uls-preferences'] = '';
$wgDefaultUserOptions['uls-ime-enable'] = 1;
$wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
$wgExtensionFunctions[] = function() {

View File

@@ -104,6 +104,7 @@
ULSPreferences = function () {
this.preferenceName = 'uls-preferences';
this.imeEnablePreferenceName = 'uls-ime-enable',
this.username = mw.user.getName();
this.isAnon = mw.user.isAnon();
this.preferences = null;
@@ -115,13 +116,30 @@
* Initialize
*/
init: function () {
var options,
ulsImeEnable = mw.user.options.get( this.imeEnablePreferenceName );
if ( this.isAnon ) {
this.preferences = $.jStorage.get( this.preferenceName );
} else {
var options = mw.user.options.get( this.preferenceName );
options = mw.user.options.get( this.preferenceName );
this.preferences = $.parseJSON( options );
}
this.preferences = this.preferences || {};
if ( this.preferences.ime === undefined ) {
this.preferences.ime = {};
}
if ( ulsImeEnable === undefined ) {
this.preferences.ime.enable = mw.config.get( 'wgULSIMEEnabled' );
} else if ( ulsImeEnable === 1 || ulsImeEnable === '1' ) {
this.preferences.ime.enable = true;
} else {
this.preferences.ime.enable = false;
}
},
/**
@@ -151,22 +169,45 @@
save: function ( callback ) {
var ulsPreferences = this;
callback = callback || $.noop;
if ( this.isAnon ) {
// Anonymous user. Save preferences in local storage
$.jStorage.set( this.preferenceName, this.preferences );
callback.call( this, true );
} else {
var successFunction, failFunction;
successFunction = function () {
callback.call( this, true );
};
failFunction = function () {
callback.call( this, false );
};
// Logged in user. Use MW APIs to change preferences
saveOptionsWithToken( {
action: 'options',
optionname: ulsPreferences.preferenceName,
optionvalue: $.toJSON( ulsPreferences.preferences )
}, function () {
callback.call( this, true );
}, function () {
callback.call( this, false );
} );
},
successFunction,
failFunction
);
if ( ulsPreferences.preferences.ime !== undefined &&
ulsPreferences.preferences.ime.enable !== undefined
) {
// Logged in user. Use MW APIs to change preferences
saveOptionsWithToken( {
action: 'options',
optionname: ulsPreferences.imeEnablePreferenceName,
optionvalue: ulsPreferences.preferences.ime.enable ? '1' : ''
},
successFunction,
failFunction
);
}
}
}
};