2 * @class mw.Api.plugin.watch
11 * @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an
12 * array thereof. If an array is passed, the return value passed to the promise will also be an
13 * array of appropriate objects.
14 * @param {Function} [ok] Success callback (deprecated)
15 * @param {Function} [err] Error callback (deprecated)
16 * @return {jQuery.Promise}
17 * @return {Function} return.done
18 * @return {Object|Object[]} return.done.watch Object or list of objects (depends on the `pages`
20 * @return {string} return.done.watch.title Full pagename
21 * @return {boolean} return.done.watch.watched Whether the page is now watched or unwatched
22 * @return {string} return.done.watch.message Parsed HTML of the confirmational interface message
24 function doWatchInternal( pages
, ok
, err
, addParams
) {
25 // XXX: Parameter addParams is undocumented because we inherit this
26 // documentation in the public method..
27 var params
, apiPromise
,
30 // Backwards compatibility (< MW 1.20)
32 mw
.track( 'mw.deprecate', 'api.cbParam' );
33 mw
.log
.warn( 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.' );
34 d
.done( ok
).fail( err
);
39 token
: mw
.user
.tokens
.get( 'watchToken' ),
40 uselang
: mw
.config
.get( 'wgUserLanguage' ),
41 titles
: $.isArray( pages
) ? pages
.join( '|' ) : String( pages
)
45 $.extend( params
, addParams
);
48 apiPromise
= this.post( params
)
49 .done( function ( data
) {
50 // If a single page was given (not an array) respond with a single item as well.
51 d
.resolve( $.isArray( pages
) ? data
.watch
: data
.watch
[0] );
55 return d
.promise( { abort
: apiPromise
.abort
} );
58 $.extend( mw
.Api
.prototype, {
60 * Convenience method for `action=watch`.
62 * @inheritdoc #doWatchInternal
64 watch: function ( pages
, ok
, err
) {
65 return doWatchInternal
.call( this, pages
, ok
, err
);
68 * Convenience method for `action=watch&unwatch=1`.
70 * @inheritdoc #doWatchInternal
72 unwatch: function ( pages
, ok
, err
) {
73 return doWatchInternal
.call( this, pages
, ok
, err
, { unwatch
: 1 } );
80 * @mixins mw.Api.plugin.watch
83 }( mediaWiki
, jQuery
) );