7b29d4b40f28adbbd00c1d1fdd7f36312ffeb3ca
2 * JavaScript for Special:RecentChanges
12 var model
= new mw
.rcfilters
.dm
.FiltersViewModel(),
13 controller
= new mw
.rcfilters
.Controller( model
),
14 widget
= new mw
.rcfilters
.ui
.FilterWrapperWidget( controller
, model
);
16 model
.initializeFilters( {
18 title
: mw
.msg( 'rcfilters-filtergroup-registration' ),
19 type
: 'send_unselected_if_any',
23 label
: mw
.msg( 'rcfilters-filter-registered-label' ),
24 description
: mw
.msg( 'rcfilters-filter-registered-description' )
28 label
: mw
.msg( 'rcfilters-filter-unregistered-label' ),
29 description
: mw
.msg( 'rcfilters-filter-unregistered-description' )
34 title
: mw
.msg( 'rcfilters-filtergroup-userExpLevel' ),
35 // Type 'string_options' means that the group is evaluated by
36 // string values separated by comma; for example, param=opt1,opt2
37 // If all options are selected they are replaced by the term "all".
38 // The filters are the values for the parameter defined by the group.
39 // ** In this case, the parameter name is the group name. **
40 type
: 'string_options',
45 label
: mw
.msg( 'rcfilters-filter-userExpLevel-newcomer-label' ),
46 description
: mw
.msg( 'rcfilters-filter-userExpLevel-newcomer-description' )
50 label
: mw
.msg( 'rcfilters-filter-userExpLevel-learner-label' ),
51 description
: mw
.msg( 'rcfilters-filter-userExpLevel-learner-description' )
55 label
: mw
.msg( 'rcfilters-filter-userExpLevel-experienced-label' ),
56 description
: mw
.msg( 'rcfilters-filter-userExpLevel-experienced-description' )
61 title
: mw
.msg( 'rcfilters-filtergroup-authorship' ),
62 // Type 'send_unselected_if_any' means that the controller will go over
63 // all unselected filters in the group and use their parameters
64 // as truthy in the query string.
65 // This is to handle the "negative" filters. We are showing users
66 // a positive message ("Show xxx") but the filters themselves are
67 // based on "hide YYY". The purpose of this is to correctly map
68 // the functionality to the UI, whether we are dealing with 2
69 // parameters in the group or more.
70 type
: 'send_unselected_if_any',
74 label
: mw
.msg( 'rcfilters-filter-editsbyself-label' ),
75 description
: mw
.msg( 'rcfilters-filter-editsbyself-description' )
79 label
: mw
.msg( 'rcfilters-filter-editsbyother-label' ),
80 description
: mw
.msg( 'rcfilters-filter-editsbyother-description' )
85 title
: mw
.msg( 'rcfilters-filtergroup-automated' ),
86 type
: 'send_unselected_if_any',
90 label
: mw
.msg( 'rcfilters-filter-bots-label' ),
91 description
: mw
.msg( 'rcfilters-filter-bots-description' ),
96 label
: mw
.msg( 'rcfilters-filter-humans-label' ),
97 description
: mw
.msg( 'rcfilters-filter-humans-description' ),
103 title
: mw
.msg( 'rcfilters-filtergroup-significance' ),
104 type
: 'send_unselected_if_any',
108 label
: mw
.msg( 'rcfilters-filter-minor-label' ),
109 description
: mw
.msg( 'rcfilters-filter-minor-description' )
113 label
: mw
.msg( 'rcfilters-filter-major-label' ),
114 description
: mw
.msg( 'rcfilters-filter-major-description' )
119 title
: mw
.msg( 'rcfilters-filtergroup-changetype' ),
120 type
: 'send_unselected_if_any',
123 name
: 'hidepageedits',
124 label
: mw
.msg( 'rcfilters-filter-pageedits-label' ),
125 description
: mw
.msg( 'rcfilters-filter-pageedits-description' ),
129 name
: 'hidenewpages',
130 label
: mw
.msg( 'rcfilters-filter-newpages-label' ),
131 description
: mw
.msg( 'rcfilters-filter-newpages-description' ),
135 name
: 'hidecategorization',
136 label
: mw
.msg( 'rcfilters-filter-categorization-label' ),
137 description
: mw
.msg( 'rcfilters-filter-categorization-description' ),
142 label
: mw
.msg( 'rcfilters-filter-logactions-label' ),
143 description
: mw
.msg( 'rcfilters-filter-logactions-description' ),
150 $( '.rcoptions' ).before( widget
.$element
);
153 controller
.initialize();
155 // HACK: Remove old-style filter links for filters handled by the widget
156 // Ideally the widget would handle all filters and we'd just remove .rcshowhide entirely
157 $( '.rcshowhide' ).children().each( function () {
158 // HACK: Interpret the class name to get the filter name
159 // This should really be set as a data attribute
162 // Some of the older browsers we support don't have .classList,
163 // so we have to interpret the class attribute manually.
164 classes
= this.getAttribute( 'class' ).split( ' ' );
165 for ( i
= 0; i
< classes
.length
; i
++ ) {
166 if ( classes
[ i
].substr( 0, 'rcshow'.length
) === 'rcshow' ) {
167 name
= classes
[ i
].substr( 'rcshow'.length
);
171 if ( name
=== null ) {
174 if ( name
=== 'hidemine' ) {
175 // HACK: the span for hidemyself is called hidemine
178 // This span corresponds to a filter that's in our model, so remove it
179 if ( model
.getItemByName( name
) ) {
180 // HACK: Remove the text node after the span.
181 // If there isn't one, we're at the end, so remove the text node before the span.
182 // This would be unnecessary if we added separators with CSS.
183 if ( this.nextSibling
&& this.nextSibling
.nodeType
=== Node
.TEXT_NODE
) {
184 this.parentNode
.removeChild( this.nextSibling
);
185 } else if ( this.previousSibling
&& this.previousSibling
.nodeType
=== Node
.TEXT_NODE
) {
186 this.parentNode
.removeChild( this.previousSibling
);
188 // Remove the span itself
189 this.parentNode
.removeChild( this );
193 $( '.rcoptions form' ).submit( function () {
194 var $form
= $( this );
196 // Get current filter values
197 $.each( model
.getParametersFromFilters(), function ( paramName
, paramValue
) {
198 var $existingInput
= $form
.find( 'input[name=' + paramName
+ ']' );
199 // Check if the hidden input already exists
200 // This happens if the parameter was already given
202 if ( $existingInput
.length
) {
204 $existingInput
.val( paramValue
);
206 // Append hidden fields with filter values
209 .attr( 'type', 'hidden' )
210 .attr( 'name', paramName
)
216 // Continue the submission process
224 module
.exports
= rcfilters
;
226 }( mediaWiki
, jQuery
) );