2 * Additional mw.Api methods to assist with (un)watching wiki pages.
7 $.extend( mw
.Api
.prototype, {
9 * Convinience method for 'action=watch'.
11 * @param page {String|mw.Title} Full page name or instance of mw.Title
12 * @param success {Function} callback to which the watch object will be passed
13 * watch object contains 'title' (full page name), 'watched' (boolean) and
14 * 'message' (parsed HTML of the 'addedwatchtext' message).
15 * @param _unwatch {Boolean} Internally used to re-use this logic for unwatch(),
16 * do not use outside this module.
17 * @param err {Function} callback if error (optional)
20 watch: function( page
, success
, err
, _unwatch
) {
24 title
: String( page
),
25 token
: mw
.user
.tokens
.get( 'watchToken' ),
26 uselang
: mw
.config
.get( 'wgUserLanguage' )
31 ok = function( data
) {
32 success( data
.watch
);
34 return this.post( params
, { ok
: ok
, err
: err
} );
37 * Convinience method for 'action=watch&unwatch=1'.
39 * @param page {String|mw.Title} Full page name or instance of mw.Title
40 * @param success {Function} callback to which the watch object will be passed
41 * watch object contains 'title' (full page name), 'unwatched' (boolean) and
42 * 'message' (parsed HTML of the 'removedwatchtext' message).
43 * @param err {Function} callback if error (optional)
46 unwatch: function( page
, success
, err
) {
47 return this.watch( page
, success
, err
, true );
52 } )( jQuery
, mediaWiki
);