]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - resources/src/mediawiki/api/watch.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / mediawiki / api / watch.js
1 /**
2  * @class mw.Api.plugin.watch
3  * @since 1.19
4  */
5 ( function ( mw, $ ) {
6
7         /**
8          * @private
9          * @static
10          * @context mw.Api
11          *
12          * @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an
13          *  array thereof. If an array is passed, the return value passed to the promise will also be an
14          *  array of appropriate objects.
15          * @param {Object} [addParams]
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`
19          *  parameter)
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          */
23         function doWatchInternal( pages, addParams ) {
24                 // XXX: Parameter addParams is undocumented because we inherit this
25                 // documentation in the public method...
26                 var apiPromise = this.postWithToken( 'watch',
27                         $.extend(
28                                 {
29                                         formatversion: 2,
30                                         action: 'watch',
31                                         titles: Array.isArray( pages ) ? pages.join( '|' ) : String( pages )
32                                 },
33                                 addParams
34                         )
35                 );
36
37                 return apiPromise
38                         .then( function ( data ) {
39                                 // If a single page was given (not an array) respond with a single item as well.
40                                 return Array.isArray( pages ) ? data.watch : data.watch[ 0 ];
41                         } )
42                         .promise( { abort: apiPromise.abort } );
43         }
44
45         $.extend( mw.Api.prototype, {
46                 /**
47                  * Convenience method for `action=watch`.
48                  *
49                  * @inheritdoc #doWatchInternal
50                  */
51                 watch: function ( pages ) {
52                         return doWatchInternal.call( this, pages );
53                 },
54
55                 /**
56                  * Convenience method for `action=watch&unwatch=1`.
57                  *
58                  * @inheritdoc #doWatchInternal
59                  */
60                 unwatch: function ( pages ) {
61                         return doWatchInternal.call( this, pages, { unwatch: 1 } );
62                 }
63         } );
64
65         /**
66          * @class mw.Api
67          * @mixins mw.Api.plugin.watch
68          */
69
70 }( mediaWiki, jQuery ) );