Index: trunk/phase3/resources/Resources.php |
— | — | @@ -526,6 +526,10 @@ |
527 | 527 | 'mediawiki.Title' |
528 | 528 | ), |
529 | 529 | ), |
| 530 | + 'mediawiki.api.watch' => array( |
| 531 | + 'scripts' => 'resources/mediawiki/mediawiki.api.watch.js', |
| 532 | + 'dependencies' => 'mediawiki.api', |
| 533 | + ), |
530 | 534 | 'mediawiki.debug' => array( |
531 | 535 | 'scripts' => 'resources/mediawiki/mediawiki.debug.js', |
532 | 536 | 'styles' => 'resources/mediawiki/mediawiki.debug.css', |
— | — | @@ -614,6 +618,7 @@ |
615 | 619 | ), |
616 | 620 | 'mediawiki.action.watch.ajax' => array( |
617 | 621 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js', |
| 622 | + 'dependencies' => 'mediawiki.api.watch', |
618 | 623 | 'messages' => array( |
619 | 624 | 'watch', |
620 | 625 | 'unwatch', |
Index: trunk/phase3/resources/mediawiki/mediawiki.api.js |
— | — | @@ -182,7 +182,6 @@ |
183 | 183 | // upload succeeded, but no image info. |
184 | 184 | // this is probably impossible, but might as well check for it |
185 | 185 | 'noimageinfo', |
186 | | - |
187 | 186 | // remote errors, defined in API |
188 | 187 | 'uploaddisabled', |
189 | 188 | 'nomodule', |
— | — | @@ -207,7 +206,9 @@ |
208 | 207 | 'overwrite', |
209 | 208 | 'badtoken', |
210 | 209 | 'fetchfileerror', |
211 | | - 'fileexists-shared-forbidden' |
| 210 | + 'fileexists-shared-forbidden', |
| 211 | + 'invalidtitle', |
| 212 | + 'notloggedin' |
212 | 213 | ]; |
213 | 214 | |
214 | 215 | /** |
Index: trunk/phase3/resources/mediawiki/mediawiki.api.watch.js |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +/** |
| 3 | + * Additional mw.Api methods to assist with (un)watching wiki pages. |
| 4 | + */ |
| 5 | +( function( $, mw ) { |
| 6 | + |
| 7 | + $.extend( mw.Api.prototype, { |
| 8 | + /** |
| 9 | + * Convinience method for 'action=watch'. |
| 10 | + * |
| 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 err {Function} callback if error (optional) |
| 16 | + * @param unwatch {Boolean} Internal variable, do not use. Used by unwatch() to |
| 17 | + * reuse this function. |
| 18 | + * @return {jqXHR} |
| 19 | + */ |
| 20 | + watch: function( page, success, err, unwatch ) { |
| 21 | + var params, ok; |
| 22 | + params = { |
| 23 | + action: 'watch', |
| 24 | + title: String( page ), |
| 25 | + token: mw.user.tokens.get( 'watchToken' ), |
| 26 | + uselang: mw.config.get( 'wgUserLanguage' ) |
| 27 | + }; |
| 28 | + ok = function( data ) { |
| 29 | + success( data.watch ); |
| 30 | + }; |
| 31 | + return this.post( params, { ok: ok, err: err } ); |
| 32 | + }, |
| 33 | + /** |
| 34 | + * Convinience method for 'action=watch&unwatch='. |
| 35 | + * |
| 36 | + * @param page {String|mw.Title} Full page name or instance of mw.Title |
| 37 | + * @param success {Function} callback to which the watch object will be passed |
| 38 | + * watch object contains 'title' (full page name), 'unwatched' (boolean) and |
| 39 | + * 'message' (parsed HTML of the 'removedwatchtext' message). |
| 40 | + * @param err {Function} callback if error (optional) |
| 41 | + * @return {jqXHR} |
| 42 | + */ |
| 43 | + unwatch: function( page, success, err, unwatch ) { |
| 44 | + var params, ok; |
| 45 | + params = { |
| 46 | + action: 'watch', |
| 47 | + unwatch: 1, |
| 48 | + title: String( page ), |
| 49 | + token: mw.user.tokens.get( 'watchToken' ), |
| 50 | + uselang: mw.config.get( 'wgUserLanguage' ) |
| 51 | + }; |
| 52 | + ok = function( data ) { |
| 53 | + success( data.watch ); |
| 54 | + }; |
| 55 | + return this.post( params, { ok: ok, err: err } ); |
| 56 | + } |
| 57 | + |
| 58 | + } ); |
| 59 | + |
| 60 | +} )( jQuery, mediaWiki ); |
Index: trunk/phase3/resources/mediawiki/mediawiki.api.parse.js |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | action: 'parse' |
21 | 21 | }, |
22 | 22 | ok = function( data ) { |
23 | | - if ( data && data.parse && data.parse.text && data.parse.text['*'] ) { |
| 23 | + if ( data.parse && data.parse.text && data.parse.text['*'] ) { |
24 | 24 | success( data.parse.text['*'] ); |
25 | 25 | } |
26 | 26 | }; |