5 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel View model
9 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListViewModel View model
10 * @param {mw.rcfilters.Controller} controller
11 * @param {jQuery} $changesListRoot Root element of the changes list to attach to
12 * @param {Object} [config] Configuration object
14 mw
.rcfilters
.ui
.ChangesListWrapperWidget
= function MwRcfiltersUiChangesListWrapperWidget(
21 config
= $.extend( {}, config
, {
22 $element
: $changesListRoot
26 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.parent
.call( this, config
);
28 this.filtersViewModel
= filtersViewModel
;
29 this.changesListViewModel
= changesListViewModel
;
30 this.controller
= controller
;
33 this.filtersViewModel
.connect( this, {
34 itemUpdate
: 'onItemUpdate',
35 highlightChange
: 'onHighlightChange'
37 this.changesListViewModel
.connect( this, {
38 invalidate
: 'onModelInvalidate',
39 update
: 'onModelUpdate',
40 newChangesExist
: 'onNewChangesExist'
44 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget' )
45 // We handle our own display/hide of the empty results message
46 .removeClass( 'mw-changeslist-empty' );
48 // Set up highlight containers
49 this.setupHighlightContainers( this.$element
);
51 if ( mw
.rcfilters
.featureFlags
.liveUpdate
) {
52 this.setupNewChangesButtonContainer( this.$element
);
58 OO
.inheritClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.Widget
);
61 * Respond to the highlight feature being toggled on and off
63 * @param {boolean} highlightEnabled
65 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onHighlightChange = function ( highlightEnabled
) {
66 if ( highlightEnabled
) {
67 this.applyHighlight();
69 this.clearHighlight();
74 * Respond to a filter item model update
76 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onItemUpdate = function () {
77 if ( this.filtersViewModel
.isHighlightEnabled() ) {
78 this.clearHighlight();
79 this.applyHighlight();
84 * Respond to changes list model invalidate
86 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelInvalidate = function () {
87 $( '.rcfilters-spinner' ).removeClass( 'mw-rcfilters-ui-ready' );
88 this.$element
.removeClass( 'mw-rcfilters-ui-ready' );
92 * Respond to changes list model update
94 * @param {jQuery|string} $changesListContent The content of the updated changes list
95 * @param {jQuery} $fieldset The content of the updated fieldset
96 * @param {boolean} isInitialDOM Whether $changesListContent is the existing (already attached) DOM
97 * @param {boolean} from Timestamp of the new changes
99 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelUpdate = function (
100 $changesListContent
, $fieldset
, isInitialDOM
, from
103 $message
= $( '<div>' )
104 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results' ),
105 isEmpty
= $changesListContent
=== 'NO_RESULTS',
106 // For enhanced mode, we have to load these modules, which are
107 // not loaded for the 'regular' mode in the backend
108 loaderPromise
= mw
.user
.options
.get( 'usenewrc' ) ?
109 mw
.loader
.using( [ 'mediawiki.special.changeslist.enhanced', 'mediawiki.icon' ] ) :
110 $.Deferred().resolve(),
113 this.$element
.toggleClass( 'mw-changeslist', !isEmpty
);
115 this.$element
.empty();
117 if ( this.filtersViewModel
.hasConflict() ) {
118 conflictItem
= this.filtersViewModel
.getFirstConflictedItem();
123 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-conflict' )
124 .text( mw
.message( 'rcfilters-noresults-conflict' ).text() ),
126 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-message' )
127 .text( mw
.message( conflictItem
.getCurrentConflictResultMessage() ).text() )
133 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-noresult' )
134 .text( mw
.message( 'recentchanges-noresult' ).text() )
138 this.$element
.append( $message
);
140 if ( !isInitialDOM
) {
141 this.$element
.empty().append( $changesListContent
);
144 this.emphasizeNewChanges( from );
148 // Set up highlight containers
149 this.setupHighlightContainers( this.$element
);
152 this.applyHighlight();
156 loaderPromise
.done( function () {
157 if ( !isInitialDOM
&& !isEmpty
) {
158 // Make sure enhanced RC re-initializes correctly
159 mw
.hook( 'wikipage.content' ).fire( widget
.$element
);
162 $( '.rcfilters-spinner' ).addClass( 'mw-rcfilters-ui-ready' );
163 widget
.$element
.addClass( 'mw-rcfilters-ui-ready' );
168 * Emphasize the elements (or groups) newer than the 'from' parameter
169 * @param {string} from Anything newer than this is considered 'new'
171 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.emphasizeNewChanges = function ( from ) {
174 $newChanges
= $( [] ),
175 selector
= this.inEnhancedMode() ?
176 'table.mw-enhanced-rc[data-mw-ts]' :
178 set = this.$element
.find( selector
),
181 set.each( function ( index
) {
182 var $this = $( this ),
183 ts
= $this.data( 'mw-ts' );
186 $newChanges
= $newChanges
.add( $this );
189 // guards against putting the marker after the last element
190 if ( index
=== ( length
- 1 ) ) {
197 $indicator
= $( '<div>' )
198 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator' );
200 $firstNew
.after( $indicator
);
209 * Respond to changes list model newChangesExist
211 * @param {boolean} newChangesExist Whether new changes exist
213 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onNewChangesExist = function ( newChangesExist
) {
214 this.showNewChangesLink
.toggle( newChangesExist
);
218 * Respond to the user clicking the 'show new changes' button
220 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onShowNewChangesClick = function () {
221 this.controller
.showNewChanges();
225 * Setup the container for the 'new changes' button.
227 * @param {jQuery} $content
229 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupNewChangesButtonContainer = function ( $content
) {
230 this.showNewChangesLink
= new OO
.ui
.ButtonWidget( {
232 label
: mw
.message( 'rcfilters-show-new-changes' ).text(),
233 flags
: [ 'progressive' ]
235 this.showNewChangesLink
.connect( this, { click
: 'onShowNewChangesClick' } );
236 this.showNewChangesLink
.toggle( false );
240 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-newChanges' )
241 .append( this.showNewChangesLink
.$element
)
246 * Set up the highlight containers with all color circle indicators.
248 * @param {jQuery|string} $content The content of the updated changes list
250 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupHighlightContainers = function ( $content
) {
251 var highlightClass
= 'mw-rcfilters-ui-changesListWrapperWidget-highlights',
252 $highlights
= $( '<div>' )
253 .addClass( highlightClass
)
256 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-none' )
257 .prop( 'data-color', 'none' )
260 if ( $( '.mw-rcfilters-ui-changesListWrapperWidget-highlights' ).length
) {
265 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
268 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-' + color
)
269 .prop( 'data-color', color
)
273 if ( this.inEnhancedMode() ) {
275 $content
.find( 'td.mw-enhanced-rc' )
279 .append( $highlights
.clone() )
283 $content
.find( 'ul.special li' )
284 .prepend( $highlights
.clone() );
289 * @return {boolean} Whether the changes are grouped by page
291 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.inEnhancedMode = function () {
292 var uri
= new mw
.Uri();
293 return ( uri
.query
.enhanced
!== undefined && Number( uri
.query
.enhanced
) ) ||
294 ( uri
.query
.enhanced
=== undefined && Number( mw
.user
.options
.get( 'usenewrc' ) ) );
298 * Apply color classes based on filters highlight configuration
300 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.applyHighlight = function () {
301 if ( !this.filtersViewModel
.isHighlightEnabled() ) {
305 this.filtersViewModel
.getHighlightedItems().forEach( function ( filterItem
) {
306 var $elements
= this.$element
.find( '.' + filterItem
.getCssClass() );
308 // Add highlight class to all highlighted list items
310 .addClass( 'mw-rcfilters-highlight-color-' + filterItem
.getHighlightColor() );
312 $elements
.each( function () {
313 var filterString
= $( this ).attr( 'data-highlightedFilters' ) || '',
314 filters
= filterString
? filterString
.split( '|' ) : [];
316 if ( filters
.indexOf( filterItem
.getLabel() ) === -1 ) {
317 filters
.push( filterItem
.getLabel() );
321 .attr( 'data-highlightedFilters', filters
.join( '|' ) );
324 // Apply a title for relevant filters
325 this.$element
.find( '[data-highlightedFilters]' ).each( function () {
326 var filterString
= $( this ).attr( 'data-highlightedFilters' ) || '',
327 filters
= filterString
? filterString
.split( '|' ) : [];
329 if ( filterString
) {
330 $( this ).attr( 'title', mw
.msg( 'rcfilters-highlighted-filters-list', filters
.join( ', ' ) ) );
334 // Turn on highlights
335 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );
339 * Remove all color classes
341 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.clearHighlight = function () {
342 // Remove highlight classes
343 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
344 this.$element
.find( '.mw-rcfilters-highlight-color-' + color
).removeClass( 'mw-rcfilters-highlight-color-' + color
);
347 this.$element
.find( '[data-highlightedFilters]' )
348 .removeAttr( 'title' )
349 .removeAttr( 'data-highlightedFilters' );
350 // Turn off highlights
351 this.$element
.removeClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );