Skip to content

Commit ebc36b7

Browse files
catropejdforrester
authored andcommitted
RCFilters: Basic implementation of live updates
Adds a live updates button that refreshes the changes list every 3 seconds. For now this is pretty dumb in that it re-requests the entire list every time; the next step would be to make it only load new changes using the &from= query parameter. Bug: T167743 Change-Id: Ic2ddea840e5c46f42b32ae4fff91138cacc28ec0
1 parent 68e16c2 commit ebc36b7

11 files changed

+159
-6
lines changed

includes/DefaultSettings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6778,6 +6778,11 @@
67786778
*/
67796779
$wgStructuredChangeFiltersEnableExperimentalViews = false;
67806780

6781+
/**
6782+
* Whether to allow users to use the experimental live update feature in the new RecentChanges UI
6783+
*/
6784+
$wgStructuredChangeFiltersEnableLiveUpdate = false;
6785+
67816786
/**
67826787
* Use new page patrolling to check new pages on Special:Newpages
67836788
*/

includes/specials/SpecialRecentchanges.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public function __construct( $name = 'Recentchanges', $restriction = '' ) {
139139
*/
140140
public function execute( $subpage ) {
141141
global $wgStructuredChangeFiltersEnableSaving,
142-
$wgStructuredChangeFiltersEnableExperimentalViews;
142+
$wgStructuredChangeFiltersEnableExperimentalViews,
143+
$wgStructuredChangeFiltersEnableLiveUpdate;
143144

144145
// Backwards-compatibility: redirect to new feed URLs
145146
$feedFormat = $this->getRequest()->getVal( 'feed' );
@@ -189,6 +190,10 @@ public function execute( $subpage ) {
189190
'wgStructuredChangeFiltersEnableExperimentalViews',
190191
$wgStructuredChangeFiltersEnableExperimentalViews
191192
);
193+
$out->addJsConfigVars(
194+
'wgStructuredChangeFiltersEnableLiveUpdate',
195+
$wgStructuredChangeFiltersEnableLiveUpdate
196+
);
192197
$out->addJsConfigVars(
193198
'wgRCFiltersChangeTags',
194199
$this->buildChangeTagList()

languages/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@
14461446
"rcfilters-view-namespaces-tooltip": "Filter results by namespace",
14471447
"rcfilters-view-tags-tooltip": "Filter results using edit tags",
14481448
"rcfilters-view-return-to-default-tooltip": "Return to main filter menu",
1449+
"rcfilters-liveupdates-button": "Live updates",
14491450
"rcnotefrom": "Below {{PLURAL:$5|is the change|are the changes}} since <strong>$3, $4</strong> (up to <strong>$1</strong> shown).",
14501451
"rclistfromreset": "Reset date selection",
14511452
"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
@@ -1636,6 +1636,7 @@
16361636
"rcfilters-view-namespaces-tooltip": "Tooltip for the button that loads the namespace view in [[Special:RecentChanges]]",
16371637
"rcfilters-view-tags-tooltip": "Tooltip for the button that loads the tags view in [[Special:RecentChanges]]",
16381638
"rcfilters-view-return-to-default-tooltip": "Tooltip for the button that returns to the default filter view in [[Special:RecentChanges]]",
1639+
"rcfilters-liveupdates-button": "Label for the button to enable or disable live updates on [[Special:RecentChanges]]",
16391640
"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",
16401641
"rclistfromreset": "Used on [[Special:RecentChanges]] to reset a selection of a certain date range.",
16411642
"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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@
17891789
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js',
17901790
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterItemHighlightButton.js',
17911791
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.HighlightColorPickerWidget.js',
1792+
'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.LiveUpdateButtonWidget.js',
17921793
'resources/src/mediawiki.rcfilters/mw.rcfilters.HighlightColors.js',
17931794
'resources/src/mediawiki.rcfilters/mw.rcfilters.init.js',
17941795
],
@@ -1812,6 +1813,7 @@
18121813
'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.SavedLinksListWidget.less',
18131814
'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.SavedLinksListItemWidget.less',
18141815
'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.less',
1816+
'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.LiveUpdateButtonWidget.less',
18151817
],
18161818
'skinStyles' => [
18171819
'monobook' => [
@@ -1859,6 +1861,7 @@
18591861
'rcfilters-view-namespaces-tooltip',
18601862
'rcfilters-view-tags-tooltip',
18611863
'rcfilters-view-return-to-default-tooltip',
1864+
'rcfilters-liveupdates-button',
18621865
'blanknamespace',
18631866
'namespaces',
18641867
'invert',
@@ -1877,6 +1880,7 @@
18771880
'oojs-ui.styles.icons-interactions',
18781881
'oojs-ui.styles.icons-content',
18791882
'oojs-ui.styles.icons-layout',
1883+
'oojs-ui.styles.icons-media',
18801884
],
18811885
],
18821886
'mediawiki.special' => [

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/**
2929
* @event update
3030
* @param {jQuery|string} changesListContent
31+
* @param {jQuery} $fieldset
3132
*
3233
* The list of change is now up to date
3334
*/

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,42 @@
271271
this._trackHighlight( 'clear', filterName );
272272
};
273273

274+
/**
275+
* Enable or disable live updates.
276+
* @param {boolean} enable True to enable, false to disable
277+
*/
278+
mw.rcfilters.Controller.prototype.toggleLiveUpdate = function ( enable ) {
279+
if ( enable && !this.liveUpdateTimeout ) {
280+
this._scheduleLiveUpdate();
281+
} else if ( !enable && this.liveUpdateTimeout ) {
282+
clearTimeout( this.liveUpdateTimeout );
283+
this.liveUpdateTimeout = null;
284+
}
285+
};
286+
287+
/**
288+
* Set a timeout for the next live update.
289+
* @private
290+
*/
291+
mw.rcfilters.Controller.prototype._scheduleLiveUpdate = function () {
292+
this.liveUpdateTimeout = setTimeout( this._doLiveUpdate.bind( this ), 3000 );
293+
};
294+
295+
/**
296+
* Perform a live update.
297+
* @private
298+
*/
299+
mw.rcfilters.Controller.prototype._doLiveUpdate = function () {
300+
var controller = this;
301+
this.updateChangesList( {}, true )
302+
.always( function () {
303+
if ( controller.liveUpdateTimeout ) {
304+
// Live update was not disabled in the meantime
305+
controller._scheduleLiveUpdate();
306+
}
307+
} );
308+
};
309+
274310
/**
275311
* Save the current model state as a saved query
276312
*
@@ -555,11 +591,15 @@
555591
* Update the list of changes and notify the model
556592
*
557593
* @param {Object} [params] Extra parameters to add to the API call
594+
* @param {boolean} [isLiveUpdate] Don't update the URL or invalidate the changes list
595+
* @return {jQuery.Promise} Promise that is resolved when the update is complete
558596
*/
559-
mw.rcfilters.Controller.prototype.updateChangesList = function ( params ) {
560-
this._updateURL( params );
561-
this.changesListModel.invalidate();
562-
this._fetchChangesList()
597+
mw.rcfilters.Controller.prototype.updateChangesList = function ( params, isLiveUpdate ) {
598+
if ( !isLiveUpdate ) {
599+
this._updateURL( params );
600+
this.changesListModel.invalidate();
601+
}
602+
return this._fetchChangesList()
563603
.then(
564604
// Success
565605
function ( pieces ) {

resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterWrapperWidget.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
&-viewToggleButtons {
88
margin-top: 1em;
99
}
10+
11+
&-bottom {
12+
margin-top: 1em;
13+
}
1014
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.mw-rcfilters-ui-liveUpdateButtonWidget {
2+
&.oo-ui-toggleWidget-on {
3+
position: relative;
4+
overflow: hidden;
5+
&:after {
6+
content: '';
7+
mix-blend-mode: screen;
8+
position: absolute;
9+
width: 1.875em;
10+
height: 1.875em;
11+
top: 1.875em / 4;
12+
left: 0.46875em;
13+
background: rgba( 51, 102, 204, 0.5 );
14+
border-radius: 100%;
15+
transform-origin: 50% 50%;
16+
opacity: 0;
17+
animation: ripple 1.2s ease-out infinite;
18+
animation-delay: 1s;
19+
}
20+
}
21+
}
22+
23+
@keyframes ripple {
24+
0%,
25+
35% {
26+
transform: scale( 0 );
27+
opacity: 1;
28+
}
29+
50% {
30+
transform: scale( 1.5 );
31+
opacity: 0.8;
32+
}
33+
100% {
34+
opacity: 0;
35+
transform: scale( 4 );
36+
}
37+
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
1515
*/
1616
mw.rcfilters.ui.FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget( controller, model, savedQueriesModel, config ) {
17+
var $bottom;
1718
config = config || {};
1819

1920
// Parent
@@ -33,6 +34,10 @@
3334
{ $overlay: this.$overlay }
3435
);
3536

37+
this.liveUpdateButton = new mw.rcfilters.ui.LiveUpdateButtonWidget(
38+
this.controller
39+
);
40+
3641
// Initialize
3742
this.$element
3843
.addClass( 'mw-rcfilters-ui-filterWrapperWidget' );
@@ -50,8 +55,16 @@
5055

5156
}
5257

58+
$bottom = $( '<div>' )
59+
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' );
60+
61+
if ( mw.config.get( 'wgStructuredChangeFiltersEnableLiveUpdate' ) ) {
62+
$bottom.append( this.liveUpdateButton.$element );
63+
}
64+
5365
this.$element.append(
54-
this.filterTagWidget.$element
66+
this.filterTagWidget.$element,
67+
$bottom
5568
);
5669
};
5770

0 commit comments

Comments
 (0)