pending.abort();
}
- api.getToken( 'edit' ).then( stashEdit );
+ api.getToken( 'csrf' ).then( stashEdit );
}
function onKeyPress( e ) {
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 () {} } );
* 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'
$.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.
*
* @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' );
},
/**
}
} else {
if ( value !== null ) {
- deferreds.push( this.postWithToken( 'options', {
+ deferreds.push( this.postWithToken( 'csrf', {
formatversion: 2,
action: 'options',
optionname: name,
} ) );
} else {
// Omitting value resets the option
- deferreds.push( this.postWithToken( 'options', {
+ deferreds.push( this.postWithToken( 'csrf', {
formatversion: 2,
action: 'options',
optionname: name
}
if ( grouped.length ) {
- deferreds.push( this.postWithToken( 'options', {
+ deferreds.push( this.postWithToken( 'csrf', {
formatversion: 2,
action: 'options',
change: grouped
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 );
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 ) {
this.server.respond( [ 200, { 'Content-Type': 'application/json' }, '{ "example": "quux" }' ] );
- return api.postWithToken( 'edit',
+ return api.postWithToken( 'csrf',
{ action: 'example' },
{
headers: {
.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' );