Sn1per has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/326242 )
Change subject: Mark pages on watchlist as visited using JS without reload ...................................................................... Mark pages on watchlist as visited using JS without reload When the "mark pages as visited" is clicked, a dialog appears, asking for confirmation. On confirmation, an API request is sent to mark all pages as visited, and all unvisited watchlist entries are changed to appear visited. Based on a userscript by User:NQ (from English Wikipedia) https://en.wikipedia.org/wiki/User:NQ/WatchlistResetConfirm.js Bug: T150045 Change-Id: I45fb02a1edc1b0331925e9a244a2455f86ad3886 --- M languages/i18n/en.json M languages/i18n/qqq.json M resources/Resources.php M resources/src/mediawiki.special/mediawiki.special.watchlist.js 4 files changed, 66 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/42/326242/1 diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 2004e0f..0774b0f 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2114,6 +2114,7 @@ "wlshowhidemine": "my edits", "wlshowhidecategorization": "page categorization", "watchlist-options": "Watchlist options", + "watchlist-mark-all-visited": "Are you sure you want to reset unseen watchlist changes by marking all pages as visited?", "watching": "Watching...", "unwatching": "Unwatching...", "watcherrortext": "An error occurred while changing your watchlist settings for \"$1\".", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index d292c72..e4cfb10 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2298,6 +2298,7 @@ "wlshowhidemine": "Option text in [[Special:Watchlist]]. Cf. {{msg-mw|rcshowhidemine}}.", "wlshowhidecategorization": "Option text in [[Special:Watchlist]]. Cf. {{msg-mw|rcshowhidecategorization}}.", "watchlist-options": "Legend of the fieldset of [[Special:Watchlist]]\n\nSee also:\n* {{msg-mw|Watchlist-details|watchlist header}}\n* {{msg-mw|Wlheader-enotif|watchlist header}}\n* {{msg-mw|enotif reset|Submit button text}}", + "watchlist-mark-all-visited": "Dialog text in [[Special:Watchlist]] displayed for confirming whether the user wants to reset unseen watchlist changes by marking all pages as visited.", "watching": "Text displayed when clicked on the watch tab: {{msg-mw|Watch}}. It means the wiki is adding that page to your watchlist.", "unwatching": "Text displayed when clicked on the unwatch tab: {{msg-mw|Unwatch}}. It means the wiki is removing that page from your watchlist.", "watcherrortext": "When a user clicked the watch/unwatch tab and the action did not succeed, this message is displayed.\n\nThis message is used raw and should not contain wikitext.\n\nParameters:\n* $1 - ...\nSee also:\n* {{msg-mw|Addedwatchtext}}", diff --git a/resources/Resources.php b/resources/Resources.php index 5c74186..738bf1a 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -2033,8 +2033,19 @@ ], 'mediawiki.special.watchlist' => [ 'scripts' => 'resources/src/mediawiki.special/mediawiki.special.watchlist.js', + 'messages' => [ + 'cancel', + 'confirm', + 'enotif_reset', + 'watchlist-mark-all-visited' + ], 'dependencies' => [ + 'mediawiki.api', + 'mediawiki.jqueryMsg', + 'oojs-ui-core', + 'oojs-ui-windows', 'user.options', + 'user.tokens', ] ], 'mediawiki.special.version' => [ diff --git a/resources/src/mediawiki.special/mediawiki.special.watchlist.js b/resources/src/mediawiki.special/mediawiki.special.watchlist.js index 0be13a6..ea679da 100644 --- a/resources/src/mediawiki.special/mediawiki.special.watchlist.js +++ b/resources/src/mediawiki.special/mediawiki.special.watchlist.js @@ -3,6 +3,57 @@ */ ( function ( mw, $ ) { $( function () { + var $watchlistReset, messageDialog, windowManager; + + // 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 + // (User:NQ/WatchlistResetConfirm.js) + $watchlistReset = $( '#mw-watchlist-resetbutton' ); + windowManager = new OO.ui.WindowManager(); + $( 'body' ).append( windowManager.$element ); + + // Confirmation dialog + messageDialog = new OO.ui.MessageDialog(); + windowManager.addWindows( [ messageDialog ] ); + + $watchlistReset.submit( function ( event ) { + event.preventDefault(); + + windowManager.openWindow( messageDialog, { + title: mw.msg( 'enotif_reset' ), + message: mw.msg( 'watchlist-mark-all-visited' ), + actions: [ + { + action: 'reject', + label: mw.msg( 'cancel' ), + flags: [ 'safe' ] + }, + { + action: 'reset', + label: mw.msg( 'confirm' ), + flags: [ 'primary', 'destructive' ] + } + ] + } ).then( function ( opened ) { + opened.then( function ( closing, data ) { + if ( data && data.action === 'reset' ) { + // Use action=setnotificationtimestamp to mark all as visited, + // then set all watchlist lines accordingly + new mw.Api().post( { + action: 'setnotificationtimestamp', + entirewatchlist: '', + token: mw.user.tokens.get( 'editToken' ) + } ).done( function () { + $( '.mw-changeslist-line-watched' ) + .removeClass( 'mw-changeslist-line-watched' ) + .addClass( 'mw-changeslist-line-not-watched' ); + } ); + + } + } ); + } ); + } ); + // if the user wishes to reload the watchlist whenever a filter changes if ( mw.user.options.get( 'watchlistreloadautomatically' ) ) { // add a listener on all form elements in the header form @@ -13,4 +64,5 @@ } } ); -}( mediaWiki, jQuery ) ); +}( mediaWiki, jQuery ) +); -- To view, visit https://gerrit.wikimedia.org/r/326242 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I45fb02a1edc1b0331925e9a244a2455f86ad3886 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sn1per <geof...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits