X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.watchlist.js;h=535ca9375322c89d74e85d08c53b01a2d8d7b91c;hb=802c199d0bd80ff0f4d730c61fd58cbf08a52d8d;hp=7cc9b9bb5ad3240f368f930fcf3c03fea3e6885e;hpb=64b83bdb3afd0ee4f8fc1893a865409c198e601e;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special/mediawiki.special.watchlist.js b/resources/src/mediawiki.special/mediawiki.special.watchlist.js index 7cc9b9bb5a..535ca93753 100644 --- a/resources/src/mediawiki.special/mediawiki.special.watchlist.js +++ b/resources/src/mediawiki.special/mediawiki.special.watchlist.js @@ -3,7 +3,7 @@ */ ( function ( mw, $, OO ) { $( function () { - var $progressBar, $resetForm = $( '#mw-watchlist-resetbutton' ); + var api = new mw.Api(), $progressBar, $resetForm = $( '#mw-watchlist-resetbutton' ); // If the user wants to reset their watchlist, use an API call to do so (no reload required) // Adapted from a user script by User:NQ of English Wikipedia @@ -19,8 +19,7 @@ if ( !$progressBar ) { $progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element; $progressBar.css( { - position: 'absolute', - width: '100%' + position: 'absolute', width: '100%' } ); } // Show progress bar @@ -28,10 +27,8 @@ // Use action=setnotificationtimestamp to mark all as visited, // then set all watchlist lines accordingly - new mw.Api().postWithToken( 'csrf', { - formatversion: 2, - action: 'setnotificationtimestamp', - entirewatchlist: true + api.postWithToken( 'csrf', { + formatversion: 2, action: 'setnotificationtimestamp', entirewatchlist: true } ).done( function () { // Enable button again $button.prop( 'disabled', false ); @@ -56,6 +53,103 @@ $( '#mw-watchlist-form' ).submit(); } ); } + + if ( mw.user.options.get( 'watchlistunwatchlinks' ) ) { + // Watch/unwatch toggle link: + // If a page is on the watchlist, a '×' is shown which, when clicked, removes the page from the watchlist. + // After unwatching a page, the '×' becomes a '+', which if clicked re-watches the page. + // Unwatched page entries are struck through and have lowered opacity. + $( '.mw-unwatch-link, .mw-watch-link' ).click( function ( event ) { + var $unwatchLink = $( this ), // EnhancedChangesList uses for each row, while OldChangesList uses
  • for each row + $watchlistLine = $unwatchLink.closest( 'li, table' ) + .find( '[data-target-page]' ), + pageTitle = $watchlistLine.data( 'targetPage' ), + isTalk = mw.Title.newFromText( pageTitle ).getNamespaceId() % 2 === 1; + + // Utility function for looping through each watchlist line that matches + // a certain page or its associated page (e.g. Talk) + function forEachMatchingTitle( title, callback ) { + + var titleObj = mw.Title.newFromText( title ), + pageNamespaceId = titleObj.getNamespaceId(), + isTalk = pageNamespaceId % 2 === 1, + associatedTitle = mw.Title.makeTitle( isTalk ? pageNamespaceId - 1 : pageNamespaceId + 1, + titleObj.getMainText() ).getPrefixedText(); + $( '.mw-changeslist-line' ).each( function () { + var $this = $( this ), $row, $unwatchLink; + + $this.find( '[data-target-page]' ).each( function () { + var $this = $( this ), rowTitle = $this.data( 'targetPage' ); + if ( rowTitle === title || rowTitle === associatedTitle ) { + + // EnhancedChangesList groups log entries by performer rather than target page. Therefore... + // * If using OldChangesList, use the
  • + // * If using EnhancedChangesList and $this is part of a grouped log entry, use the
  • sub-entry + // * If using EnhancedChangesList and $this is not part of a grouped log entry, use the grouped entry + $row = + $this.closest( + 'li, table.mw-collapsible.mw-changeslist-log td[data-target-page], table' ); + $unwatchLink = $row.find( '.mw-unwatch-link, .mw-watch-link' ); + + callback( rowTitle, $row, $unwatchLink ); + } + } ); + } ); + } + + // Depending on whether we are watching or unwatching, for each entry of the page (and its associated page i.e. Talk), + // change the text, tooltip, and non-JS href of the (un)watch button, and update the styling of the watchlist entry. + if ( $unwatchLink.hasClass( 'mw-unwatch-link' ) ) { + api.unwatch( pageTitle ) + .done( function () { + forEachMatchingTitle( pageTitle, + function ( rowPageTitle, $row, $rowUnwatchLink ) { + $rowUnwatchLink + .text( mw.msg( 'watchlist-unwatch-undo' ) ) + .attr( 'title', mw.msg( 'tooltip-ca-watch' ) ) + .attr( 'href', + mw.util.getUrl( rowPageTitle, { action: 'watch' } ) ) + .removeClass( 'mw-unwatch-link loading' ) + .addClass( 'mw-watch-link' ); + $row.find( + '.mw-changeslist-line-inner, .mw-enhanced-rc-nested' ) + .addBack( '.mw-enhanced-rc-nested' ) // For matching log sub-entry + .addClass( 'mw-changelist-line-inner-unwatched' ); + } ); + + mw.notify( + mw.message( isTalk ? 'removedwatchtext-talk' : 'removedwatchtext', + pageTitle ), { tag: 'watch-self' } ); + } ); + } else { + api.watch( pageTitle ) + .then( function () { + forEachMatchingTitle( pageTitle, + function ( rowPageTitle, $row, $rowUnwatchLink ) { + $rowUnwatchLink + .text( mw.msg( 'watchlist-unwatch' ) ) + .attr( 'title', mw.msg( 'tooltip-ca-unwatch' ) ) + .attr( 'href', + mw.util.getUrl( rowPageTitle, { action: 'unwatch' } ) ) + .removeClass( 'mw-watch-link loading' ) + .addClass( 'mw-unwatch-link' ); + $row.find( '.mw-changelist-line-inner-unwatched' ) + .addBack( '.mw-enhanced-rc-nested' ) + .removeClass( 'mw-changelist-line-inner-unwatched' ); + } ); + + mw.notify( + mw.message( isTalk ? 'addedwatchtext-talk' : 'addedwatchtext', + pageTitle ), { tag: 'watch-self' } ); + } ); + } + + event.preventDefault(); + event.stopPropagation(); + $unwatchLink.blur(); + } ); + } } ); -}( mediaWiki, jQuery, OO ) ); +}( mediaWiki, jQuery, OO ) +);