Use mw.Api.plugin.options to set user options

This requires MediaWiki version 1.25+.

Change-Id: I3a76b0b4ec403b3acdc29e64b0c750a3b57e252a
This commit is contained in:
Fomafix
2016-02-15 14:13:13 +00:00
committed by [[mw:User:Fomafix]]
parent c329f1473d
commit cd58ac2f18
3 changed files with 8 additions and 12 deletions

View File

@@ -156,6 +156,7 @@
}, },
"dependencies": [ "dependencies": [
"mediawiki.api", "mediawiki.api",
"mediawiki.api.options",
"mediawiki.cookie", "mediawiki.cookie",
"jquery.client", "jquery.client",
"jquery.cookie" "jquery.cookie"
@@ -219,7 +220,8 @@
"scripts": "js/ext.uls.preferences.js", "scripts": "js/ext.uls.preferences.js",
"dependencies": [ "dependencies": [
"mediawiki.user", "mediawiki.user",
"mediawiki.api" "mediawiki.api",
"mediawiki.api.options"
], ],
"localBasePath": "resources", "localBasePath": "resources",
"remoteExtPath": "UniversalLanguageSelector/resources" "remoteExtPath": "UniversalLanguageSelector/resources"

View File

@@ -82,12 +82,7 @@
} }
api = new mw.Api(); api = new mw.Api();
// @todo Change this to api.saveOption when ULS minimum MW version is 1.25 api.saveOption( 'language', language )
api.postWithToken( 'options', {
action: 'options',
optionname: 'language',
optionvalue: language
} )
.done( function () { .done( function () {
location.reload(); location.reload();
} ) } )

View File

@@ -149,11 +149,10 @@
callback.call( this, true ); callback.call( this, true );
} else { } else {
// Logged in user. Use MW APIs to change preferences // Logged in user. Use MW APIs to change preferences
new mw.Api().postWithToken( 'options', { new mw.Api().saveOption(
action: 'options', ulsPreferences.preferenceName,
optionname: ulsPreferences.preferenceName, JSON.stringify( ulsPreferences.preferences )
optionvalue: JSON.stringify( ulsPreferences.preferences ) ).done( function () {
} ).done( function () {
callback.call( this, true ); callback.call( this, true );
} ).fail( function () { } ).fail( function () {
callback.call( this, false ); callback.call( this, false );