b11322eccd3287ad20e2d9ac0d18b487886a5715
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.init.js
1 /*!
2 * JavaScript for Special:RecentChanges
3 */
4 ( function ( mw, $ ) {
5 var rcfilters = {
6 /**
7 * @member mw.rcfilters
8 * @private
9 */
10 init: function () {
11 var $topLinks,
12 rcTopSection,
13 $watchlistDetails,
14 wlTopSection,
15 savedQueriesPreferenceName = mw.config.get( 'wgStructuredChangeFiltersSavedQueriesPreferenceName' ),
16 filtersModel = new mw.rcfilters.dm.FiltersViewModel(),
17 changesListModel = new mw.rcfilters.dm.ChangesListViewModel(),
18 savedQueriesModel = new mw.rcfilters.dm.SavedQueriesModel( filtersModel ),
19 controller = new mw.rcfilters.Controller(
20 filtersModel, changesListModel, savedQueriesModel,
21 {
22 savedQueriesPreferenceName: savedQueriesPreferenceName
23 }
24 ),
25 $overlay = $( '<div>' )
26 .addClass( 'mw-rcfilters-ui-overlay' ),
27 filtersWidget = new mw.rcfilters.ui.FilterWrapperWidget(
28 controller, filtersModel, savedQueriesModel, changesListModel, { $overlay: $overlay } ),
29 savedLinksListWidget = new mw.rcfilters.ui.SavedLinksListWidget(
30 controller, savedQueriesModel, { $overlay: $overlay }
31 ),
32 specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
33
34 // TODO: The changesListWrapperWidget should be able to initialize
35 // after the model is ready.
36 // eslint-disable-next-line no-new
37 new mw.rcfilters.ui.ChangesListWrapperWidget(
38 filtersModel, changesListModel, controller, $( '.mw-changeslist, .mw-changeslist-empty' ) );
39
40 // Remove the -loading class that may have been added on the server side.
41 // If we are in fact going to load a default saved query, this .initialize()
42 // call will do that and add the -loading class right back.
43 $( 'body' ).removeClass( 'mw-rcfilters-ui-loading' );
44
45 controller.initialize(
46 mw.config.get( 'wgStructuredChangeFilters' ),
47 mw.config.get( 'wgFormattedNamespaces' ),
48 mw.config.get( 'wgRCFiltersChangeTags' )
49 );
50
51 // eslint-disable-next-line no-new
52 new mw.rcfilters.ui.FormWrapperWidget(
53 filtersModel, changesListModel, controller, $( 'fieldset.cloptions' ) );
54
55 $( '.rcfilters-container' ).append( filtersWidget.$element );
56 $( 'body' )
57 .append( $overlay )
58 .addClass( 'mw-rcfilters-ui-initialized' );
59
60 $( 'a.mw-helplink' ).attr(
61 'href',
62 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:New_filters_for_edit_review'
63 );
64
65 controller.replaceUrl();
66
67 if ( specialPage === 'Recentchanges' ||
68 specialPage === 'Recentchangeslinked' ) {
69 $topLinks = $( '.mw-recentchanges-toplinks' ).detach();
70
71 rcTopSection = new mw.rcfilters.ui.RcTopSectionWidget(
72 savedLinksListWidget, $topLinks
73 );
74 filtersWidget.setTopSection( rcTopSection.$element );
75 } // end Special:RC
76
77 if ( specialPage === 'Watchlist' ) {
78 $( '#contentSub, form#mw-watchlist-resetbutton' ).detach();
79 $watchlistDetails = $( '.watchlistDetails' ).detach().contents();
80
81 wlTopSection = new mw.rcfilters.ui.WatchlistTopSectionWidget(
82 controller, changesListModel, savedLinksListWidget, $watchlistDetails
83 );
84 filtersWidget.setTopSection( wlTopSection.$element );
85 } // end Special:WL
86
87 // Log performance data
88 if ( window.performance && window.performance.now ) {
89 mw.track(
90 'timing.MediaWiki.timing.structuredChangeFilters.ready.' + specialPage,
91 window.performance.now()
92 );
93 mw.track(
94 'timing.MediaWiki.timing.structuredChangeFilters.backendResponse.' + specialPage,
95 mw.config.get( 'wgBackendResponseTime' )
96 );
97 }
98
99 /**
100 * Fired when initialization of the filtering interface for changes list is complete.
101 *
102 * @event structuredChangeFilters_ui_initialized
103 * @member mw.hook
104 */
105 mw.hook( 'structuredChangeFilters.ui.initialized' ).fire();
106 }
107 };
108
109 // Early execute of init
110 if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
111 rcfilters.init();
112 } else {
113 $( rcfilters.init );
114 }
115
116 module.exports = rcfilters;
117
118 }( mediaWiki, jQuery ) );