Add structure test to ensure PSR-4 autoloader covers everything
[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 // Set up the help system
18 $( '.config-help-field-data' ).hide()
19 .closest( '.config-help-field-container' ).find( '.config-help-field-hint' )
20 .show()
21 .click( function () {
22 $( this ).closest( '.config-help-field-container' ).find( '.config-help-field-data' )
23 .slideToggle( 'fast' );
24 } );
25
26 // Show/hide code for DB-specific options
27 // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here?
28 $( '.dbRadio' ).each( function () {
29 $( document.getElementById( $( this ).attr( 'rel' ) ) ).hide();
30 } );
31 $( document.getElementById( $( '.dbRadio:checked' ).attr( 'rel' ) ) ).show();
32 $( '.dbRadio' ).click( function () {
33 var $checked = $( '.dbRadio:checked' ),
34 $wrapper = $( document.getElementById( $checked.attr( 'rel' ) ) );
35 if ( $wrapper.is( ':hidden' ) ) {
36 $( '.dbWrapper' ).hide( 'slow' );
37 $wrapper.show( 'slow' );
38 }
39 } );
40
41 // Scroll to the bottom of upgrade log
42 $( '#config-live-log' ).children( 'textarea' ).each( function () {
43 this.scrollTop = this.scrollHeight;
44 } );
45
46 // Show/hide Creative Commons thingy
47 $( '.licenseRadio' ).click( function () {
48 var $wrapper = $( '#config-cc-wrapper' );
49 if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
50 $wrapper.show( 'slow' );
51 } else {
52 $wrapper.hide( 'slow' );
53 }
54 } );
55
56 // Show/hide random stuff (email, upload)
57 $( '.showHideRadio' ).click( function () {
58 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
59 if ( $( this ).is( ':checked' ) ) {
60 $wrapper.show( 'slow' );
61 } else {
62 $wrapper.hide( 'slow' );
63 }
64 } );
65 $( '.hideShowRadio' ).click( function () {
66 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
67 if ( $( this ).is( ':checked' ) ) {
68 $wrapper.hide( 'slow' );
69 } else {
70 $wrapper.show( 'slow' );
71 }
72 } );
73
74 // Hide "other" textboxes by default
75 // Should not be done in CSS for javascript disabled compatibility
76 if ( !$( '#config__NamespaceType_other' ).is( ':checked' ) ) {
77 $( '.enabledByOther' ).closest( '.config-block' ).hide();
78 }
79
80 // Enable/disable "other" textboxes
81 $( '.enableForOther' ).click( function () {
82 var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) );
83 // FIXME: Ugh, this is ugly
84 if ( $( this ).val() === 'other' ) {
85 $textbox.prop( 'readonly', false ).closest( '.config-block' ).slideDown( 'fast' );
86 } else {
87 $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
88 }
89 } );
90
91 // Synchronize radio button label for sitename with textbox
92 $label = $( 'label[for="config__NamespaceType_site-name"]' );
93 labelText = $label.text();
94 $label.text( labelText.replace( '$1', '' ) );
95 $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText );
96
97 // Show/Hide memcached servers when needed
98 $( 'input[name$="config__MainCacheType"]' ).change( function () {
99 var $memc = $( '#config-memcachewrapper' );
100 if ( $( 'input[name$="config__MainCacheType"]:checked' ).val() === 'memcached' ) {
101 $memc.show( 'slow' );
102 } else {
103 $memc.hide( 'slow' );
104 }
105 } );
106
107 function areReqsSatisfied( name ) {
108 var i, ext, skin, node;
109 if ( !extDependencyMap[ name ] ) {
110 return true;
111 }
112
113 if ( extDependencyMap[ name ].extensions ) {
114 for ( i in extDependencyMap[ name ].extensions ) {
115 ext = extDependencyMap[ name ].extensions[ i ];
116 node = document.getElementById( 'config_ext-' + ext );
117 if ( !node || !node.checked ) {
118 return false;
119 }
120 }
121 }
122 if ( extDependencyMap[ name ].skins ) {
123 for ( i in extDependencyMap[ name ].skins ) {
124 skin = extDependencyMap[ name ].skins[ i ];
125 node = document.getElementById( 'config_skin-' + skin );
126 if ( !node || !node.checked ) {
127 return false;
128 }
129 }
130 }
131
132 return true;
133 }
134
135 // Disable checkboxes if the extension has dependencies
136 $( '.mw-ext-with-dependencies input' ).prop( 'disabled', true );
137 $( '.config-ext-input[data-name]' ).on( 'change', function () {
138 $( '.mw-ext-with-dependencies input' ).each( function () {
139 var name = this.getAttribute( 'data-name' );
140 if ( areReqsSatisfied( name ) ) {
141 // Re-enable it!
142 this.disabled = false;
143 } else {
144 // Uncheck and disable the checkbox
145 this.checked = false;
146 this.disabled = true;
147 }
148 } );
149 } );
150 } );
151 }( jQuery ) );