Merge "Minor CSS cleanup for Vector and Monobook skins"
[mediawiki.git] / resources / mediawiki.api / mediawiki.api.watch.js
blobe2be5c783faf4e83085a8fb0b45a43afa8fb2234
1 /**
2  * @class mw.Api.plugin.watch
3  * @since 1.19
4  */
5 ( function ( mw, $ ) {
7         /**
8          * @private
9          * @context mw.Api
10          *
11          * @param {String|mw.Title} page Full page name or instance of mw.Title
12          * @param {Function} [ok] Success callback (deprecated)
13          * @param {Function} [err] Error callback (deprecated)
14          * @return {jQuery.Promise}
15          * @return {Function} return.done
16          * @return {Object} return.done.watch
17          * @return {string} return.done.watch.title Full pagename
18          * @return {boolean} return.done.watch.watched
19          * @return {string} return.done.watch.message Parsed HTML of the confirmational interface message
20          */
21         function doWatchInternal( page, ok, err, addParams ) {
22                 var params,
23                         d = $.Deferred(),
24                         apiPromise;
25                 // Backwards compatibility (< MW 1.20)
26                 d.done( ok );
27                 d.fail( err );
29                 params = {
30                         action: 'watch',
31                         title: String( page ),
32                         token: mw.user.tokens.get( 'watchToken' ),
33                         uselang: mw.config.get( 'wgUserLanguage' )
34                 };
36                 if ( addParams ) {
37                         $.extend( params, addParams );
38                 }
40                 apiPromise = this.post( params )
41                         .done( function ( data ) {
42                                 d.resolve( data.watch );
43                         } )
44                         .fail( d.reject );
46                 return d.promise( { abort: apiPromise.abort } );
47         }
49         $.extend( mw.Api.prototype, {
50                 /**
51                  * Convenience method for `action=watch`.
52                  *
53                  * @inheritdoc #doWatchInternal
54                  */
55                 watch: function ( page, ok, err ) {
56                         return doWatchInternal.call( this, page, ok, err );
57                 },
58                 /**
59                  * Convenience method for `action=watch&unwatch=1`.
60                  *
61                  * @inheritdoc #doWatchInternal
62                  */
63                 unwatch: function ( page, ok, err ) {
64                         return doWatchInternal.call( this, page, ok, err, { unwatch: 1 } );
65                 }
67         } );
69         /**
70          * @class mw.Api
71          * @mixins mw.Api.plugin.watch
72          */
74 }( mediaWiki, jQuery ) );