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.watch.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.watch.js')
-rw-r--r-- | resources/src/mediawiki.api/mediawiki.api.watch.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/resources/src/mediawiki.api/mediawiki.api.watch.js b/resources/src/mediawiki.api/mediawiki.api.watch.js new file mode 100644 index 00000000..af2dee10 --- /dev/null +++ b/resources/src/mediawiki.api/mediawiki.api.watch.js @@ -0,0 +1,79 @@ +/** + * @class mw.Api.plugin.watch + * @since 1.19 + */ +( function ( mw, $ ) { + + /** + * @private + * @static + * @context mw.Api + * + * @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an + * array thereof. If an array is passed, the return value passed to the promise will also be an + * array of appropriate objects. + * @param {Function} [ok] Success callback (deprecated) + * @param {Function} [err] Error callback (deprecated) + * @return {jQuery.Promise} + * @return {Function} return.done + * @return {Object|Object[]} return.done.watch Object or list of objects (depends on the `pages` + * parameter) + * @return {string} return.done.watch.title Full pagename + * @return {boolean} return.done.watch.watched Whether the page is now watched or unwatched + * @return {string} return.done.watch.message Parsed HTML of the confirmational interface message + */ + function doWatchInternal( pages, ok, err, addParams ) { + // XXX: Parameter addParams is undocumented because we inherit this + // documentation in the public method... + var apiPromise = this.postWithToken( 'watch', + $.extend( + { + action: 'watch', + titles: $.isArray( pages ) ? pages.join( '|' ) : String( pages ), + uselang: mw.config.get( 'wgUserLanguage' ) + }, + addParams + ) + ); + + // Backwards compatibility (< MW 1.20) + if ( ok || err ) { + mw.track( 'mw.deprecate', 'api.cbParam' ); + mw.log.warn( 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.' ); + } + + return apiPromise + .then( function ( data ) { + // If a single page was given (not an array) respond with a single item as well. + return $.isArray( pages ) ? data.watch : data.watch[0]; + } ) + .done( ok ) + .fail( err ) + .promise( { abort: apiPromise.abort } ); + } + + $.extend( mw.Api.prototype, { + /** + * Convenience method for `action=watch`. + * + * @inheritdoc #doWatchInternal + */ + watch: function ( pages, ok, err ) { + return doWatchInternal.call( this, pages, ok, err ); + }, + /** + * Convenience method for `action=watch&unwatch=1`. + * + * @inheritdoc #doWatchInternal + */ + unwatch: function ( pages, ok, err ) { + return doWatchInternal.call( this, pages, ok, err, { unwatch: 1 } ); + } + } ); + + /** + * @class mw.Api + * @mixins mw.Api.plugin.watch + */ + +}( mediaWiki, jQuery ) ); |