Special case opus mime detction
[mediawiki.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.init.js
blob679215bc710eb994d9ffd1e50006af1fecf27966
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                                 authorship: {
18                                         title: mw.msg( 'rcfilters-filtergroup-authorship' ),
19                                         // Type 'send_unselected_if_any' means that the controller will go over
20                                         // all unselected filters in the group and use their parameters
21                                         // as truthy in the query string.
22                                         // This is to handle the "negative" filters. We are showing users
23                                         // a positive message ("Show xxx") but the filters themselves are
24                                         // based on "hide YYY". The purpose of this is to correctly map
25                                         // the functionality to the UI, whether we are dealing with 2
26                                         // parameters in the group or more.
27                                         type: 'send_unselected_if_any',
28                                         filters: [
29                                                 {
30                                                         name: 'hidemyself',
31                                                         label: mw.msg( 'rcfilters-filter-editsbyself-label' ),
32                                                         description: mw.msg( 'rcfilters-filter-editsbyself-description' )
33                                                 },
34                                                 {
35                                                         name: 'hidebyothers',
36                                                         label: mw.msg( 'rcfilters-filter-editsbyother-label' ),
37                                                         description: mw.msg( 'rcfilters-filter-editsbyother-description' )
38                                                 }
39                                         ]
40                                 },
41                                 userExpLevel: {
42                                         title: mw.msg( 'rcfilters-filtergroup-userExpLevel' ),
43                                         // Type 'string_options' means that the group is evaluated by
44                                         // string values separated by comma; for example, param=opt1,opt2
45                                         // If all options are selected they are replaced by the term "all".
46                                         // The filters are the values for the parameter defined by the group.
47                                         // ** In this case, the parameter name is the group name. **
48                                         type: 'string_options',
49                                         separator: ',',
50                                         filters: [
51                                                 {
52                                                         name: 'newcomer',
53                                                         label: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-label' ),
54                                                         description: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-description' )
55                                                 },
56                                                 {
57                                                         name: 'learner',
58                                                         label: mw.msg( 'rcfilters-filter-userExpLevel-learner-label' ),
59                                                         description: mw.msg( 'rcfilters-filter-userExpLevel-learner-description' )
60                                                 },
61                                                 {
62                                                         name: 'experienced',
63                                                         label: mw.msg( 'rcfilters-filter-userExpLevel-experienced-label' ),
64                                                         description: mw.msg( 'rcfilters-filter-userExpLevel-experienced-description' )
65                                                 }
66                                         ]
67                                 }
68                         } );
70                         $( '.rcoptions' ).before( widget.$element );
72                         // Initialize values
73                         controller.initialize();
75                         $( '.rcoptions form' ).submit( function () {
76                                 var $form = $( this );
78                                 // Get current filter values
79                                 $.each( model.getParametersFromFilters(), function ( paramName, paramValue ) {
80                                         var $existingInput = $form.find( 'input[name=' + paramName + ']' );
81                                         // Check if the hidden input already exists
82                                         // This happens if the parameter was already given
83                                         // on load
84                                         if ( $existingInput.length ) {
85                                                 // Update the value
86                                                 $existingInput.val( paramValue );
87                                         } else {
88                                                 // Append hidden fields with filter values
89                                                 $form.append(
90                                                         $( '<input>' )
91                                                                 .attr( 'type', 'hidden' )
92                                                                 .attr( 'name', paramName )
93                                                                 .val( paramValue )
94                                                 );
95                                         }
96                                 } );
98                                 // Continue the submission process
99                                 return true;
100                         } );
101                 }
102         };
104         $( rcfilters.init );
106         module.exports = rcfilters;
108 }( mediaWiki, jQuery ) );