Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.init.js
blob34df2f5a5bbbe7935728ba41175ee2de8cc259e8
1 /*!
2 * JavaScript for Special:RecentChanges
3 */
4 ( function ( mw, $ ) {
5 /**
6 * @class mw.rcfilters
7 * @singleton
8 */
9 var rcfilters = {
10 /** */
11 init: function () {
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( {
17 registration: {
18 title: mw.msg( 'rcfilters-filtergroup-registration' ),
19 type: 'send_unselected_if_any',
20 filters: [
22 name: 'hideliu',
23 label: mw.msg( 'rcfilters-filter-registered-label' ),
24 description: mw.msg( 'rcfilters-filter-registered-description' )
27 name: 'hideanon',
28 label: mw.msg( 'rcfilters-filter-unregistered-label' ),
29 description: mw.msg( 'rcfilters-filter-unregistered-description' )
33 userExpLevel: {
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',
41 separator: ',',
42 filters: [
44 name: 'newcomer',
45 label: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-label' ),
46 description: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-description' )
49 name: 'learner',
50 label: mw.msg( 'rcfilters-filter-userExpLevel-learner-label' ),
51 description: mw.msg( 'rcfilters-filter-userExpLevel-learner-description' )
54 name: 'experienced',
55 label: mw.msg( 'rcfilters-filter-userExpLevel-experienced-label' ),
56 description: mw.msg( 'rcfilters-filter-userExpLevel-experienced-description' )
60 authorship: {
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',
71 filters: [
73 name: 'hidemyself',
74 label: mw.msg( 'rcfilters-filter-editsbyself-label' ),
75 description: mw.msg( 'rcfilters-filter-editsbyself-description' )
78 name: 'hidebyothers',
79 label: mw.msg( 'rcfilters-filter-editsbyother-label' ),
80 description: mw.msg( 'rcfilters-filter-editsbyother-description' )
84 automated: {
85 title: mw.msg( 'rcfilters-filtergroup-automated' ),
86 type: 'send_unselected_if_any',
87 filters: [
89 name: 'hidebots',
90 label: mw.msg( 'rcfilters-filter-bots-label' ),
91 description: mw.msg( 'rcfilters-filter-bots-description' )
94 name: 'hidehumans',
95 label: mw.msg( 'rcfilters-filter-humans-label' ),
96 description: mw.msg( 'rcfilters-filter-humans-description' )
100 significance: {
101 title: mw.msg( 'rcfilters-filtergroup-significance' ),
102 type: 'send_unselected_if_any',
103 filters: [
105 name: 'hideminor',
106 label: mw.msg( 'rcfilters-filter-minor-label' ),
107 description: mw.msg( 'rcfilters-filter-minor-description' )
110 name: 'hidemajor',
111 label: mw.msg( 'rcfilters-filter-major-label' ),
112 description: mw.msg( 'rcfilters-filter-major-description' )
116 changetype: {
117 title: mw.msg( 'rcfilters-filtergroup-changetype' ),
118 type: 'send_unselected_if_any',
119 filters: [
121 name: 'hidepageedits',
122 label: mw.msg( 'rcfilters-filter-pageedits-label' ),
123 description: mw.msg( 'rcfilters-filter-pageedits-description' )
126 name: 'hidenewpages',
127 label: mw.msg( 'rcfilters-filter-newpages-label' ),
128 description: mw.msg( 'rcfilters-filter-newpages-description' )
131 name: 'hidecategorization',
132 label: mw.msg( 'rcfilters-filter-categorization-label' ),
133 description: mw.msg( 'rcfilters-filter-categorization-description' )
136 name: 'hidelog',
137 label: mw.msg( 'rcfilters-filter-logactions-label' ),
138 description: mw.msg( 'rcfilters-filter-logactions-description' )
142 } );
144 $( '.rcoptions' ).before( widget.$element );
146 // Initialize values
147 controller.initialize();
149 $( '.rcoptions form' ).submit( function () {
150 var $form = $( this );
152 // Get current filter values
153 $.each( model.getParametersFromFilters(), function ( paramName, paramValue ) {
154 var $existingInput = $form.find( 'input[name=' + paramName + ']' );
155 // Check if the hidden input already exists
156 // This happens if the parameter was already given
157 // on load
158 if ( $existingInput.length ) {
159 // Update the value
160 $existingInput.val( paramValue );
161 } else {
162 // Append hidden fields with filter values
163 $form.append(
164 $( '<input>' )
165 .attr( 'type', 'hidden' )
166 .attr( 'name', paramName )
167 .val( paramValue )
170 } );
172 // Continue the submission process
173 return true;
174 } );
178 $( rcfilters.init );
180 module.exports = rcfilters;
182 }( mediaWiki, jQuery ) );