mw.Api: Replace deprecated token names by 'csrf'
authorFomafix <fomafix@googlemail.com>
Fri, 15 Apr 2016 15:52:42 +0000 (15:52 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Fri, 15 Apr 2016 15:52:42 +0000 (15:52 +0000)
Since 65077ede the deprecated token names like 'edit' or 'options' generate
a warning.

Change-Id: I1587f66bd9e5cdb8cc24cf68eced1d28ae22f44e

resources/src/mediawiki.action/mediawiki.action.edit.stash.js
resources/src/mediawiki/api.js
resources/src/mediawiki/api/edit.js
resources/src/mediawiki/api/options.js
resources/src/mediawiki/api/upload.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js

index abe912d..20bfa0e 100644 (file)
@@ -44,7 +44,7 @@
                                pending.abort();
                        }
 
-                       api.getToken( 'edit' ).then( stashEdit );
+                       api.getToken( 'csrf' ).then( stashEdit );
                }
 
                function onKeyPress( e ) {
index 3bc0ad3..b4ff40a 100644 (file)
@@ -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 () {} } );
                 * 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'
index 22affb1..60276cd 100644 (file)
@@ -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.
                 *
                 * @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' );
                },
 
                /**
index bd6fa06..0af2a75 100644 (file)
@@ -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
index a6a0d8c..3c8b3f6 100644 (file)
                                                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 );
index 520db42..3a959a3 100644 (file)
                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' );