mediawiki.api.edit: Use the new 'tokens' api action
authorKaldari <rkaldari@wikimedia.org>
Sun, 8 Jul 2012 04:58:30 +0000 (21:58 -0700)
committerTimo Tijhof <ttijhof@wikimedia.org>
Sun, 8 Jul 2012 19:29:50 +0000 (21:29 +0200)
Use action=tokens instead of the old way with info properties
for a fake title.

Change-Id: I35cd26180e7af7122ff64ce146199cdaa5f7d88b

resources/mediawiki.api/mediawiki.api.edit.js

index a9d488a..5197396 100644 (file)
                 */
                getEditToken: function( tokenCallback, err ) {
                        var parameters = {
-                                       prop: 'info',
-                                       intoken: 'edit',
-                                       // we need some kind of dummy page to get a token from. This will return a response
-                                       // complaining that the page is missing, but we should also get an edit token
-                                       titles: 'DummyPageForEditToken'
+                                       action: 'tokens',
+                                       type: 'edit'
                                },
                                ok = function( data ) {
                                        var token;
-                                       $.each( data.query.pages, function( i, page ) {
-                                               if ( page.edittoken ) {
-                                                       token = page.edittoken;
-                                                       return false;
-                                               }
-                                       } );
-                                       if ( token !== undefined ) {
+                                       // If token type is not available for this user,
+                                       // key 'edittoken' is missing or can contain Boolean false
+                                       if ( data.tokens && data.tokens.edittoken ) {
+                                               token = data.tokens.edittoken;
                                                cachedToken = token;
                                                tokenCallback( token );
                                        } else {