2 /* eslint no-underscore-dangle: "off" */
4 * Controller for the filters in Recent Changes
6 * @param {mw.rcfilters.dm.FiltersViewModel} filtersModel Filters view model
7 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel Changes list view model
8 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
10 mw
.rcfilters
.Controller
= function MwRcfiltersController( filtersModel
, changesListModel
, savedQueriesModel
) {
11 this.filtersModel
= filtersModel
;
12 this.changesListModel
= changesListModel
;
13 this.savedQueriesModel
= savedQueriesModel
;
14 this.requestCounter
= 0;
15 this.baseFilterState
= {};
16 this.uriProcessor
= null;
17 this.initializing
= false;
21 OO
.initClass( mw
.rcfilters
.Controller
);
24 * Initialize the filter and parameter states
26 * @param {Array} filterStructure Filter definition and structure for the model
27 * @param {Object} [namespaceStructure] Namespace definition
28 * @param {Object} [tagList] Tag definition
30 mw
.rcfilters
.Controller
.prototype.initialize = function ( filterStructure
, namespaceStructure
, tagList
) {
31 var parsedSavedQueries
,
35 $changesList
= $( '.mw-changeslist' ).first().contents(),
36 createFilterDataFromNumber = function ( num
, convertedNumForLabel
) {
39 label
: mw
.language
.convertNumber( convertedNumForLabel
)
44 if ( namespaceStructure
) {
46 $.each( namespaceStructure
, function ( namespaceID
, label
) {
47 // Build and clean up the individual namespace items definition
50 label
: label
|| mw
.msg( 'blanknamespace' ),
53 ( namespaceID
< 0 || namespaceID
% 2 === 0 ) ?
56 cssClass
: 'mw-changeslist-ns-' + namespaceID
61 title
: mw
.msg( 'namespaces' ),
64 // Group definition (single group)
65 name
: 'namespace', // parameter name is singular
66 type
: 'string_options',
67 title
: mw
.msg( 'namespaces' ),
68 labelPrefixKey
: { 'default': 'rcfilters-tag-prefix-namespace', inverted
: 'rcfilters-tag-prefix-namespace-inverted' },
77 title
: mw
.msg( 'rcfilters-view-tags' ),
80 // Group definition (single group)
81 name
: 'tagfilter', // Parameter name
82 type
: 'string_options',
83 title
: 'rcfilters-view-tags', // Message key
84 labelPrefixKey
: 'rcfilters-tag-prefix-tags',
92 // Add parameter range operations
97 type
: 'single_option',
98 title
: '', // Because it's a hidden group, this title actually appears nowhere
100 allowArbitrary
: true,
101 validate
: $.isNumeric
,
102 sortFunc: function ( a
, b
) { return Number( a
.name
) - Number( b
.name
); },
104 filters
: [ 50, 100, 250, 500 ].map( function ( num
) {
105 return createFilterDataFromNumber( num
, num
);
110 type
: 'single_option',
111 title
: '', // Because it's a hidden group, this title actually appears nowhere
113 allowArbitrary
: true,
114 validate
: $.isNumeric
,
115 sortFunc: function ( a
, b
) { return Number( a
.name
) - Number( b
.name
); },
118 // Hours (1, 2, 6, 12)
119 0.04166, 0.0833, 0.25, 0.5,
122 ].map( function ( num
) {
123 return createFilterDataFromNumber(
125 // Convert fractions of days to number of hours for the labels
126 num
< 1 ? Math
.round( num
* 24 ) : num
133 // Before we do anything, we need to see if we require another item in the
134 // groups that have 'AllowArbitrary'. For the moment, those are only single_option
135 // groups; if we ever expand it, this might need further generalization:
136 $.each( views
, function ( viewName
, viewData
) {
137 viewData
.groups
.forEach( function ( groupData
) {
138 // This is only true for single_option and string_options
139 // We assume these are the only groups that will allow for
140 // arbitrary, since it doesn't make any sense for the other
142 var uriValue
= uri
.query
[ groupData
.name
];
145 // If the group allows for arbitrary data
146 groupData
.allowArbitrary
&&
147 // and it is single_option (or string_options, but we
148 // don't have cases of those yet, nor do we plan to)
149 groupData
.type
=== 'single_option' &&
150 // and if there is a valid value in the URI already
151 uri
.query
[ groupData
.name
] !== undefined &&
152 // and, if there is a validate method and it passes on
154 ( !groupData
.validate
|| groupData
.validate( uri
.query
[ groupData
.name
] ) ) &&
155 // but if that value isn't already in the definition
157 .map( function ( filterData
) {
158 return filterData
.name
;
160 .indexOf( uri
.query
[ groupData
.name
] ) === -1
162 // Add the filter information
163 if ( groupData
.name
=== 'days' ) {
164 // Specific fix for hours/days which go by the same param
165 groupData
.filters
.push( createFilterDataFromNumber(
167 // In this case we don't want to round because it can be arbitrary
168 // weird numbers but we want to round to 2 decimal digits
169 Number( uriValue
) < 1 ?
170 ( Number( uriValue
) * 24 ).toFixed( 2 ) :
174 groupData
.filters
.push( createFilterDataFromNumber( uriValue
, uriValue
) );
177 // If there's a sort function set up, re-sort the values
178 if ( groupData
.sortFunc
) {
179 groupData
.filters
.sort( groupData
.sortFunc
);
185 // Initialize the model
186 this.filtersModel
.initializeFilters( filterStructure
, views
);
188 this._buildBaseFilterState();
190 this.uriProcessor
= new mw
.rcfilters
.UriProcessor(
195 parsedSavedQueries
= JSON
.parse( mw
.user
.options
.get( 'rcfilters-saved-queries' ) || '{}' );
197 parsedSavedQueries
= {};
200 // The queries are saved in a minimized state, so we need
201 // to send over the base state so the saved queries model
202 // can normalize them per each query item
203 this.savedQueriesModel
.initialize(
205 this._getBaseFilterState()
208 // Check whether we need to load defaults.
209 // We do this by checking whether the current URI query
210 // contains any parameters recognized by the system.
211 // If it does, we load the given state.
212 // If it doesn't, we have no values at all, and we assume
213 // the user loads the base-page and we load defaults.
214 // Defaults should only be applied on load (if necessary)
216 this.initializing
= true;
218 this.savedQueriesModel
.getDefault() &&
219 !this.uriProcessor
.doesQueryContainRecognizedParams( uri
.query
)
221 // We have defaults from a saved query.
222 // We will load them straight-forward (as if
223 // they were clicked in the menu) so we trigger
224 // a full ajax request and change of URL
225 this.applySavedQuery( this.savedQueriesModel
.getDefault() );
227 // There are either recognized parameters in the URL
228 // or there are none, but there is also no default
229 // saved query (so defaults are from the backend)
230 // We want to update the state but not fetch results
232 this.updateStateFromUrl( false );
234 // Update the changes list with the existing data
235 // so it gets processed
236 this.changesListModel
.update(
237 $changesList
.length
? $changesList
: 'NO_RESULTS',
238 $( 'fieldset.rcoptions' ).first()
242 this.initializing
= false;
243 this.switchView( 'default' );
247 * Switch the view of the filters model
249 * @param {string} view Requested view
251 mw
.rcfilters
.Controller
.prototype.switchView = function ( view
) {
252 this.filtersModel
.switchView( view
);
256 * Reset to default filters
258 mw
.rcfilters
.Controller
.prototype.resetToDefaults = function () {
259 this.uriProcessor
.updateModelBasedOnQuery( this._getDefaultParams() );
260 this.updateChangesList();
264 * Empty all selected filters
266 mw
.rcfilters
.Controller
.prototype.emptyFilters = function () {
267 var highlightedFilterNames
= this.filtersModel
268 .getHighlightedItems()
269 .map( function ( filterItem
) { return { name
: filterItem
.getName() }; } );
271 this.filtersModel
.emptyAllFilters();
272 this.filtersModel
.clearAllHighlightColors();
273 // Check all filter interactions
274 this.filtersModel
.reassessFilterInteractions();
276 this.updateChangesList();
278 if ( highlightedFilterNames
) {
279 this._trackHighlight( 'clearAll', highlightedFilterNames
);
284 * Update the selected state of a filter
286 * @param {string} filterName Filter name
287 * @param {boolean} [isSelected] Filter selected state
289 mw
.rcfilters
.Controller
.prototype.toggleFilterSelect = function ( filterName
, isSelected
) {
290 var filterItem
= this.filtersModel
.getItemByName( filterName
);
293 // If no filter was found, break
297 isSelected
= isSelected
=== undefined ? !filterItem
.isSelected() : isSelected
;
299 if ( filterItem
.isSelected() !== isSelected
) {
300 this.filtersModel
.toggleFilterSelected( filterName
, isSelected
);
302 this.updateChangesList();
304 // Check filter interactions
305 this.filtersModel
.reassessFilterInteractions( filterItem
);
310 * Clear both highlight and selection of a filter
312 * @param {string} filterName Name of the filter item
314 mw
.rcfilters
.Controller
.prototype.clearFilter = function ( filterName
) {
315 var filterItem
= this.filtersModel
.getItemByName( filterName
),
316 isHighlighted
= filterItem
.isHighlighted();
318 if ( filterItem
.isSelected() || isHighlighted
) {
319 this.filtersModel
.clearHighlightColor( filterName
);
320 this.filtersModel
.toggleFilterSelected( filterName
, false );
321 this.updateChangesList();
322 this.filtersModel
.reassessFilterInteractions( filterItem
);
325 if ( isHighlighted
) {
326 this._trackHighlight( 'clear', filterName
);
331 * Toggle the highlight feature on and off
333 mw
.rcfilters
.Controller
.prototype.toggleHighlight = function () {
334 this.filtersModel
.toggleHighlight();
337 if ( this.filtersModel
.isHighlightEnabled() ) {
338 mw
.hook( 'RcFilters.highlight.enable' ).fire();
343 * Toggle the namespaces inverted feature on and off
345 mw
.rcfilters
.Controller
.prototype.toggleInvertedNamespaces = function () {
346 this.filtersModel
.toggleInvertedNamespaces();
347 this.updateChangesList();
351 * Set the highlight color for a filter item
353 * @param {string} filterName Name of the filter item
354 * @param {string} color Selected color
356 mw
.rcfilters
.Controller
.prototype.setHighlightColor = function ( filterName
, color
) {
357 this.filtersModel
.setHighlightColor( filterName
, color
);
359 this._trackHighlight( 'set', { name
: filterName
, color
: color
} );
363 * Clear highlight for a filter item
365 * @param {string} filterName Name of the filter item
367 mw
.rcfilters
.Controller
.prototype.clearHighlightColor = function ( filterName
) {
368 this.filtersModel
.clearHighlightColor( filterName
);
370 this._trackHighlight( 'clear', filterName
);
374 * Enable or disable live updates.
375 * @param {boolean} enable True to enable, false to disable
377 mw
.rcfilters
.Controller
.prototype.toggleLiveUpdate = function ( enable
) {
378 if ( enable
&& !this.liveUpdateTimeout
) {
379 this._scheduleLiveUpdate();
380 } else if ( !enable
&& this.liveUpdateTimeout
) {
381 clearTimeout( this.liveUpdateTimeout
);
382 this.liveUpdateTimeout
= null;
387 * Set a timeout for the next live update.
390 mw
.rcfilters
.Controller
.prototype._scheduleLiveUpdate = function () {
391 this.liveUpdateTimeout
= setTimeout( this._doLiveUpdate
.bind( this ), 3000 );
395 * Perform a live update.
398 mw
.rcfilters
.Controller
.prototype._doLiveUpdate = function () {
399 var controller
= this;
400 this.updateChangesList( {}, true )
401 .always( function () {
402 if ( controller
.liveUpdateTimeout
) {
403 // Live update was not disabled in the meantime
404 controller
._scheduleLiveUpdate();
410 * Save the current model state as a saved query
412 * @param {string} [label] Label of the saved query
414 mw
.rcfilters
.Controller
.prototype.saveCurrentQuery = function ( label
) {
415 var highlightedItems
= {},
416 highlightEnabled
= this.filtersModel
.isHighlightEnabled();
418 // Prepare highlights
419 this.filtersModel
.getHighlightedItems().forEach( function ( item
) {
420 highlightedItems
[ item
.getName() ] = highlightEnabled
?
421 item
.getHighlightColor() : null;
423 // These are filter states; highlight is stored as boolean
424 highlightedItems
.highlight
= this.filtersModel
.isHighlightEnabled();
427 this.savedQueriesModel
.addNewQuery(
428 label
|| mw
.msg( 'rcfilters-savedqueries-defaultlabel' ),
430 filters
: this.filtersModel
.getSelectedState(),
431 highlights
: highlightedItems
,
432 invert
: this.filtersModel
.areNamespacesInverted()
437 this._saveSavedQueries();
441 * Remove a saved query
443 * @param {string} queryID Query id
445 mw
.rcfilters
.Controller
.prototype.removeSavedQuery = function ( queryID
) {
446 this.savedQueriesModel
.removeQuery( queryID
);
448 this._saveSavedQueries();
452 * Rename a saved query
454 * @param {string} queryID Query id
455 * @param {string} newLabel New label for the query
457 mw
.rcfilters
.Controller
.prototype.renameSavedQuery = function ( queryID
, newLabel
) {
458 var queryItem
= this.savedQueriesModel
.getItemByID( queryID
);
461 queryItem
.updateLabel( newLabel
);
463 this._saveSavedQueries();
467 * Set a saved query as default
469 * @param {string} queryID Query Id. If null is given, default
472 mw
.rcfilters
.Controller
.prototype.setDefaultSavedQuery = function ( queryID
) {
473 this.savedQueriesModel
.setDefault( queryID
);
474 this._saveSavedQueries();
480 * @param {string} queryID Query id
482 mw
.rcfilters
.Controller
.prototype.applySavedQuery = function ( queryID
) {
483 var data
, highlights
,
484 queryItem
= this.savedQueriesModel
.getItemByID( queryID
);
487 data
= queryItem
.getData();
488 highlights
= data
.highlights
;
490 // Backwards compatibility; initial version mispelled 'highlight' with 'highlights'
491 highlights
.highlight
= highlights
.highlights
|| highlights
.highlight
;
493 // Update model state from filters
494 this.filtersModel
.toggleFiltersSelected( data
.filters
);
496 // Update namespace inverted property
497 this.filtersModel
.toggleInvertedNamespaces( !!Number( data
.invert
) );
499 // Update highlight state
500 this.filtersModel
.toggleHighlight( !!Number( highlights
.highlight
) );
501 this.filtersModel
.getItems().forEach( function ( filterItem
) {
502 var color
= highlights
[ filterItem
.getName() ];
504 filterItem
.setHighlightColor( color
);
506 filterItem
.clearHighlightColor();
510 // Check all filter interactions
511 this.filtersModel
.reassessFilterInteractions();
513 this.updateChangesList();
518 * Check whether the current filter and highlight state exists
519 * in the saved queries model.
521 * @return {boolean} Query exists
523 mw
.rcfilters
.Controller
.prototype.findQueryMatchingCurrentState = function () {
524 var highlightedItems
= {};
526 // Prepare highlights of the current query
527 this.filtersModel
.getItemsSupportingHighlights().forEach( function ( item
) {
528 highlightedItems
[ item
.getName() ] = item
.getHighlightColor();
530 highlightedItems
.highlight
= this.filtersModel
.isHighlightEnabled();
532 return this.savedQueriesModel
.findMatchingQuery(
534 filters
: this.filtersModel
.getSelectedState(),
535 highlights
: highlightedItems
,
536 invert
: this.filtersModel
.areNamespacesInverted()
542 * Get an object representing the base state of parameters
545 * This is meant to make sure that the saved queries that are
546 * in memory are always the same structure as what we would get
547 * by calling the current model's "getSelectedState" and by checking
550 * In cases where a user saved a query when the system had a certain
551 * set of filters, and then a filter was added to the system, we want
552 * to make sure that the stored queries can still be comparable to
553 * the current state, which means that we need the base state for
556 * - Saved queries are stored in "minimal" view (only changed filters
557 * are stored); When we initialize the system, we merge each minimal
558 * query with the base state (using 'getNormalizedFilters') so all
559 * saved queries have the exact same structure as what we would get
560 * by checking the getSelectedState of the filter.
561 * - When we save the queries, we minimize the object to only represent
562 * whatever has actually changed, rather than store the entire
563 * object. To check what actually is different so we can store it,
564 * we need to obtain a base state to compare against, this is
565 * what #_getMinimalFilterList does
567 mw
.rcfilters
.Controller
.prototype._buildBaseFilterState = function () {
568 var defaultParams
= this.filtersModel
.getDefaultParams(),
569 highlightedItems
= {};
571 // Prepare highlights
572 this.filtersModel
.getItemsSupportingHighlights().forEach( function ( item
) {
573 highlightedItems
[ item
.getName() ] = null;
575 highlightedItems
.highlight
= false;
577 this.baseFilterState
= {
578 filters
: this.filtersModel
.getFiltersFromParameters( defaultParams
),
579 highlights
: highlightedItems
,
585 * Get an object representing the base filter state of both
586 * filters and highlights. The structure is similar to what we use
587 * to store each query in the saved queries object:
593 * filterName: (string|null)
597 * @return {Object} Object representing the base state of
598 * parameters and highlights
600 mw
.rcfilters
.Controller
.prototype._getBaseFilterState = function () {
601 return this.baseFilterState
;
605 * Get an object that holds only the parameters and highlights that have
606 * values different than the base default value.
608 * This is the reverse of the normalization we do initially on loading and
609 * initializing the saved queries model.
611 * @param {Object} valuesObject Object representing the state of both
612 * filters and highlights in its normalized version, to be minimized.
613 * @return {Object} Minimal filters and highlights list
615 mw
.rcfilters
.Controller
.prototype._getMinimalFilterList = function ( valuesObject
) {
616 var result
= { filters
: {}, highlights
: {} },
617 baseState
= this._getBaseFilterState();
620 $.each( valuesObject
.filters
, function ( name
, value
) {
621 if ( baseState
.filters
!== undefined && baseState
.filters
[ name
] !== value
) {
622 result
.filters
[ name
] = value
;
626 $.each( valuesObject
.highlights
, function ( name
, value
) {
627 if ( baseState
.highlights
!== undefined && baseState
.highlights
[ name
] !== value
) {
628 result
.highlights
[ name
] = value
;
636 * Save the current state of the saved queries model with all
637 * query item representation in the user settings.
639 mw
.rcfilters
.Controller
.prototype._saveSavedQueries = function () {
641 state
= this.savedQueriesModel
.getState(),
644 // Minimize before save
645 $.each( state
.queries
, function ( queryID
, info
) {
646 state
.queries
[ queryID
].data
= controller
._getMinimalFilterList( info
.data
);
650 stringified
= JSON
.stringify( state
);
652 if ( stringified
.length
> 65535 ) {
653 // Sanity check, since the preference can only hold that.
657 // Save the preference
658 new mw
.Api().saveOption( 'rcfilters-saved-queries', stringified
);
659 // Update the preference for this session
660 mw
.user
.options
.set( 'rcfilters-saved-queries', stringified
);
664 * Synchronize the URL with the current state of the filters
665 * without adding an history entry.
667 mw
.rcfilters
.Controller
.prototype.replaceUrl = function () {
668 mw
.rcfilters
.UriProcessor
.static.replaceState( this._getUpdatedUri() );
672 * Update filter state (selection and highlighting) based
673 * on current URL values.
675 * @param {boolean} [fetchChangesList=true] Fetch new results into the changes
676 * list based on the updated model.
678 mw
.rcfilters
.Controller
.prototype.updateStateFromUrl = function ( fetchChangesList
) {
679 fetchChangesList
= fetchChangesList
=== undefined ? true : !!fetchChangesList
;
681 this.uriProcessor
.updateModelBasedOnQuery( new mw
.Uri().query
);
683 // Only update and fetch new results if it is requested
684 if ( fetchChangesList
) {
685 this.updateChangesList();
690 * Update the list of changes and notify the model
692 * @param {Object} [params] Extra parameters to add to the API call
693 * @param {boolean} [isLiveUpdate] Don't update the URL or invalidate the changes list
694 * @return {jQuery.Promise} Promise that is resolved when the update is complete
696 mw
.rcfilters
.Controller
.prototype.updateChangesList = function ( params
, isLiveUpdate
) {
697 if ( !isLiveUpdate
) {
698 this._updateURL( params
);
699 this.changesListModel
.invalidate();
701 return this._fetchChangesList()
704 function ( pieces
) {
705 var $changesListContent
= pieces
.changes
,
706 $fieldset
= pieces
.fieldset
;
707 this.changesListModel
.update( $changesListContent
, $fieldset
);
709 // Do nothing for failure
714 * Get an object representing the default parameter state, whether
715 * it is from the model defaults or from the saved queries.
717 * @return {Object} Default parameters
719 mw
.rcfilters
.Controller
.prototype._getDefaultParams = function () {
720 var data
, queryHighlights
,
722 savedHighlights
= {},
723 defaultSavedQueryItem
= this.savedQueriesModel
.getItemByID( this.savedQueriesModel
.getDefault() );
725 if ( mw
.config
.get( 'wgStructuredChangeFiltersEnableSaving' ) &&
726 defaultSavedQueryItem
) {
728 data
= defaultSavedQueryItem
.getData();
730 queryHighlights
= data
.highlights
|| {};
731 savedParams
= this.filtersModel
.getParametersFromFilters( data
.filters
|| {} );
733 // Translate highlights to parameters
734 savedHighlights
.highlight
= String( Number( queryHighlights
.highlight
) );
735 $.each( queryHighlights
, function ( filterName
, color
) {
736 if ( filterName
!== 'highlights' ) {
737 savedHighlights
[ filterName
+ '_color' ] = color
;
741 return $.extend( true, {}, savedParams
, savedHighlights
, { invert
: data
.invert
} );
746 this.filtersModel
.getDefaultParams()
751 * Get an object representing the default parameter state, whether
752 * it is from the model defaults or from the saved queries.
754 * @return {Object} Default parameters
756 mw
.rcfilters
.Controller
.prototype._getDefaultParams = function () {
757 var data
, queryHighlights
,
759 savedHighlights
= {},
760 defaultSavedQueryItem
= this.savedQueriesModel
.getItemByID( this.savedQueriesModel
.getDefault() );
762 if ( mw
.config
.get( 'wgStructuredChangeFiltersEnableSaving' ) &&
763 defaultSavedQueryItem
) {
765 data
= defaultSavedQueryItem
.getData();
767 queryHighlights
= data
.highlights
|| {};
768 savedParams
= this.filtersModel
.getParametersFromFilters( data
.filters
|| {} );
770 // Translate highlights to parameters
771 savedHighlights
.highlight
= String( Number( queryHighlights
.highlight
) );
772 $.each( queryHighlights
, function ( filterName
, color
) {
773 if ( filterName
!== 'highlights' ) {
774 savedHighlights
[ filterName
+ '_color' ] = color
;
778 return $.extend( true, {}, savedParams
, savedHighlights
);
781 return this.filtersModel
.getDefaultParams();
785 * Update the URL of the page to reflect current filters
787 * This should not be called directly from outside the controller.
788 * If an action requires changing the URL, it should either use the
789 * highlighting actions below, or call #updateChangesList which does
790 * the uri corrections already.
792 * @param {Object} [params] Extra parameters to add to the API call
794 mw
.rcfilters
.Controller
.prototype._updateURL = function ( params
) {
795 var currentUri
= new mw
.Uri(),
796 updatedUri
= this._getUpdatedUri();
798 updatedUri
.extend( params
|| {} );
801 this.uriProcessor
.getVersion( currentUri
.query
) !== 2 ||
802 this.uriProcessor
.isNewState( currentUri
.query
, updatedUri
.query
)
804 mw
.rcfilters
.UriProcessor
.static.replaceState( updatedUri
);
809 * Get an updated mw.Uri object based on the model state
811 * @return {mw.Uri} Updated Uri
813 mw
.rcfilters
.Controller
.prototype._getUpdatedUri = function () {
814 var uri
= new mw
.Uri();
817 uri
.query
= this.uriProcessor
.minimizeQuery(
821 // We want to retain unrecognized params
822 // The uri params from model will override
823 // any recognized value in the current uri
824 // query, retain unrecognized params, and
825 // the result will then be minimized
827 this.uriProcessor
.getUriParametersFromModel(),
836 * Fetch the list of changes from the server for the current filters
838 * @return {jQuery.Promise} Promise object that will resolve with the changes list
839 * or with a string denoting no results.
841 mw
.rcfilters
.Controller
.prototype._fetchChangesList = function () {
842 var uri
= this._getUpdatedUri(),
843 requestId
= ++this.requestCounter
,
844 latestRequest = function () {
845 return requestId
=== this.requestCounter
;
848 return $.ajax( uri
.toString(), { contentType
: 'html' } )
853 if ( !latestRequest() ) {
854 return $.Deferred().reject();
857 $parsed
= $( $.parseHTML( html
) );
861 changes
: $parsed
.find( '.mw-changeslist' ).first().contents(),
863 fieldset
: $parsed
.find( 'fieldset.rcoptions' ).first()
867 function ( responseObj
) {
870 if ( !latestRequest() ) {
871 return $.Deferred().reject();
874 $parsed
= $( $.parseHTML( responseObj
.responseText
) );
876 // Force a resolve state to this promise
877 return $.Deferred().resolve( {
878 changes
: 'NO_RESULTS',
879 fieldset
: $parsed
.find( 'fieldset.rcoptions' ).first()
886 * Track usage of highlight feature
888 * @param {string} action
889 * @param {array|object|string} filters
891 mw
.rcfilters
.Controller
.prototype._trackHighlight = function ( action
, filters
) {
892 filters
= typeof filters
=== 'string' ? { name
: filters
} : filters
;
893 filters
= !Array
.isArray( filters
) ? [ filters
] : filters
;
895 'event.ChangesListHighlights',
899 userId
: mw
.user
.getId()
904 }( mediaWiki
, jQuery
) );