Index: trunk/phase3/resources/Resources.php |
— | — | @@ -537,7 +537,10 @@ |
538 | 538 | ), |
539 | 539 | 'mediawiki.api.watch' => array( |
540 | 540 | 'scripts' => 'resources/mediawiki.api/mediawiki.api.watch.js', |
541 | | - 'dependencies' => array( 'mediawiki.api', 'mediawiki.user' ), |
| 541 | + 'dependencies' => array( |
| 542 | + 'mediawiki.api', |
| 543 | + 'user.tokens', |
| 544 | + ), |
542 | 545 | ), |
543 | 546 | 'mediawiki.debug' => array( |
544 | 547 | 'scripts' => 'resources/mediawiki/mediawiki.debug.js', |
Index: trunk/phase3/resources/mediawiki.api/mediawiki.api.watch.js |
— | — | @@ -12,10 +12,12 @@ |
13 | 13 | * @param success {Function} callback to which the watch object will be passed |
14 | 14 | * watch object contains 'title' (full page name), 'watched' (boolean) and |
15 | 15 | * '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. |
16 | 18 | * @param err {Function} callback if error (optional) |
17 | 19 | * @return {jqXHR} |
18 | 20 | */ |
19 | | - watch: function( page, success, err ) { |
| 21 | + watch: function( page, success, err, _unwatch ) { |
20 | 22 | var params, ok; |
21 | 23 | params = { |
22 | 24 | action: 'watch', |
— | — | @@ -23,13 +25,16 @@ |
24 | 26 | token: mw.user.tokens.get( 'watchToken' ), |
25 | 27 | uselang: mw.config.get( 'wgUserLanguage' ) |
26 | 28 | }; |
| 29 | + if ( _unwatch ) { |
| 30 | + params.unwatch = 1; |
| 31 | + } |
27 | 32 | ok = function( data ) { |
28 | 33 | success( data.watch ); |
29 | 34 | }; |
30 | 35 | return this.post( params, { ok: ok, err: err } ); |
31 | 36 | }, |
32 | 37 | /** |
33 | | - * Convinience method for 'action=watch&unwatch='. |
| 38 | + * Convinience method for 'action=watch&unwatch=1'. |
34 | 39 | * |
35 | 40 | * @param page {String|mw.Title} Full page name or instance of mw.Title |
36 | 41 | * @param success {Function} callback to which the watch object will be passed |
— | — | @@ -39,18 +44,7 @@ |
40 | 45 | * @return {jqXHR} |
41 | 46 | */ |
42 | 47 | unwatch: function( page, success, err ) { |
43 | | - var params, ok; |
44 | | - params = { |
45 | | - action: 'watch', |
46 | | - unwatch: 1, |
47 | | - title: String( page ), |
48 | | - token: mw.user.tokens.get( 'watchToken' ), |
49 | | - uselang: mw.config.get( 'wgUserLanguage' ) |
50 | | - }; |
51 | | - ok = function( data ) { |
52 | | - success( data.watch ); |
53 | | - }; |
54 | | - return this.post( params, { ok: ok, err: err } ); |
| 48 | + return this.watch( page, success, err, true ); |
55 | 49 | } |
56 | 50 | |
57 | 51 | } ); |