RCFilters: Have the model accept multiple views
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.Controller.js
1 ( function ( mw, $ ) {
2 /* eslint no-underscore-dangle: "off" */
3 /**
4 * Controller for the filters in Recent Changes
5 *
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
9 */
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;
18 };
19
20 /* Initialization */
21 OO.initClass( mw.rcfilters.Controller );
22
23 /**
24 * Initialize the filter and parameter states
25 *
26 * @param {Array} filterStructure Filter definition and structure for the model
27 * @param {Object} [namespaceStructure] Namespace definition
28 * @param {Object} [tagList] Tag definition
29 */
30 mw.rcfilters.Controller.prototype.initialize = function ( filterStructure, namespaceStructure, tagList ) {
31 var parsedSavedQueries,
32 views = {},
33 items = [],
34 uri = new mw.Uri(),
35 $changesList = $( '.mw-changeslist' ).first().contents();
36
37 // Prepare views
38 if ( namespaceStructure ) {
39 items = [];
40 $.each( namespaceStructure, function ( namespaceID, label ) {
41 // Build and clean up the individual namespace items definition
42 items.push( {
43 name: namespaceID,
44 label: label || mw.msg( 'blanknamespace' ),
45 description: '',
46 identifiers: [
47 ( namespaceID < 0 || namespaceID % 2 === 0 ) ?
48 'subject' : 'talk'
49 ],
50 cssClass: 'mw-changeslist-ns-' + namespaceID
51 } );
52 } );
53
54 views.namespaces = {
55 title: mw.msg( 'namespaces' ),
56 trigger: ':',
57 groups: [ {
58 // Group definition (single group)
59 name: 'namespaces',
60 definition: {
61 type: 'string_options',
62 title: mw.msg( 'namespaces' ),
63 labelPrefixKey: { 'default': 'rcfilters-tag-prefix-namespace', inverted: 'rcfilters-tag-prefix-namespace-inverted' },
64 separator: ';',
65 fullCoverage: true
66 },
67 items: items
68 } ]
69 };
70 }
71 if ( tagList ) {
72 views.tags = {
73 title: mw.msg( 'rcfilters-view-tags' ),
74 trigger: '#',
75 groups: [ {
76 // Group definition (single group)
77 name: 'tagfilter', // Parameter name
78 definition: {
79 type: 'string_options',
80 title: 'rcfilters-view-tags', // Message key
81 labelPrefixKey: 'rcfilters-tag-prefix-tags',
82 separator: '|',
83 fullCoverage: false
84 },
85 items: tagList
86 } ]
87 };
88 }
89
90 // Initialize the model
91 this.filtersModel.initializeFilters( filterStructure, views );
92
93 this._buildBaseFilterState();
94
95 this.uriProcessor = new mw.rcfilters.UriProcessor(
96 this.filtersModel
97 );
98
99 try {
100 parsedSavedQueries = JSON.parse( mw.user.options.get( 'rcfilters-saved-queries' ) || '{}' );
101 } catch ( err ) {
102 parsedSavedQueries = {};
103 }
104
105 // The queries are saved in a minimized state, so we need
106 // to send over the base state so the saved queries model
107 // can normalize them per each query item
108 this.savedQueriesModel.initialize(
109 parsedSavedQueries,
110 this._getBaseFilterState()
111 );
112
113 // Check whether we need to load defaults.
114 // We do this by checking whether the current URI query
115 // contains any parameters recognized by the system.
116 // If it does, we load the given state.
117 // If it doesn't, we have no values at all, and we assume
118 // the user loads the base-page and we load defaults.
119 // Defaults should only be applied on load (if necessary)
120 // or on request
121 this.initializing = true;
122 if (
123 this.savedQueriesModel.getDefault() &&
124 !this.uriProcessor.doesQueryContainRecognizedParams( uri.query )
125 ) {
126 // We have defaults from a saved query.
127 // We will load them straight-forward (as if
128 // they were clicked in the menu) so we trigger
129 // a full ajax request and change of URL
130 this.applySavedQuery( this.savedQueriesModel.getDefault() );
131 } else {
132 // There are either recognized parameters in the URL
133 // or there are none, but there is also no default
134 // saved query (so defaults are from the backend)
135 // We want to update the state but not fetch results
136 // again
137 this.updateStateFromUrl( false );
138
139 // Update the changes list with the existing data
140 // so it gets processed
141 this.changesListModel.update(
142 $changesList.length ? $changesList : 'NO_RESULTS',
143 $( 'fieldset.rcoptions' ).first()
144 );
145 }
146
147 this.initializing = false;
148 this.switchView( 'default' );
149 };
150
151 /**
152 * Switch the view of the filters model
153 *
154 * @param {string} view Requested view
155 */
156 mw.rcfilters.Controller.prototype.switchView = function ( view ) {
157 this.filtersModel.switchView( view );
158 };
159
160 /**
161 * Reset to default filters
162 */
163 mw.rcfilters.Controller.prototype.resetToDefaults = function () {
164 this.uriProcessor.updateModelBasedOnQuery( this._getDefaultParams() );
165 this.updateChangesList();
166 };
167
168 /**
169 * Empty all selected filters
170 */
171 mw.rcfilters.Controller.prototype.emptyFilters = function () {
172 var highlightedFilterNames = this.filtersModel
173 .getHighlightedItems()
174 .map( function ( filterItem ) { return { name: filterItem.getName() }; } );
175
176 this.filtersModel.emptyAllFilters();
177 this.filtersModel.clearAllHighlightColors();
178 // Check all filter interactions
179 this.filtersModel.reassessFilterInteractions();
180
181 this.updateChangesList();
182
183 if ( highlightedFilterNames ) {
184 this._trackHighlight( 'clearAll', highlightedFilterNames );
185 }
186 };
187
188 /**
189 * Update the selected state of a filter
190 *
191 * @param {string} filterName Filter name
192 * @param {boolean} [isSelected] Filter selected state
193 */
194 mw.rcfilters.Controller.prototype.toggleFilterSelect = function ( filterName, isSelected ) {
195 var filterItem = this.filtersModel.getItemByName( filterName );
196
197 if ( !filterItem ) {
198 // If no filter was found, break
199 return;
200 }
201
202 isSelected = isSelected === undefined ? !filterItem.isSelected() : isSelected;
203
204 if ( filterItem.isSelected() !== isSelected ) {
205 this.filtersModel.toggleFilterSelected( filterName, isSelected );
206
207 this.updateChangesList();
208
209 // Check filter interactions
210 this.filtersModel.reassessFilterInteractions( filterItem );
211 }
212 };
213
214 /**
215 * Clear both highlight and selection of a filter
216 *
217 * @param {string} filterName Name of the filter item
218 */
219 mw.rcfilters.Controller.prototype.clearFilter = function ( filterName ) {
220 var filterItem = this.filtersModel.getItemByName( filterName ),
221 isHighlighted = filterItem.isHighlighted();
222
223 if ( filterItem.isSelected() || isHighlighted ) {
224 this.filtersModel.clearHighlightColor( filterName );
225 this.filtersModel.toggleFilterSelected( filterName, false );
226 this.updateChangesList();
227 this.filtersModel.reassessFilterInteractions( filterItem );
228 }
229
230 if ( isHighlighted ) {
231 this._trackHighlight( 'clear', filterName );
232 }
233 };
234
235 /**
236 * Toggle the highlight feature on and off
237 */
238 mw.rcfilters.Controller.prototype.toggleHighlight = function () {
239 this.filtersModel.toggleHighlight();
240 this._updateURL();
241
242 if ( this.filtersModel.isHighlightEnabled() ) {
243 mw.hook( 'RcFilters.highlight.enable' ).fire();
244 }
245 };
246
247 /**
248 * Toggle the namespaces inverted feature on and off
249 */
250 mw.rcfilters.Controller.prototype.toggleInvertedNamespaces = function () {
251 this.filtersModel.toggleInvertedNamespaces();
252 this.updateChangesList();
253 };
254
255 /**
256 * Set the highlight color for a filter item
257 *
258 * @param {string} filterName Name of the filter item
259 * @param {string} color Selected color
260 */
261 mw.rcfilters.Controller.prototype.setHighlightColor = function ( filterName, color ) {
262 this.filtersModel.setHighlightColor( filterName, color );
263 this._updateURL();
264 this._trackHighlight( 'set', { name: filterName, color: color } );
265 };
266
267 /**
268 * Clear highlight for a filter item
269 *
270 * @param {string} filterName Name of the filter item
271 */
272 mw.rcfilters.Controller.prototype.clearHighlightColor = function ( filterName ) {
273 this.filtersModel.clearHighlightColor( filterName );
274 this._updateURL();
275 this._trackHighlight( 'clear', filterName );
276 };
277
278 /**
279 * Save the current model state as a saved query
280 *
281 * @param {string} [label] Label of the saved query
282 */
283 mw.rcfilters.Controller.prototype.saveCurrentQuery = function ( label ) {
284 var highlightedItems = {},
285 highlightEnabled = this.filtersModel.isHighlightEnabled();
286
287 // Prepare highlights
288 this.filtersModel.getHighlightedItems().forEach( function ( item ) {
289 highlightedItems[ item.getName() ] = highlightEnabled ?
290 item.getHighlightColor() : null;
291 } );
292 // These are filter states; highlight is stored as boolean
293 highlightedItems.highlight = this.filtersModel.isHighlightEnabled();
294
295 // Add item
296 this.savedQueriesModel.addNewQuery(
297 label || mw.msg( 'rcfilters-savedqueries-defaultlabel' ),
298 {
299 filters: this.filtersModel.getSelectedState(),
300 highlights: highlightedItems,
301 invert: this.filtersModel.areNamespacesInverted()
302 }
303 );
304
305 // Save item
306 this._saveSavedQueries();
307 };
308
309 /**
310 * Remove a saved query
311 *
312 * @param {string} queryID Query id
313 */
314 mw.rcfilters.Controller.prototype.removeSavedQuery = function ( queryID ) {
315 var query = this.savedQueriesModel.getItemByID( queryID );
316
317 this.savedQueriesModel.removeItems( [ query ] );
318
319 // Check if this item was the default
320 if ( this.savedQueriesModel.getDefault() === queryID ) {
321 // Nulify the default
322 this.savedQueriesModel.setDefault( null );
323 }
324 this._saveSavedQueries();
325 };
326
327 /**
328 * Rename a saved query
329 *
330 * @param {string} queryID Query id
331 * @param {string} newLabel New label for the query
332 */
333 mw.rcfilters.Controller.prototype.renameSavedQuery = function ( queryID, newLabel ) {
334 var queryItem = this.savedQueriesModel.getItemByID( queryID );
335
336 if ( queryItem ) {
337 queryItem.updateLabel( newLabel );
338 }
339 this._saveSavedQueries();
340 };
341
342 /**
343 * Set a saved query as default
344 *
345 * @param {string} queryID Query Id. If null is given, default
346 * query is reset.
347 */
348 mw.rcfilters.Controller.prototype.setDefaultSavedQuery = function ( queryID ) {
349 this.savedQueriesModel.setDefault( queryID );
350 this._saveSavedQueries();
351 };
352
353 /**
354 * Load a saved query
355 *
356 * @param {string} queryID Query id
357 */
358 mw.rcfilters.Controller.prototype.applySavedQuery = function ( queryID ) {
359 var data, highlights,
360 queryItem = this.savedQueriesModel.getItemByID( queryID );
361
362 if ( queryItem ) {
363 data = queryItem.getData();
364 highlights = data.highlights;
365
366 // Backwards compatibility; initial version mispelled 'highlight' with 'highlights'
367 highlights.highlight = highlights.highlights || highlights.highlight;
368
369 // Update model state from filters
370 this.filtersModel.toggleFiltersSelected( data.filters );
371
372 // Update namespace inverted property
373 this.filtersModel.toggleInvertedNamespaces( !!Number( data.invert ) );
374
375 // Update highlight state
376 this.filtersModel.toggleHighlight( !!Number( highlights.highlight ) );
377 this.filtersModel.getItems().forEach( function ( filterItem ) {
378 var color = highlights[ filterItem.getName() ];
379 if ( color ) {
380 filterItem.setHighlightColor( color );
381 } else {
382 filterItem.clearHighlightColor();
383 }
384 } );
385
386 // Check all filter interactions
387 this.filtersModel.reassessFilterInteractions();
388
389 this.updateChangesList();
390 }
391 };
392
393 /**
394 * Check whether the current filter and highlight state exists
395 * in the saved queries model.
396 *
397 * @return {boolean} Query exists
398 */
399 mw.rcfilters.Controller.prototype.findQueryMatchingCurrentState = function () {
400 var highlightedItems = {};
401
402 // Prepare highlights of the current query
403 this.filtersModel.getItemsSupportingHighlights().forEach( function ( item ) {
404 highlightedItems[ item.getName() ] = item.getHighlightColor();
405 } );
406 highlightedItems.highlight = this.filtersModel.isHighlightEnabled();
407
408 return this.savedQueriesModel.findMatchingQuery(
409 {
410 filters: this.filtersModel.getSelectedState(),
411 highlights: highlightedItems,
412 invert: this.filtersModel.areNamespacesInverted()
413 }
414 );
415 };
416
417 /**
418 * Get an object representing the base state of parameters
419 * and highlights.
420 *
421 * This is meant to make sure that the saved queries that are
422 * in memory are always the same structure as what we would get
423 * by calling the current model's "getSelectedState" and by checking
424 * highlight items.
425 *
426 * In cases where a user saved a query when the system had a certain
427 * set of filters, and then a filter was added to the system, we want
428 * to make sure that the stored queries can still be comparable to
429 * the current state, which means that we need the base state for
430 * two operations:
431 *
432 * - Saved queries are stored in "minimal" view (only changed filters
433 * are stored); When we initialize the system, we merge each minimal
434 * query with the base state (using 'getNormalizedFilters') so all
435 * saved queries have the exact same structure as what we would get
436 * by checking the getSelectedState of the filter.
437 * - When we save the queries, we minimize the object to only represent
438 * whatever has actually changed, rather than store the entire
439 * object. To check what actually is different so we can store it,
440 * we need to obtain a base state to compare against, this is
441 * what #_getMinimalFilterList does
442 */
443 mw.rcfilters.Controller.prototype._buildBaseFilterState = function () {
444 var defaultParams = this.filtersModel.getDefaultParams(),
445 highlightedItems = {};
446
447 // Prepare highlights
448 this.filtersModel.getItemsSupportingHighlights().forEach( function ( item ) {
449 highlightedItems[ item.getName() ] = null;
450 } );
451 highlightedItems.highlight = false;
452
453 this.baseFilterState = {
454 filters: this.filtersModel.getFiltersFromParameters( defaultParams ),
455 highlights: highlightedItems,
456 invert: false
457 };
458 };
459
460 /**
461 * Get an object representing the base filter state of both
462 * filters and highlights. The structure is similar to what we use
463 * to store each query in the saved queries object:
464 * {
465 * filters: {
466 * filterName: (bool)
467 * },
468 * highlights: {
469 * filterName: (string|null)
470 * }
471 * }
472 *
473 * @return {Object} Object representing the base state of
474 * parameters and highlights
475 */
476 mw.rcfilters.Controller.prototype._getBaseFilterState = function () {
477 return this.baseFilterState;
478 };
479
480 /**
481 * Get an object that holds only the parameters and highlights that have
482 * values different than the base default value.
483 *
484 * This is the reverse of the normalization we do initially on loading and
485 * initializing the saved queries model.
486 *
487 * @param {Object} valuesObject Object representing the state of both
488 * filters and highlights in its normalized version, to be minimized.
489 * @return {Object} Minimal filters and highlights list
490 */
491 mw.rcfilters.Controller.prototype._getMinimalFilterList = function ( valuesObject ) {
492 var result = { filters: {}, highlights: {} },
493 baseState = this._getBaseFilterState();
494
495 // XOR results
496 $.each( valuesObject.filters, function ( name, value ) {
497 if ( baseState.filters !== undefined && baseState.filters[ name ] !== value ) {
498 result.filters[ name ] = value;
499 }
500 } );
501
502 $.each( valuesObject.highlights, function ( name, value ) {
503 if ( baseState.highlights !== undefined && baseState.highlights[ name ] !== value ) {
504 result.highlights[ name ] = value;
505 }
506 } );
507
508 return result;
509 };
510
511 /**
512 * Save the current state of the saved queries model with all
513 * query item representation in the user settings.
514 */
515 mw.rcfilters.Controller.prototype._saveSavedQueries = function () {
516 var stringified,
517 state = this.savedQueriesModel.getState(),
518 controller = this;
519
520 // Minimize before save
521 $.each( state.queries, function ( queryID, info ) {
522 state.queries[ queryID ].data = controller._getMinimalFilterList( info.data );
523 } );
524
525 // Stringify state
526 stringified = JSON.stringify( state );
527
528 if ( stringified.length > 65535 ) {
529 // Sanity check, since the preference can only hold that.
530 return;
531 }
532
533 // Save the preference
534 new mw.Api().saveOption( 'rcfilters-saved-queries', stringified );
535 // Update the preference for this session
536 mw.user.options.set( 'rcfilters-saved-queries', stringified );
537 };
538
539 /**
540 * Synchronize the URL with the current state of the filters
541 * without adding an history entry.
542 */
543 mw.rcfilters.Controller.prototype.replaceUrl = function () {
544 mw.rcfilters.UriProcessor.static.replaceState( this._getUpdatedUri() );
545 };
546
547 /**
548 * Update filter state (selection and highlighting) based
549 * on current URL values.
550 *
551 * @param {boolean} [fetchChangesList=true] Fetch new results into the changes
552 * list based on the updated model.
553 */
554 mw.rcfilters.Controller.prototype.updateStateFromUrl = function ( fetchChangesList ) {
555 fetchChangesList = fetchChangesList === undefined ? true : !!fetchChangesList;
556
557 this.uriProcessor.updateModelBasedOnQuery( new mw.Uri().query );
558
559 // Only update and fetch new results if it is requested
560 if ( fetchChangesList ) {
561 this.updateChangesList();
562 }
563 };
564
565 /**
566 * Update the list of changes and notify the model
567 *
568 * @param {Object} [params] Extra parameters to add to the API call
569 */
570 mw.rcfilters.Controller.prototype.updateChangesList = function ( params ) {
571 this._updateURL( params );
572 this.changesListModel.invalidate();
573 this._fetchChangesList()
574 .then(
575 // Success
576 function ( pieces ) {
577 var $changesListContent = pieces.changes,
578 $fieldset = pieces.fieldset;
579 this.changesListModel.update( $changesListContent, $fieldset );
580 }.bind( this )
581 // Do nothing for failure
582 );
583 };
584
585 /**
586 * Get an object representing the default parameter state, whether
587 * it is from the model defaults or from the saved queries.
588 *
589 * @return {Object} Default parameters
590 */
591 mw.rcfilters.Controller.prototype._getDefaultParams = function () {
592 var data, queryHighlights,
593 savedParams = {},
594 savedHighlights = {},
595 defaultSavedQueryItem = this.savedQueriesModel.getItemByID( this.savedQueriesModel.getDefault() );
596
597 if ( mw.config.get( 'wgStructuredChangeFiltersEnableSaving' ) &&
598 defaultSavedQueryItem ) {
599
600 data = defaultSavedQueryItem.getData();
601
602 queryHighlights = data.highlights || {};
603 savedParams = this.filtersModel.getParametersFromFilters( data.filters || {} );
604
605 // Translate highlights to parameters
606 savedHighlights.highlight = String( Number( queryHighlights.highlight ) );
607 $.each( queryHighlights, function ( filterName, color ) {
608 if ( filterName !== 'highlights' ) {
609 savedHighlights[ filterName + '_color' ] = color;
610 }
611 } );
612
613 return $.extend( true, {}, savedParams, savedHighlights, { invert: data.invert } );
614 }
615
616 return $.extend(
617 { highlight: '0' },
618 this.filtersModel.getDefaultParams()
619 );
620 };
621
622 /**
623 * Get an object representing the default parameter state, whether
624 * it is from the model defaults or from the saved queries.
625 *
626 * @return {Object} Default parameters
627 */
628 mw.rcfilters.Controller.prototype._getDefaultParams = function () {
629 var data, queryHighlights,
630 savedParams = {},
631 savedHighlights = {},
632 defaultSavedQueryItem = this.savedQueriesModel.getItemByID( this.savedQueriesModel.getDefault() );
633
634 if ( mw.config.get( 'wgStructuredChangeFiltersEnableSaving' ) &&
635 defaultSavedQueryItem ) {
636
637 data = defaultSavedQueryItem.getData();
638
639 queryHighlights = data.highlights || {};
640 savedParams = this.filtersModel.getParametersFromFilters( data.filters || {} );
641
642 // Translate highlights to parameters
643 savedHighlights.highlight = String( Number( queryHighlights.highlight ) );
644 $.each( queryHighlights, function ( filterName, color ) {
645 if ( filterName !== 'highlights' ) {
646 savedHighlights[ filterName + '_color' ] = color;
647 }
648 } );
649
650 return $.extend( true, {}, savedParams, savedHighlights );
651 }
652
653 return this.filtersModel.getDefaultParams();
654 };
655
656 /**
657 * Update the URL of the page to reflect current filters
658 *
659 * This should not be called directly from outside the controller.
660 * If an action requires changing the URL, it should either use the
661 * highlighting actions below, or call #updateChangesList which does
662 * the uri corrections already.
663 *
664 * @param {Object} [params] Extra parameters to add to the API call
665 */
666 mw.rcfilters.Controller.prototype._updateURL = function ( params ) {
667 var currentUri = new mw.Uri(),
668 updatedUri = this._getUpdatedUri();
669
670 updatedUri.extend( params || {} );
671
672 if (
673 this.uriProcessor.getVersion( currentUri.query ) !== 2 ||
674 this.uriProcessor.isNewState( currentUri.query, updatedUri.query )
675 ) {
676 mw.rcfilters.UriProcessor.static.replaceState( updatedUri );
677 }
678 };
679
680 /**
681 * Get an updated mw.Uri object based on the model state
682 *
683 * @return {mw.Uri} Updated Uri
684 */
685 mw.rcfilters.Controller.prototype._getUpdatedUri = function () {
686 var uri = new mw.Uri();
687
688 // Minimize url
689 uri.query = this.uriProcessor.minimizeQuery(
690 $.extend(
691 true,
692 {},
693 // We want to retain unrecognized params
694 // The uri params from model will override
695 // any recognized value in the current uri
696 // query, retain unrecognized params, and
697 // the result will then be minimized
698 uri.query,
699 this.uriProcessor.getUriParametersFromModel(),
700 { urlversion: '2' }
701 )
702 );
703
704 return uri;
705 };
706
707 /**
708 * Fetch the list of changes from the server for the current filters
709 *
710 * @return {jQuery.Promise} Promise object that will resolve with the changes list
711 * or with a string denoting no results.
712 */
713 mw.rcfilters.Controller.prototype._fetchChangesList = function () {
714 var uri = this._getUpdatedUri(),
715 requestId = ++this.requestCounter,
716 latestRequest = function () {
717 return requestId === this.requestCounter;
718 }.bind( this );
719
720 return $.ajax( uri.toString(), { contentType: 'html' } )
721 .then(
722 // Success
723 function ( html ) {
724 var $parsed;
725 if ( !latestRequest() ) {
726 return $.Deferred().reject();
727 }
728
729 $parsed = $( $.parseHTML( html ) );
730
731 return {
732 // Changes list
733 changes: $parsed.find( '.mw-changeslist' ).first().contents(),
734 // Fieldset
735 fieldset: $parsed.find( 'fieldset.rcoptions' ).first()
736 };
737 },
738 // Failure
739 function ( responseObj ) {
740 var $parsed;
741
742 if ( !latestRequest() ) {
743 return $.Deferred().reject();
744 }
745
746 $parsed = $( $.parseHTML( responseObj.responseText ) );
747
748 // Force a resolve state to this promise
749 return $.Deferred().resolve( {
750 changes: 'NO_RESULTS',
751 fieldset: $parsed.find( 'fieldset.rcoptions' ).first()
752 } ).promise();
753 }
754 );
755 };
756
757 /**
758 * Track usage of highlight feature
759 *
760 * @param {string} action
761 * @param {array|object|string} filters
762 */
763 mw.rcfilters.Controller.prototype._trackHighlight = function ( action, filters ) {
764 filters = typeof filters === 'string' ? { name: filters } : filters;
765 filters = !Array.isArray( filters ) ? [ filters ] : filters;
766 mw.track(
767 'event.ChangesListHighlights',
768 {
769 action: action,
770 filters: filters,
771 userId: mw.user.getId()
772 }
773 );
774 };
775
776 }( mediaWiki, jQuery ) );