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",
"type": "other",
"license-name": "MIT",
"requires": {
"MediaWiki": ">= 1.25.0"
},
"MessagesDirs": {
"CookieWarning": [
"i18n"
@ -81,6 +84,7 @@
"ext.CookieWarning": {
"dependencies": [
"mediawiki.api",
"mediawiki.api.options",
"mediawiki.cookie",
"mediawiki.user"
],

View file

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