(bug 41763) Add a hook for support uls-preferences
Change-Id: I8fdc1a0527c9a99b6e5eb95c183955a162233b1d
This commit is contained in:
@@ -240,4 +240,12 @@ class UniversalLanguageSelectorHooks {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function onGetPreferences( $user, &$preferences ) {
|
||||||
|
$preferences['uls-preferences'] = array(
|
||||||
|
'type' => 'api',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,14 +71,14 @@ $wgULSLanguageDetection = true;
|
|||||||
/**
|
/**
|
||||||
* Enable language selection. If language selection is disabled, the classes
|
* Enable language selection. If language selection is disabled, the classes
|
||||||
* and RL modules are registered for the use of other extensions, but no
|
* and RL modules are registered for the use of other extensions, but no
|
||||||
* language selection toolbar is shown, and it will not be possible to change
|
* language selection toolbar is shown, and it will not be possible to change
|
||||||
* the interface language using a cookie.
|
* the interface language using a cookie.
|
||||||
*/
|
*/
|
||||||
$wgULSEnable = true;
|
$wgULSEnable = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable ULS language selection for anonymous users. Equivalent to $wgULSEnable
|
* Enable ULS language selection for anonymous users. Equivalent to $wgULSEnable
|
||||||
* except that it only applies to anonymous users. Setting this to false will
|
* except that it only applies to anonymous users. Setting this to false will
|
||||||
* avoid breaking Squid caches (see bug 41451).
|
* avoid breaking Squid caches (see bug 41451).
|
||||||
*/
|
*/
|
||||||
$wgULSEnableAnon = true;
|
$wgULSEnableAnon = true;
|
||||||
@@ -101,6 +101,9 @@ $wgHooks['MakeGlobalVariablesScript'][] = 'UniversalLanguageSelectorHooks::addVa
|
|||||||
$wgAPIModules['languagesearch'] = 'ApiLanguageSearch';
|
$wgAPIModules['languagesearch'] = 'ApiLanguageSearch';
|
||||||
$wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLanguage';
|
$wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLanguage';
|
||||||
|
|
||||||
|
$wgDefaultUserOptions['uls-preferences'] = '';
|
||||||
|
$wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
|
||||||
|
|
||||||
$wgResourceModules['ext.uls.init'] = array(
|
$wgResourceModules['ext.uls.init'] = array(
|
||||||
'scripts' => 'resources/js/ext.uls.init.js',
|
'scripts' => 'resources/js/ext.uls.init.js',
|
||||||
'styles' => 'resources/css/ext.uls.css',
|
'styles' => 'resources/css/ext.uls.css',
|
||||||
|
|||||||
@@ -68,7 +68,9 @@
|
|||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
save: function ( callback ) {
|
save: function ( callback ) {
|
||||||
var that = this, api;
|
var ulsPreferences = this,
|
||||||
|
api;
|
||||||
|
|
||||||
callback = callback || $.noop;
|
callback = callback || $.noop;
|
||||||
if ( this.isAnon ) {
|
if ( this.isAnon ) {
|
||||||
// Anonymous user- Save preferences in local storage
|
// Anonymous user- Save preferences in local storage
|
||||||
@@ -77,20 +79,21 @@
|
|||||||
} else {
|
} else {
|
||||||
// Logged in user. Use MW apis to change preferences
|
// Logged in user. Use MW apis to change preferences
|
||||||
api = new mw.Api();
|
api = new mw.Api();
|
||||||
|
|
||||||
api.post( {
|
api.post( {
|
||||||
action: 'tokens',
|
action: 'tokens',
|
||||||
type: 'options'
|
type: 'options'
|
||||||
} ).done( function ( tokenresult ) {
|
} ).done( function ( tokenresult ) {
|
||||||
var token = tokenresult.tokens.optionstoken;
|
var token = tokenresult.tokens.optionstoken;
|
||||||
|
|
||||||
api.post( {
|
api.post( {
|
||||||
action: 'options',
|
action: 'options',
|
||||||
change: 'hideminor=1',
|
optionname: ulsPreferences.preferenceName,
|
||||||
optionname: that.preferenceName,
|
optionvalue: $.toJSON( ulsPreferences.preferences ),
|
||||||
optionvalue: $.toJSON( that.preferences ),
|
|
||||||
token: token
|
token: token
|
||||||
} ).done( function () {
|
} ).done( function ( data ) {
|
||||||
callback.call( this, true );
|
callback.call( this, true );
|
||||||
} ).fail( function () {
|
} ).fail( function ( data ) {
|
||||||
callback.call( this, false );
|
callback.call( this, false );
|
||||||
} );
|
} );
|
||||||
} ).fail( function () {
|
} ).fail( function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user