2 * JavaScript for Special:RecentChanges
12 var filtersModel
= new mw
.rcfilters
.dm
.FiltersViewModel(),
13 changesListModel
= new mw
.rcfilters
.dm
.ChangesListViewModel(),
14 controller
= new mw
.rcfilters
.Controller( filtersModel
, changesListModel
),
15 $overlay
= $( '<div>' )
16 .addClass( 'mw-rcfilters-ui-overlay' ),
17 filtersWidget
= new mw
.rcfilters
.ui
.FilterWrapperWidget(
18 controller
, filtersModel
, { $overlay
: $overlay
} );
20 // eslint-disable-next-line no-new
21 new mw
.rcfilters
.ui
.ChangesListWrapperWidget(
22 changesListModel
, $( '.mw-changeslist, .mw-changeslist-empty' ) );
24 // eslint-disable-next-line no-new
25 new mw
.rcfilters
.ui
.FormWrapperWidget(
26 changesListModel
, $( '.rcoptions form' ) );
28 filtersModel
.initializeFilters( {
30 title
: mw
.msg( 'rcfilters-filtergroup-registration' ),
31 type
: 'send_unselected_if_any',
35 label
: mw
.msg( 'rcfilters-filter-registered-label' ),
36 description
: mw
.msg( 'rcfilters-filter-registered-description' )
40 label
: mw
.msg( 'rcfilters-filter-unregistered-label' ),
41 description
: mw
.msg( 'rcfilters-filter-unregistered-description' )
46 title
: mw
.msg( 'rcfilters-filtergroup-userExpLevel' ),
47 // Type 'string_options' means that the group is evaluated by
48 // string values separated by comma; for example, param=opt1,opt2
49 // If all options are selected they are replaced by the term "all".
50 // The filters are the values for the parameter defined by the group.
51 // ** In this case, the parameter name is the group name. **
52 type
: 'string_options',
57 label
: mw
.msg( 'rcfilters-filter-userExpLevel-newcomer-label' ),
58 description
: mw
.msg( 'rcfilters-filter-userExpLevel-newcomer-description' )
62 label
: mw
.msg( 'rcfilters-filter-userExpLevel-learner-label' ),
63 description
: mw
.msg( 'rcfilters-filter-userExpLevel-learner-description' )
67 label
: mw
.msg( 'rcfilters-filter-userExpLevel-experienced-label' ),
68 description
: mw
.msg( 'rcfilters-filter-userExpLevel-experienced-description' )
73 title
: mw
.msg( 'rcfilters-filtergroup-authorship' ),
74 // Type 'send_unselected_if_any' means that the controller will go over
75 // all unselected filters in the group and use their parameters
76 // as truthy in the query string.
77 // This is to handle the "negative" filters. We are showing users
78 // a positive message ("Show xxx") but the filters themselves are
79 // based on "hide YYY". The purpose of this is to correctly map
80 // the functionality to the UI, whether we are dealing with 2
81 // parameters in the group or more.
82 type
: 'send_unselected_if_any',
86 label
: mw
.msg( 'rcfilters-filter-editsbyself-label' ),
87 description
: mw
.msg( 'rcfilters-filter-editsbyself-description' )
91 label
: mw
.msg( 'rcfilters-filter-editsbyother-label' ),
92 description
: mw
.msg( 'rcfilters-filter-editsbyother-description' )
97 title
: mw
.msg( 'rcfilters-filtergroup-automated' ),
98 type
: 'send_unselected_if_any',
102 label
: mw
.msg( 'rcfilters-filter-bots-label' ),
103 description
: mw
.msg( 'rcfilters-filter-bots-description' ),
108 label
: mw
.msg( 'rcfilters-filter-humans-label' ),
109 description
: mw
.msg( 'rcfilters-filter-humans-description' ),
115 title
: mw
.msg( 'rcfilters-filtergroup-significance' ),
116 type
: 'send_unselected_if_any',
120 label
: mw
.msg( 'rcfilters-filter-minor-label' ),
121 description
: mw
.msg( 'rcfilters-filter-minor-description' )
125 label
: mw
.msg( 'rcfilters-filter-major-label' ),
126 description
: mw
.msg( 'rcfilters-filter-major-description' )
131 title
: mw
.msg( 'rcfilters-filtergroup-changetype' ),
132 type
: 'send_unselected_if_any',
135 name
: 'hidepageedits',
136 label
: mw
.msg( 'rcfilters-filter-pageedits-label' ),
137 description
: mw
.msg( 'rcfilters-filter-pageedits-description' ),
141 name
: 'hidenewpages',
142 label
: mw
.msg( 'rcfilters-filter-newpages-label' ),
143 description
: mw
.msg( 'rcfilters-filter-newpages-description' ),
147 name
: 'hidecategorization',
148 label
: mw
.msg( 'rcfilters-filter-categorization-label' ),
149 description
: mw
.msg( 'rcfilters-filter-categorization-description' ),
154 label
: mw
.msg( 'rcfilters-filter-logactions-label' ),
155 description
: mw
.msg( 'rcfilters-filter-logactions-description' ),
162 $( '.rcoptions' ).before( filtersWidget
.$element
);
163 $( 'body' ).append( $overlay
);
166 controller
.initialize();
168 // HACK: Remove old-style filter links for filters handled by the widget
169 // Ideally the widget would handle all filters and we'd just remove .rcshowhide entirely
170 $( '.rcshowhide' ).children().each( function () {
171 // HACK: Interpret the class name to get the filter name
172 // This should really be set as a data attribute
175 // Some of the older browsers we support don't have .classList,
176 // so we have to interpret the class attribute manually.
177 classes
= this.getAttribute( 'class' ).split( ' ' );
178 for ( i
= 0; i
< classes
.length
; i
++ ) {
179 if ( classes
[ i
].substr( 0, 'rcshow'.length
) === 'rcshow' ) {
180 name
= classes
[ i
].substr( 'rcshow'.length
);
184 if ( name
=== null ) {
187 if ( name
=== 'hidemine' ) {
188 // HACK: the span for hidemyself is called hidemine
191 // This span corresponds to a filter that's in our model, so remove it
192 if ( filtersModel
.getItemByName( name
) ) {
193 // HACK: Remove the text node after the span.
194 // If there isn't one, we're at the end, so remove the text node before the span.
195 // This would be unnecessary if we added separators with CSS.
196 if ( this.nextSibling
&& this.nextSibling
.nodeType
=== Node
.TEXT_NODE
) {
197 this.parentNode
.removeChild( this.nextSibling
);
198 } else if ( this.previousSibling
&& this.previousSibling
.nodeType
=== Node
.TEXT_NODE
) {
199 this.parentNode
.removeChild( this.previousSibling
);
201 // Remove the span itself
202 this.parentNode
.removeChild( this );
206 window
.addEventListener( 'popstate', function () {
207 controller
.updateFromURL();
208 controller
.updateChangesList();
215 module
.exports
= rcfilters
;
217 }( mediaWiki
, jQuery
) );