Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -1820,7 +1820,8 @@ |
1821 | 1821 | ), |
1822 | 1822 | 'watching' => array( |
1823 | 1823 | 'watching', |
1824 | | - 'unwatching', |
| 1824 | + 'watching', |
| 1825 | + 'watcherrortext', |
1825 | 1826 | ), |
1826 | 1827 | 'enotif' => array( |
1827 | 1828 | 'enotif_mailer', |
Index: trunk/phase3/languages/messages/MessagesQqq.php |
— | — | @@ -2360,6 +2360,7 @@ |
2361 | 2361 | 'addedwatchtext' => 'Explanation shown when clicking on the {{msg|watch}} tab. See also {{msg|addedwatch}}.', |
2362 | 2362 | 'removedwatch' => 'Page title displayed when clicking on {{msg|unwatch}} tab (only when not using the AJAX feauture which allows watching a page without reloading the page or such). See also {{msg|removedwatchtext}}.', |
2363 | 2363 | 'removedwatchtext' => "After a page has been removed from a user's watchlist by clicking the {{msg|unwatch}} tab at the top of an article, this message appears just below the title of the article. $1 is the title of the article. See also {{msg|removedwatch}} and {{msg|addedwatchtext}}.", |
| 2364 | +'watcherrortext' => "When a user clicked the watch/unwatch tab and the action did not succeed, this message is displayed. See also {{msg|addedwatchtext}}. and {{msg|addedwatchtext}}. This message is used raw and should not contain wikitext.", |
2364 | 2365 | 'watch' => 'Name of the Watch tab. Should be in the imperative mood.', |
2365 | 2366 | 'watchthispage' => '{{Identical|Watch this page}}', |
2366 | 2367 | 'unwatch' => 'Label of "Unwatch" tab.', |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2718,6 +2718,7 @@ |
2719 | 2719 | Future changes to this page and its associated talk page will be listed there, and the page will appear '''bolded''' in the [[Special:RecentChanges|list of recent changes]] to make it easier to pick out.", |
2720 | 2720 | 'removedwatch' => 'Removed from watchlist', |
2721 | 2721 | 'removedwatchtext' => 'The page "[[:$1]]" has been removed from [[Special:Watchlist|your watchlist]].', |
| 2722 | +'watcherrortext' => 'An error occurred while changing your watchlist settings for "$1".', |
2722 | 2723 | 'watch' => 'Watch', |
2723 | 2724 | 'watchthispage' => 'Watch this page', |
2724 | 2725 | 'unwatch' => 'Unwatch', |
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js |
— | — | @@ -23,9 +23,41 @@ |
24 | 24 | } |
25 | 25 | }; |
26 | 26 | |
| 27 | +var errorHandler = function( $link ) { |
| 28 | + |
| 29 | + // Reset link text to whatever it was before we switching it to the '(un)watch'+ing message. |
| 30 | + setLinkText( $link, $link.data( 'action' ) ); |
| 31 | + |
| 32 | + // Format error message |
| 33 | + var cleanTitle = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ); |
| 34 | + var link = mw.html.element( |
| 35 | + 'a', { |
| 36 | + 'href': mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) ), |
| 37 | + 'title': cleanTitle |
| 38 | + }, cleanTitle |
| 39 | + ); |
| 40 | + var msg = mw.msg( 'watcherrortext', link ); |
| 41 | + |
| 42 | + // Report to user about the error |
| 43 | + mw.util.jsMessage( msg, 'watch' ); |
| 44 | +}; |
| 45 | + |
| 46 | +/** |
| 47 | + * Process the result of the API watch action. |
| 48 | + * |
| 49 | + * @param response Data object from API request. |
| 50 | + * @param $link jQuery object of the watch link. |
| 51 | + * @return Boolean true on success, false otherwise. |
| 52 | + */ |
27 | 53 | var processResult = function( response, $link ) { |
28 | | - watchResponse = response.watch; |
29 | 54 | |
| 55 | + if ( ( 'error' in response ) || !response.watch ) { |
| 56 | + errorHandler( $link ); |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + var watchResponse = response.watch; |
| 61 | + |
30 | 62 | // To ensure we set the same status for all watch links with the |
31 | 63 | // same target we trigger a custom event on *all* watch links. |
32 | 64 | if ( watchResponse.watched !== undefined ) { |
— | — | @@ -35,7 +67,7 @@ |
36 | 68 | } else { |
37 | 69 | // Either we got an error code or it just plain broke. |
38 | 70 | window.location.href = $link[0].href; |
39 | | - return; |
| 71 | + return false; |
40 | 72 | } |
41 | 73 | |
42 | 74 | mw.util.jsMessage( watchResponse.message, 'watch' ); |
— | — | @@ -47,6 +79,7 @@ |
48 | 80 | } else { |
49 | 81 | $( '#wpWatchthis' ).removeAttr( 'checked' ); |
50 | 82 | } |
| 83 | + return true; |
51 | 84 | }; |
52 | 85 | |
53 | 86 | $( document ).ready( function() { |
— | — | @@ -88,15 +121,23 @@ |
89 | 122 | // API return contains a localized data.watch.message string. |
90 | 123 | 'uselang': mw.config.get( 'wgUserLanguage' ) |
91 | 124 | }; |
| 125 | + |
92 | 126 | if ( $link.data( 'action' ) == 'unwatch' ) { |
93 | 127 | reqData.unwatch = ''; |
94 | 128 | } |
95 | | - $.getJSON( mw.util.wikiScript( 'api' ), |
96 | | - reqData, |
97 | | - function( data, textStatus, xhr ) { |
| 129 | + |
| 130 | + $.ajax({ |
| 131 | + url: mw.util.wikiScript( 'api' ), |
| 132 | + dataType: 'json', |
| 133 | + type: 'POST', |
| 134 | + data: reqData, |
| 135 | + success: function( data, textStatus, xhr ) { |
98 | 136 | processResult( data, $link ); |
| 137 | + }, |
| 138 | + error: function(){ |
| 139 | + processResult( {}, $link ); |
99 | 140 | } |
100 | | - ); |
| 141 | + }); |
101 | 142 | |
102 | 143 | return false; |
103 | 144 | }); |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -482,7 +482,15 @@ |
483 | 483 | ), |
484 | 484 | 'mediawiki.action.watch.ajax' => array( |
485 | 485 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js', |
486 | | - 'dependencies' => 'mediawiki.util', |
| 486 | + 'messages' => array( |
| 487 | + 'watch', |
| 488 | + 'unwatch', |
| 489 | + 'watching', |
| 490 | + 'unwatching', |
| 491 | + 'tooltip-ca-watch', |
| 492 | + 'tooltip-ca-unwatch', |
| 493 | + 'watcherrortext', |
| 494 | + ), |
487 | 495 | ), |
488 | 496 | |
489 | 497 | /* Special pages */ |
— | — | @@ -580,14 +588,6 @@ |
581 | 589 | 'scripts' => 'common/ajax.js', |
582 | 590 | 'remoteBasePath' => $GLOBALS['wgStylePath'], |
583 | 591 | 'localBasePath' => "{$GLOBALS['IP']}/skins", |
584 | | - 'messages' => array( |
585 | | - 'watch', |
586 | | - 'unwatch', |
587 | | - 'watching', |
588 | | - 'unwatching', |
589 | | - 'tooltip-ca-watch', |
590 | | - 'tooltip-ca-unwatch', |
591 | | - ), |
592 | 592 | 'dependencies' => 'mediawiki.legacy.wikibits', |
593 | 593 | ), |
594 | 594 | 'mediawiki.legacy.commonPrint' => array( |