From 635a715fd547bfa5d135c41a4b1e4749e03b4142 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Fri, 15 Apr 2016 15:52:42 +0000 Subject: [PATCH] mw.Api: Replace deprecated token names by 'csrf' Since 65077ede the deprecated token names like 'edit' or 'options' generate a warning. Change-Id: I1587f66bd9e5cdb8cc24cf68eced1d28ae22f44e --- .../src/mediawiki.action/mediawiki.action.edit.stash.js | 2 +- resources/src/mediawiki/api.js | 4 ++-- resources/src/mediawiki/api/edit.js | 8 ++++---- resources/src/mediawiki/api/options.js | 6 +++--- resources/src/mediawiki/api/upload.js | 2 +- .../suites/resources/mediawiki.api/mediawiki.api.test.js | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js index abe912de10..20bfa0eaee 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js @@ -44,7 +44,7 @@ pending.abort(); } - api.getToken( 'edit' ).then( stashEdit ); + api.getToken( 'csrf' ).then( stashEdit ); } function onKeyPress( e ) { diff --git a/resources/src/mediawiki/api.js b/resources/src/mediawiki/api.js index 3bc0ad3813..b4ff40ab0f 100644 --- a/resources/src/mediawiki/api.js +++ b/resources/src/mediawiki/api.js @@ -52,7 +52,7 @@ promises[ defaultOptions.ajax.url ] = {}; $.each( mw.user.tokens.get(), function ( key, value ) { // This requires #getToken to use the same key as user.tokens. - // Format: token-type + "Token" (eg. editToken, patrolToken, watchToken). + // Format: token-type + "Token" (eg. csrfToken, patrolToken, watchToken). promises[ defaultOptions.ajax.url ][ key ] = $.Deferred() .resolve( value ) .promise( { abort: function () {} } ); @@ -274,7 +274,7 @@ * If we have a cached token try using that, and if it fails, blank out the * cached token and start over. For example to change an user option you could do: * - * new mw.Api().postWithToken( 'options', { + * new mw.Api().postWithToken( 'csrf', { * action: 'options', * optionname: 'gender', * optionvalue: 'female' diff --git a/resources/src/mediawiki/api/edit.js b/resources/src/mediawiki/api/edit.js index 22affb1dab..60276cd0bc 100644 --- a/resources/src/mediawiki/api/edit.js +++ b/resources/src/mediawiki/api/edit.js @@ -6,7 +6,7 @@ $.extend( mw.Api.prototype, { /** - * Post to API with edit token. If we have no token, get one and try to post. + * Post to API with csrf token. If we have no token, get one and try to post. * If we have a cached token try using that, and if it fails, blank out the * cached token and start over. * @@ -15,18 +15,18 @@ * @return {jQuery.Promise} See #post */ postWithEditToken: function ( params, ajaxOptions ) { - return this.postWithToken( 'edit', params, ajaxOptions ); + return this.postWithToken( 'csrf', params, ajaxOptions ); }, /** - * API helper to grab an edit token. + * API helper to grab a csrf token. * * @return {jQuery.Promise} * @return {Function} return.done * @return {string} return.done.token Received token. */ getEditToken: function () { - return this.getToken( 'edit' ); + return this.getToken( 'csrf' ); }, /** diff --git a/resources/src/mediawiki/api/options.js b/resources/src/mediawiki/api/options.js index bd6fa06808..0af2a754b7 100644 --- a/resources/src/mediawiki/api/options.js +++ b/resources/src/mediawiki/api/options.js @@ -54,7 +54,7 @@ } } else { if ( value !== null ) { - deferreds.push( this.postWithToken( 'options', { + deferreds.push( this.postWithToken( 'csrf', { formatversion: 2, action: 'options', optionname: name, @@ -62,7 +62,7 @@ } ) ); } else { // Omitting value resets the option - deferreds.push( this.postWithToken( 'options', { + deferreds.push( this.postWithToken( 'csrf', { formatversion: 2, action: 'options', optionname: name @@ -72,7 +72,7 @@ } if ( grouped.length ) { - deferreds.push( this.postWithToken( 'options', { + deferreds.push( this.postWithToken( 'csrf', { formatversion: 2, action: 'options', change: grouped diff --git a/resources/src/mediawiki/api/upload.js b/resources/src/mediawiki/api/upload.js index a6a0d8c95b..3c8b3f6571 100644 --- a/resources/src/mediawiki/api/upload.js +++ b/resources/src/mediawiki/api/upload.js @@ -204,7 +204,7 @@ deferred.reject( 'ok-but-empty', 'No response from API on upload attempt.' ); } else if ( result.error ) { if ( result.error.code === 'badtoken' ) { - api.badToken( 'edit' ); + api.badToken( 'csrf' ); } deferred.reject( result.error.code, result ); diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index 520db428c0..3a959a35e8 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -102,9 +102,9 @@ var api = new mw.Api(), test = this; - // Get editToken for local wiki, this should not make + // Get csrfToken for local wiki, this should not make // a request as it should be retrieved from mw.user.tokens. - return api.getToken( 'edit' ) + return api.getToken( 'csrf' ) .then( function ( token ) { assert.ok( token.length, 'Got a token' ); }, function ( err ) { @@ -285,7 +285,7 @@ this.server.respond( [ 200, { 'Content-Type': 'application/json' }, '{ "example": "quux" }' ] ); - return api.postWithToken( 'edit', + return api.postWithToken( 'csrf', { action: 'example' }, { headers: { @@ -296,7 +296,7 @@ .then( function () { assert.equal( test.server.requests[ 0 ].requestHeaders[ 'X-Foo' ], 'Bar', 'Header sent' ); - return api.postWithToken( 'edit', + return api.postWithToken( 'csrf', { action: 'example' }, function () { assert.ok( false, 'This parameter cannot be a callback' ); -- 2.20.1