diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /resources/mediawiki.api/mediawiki.api.edit.js | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'resources/mediawiki.api/mediawiki.api.edit.js')
-rw-r--r-- | resources/mediawiki.api/mediawiki.api.edit.js | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/resources/mediawiki.api/mediawiki.api.edit.js b/resources/mediawiki.api/mediawiki.api.edit.js index a9d488a8..49af9375 100644 --- a/resources/mediawiki.api/mediawiki.api.edit.js +++ b/resources/mediawiki.api/mediawiki.api.edit.js @@ -1,8 +1,7 @@ /** * Additional mw.Api methods to assist with API calls related to editing wiki pages. */ - -( function( $, mw, undefined ) { +( function ( mw, $ ) { // Cache token so we don't have to keep fetching new ones for every single request. var cachedToken = null; @@ -19,13 +18,14 @@ * @param err {Function} [optional] error callback * @return {jqXHR} */ - postWithEditToken: function( params, ok, err ) { - var api = this, useTokenToPost, getTokenIfBad; + postWithEditToken: function ( params, ok, err ) { + var useTokenToPost, getTokenIfBad, + api = this; if ( cachedToken === null ) { // We don't have a valid cached token, so get a fresh one and try posting. // We do not trap any 'badtoken' or 'notoken' errors, because we don't want // an infinite loop. If this fresh token is bad, something else is very wrong. - useTokenToPost = function( token ) { + useTokenToPost = function ( token ) { params.token = token; api.post( params, ok, err ); }; @@ -34,9 +34,10 @@ // We do have a token, but it might be expired. So if it is 'bad' then // start over with a new token. params.token = cachedToken; - getTokenIfBad = function( code, result ) { + getTokenIfBad = function ( code, result ) { if ( code === 'badtoken' ) { - cachedToken = null; // force a new token + // force a new token, clear any old one + cachedToken = null; api.postWithEditToken( params, ok, err ); } else { err( code, result ); @@ -58,23 +59,17 @@ * @param err {Function} error callback * @return {jqXHR} */ - getEditToken: function( tokenCallback, err ) { + 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 ) { + 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 { @@ -102,7 +97,7 @@ * @param err {Function} error handler * @return {jqXHR} */ - newSection: function( title, header, message, ok, err ) { + newSection: function ( title, header, message, ok, err ) { var params = { action: 'edit', section: 'new', @@ -116,4 +111,4 @@ } ); -} )( jQuery, mediaWiki ); +}( mediaWiki, jQuery ) ); |