Drop wfResetSessionID, deprecated in 1.27
[lhc/web/wiklou.git] / mw-config / config.js
1 /* global extDependencyMap */
2 ( function () {
3 $( function () {
4 var $label, labelText;
5
6 function syncText() {
7 var value = $( this ).val()
8 .replace( /[\[\]{}|#<>%+? ]/g, '_' ) // eslint-disable-line no-useless-escape
9 .replace( /&/, '&amp;' )
10 .replace( /__+/g, '_' )
11 .replace( /^_+/, '' )
12 .replace( /_+$/, '' );
13 value = value.charAt( 0 ).toUpperCase() + value.slice( 1 );
14 $label.text( labelText.replace( '$1', value ) );
15 }
16
17 // Show/hide code for DB-specific options
18 // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here?
19 $( '.dbRadio' ).each( function () {
20 $( document.getElementById( $( this ).attr( 'rel' ) ) ).hide();
21 } );
22 $( document.getElementById( $( '.dbRadio:checked' ).attr( 'rel' ) ) ).show();
23 $( '.dbRadio' ).on( 'click', function () {
24 var $checked = $( '.dbRadio:checked' ),
25 $wrapper = $( document.getElementById( $checked.attr( 'rel' ) ) );
26 if ( $wrapper.is( ':hidden' ) ) {
27 // FIXME: Use CSS transition
28 // eslint-disable-next-line no-jquery/no-animate-toggle
29 $( '.dbWrapper' ).hide( 'slow' );
30 // eslint-disable-next-line no-jquery/no-animate-toggle
31 $wrapper.show( 'slow' );
32 }
33 } );
34
35 // Scroll to the bottom of upgrade log
36 $( '#config-live-log' ).children( 'textarea' ).each( function () {
37 this.scrollTop = this.scrollHeight;
38 } );
39
40 // Show/hide Creative Commons thingy
41 $( '.licenseRadio' ).on( 'click', function () {
42 var $wrapper = $( '#config-cc-wrapper' );
43 if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
44 // FIXME: Use CSS transition
45 // eslint-disable-next-line no-jquery/no-animate-toggle
46 $wrapper.show( 'slow' );
47 } else {
48 // eslint-disable-next-line no-jquery/no-animate-toggle
49 $wrapper.hide( 'slow' );
50 }
51 } );
52
53 // Show/hide random stuff (email, upload)
54 $( '.showHideRadio' ).on( 'click', function () {
55 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
56 if ( $( this ).is( ':checked' ) ) {
57 // FIXME: Use CSS transition
58 // eslint-disable-next-line no-jquery/no-animate-toggle
59 $wrapper.show( 'slow' );
60 } else {
61 // eslint-disable-next-line no-jquery/no-animate-toggle
62 $wrapper.hide( 'slow' );
63 }
64 } );
65 $( '.hideShowRadio' ).on( 'click', function () {
66 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
67 if ( $( this ).is( ':checked' ) ) {
68 // FIXME: Use CSS transition
69 // eslint-disable-next-line no-jquery/no-animate-toggle
70 $wrapper.hide( 'slow' );
71 } else {
72 // eslint-disable-next-line no-jquery/no-animate-toggle
73 $wrapper.show( 'slow' );
74 }
75 } );
76
77 // Hide "other" textboxes by default
78 // Should not be done in CSS for javascript disabled compatibility
79 if ( !$( '#config__NamespaceType_other' ).is( ':checked' ) ) {
80 $( '.enabledByOther' ).closest( '.config-block' ).hide();
81 }
82
83 // Enable/disable "other" textboxes
84 $( '.enableForOther' ).on( 'click', function () {
85 var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) );
86 // FIXME: Ugh, this is ugly
87 if ( $( this ).val() === 'other' ) {
88 // FIXME: Use CSS transition
89 // eslint-disable-next-line no-jquery/no-slide
90 $textbox.prop( 'readonly', false ).closest( '.config-block' ).slideDown( 'fast' );
91 } else {
92 // eslint-disable-next-line no-jquery/no-slide
93 $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
94 }
95 } );
96
97 // Synchronize radio button label for sitename with textbox
98 $label = $( 'label[for="config__NamespaceType_site-name"]' );
99 labelText = $label.text();
100 $label.text( labelText.replace( '$1', '' ) );
101 $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText );
102
103 // Show/Hide memcached servers when needed
104 $( 'input[name$="config__MainCacheType"]' ).on( 'change', function () {
105 var $memc = $( '#config-memcachewrapper' );
106 if ( $( 'input[name$="config__MainCacheType"]:checked' ).val() === 'memcached' ) {
107 // FIXME: Use CSS transition
108 // eslint-disable-next-line no-jquery/no-animate-toggle
109 $memc.show( 'slow' );
110 } else {
111 // eslint-disable-next-line no-jquery/no-animate-toggle
112 $memc.hide( 'slow' );
113 }
114 } );
115
116 function areReqsSatisfied( name ) {
117 var i, ext, skin, node;
118 if ( !extDependencyMap[ name ] ) {
119 return true;
120 }
121
122 if ( extDependencyMap[ name ].extensions ) {
123 for ( i in extDependencyMap[ name ].extensions ) {
124 ext = extDependencyMap[ name ].extensions[ i ];
125 node = document.getElementById( 'config_ext-' + ext );
126 if ( !node || !node.checked ) {
127 return false;
128 }
129 }
130 }
131 if ( extDependencyMap[ name ].skins ) {
132 for ( i in extDependencyMap[ name ].skins ) {
133 skin = extDependencyMap[ name ].skins[ i ];
134 node = document.getElementById( 'config_skin-' + skin );
135 if ( !node || !node.checked ) {
136 return false;
137 }
138 }
139 }
140
141 return true;
142 }
143
144 // Disable checkboxes if the extension has dependencies
145 $( '.mw-ext-with-dependencies input' ).prop( 'disabled', true );
146 $( '.config-ext-input[data-name]' ).on( 'change', function () {
147 $( '.mw-ext-with-dependencies input' ).each( function () {
148 var name = this.getAttribute( 'data-name' );
149 if ( areReqsSatisfied( name ) ) {
150 // Re-enable it!
151 this.disabled = false;
152 } else {
153 // Uncheck and disable the checkbox
154 this.checked = false;
155 this.disabled = true;
156 }
157 } );
158 } );
159 } );
160 }() );