Skip to content

Commit 2d2cb5e

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "WLFilters: convert mark as seen button to new style"
2 parents ad2b0c7 + 7da2426 commit 2d2cb5e

File tree

8 files changed

+148
-30
lines changed

8 files changed

+148
-30
lines changed

languages/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,7 @@
14611461
"rcfilters-liveupdates-button": "Live updates",
14621462
"rcfilters-liveupdates-button-title-on": "Turn off live updates",
14631463
"rcfilters-liveupdates-button-title-off": "Display new changes as they happen",
1464+
"rcfilters-watchlist-markSeen-button": "Mark all changes as seen",
14641465
"rcnotefrom": "Below {{PLURAL:$5|is the change|are the changes}} since <strong>$3, $4</strong> (up to <strong>$1</strong> shown).",
14651466
"rclistfromreset": "Reset date selection",
14661467
"rclistfrom": "Show new changes starting from $2, $3",

languages/i18n/qqq.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@
16511651
"rcfilters-liveupdates-button": "Label for the button to enable or disable live updates on [[Special:RecentChanges]]",
16521652
"rcfilters-liveupdates-button-title-on": "Title for the button to enable or disable live updates on [[Special:RecentChanges]] when the feature is ON.",
16531653
"rcfilters-liveupdates-button-title-off": "Title for the button to enable or disable live updates on [[Special:RecentChanges]] when the feature is OFF.",
1654+
"rcfilters-watchlist-markSeen-button": "Label for the button to mark all changes as seen on [[Special:Watchlist]] when using the structured filters interface.",
16541655
"rcnotefrom": "This message is displayed at [[Special:RecentChanges]] when viewing recentchanges from some specific time.\n\nThe corresponding message is {{msg-mw|Rclistfrom}}.\n\nParameters:\n* $1 - the maximum number of changes that are displayed\n* $2 - (Optional) a date and time\n* $3 - a date\n* $4 - a time\n* $5 - Number of changes are displayed, for use with PLURAL",
16551656
"rclistfromreset": "Used on [[Special:RecentChanges]] to reset a selection of a certain date range.",
16561657
"rclistfrom": "Used on [[Special:RecentChanges]]. Parameters:\n* $1 - (Currently not use) date and time. The date and the time adds to the rclistfrom description.\n* $2 - time. The time adds to the rclistfrom link description (with split of date and time).\n* $3 - date. The date adds to the rclistfrom link description (with split of date and time).\n\nThe corresponding message is {{msg-mw|Rcnotefrom}}.",

resources/Resources.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@
17951795
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterItemHighlightButton.js',
17961796
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.HighlightColorPickerWidget.js',
17971797
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.LiveUpdateButtonWidget.js',
1798+
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.MarkSeenButtonWidget.js',
17981799
'resources/src/mediawiki.rcfilters/mw.rcfilters.HighlightColors.js',
17991800
'resources/src/mediawiki.rcfilters/mw.rcfilters.init.js',
18001801
],
@@ -1885,6 +1886,7 @@
18851886
'rcfilters-liveupdates-button',
18861887
'rcfilters-liveupdates-button-title-on',
18871888
'rcfilters-liveupdates-button-title-off',
1889+
'rcfilters-watchlist-markSeen-button',
18881890
'rcfilters-other-review-tools',
18891891
'blanknamespace',
18901892
'namespaces',

resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
this.newChangesExist = false;
1515
this.nextFrom = null;
1616
this.liveUpdate = false;
17+
this.unseenWatchedChanges = false;
1718
};
1819

1920
/* Initialization */
@@ -81,6 +82,7 @@
8182
if ( mw.rcfilters.featureFlags.liveUpdate ) {
8283
this.extractNextFrom( $fieldset );
8384
}
85+
this.checkForUnseenWatchedChanges( changesListContent );
8486
this.emit( 'update', changesListContent, $fieldset, isInitialDOM, separateOldAndNew ? from : null );
8587
};
8688

@@ -140,4 +142,20 @@
140142
return this.liveUpdate;
141143
};
142144

145+
/**
146+
* Check if some of the given changes watched and unseen
147+
*
148+
* @param {jQuery|string} changeslistContent
149+
*/
150+
mw.rcfilters.dm.ChangesListViewModel.prototype.checkForUnseenWatchedChanges = function ( changeslistContent ) {
151+
this.unseenWatchedChanges = changeslistContent !== 'NO_RESULTS' &&
152+
changeslistContent.find( '.mw-changeslist-line-watched' ).length > 0;
153+
};
154+
155+
/**
156+
* @return {boolean} Whether some of the current changes are watched and unseen
157+
*/
158+
mw.rcfilters.dm.ChangesListViewModel.prototype.hasUnseenWatchedChanges = function () {
159+
return this.unseenWatchedChanges;
160+
};
143161
}( mediaWiki ) );

resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@
996996
* Update the list of changes and notify the model
997997
*
998998
* @param {Object} [params] Extra parameters to add to the API call
999-
* @param {string} [updateMode='filterChange'] One of 'filterChange', 'liveUpdate', 'showNewChanges'
999+
* @param {string} [updateMode='filterChange'] One of 'filterChange', 'liveUpdate', 'showNewChanges', 'markSeen'
10001000
* @return {jQuery.Promise} Promise that is resolved when the update is complete
10011001
*/
10021002
mw.rcfilters.Controller.prototype.updateChangesList = function ( params, updateMode ) {
@@ -1263,4 +1263,18 @@
12631263
this.prevLoggedItems = filters;
12641264
}
12651265
};
1266+
1267+
/**
1268+
* Mark all changes as seen on Watchlist
1269+
*/
1270+
mw.rcfilters.Controller.prototype.markAllChangesAsSeen = function () {
1271+
var api = new mw.Api();
1272+
api.postWithToken( 'csrf', {
1273+
formatversion: 2,
1274+
action: 'setnotificationtimestamp',
1275+
entirewatchlist: true
1276+
} ).then( function () {
1277+
this.updateChangesList( null, 'markSeen' );
1278+
}.bind( this ) );
1279+
};
12661280
}( mediaWiki, jQuery ) );

resources/src/mediawiki.rcfilters/mw.rcfilters.init.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
$overlay = $( '<div>' )
2626
.addClass( 'mw-rcfilters-ui-overlay' ),
2727
filtersWidget = new mw.rcfilters.ui.FilterWrapperWidget(
28-
controller, filtersModel, savedQueriesModel, changesListModel, { $overlay: $overlay } );
28+
controller, filtersModel, savedQueriesModel, changesListModel, { $overlay: $overlay } ),
29+
markSeenButton,
30+
currentPage = mw.config.get( 'wgCanonicalNamespace' ) +
31+
':' +
32+
mw.config.get( 'wgCanonicalSpecialPageName' );
2933

3034
// TODO: The changesListWrapperWidget should be able to initialize
3135
// after the model is ready.
@@ -54,30 +58,38 @@
5458

5559
controller.replaceUrl();
5660

57-
toplinksTitle = new OO.ui.ButtonWidget( {
58-
framed: false,
59-
indicator: topLinksCookieValue === 'collapsed' ? 'down' : 'up',
60-
flags: [ 'progressive' ],
61-
label: $( '<span>' ).append( mw.message( 'rcfilters-other-review-tools' ).parse() ).contents()
62-
} );
63-
$( '.mw-recentchanges-toplinks-title' ).replaceWith( toplinksTitle.$element );
64-
// Move the top links to a designated area so it's near the
65-
// 'saved filters' button and make it collapsible
66-
$( '.mw-recentchanges-toplinks' )
67-
.addClass( 'mw-rcfilters-ui-ready' )
68-
.makeCollapsible( {
69-
collapsed: topLinksCookieValue === 'collapsed',
70-
$customTogglers: toplinksTitle.$element
71-
} )
72-
.on( 'beforeExpand.mw-collapsible', function () {
73-
mw.cookie.set( topLinksCookieName, 'expanded' );
74-
toplinksTitle.setIndicator( 'up' );
75-
} )
76-
.on( 'beforeCollapse.mw-collapsible', function () {
77-
mw.cookie.set( topLinksCookieName, 'collapsed' );
78-
toplinksTitle.setIndicator( 'down' );
79-
} )
80-
.appendTo( '.mw-rcfilters-ui-filterWrapperWidget-top-placeholder' );
61+
if ( currentPage === 'Special:Recentchanges' ) {
62+
toplinksTitle = new OO.ui.ButtonWidget( {
63+
framed: false,
64+
indicator: topLinksCookieValue === 'collapsed' ? 'down' : 'up',
65+
flags: [ 'progressive' ],
66+
label: $( '<span>' ).append( mw.message( 'rcfilters-other-review-tools' ).parse() ).contents()
67+
} );
68+
$( '.mw-recentchanges-toplinks-title' ).replaceWith( toplinksTitle.$element );
69+
// Move the top links to a designated area so it's near the
70+
// 'saved filters' button and make it collapsible
71+
$( '.mw-recentchanges-toplinks' )
72+
.addClass( 'mw-rcfilters-ui-ready' )
73+
.makeCollapsible( {
74+
collapsed: topLinksCookieValue === 'collapsed',
75+
$customTogglers: toplinksTitle.$element
76+
} )
77+
.on( 'beforeExpand.mw-collapsible', function () {
78+
mw.cookie.set( topLinksCookieName, 'expanded' );
79+
toplinksTitle.setIndicator( 'up' );
80+
} )
81+
.on( 'beforeCollapse.mw-collapsible', function () {
82+
mw.cookie.set( topLinksCookieName, 'collapsed' );
83+
toplinksTitle.setIndicator( 'down' );
84+
} )
85+
.appendTo( '.mw-rcfilters-ui-filterWrapperWidget-top-placeholder' );
86+
} // end Special:RC
87+
88+
if ( currentPage === 'Special:Watchlist' ) {
89+
markSeenButton = new mw.rcfilters.ui.MarkSeenButtonWidget( controller, changesListModel );
90+
$( 'form#mw-watchlist-resetbutton' ).detach();
91+
filtersWidget.prependToTopRow( markSeenButton );
92+
} // end Special:WL
8193
}
8294
};
8395

resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterWrapperWidget.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mw.rcfilters.ui.FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget(
1818
controller, model, savedQueriesModel, changesListModel, config
1919
) {
20-
var $top, $topRow, $bottom;
20+
var $top, $bottom;
2121
config = config || {};
2222

2323
// Parent
@@ -59,7 +59,7 @@
5959
);
6060

6161
// Initialize
62-
$topRow = $( '<div>' )
62+
this.$topRow = $( '<div>' )
6363
.addClass( 'mw-rcfilters-ui-row' )
6464
.append(
6565
$( '<div>' )
@@ -69,7 +69,7 @@
6969
$top = $( '<div>' )
7070
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-top' )
7171
.addClass( 'mw-rcfilters-ui-table' )
72-
.append( $topRow );
72+
.append( this.$topRow );
7373

7474
$bottom = $( '<div>' )
7575
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' )
@@ -84,7 +84,7 @@
8484
{ $overlay: this.$overlay }
8585
);
8686

87-
$topRow.append(
87+
this.$topRow.append(
8888
$( '<div>' )
8989
.addClass( 'mw-rcfilters-ui-cell' )
9090
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-top-savedLinks' )
@@ -108,4 +108,19 @@
108108

109109
OO.inheritClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.Widget );
110110
OO.mixinClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.mixin.PendingElement );
111+
112+
/* Methods */
113+
114+
/**
115+
* Add a widget at the beginning of the top row
116+
*
117+
* @param {OO.ui.Widget} widget Any widget
118+
*/
119+
mw.rcfilters.ui.FilterWrapperWidget.prototype.prependToTopRow = function ( widget ) {
120+
this.$topRow.prepend(
121+
widget.$element
122+
.addClass( 'mw-rcfilters-ui-cell' )
123+
);
124+
};
125+
111126
}( mediaWiki ) );
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
( function ( mw ) {
2+
/**
3+
* Button for marking all changes as seen on the Watchlist
4+
*
5+
* @extends OO.ui.ButtonWidget
6+
*
7+
* @constructor
8+
* @param {mw.rcfilters.Controller} controller
9+
* @param {mw.rcfilters.dm.ChangesListViewModel} model Changes list view model
10+
* @param {Object} [config] Configuration object
11+
*/
12+
mw.rcfilters.ui.MarkSeenButtonWidget = function MwRcfiltersUiMarkSeenButtonWidget( controller, model, config ) {
13+
config = config || {};
14+
15+
// Parent
16+
mw.rcfilters.ui.MarkSeenButtonWidget.parent.call( this, $.extend( {
17+
label: mw.message( 'rcfilters-watchlist-markSeen-button' ).text(),
18+
icon: 'doubleCheck'
19+
}, config ) );
20+
21+
this.controller = controller;
22+
this.model = model;
23+
24+
// Events
25+
this.connect( this, { click: 'onClick' } );
26+
this.model.connect( this, { update: 'onModelUpdate' } );
27+
28+
this.$element.addClass( 'mw-rcfilters-ui-markSeenButtonWidget' );
29+
30+
this.onModelUpdate();
31+
};
32+
33+
/* Initialization */
34+
35+
OO.inheritClass( mw.rcfilters.ui.MarkSeenButtonWidget, OO.ui.ButtonWidget );
36+
37+
/* Methods */
38+
39+
/**
40+
* Respond to the button being clicked
41+
*/
42+
mw.rcfilters.ui.MarkSeenButtonWidget.prototype.onClick = function () {
43+
this.controller.markAllChangesAsSeen();
44+
// assume there's no more unseen changes until the next model update
45+
this.setDisabled( true );
46+
};
47+
48+
/**
49+
* Respond to the model being updated with new changes
50+
*/
51+
mw.rcfilters.ui.MarkSeenButtonWidget.prototype.onModelUpdate = function () {
52+
this.setDisabled( !this.model.hasUnseenWatchedChanges() );
53+
};
54+
55+
}( mediaWiki ) );

0 commit comments

Comments
 (0)