Pass JSHint on resources/{mediawiki.api,jquery,mediawiki}/*
[lhc/web/wiklou.git] / resources / mediawiki.api / mediawiki.api.watch.js
1 /**
2 * Additional mw.Api methods to assist with (un)watching wiki pages.
3 * @since 1.19
4 */
5 ( function ( mw, $ ) {
6
7 /**
8 * @context {mw.Api}
9 */
10 function doWatchInternal( page, success, err, addParams ) {
11 var params = {
12 action: 'watch',
13 title: String( page ),
14 token: mw.user.tokens.get( 'watchToken' ),
15 uselang: mw.config.get( 'wgUserLanguage' )
16 };
17 function ok( data ) {
18 success( data.watch );
19 }
20 if ( addParams ) {
21 $.extend( params, addParams );
22 }
23 return this.post( params, { ok: ok, err: err } );
24 }
25
26 $.extend( mw.Api.prototype, {
27 /**
28 * Convinience method for 'action=watch'.
29 *
30 * @param page {String|mw.Title} Full page name or instance of mw.Title
31 * @param success {Function} Callback to which the watch object will be passed.
32 * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
33 * 'message' (parsed HTML of the 'addedwatchtext' message).
34 * @param err {Function} Error callback (optional)
35 * @return {jqXHR}
36 */
37 watch: function ( page, success, err ) {
38 return doWatchInternal.call( this, page, success, err );
39 },
40 /**
41 * Convinience method for 'action=watch&unwatch=1'.
42 *
43 * @param page {String|mw.Title} Full page name or instance of mw.Title
44 * @param success {Function} Callback to which the watch object will be passed.
45 * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and
46 * 'message' (parsed HTML of the 'removedwatchtext' message).
47 * @param err {Function} Error callback (optional)
48 * @return {jqXHR}
49 */
50 unwatch: function ( page, success, err ) {
51 return doWatchInternal.call( this, page, success, err, { unwatch: 1 } );
52 }
53
54 } );
55
56 }( mediaWiki, jQuery ) );