diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
commit | c9aa36da061816dee256a979c2ff8d2ee41824d9 (patch) | |
tree | 29f7002b80ee984b488bd047dbbd80b36bf892e9 /resources/src/mediawiki.api/mediawiki.api.edit.js | |
parent | b4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff) | |
parent | d1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff) |
Merge branch 'archwiki'
# Conflicts:
# skins/ArchLinux.php
# skins/ArchLinux/archlogo.gif
Diffstat (limited to 'resources/src/mediawiki.api/mediawiki.api.edit.js')
-rw-r--r-- | resources/src/mediawiki.api/mediawiki.api.edit.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/resources/src/mediawiki.api/mediawiki.api.edit.js b/resources/src/mediawiki.api/mediawiki.api.edit.js new file mode 100644 index 00000000..e88ae5e2 --- /dev/null +++ b/resources/src/mediawiki.api/mediawiki.api.edit.js @@ -0,0 +1,87 @@ +/** + * @class mw.Api.plugin.edit + */ +( function ( mw, $ ) { + + var msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.'; + $.extend( mw.Api.prototype, { + + /** + * Post to API with edit 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. + * + * @param {Object} params API parameters + * @param {Function} [ok] Success callback (deprecated) + * @param {Function} [err] Error callback (deprecated) + * @return {jQuery.Promise} See #post + */ + postWithEditToken: function ( params, ok, err ) { + if ( ok || err ) { + mw.track( 'mw.deprecate', 'api.cbParam' ); + mw.log.warn( msg ); + } + + return this.postWithToken( 'edit', params ).done( ok ).fail( err ); + }, + + /** + * API helper to grab an edit token. + * + * @param {Function} [ok] Success callback (deprecated) + * @param {Function} [err] Error callback (deprecated) + * @return {jQuery.Promise} + * @return {Function} return.done + * @return {string} return.done.token Received token. + */ + getEditToken: function ( ok, err ) { + if ( ok || err ) { + mw.track( 'mw.deprecate', 'api.cbParam' ); + mw.log.warn( msg ); + } + + return this.getToken( 'edit' ).done( ok ).fail( err ); + }, + + /** + * Post a new section to the page. + * @see #postWithEditToken + * @param {mw.Title|String} title Target page + * @param {string} header + * @param {string} message wikitext message + * @param {Object} [additionalParams] Additional API parameters, e.g. `{ redirect: true }` + * @param {Function} [ok] Success handler (deprecated) + * @param {Function} [err] Error handler (deprecated) + * @return {jQuery.Promise} + */ + newSection: function ( title, header, message, additionalParams, ok, err ) { + // Until we remove 'ok' and 'err' parameters, we have to support code that passes them, + // but not additionalParams... + if ( $.isFunction( additionalParams ) ) { + err = ok; + ok = additionalParams; + additionalParams = undefined; + } + + if ( ok || err ) { + mw.track( 'mw.deprecate', 'api.cbParam' ); + mw.log.warn( msg ); + } + + return this.postWithEditToken( $.extend( { + action: 'edit', + section: 'new', + format: 'json', + title: String( title ), + summary: header, + text: message + }, additionalParams ) ).done( ok ).fail( err ); + } + } ); + + /** + * @class mw.Api + * @mixins mw.Api.plugin.edit + */ + +}( mediaWiki, jQuery ) ); |