X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fmediawiki.page%2Fmediawiki.page.watch.ajax.js;h=ef287c4324f4d436f1fe26afecb03fcb73e86494;hb=65a304c44451d0a62d01b809f3ef24c921286702;hp=5ba77a14b7cec24f7dd195832806e149fc023712;hpb=709c614382c199b7d3c5fc5bdbd285d8d3a5f339;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/mediawiki.page/mediawiki.page.watch.ajax.js b/resources/mediawiki.page/mediawiki.page.watch.ajax.js index 5ba77a14b7..ef287c4324 100644 --- a/resources/mediawiki.page/mediawiki.page.watch.ajax.js +++ b/resources/mediawiki.page/mediawiki.page.watch.ajax.js @@ -40,10 +40,10 @@ .attr( 'title', mw.msg( 'tooltip-ca-' + action ) + ( accesskeyTip ? ' ' + accesskeyTip[0] : '' ) ) - .attr( 'href', mw.util.wikiScript() + '?' + $.param({ + .attr( 'href', mw.util.wikiScript() + '?' + $.param( { title: title, action: action - }) + } ) ); // Most common ID style @@ -100,7 +100,7 @@ updateWatchLink: updateWatchLink }; - $( document ).ready( function () { + $( function () { var $links = $( '.mw-watchlink a, a.mw-watchlink, ' + '#ca-watch a, #ca-unwatch a, #mw-unwatch-link1, ' + '#mw-unwatch-link2, #mw-watch-link2, #mw-watch-link1' ); @@ -126,52 +126,46 @@ updateWatchLink( $link, action, 'loading' ); api = new mw.Api(); - api[action]( - title, - // Success - function ( watchResponse ) { - var $li, otherAction; - - otherAction = action === 'watch' ? 'unwatch' : 'watch'; - $li = $link.closest( 'li' ); - - mw.notify( $.parseHTML( watchResponse.message ), { - tag: 'watch-self' - } ); - - // Set link to opposite - updateWatchLink( $link, otherAction ); - - // Bug 12395 - update the watch checkbox on edit pages when the - // page is watched or unwatched via the tab. - if ( watchResponse.watched !== undefined ) { - $( '#wpWatchthis' ).prop( 'checked', true ); - } else { - $( '#wpWatchthis' ).prop( 'checked', false ); - } - }, - // Error - function () { - var cleanTitle, msg, link; - - // Reset link to non-loading mode - updateWatchLink( $link, action ); - - // Format error message - cleanTitle = title.replace( /_/g, ' ' ); - link = mw.html.element( - 'a', { - href: mw.util.wikiGetlink( title ), - title: cleanTitle - }, cleanTitle - ); - msg = mw.message( 'watcherrortext', link ); - - // Report to user about the error - mw.notify( msg, { tag: 'watch-self' } ); + api[action]( title ) + .done( function ( watchResponse ) { + var otherAction; + otherAction = action === 'watch' ? 'unwatch' : 'watch'; + + mw.notify( $.parseHTML( watchResponse.message ), { + tag: 'watch-self' + } ); + + // Set link to opposite + updateWatchLink( $link, otherAction ); + + // Bug 12395 - update the watch checkbox on edit pages when the + // page is watched or unwatched via the tab. + if ( watchResponse.watched !== undefined ) { + $( '#wpWatchthis' ).prop( 'checked', true ); + } else { + $( '#wpWatchthis' ).prop( 'checked', false ); } - ); + } ) + .fail( function () { + var cleanTitle, msg, link; + + // Reset link to non-loading mode + updateWatchLink( $link, action ); + + // Format error message + cleanTitle = title.replace( /_/g, ' ' ); + link = mw.html.element( + 'a', { + href: mw.util.getUrl( title ), + title: cleanTitle + }, cleanTitle + ); + msg = mw.message( 'watcherrortext', link ); + + // Report to user about the error + mw.notify( msg, { tag: 'watch-self' } ); + } ); } ); } );