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