2 * Components for use on the RecentChanges page. Provided by the `mediawiki.rcfilters.filters.ui` module.
9 Controller: require( './Controller.js' ),
10 HighlightColors: require( './HighlightColors.js' ),
11 UriProcessor: require( './UriProcessor.js' ),
13 * Models used by RecentChanges Filters.
15 * @namespace rcfilters.dm
19 ChangesListViewModel: require( './dm/ChangesListViewModel.js' ),
20 FilterGroup: require( './dm/FilterGroup.js' ),
21 FilterItem: require( './dm/FilterItem.js' ),
22 FiltersViewModel: require( './dm/FiltersViewModel.js' ),
23 ItemModel: require( './dm/ItemModel.js' ),
24 SavedQueriesModel: require( './dm/SavedQueriesModel.js' ),
25 SavedQueryItemModel: require( './dm/SavedQueryItemModel.js' )
28 * Widgets used by RecentChanges Filters.
30 * @namespace rcfilters.ui
34 MainWrapperWidget: require( './ui/MainWrapperWidget.js' )
37 * Utils used by RecentChanges Filters.
39 * @namespace rcfilters.ui
42 utils: require( './utils.js' )
46 * Get list of namespaces and remove unused ones
50 * @param {Array} unusedNamespaces Names of namespaces to remove
51 * @return {Array} Filtered array of namespaces
53 function getNamespaces( unusedNamespaces ) {
54 const namespaceIds = mw.config.get( 'wgNamespaceIds' ),
55 namespaces = mw.config.get( 'wgFormattedNamespaces' );
57 for ( let i = 0, length = unusedNamespaces.length; i < length; i++ ) {
58 const name = unusedNamespaces[ i ];
59 const id = namespaceIds[ name.toLowerCase() ];
60 delete namespaces[ id ];
70 const conditionalViews = {},
71 $initialFieldset = $( 'fieldset.cloptions' ),
72 savedQueriesPreferenceName = mw.config.get( 'wgStructuredChangeFiltersSavedQueriesPreferenceName' ),
73 daysPreferenceName = mw.config.get( 'wgStructuredChangeFiltersDaysPreferenceName' ),
74 limitPreferenceName = mw.config.get( 'wgStructuredChangeFiltersLimitPreferenceName' ),
75 activeFiltersCollapsedName = mw.config.get( 'wgStructuredChangeFiltersCollapsedPreferenceName' ),
76 initialCollapsedState = mw.config.get( 'wgStructuredChangeFiltersCollapsedState' ),
77 filtersModel = new rcfilters.dm.FiltersViewModel(),
78 changesListModel = new rcfilters.dm.ChangesListViewModel( $initialFieldset ),
79 savedQueriesModel = new rcfilters.dm.SavedQueriesModel( filtersModel ),
80 specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ),
81 controller = new rcfilters.Controller(
82 filtersModel, changesListModel, savedQueriesModel,
84 savedQueriesPreferenceName: savedQueriesPreferenceName,
85 daysPreferenceName: daysPreferenceName,
86 limitPreferenceName: limitPreferenceName,
87 collapsedPreferenceName: activeFiltersCollapsedName,
88 normalizeTarget: specialPage === 'Recentchangeslinked'
92 // TODO: The changesListWrapperWidget should be able to initialize
93 // after the model is ready.
96 if ( specialPage === 'Recentchanges' ) {
97 $topSection = $( '.mw-recentchanges-toplinks' ).detach();
98 } else if ( specialPage === 'Watchlist' ) {
99 $( '.mw-watchlist-owner, .mw-watchlist-toollinks, form#mw-watchlist-resetbutton' ).remove();
100 $topSection = $( '.watchlistDetails' ).detach().contents();
101 } else if ( specialPage === 'Recentchangeslinked' ) {
102 conditionalViews.recentChangesLinked = {
125 name: 'showlinkedto',
134 const mainWrapperWidget = new rcfilters.ui.MainWrapperWidget(
140 $wrapper: $( document.body ),
141 $topSection: $topSection,
142 $filtersContainer: $( '.mw-rcfilters-container' ),
143 $changesListContainer: $( '.mw-changeslist, .mw-changeslist-empty' ),
144 $formContainer: $initialFieldset,
145 collapsed: initialCollapsedState
149 // Remove the -loading class that may have been added on the server side.
150 // If we are in fact going to load a default saved query, this .initialize()
151 // call will do that and add the -loading class right back.
152 $( document.body ).removeClass( 'mw-rcfilters-ui-loading' );
154 controller.initialize(
155 mw.config.get( 'wgStructuredChangeFilters' ),
156 // All namespaces without Media namespace
157 getNamespaces( [ 'Media' ] ),
158 require( './config.json' ).RCFiltersChangeTags,
162 mainWrapperWidget.initFormWidget( specialPage );
164 $( 'a.mw-helplink' ).attr(
166 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:New_filters_for_edit_review'
169 controller.replaceUrl();
171 mainWrapperWidget.setTopSection( specialPage );
174 * Fired when initialization of the filtering interface for changes list is complete.
176 * @event ~'structuredChangeFilters.ui.initialized'
179 mw.hook( 'structuredChangeFilters.ui.initialized' ).fire();
182 // Import i18n messages from config
183 mw.messages.set( mw.config.get( 'wgStructuredChangeFiltersMessages' ) );
185 // Don't try to run init during QUnit tests, some of the code depends on mw.config variables
186 // that are not set, and the ui code here isn't even being tested.
187 if ( !window.QUnit ) {
188 if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
189 // Early execute of init
196 module.exports = rcfilters;