Use saveOption from module 'mediawiki.api.options'

The module 'mediawiki.api.options' is present since MediaWiki 1.25.

Change-Id: I986afad78f8054596e0efe89aa9e663c6c123f03
This commit is contained in:
Fomafix 2018-03-22 20:35:37 +01:00
parent 5af96e1d18
commit fc3d0012c7
2 changed files with 10 additions and 8 deletions

View file

@ -10,6 +10,9 @@
"descriptionmsg": "cookiewarning-desc", "descriptionmsg": "cookiewarning-desc",
"type": "other", "type": "other",
"license-name": "MIT", "license-name": "MIT",
"requires": {
"MediaWiki": ">= 1.25.0"
},
"MessagesDirs": { "MessagesDirs": {
"CookieWarning": [ "CookieWarning": [
"i18n" "i18n"
@ -81,6 +84,7 @@
"ext.CookieWarning": { "ext.CookieWarning": {
"dependencies": [ "dependencies": [
"mediawiki.api", "mediawiki.api",
"mediawiki.api.options",
"mediawiki.cookie", "mediawiki.cookie",
"mediawiki.user" "mediawiki.user"
], ],

View file

@ -14,10 +14,8 @@
// the user preferences. // the user preferences.
if ( !mw.user.isAnon() ) { if ( !mw.user.isAnon() ) {
// try to save, that the cookiewarning was disabled, in the user preferences // try to save, that the cookiewarning was disabled, in the user preferences
new mw.Api().postWithToken( 'options', { new mw.Api().saveOption( 'cookiewarning_dismissed', '1' )
action: 'options', .fail( function ( code, result ) {
change: 'cookiewarning_dismissed=1'
} ).fail( function ( code, result ) {
// if it fails, fall back to the cookie // if it fails, fall back to the cookie
mw.log.warn( 'Failed to save dismissed CookieWarning: ' + code + '\n' + result.error + '. Using cookie now.' ); mw.log.warn( 'Failed to save dismissed CookieWarning: ' + code + '\n' + result.error + '. Using cookie now.' );
setCookie(); setCookie();