Index: trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js |
— | — | @@ -4,47 +4,51 @@ |
5 | 5 | */ |
6 | 6 | ( function( $, mw ) { |
7 | 7 | |
| 8 | + /** |
| 9 | + * @context {mw.Api} |
| 10 | + */ |
| 11 | + function doWatchInternal( page, success, err, addParams ) { |
| 12 | + var params = { |
| 13 | + action: 'watch', |
| 14 | + title: String( page ), |
| 15 | + token: mw.user.tokens.get( 'watchToken' ), |
| 16 | + uselang: mw.config.get( 'wgUserLanguage' ) |
| 17 | + }; |
| 18 | + function ok( data ) { |
| 19 | + success( data.watch ); |
| 20 | + } |
| 21 | + if ( addParams ) { |
| 22 | + $.extend( params, addParams ); |
| 23 | + } |
| 24 | + return this.post( params, { ok: ok, err: err } ); |
| 25 | + } |
| 26 | + |
8 | 27 | $.extend( mw.Api.prototype, { |
9 | 28 | /** |
10 | 29 | * Convinience method for 'action=watch'. |
11 | 30 | * |
12 | 31 | * @param page {String|mw.Title} Full page name or instance of mw.Title |
13 | | - * @param success {Function} callback to which the watch object will be passed |
14 | | - * watch object contains 'title' (full page name), 'watched' (boolean) and |
| 32 | + * @param success {Function} Callback to which the watch object will be passed. |
| 33 | + * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and |
15 | 34 | * 'message' (parsed HTML of the 'addedwatchtext' message). |
16 | | - * @param _unwatch {Boolean} Internally used to re-use this logic for unwatch(), |
17 | | - * do not use outside this module. |
18 | | - * @param err {Function} callback if error (optional) |
| 35 | + * @param err {Function} Error callback (optional) |
19 | 36 | * @return {jqXHR} |
20 | 37 | */ |
21 | | - watch: function( page, success, err, _unwatch ) { |
22 | | - var params, ok; |
23 | | - params = { |
24 | | - action: 'watch', |
25 | | - title: String( page ), |
26 | | - token: mw.user.tokens.get( 'watchToken' ), |
27 | | - uselang: mw.config.get( 'wgUserLanguage' ) |
28 | | - }; |
29 | | - if ( _unwatch ) { |
30 | | - params.unwatch = 1; |
31 | | - } |
32 | | - ok = function( data ) { |
33 | | - success( data.watch ); |
34 | | - }; |
35 | | - return this.post( params, { ok: ok, err: err } ); |
| 38 | + watch: function ( page, success, err ) { |
| 39 | + return doWatchInternal.call( this, page, success, err ); |
36 | 40 | }, |
37 | 41 | /** |
38 | 42 | * Convinience method for 'action=watch&unwatch=1'. |
39 | 43 | * |
40 | 44 | * @param page {String|mw.Title} Full page name or instance of mw.Title |
41 | | - * @param success {Function} callback to which the watch object will be passed |
42 | | - * watch object contains 'title' (full page name), 'unwatched' (boolean) and |
| 45 | + * @param success {Function} Callback to which the watch object will be passed. |
| 46 | + * Watch object contains properties 'title' (full pagename), 'watched' (boolean) and |
43 | 47 | * 'message' (parsed HTML of the 'removedwatchtext' message). |
44 | | - * @param err {Function} callback if error (optional) |
| 48 | + * @param err {Function} Error callback (optional) |
45 | 49 | * @return {jqXHR} |
46 | 50 | */ |
47 | | - unwatch: function( page, success, err ) { |
48 | | - return this.watch( page, success, err, true ); |
| 51 | + unwatch: function ( page, success, err ) { |
| 52 | + return doWatchInternal.call( this, page, success, err, { unwatch: 1 } ); |
49 | 53 | } |
50 | 54 | |
51 | 55 | } ); |