Make config-outdated-sqlite parameter numbers consistent with config-*-old
[lhc/web/wiklou.git] / includes / installer / WebInstallerOptions.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Deployment
20 */
21
22 class WebInstallerOptions extends WebInstallerPage {
23
24 /**
25 * @return string|null
26 */
27 public function execute() {
28 global $wgLang;
29
30 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
31 $this->submitSkins();
32 return 'skip';
33 }
34 if ( $this->parent->request->wasPosted() && $this->submit() ) {
35 return 'continue';
36 }
37
38 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
39 $this->startForm();
40 $this->addHTML(
41 # User Rights
42 // getRadioSet() builds a set of labeled radio buttons.
43 // For grep: The following messages are used as the item labels:
44 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
45 $this->parent->getRadioSet( [
46 'var' => '_RightsProfile',
47 'label' => 'config-profile',
48 'itemLabelPrefix' => 'config-profile-',
49 'values' => array_keys( $this->parent->rightsProfiles ),
50 ] ) .
51 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
52
53 # Licensing
54 // getRadioSet() builds a set of labeled radio buttons.
55 // For grep: The following messages are used as the item labels:
56 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
57 // config-license-cc-0, config-license-pd, config-license-gfdl,
58 // config-license-none, config-license-cc-choose
59 $this->parent->getRadioSet( [
60 'var' => '_LicenseCode',
61 'label' => 'config-license',
62 'itemLabelPrefix' => 'config-license-',
63 'values' => array_keys( $this->parent->licenses ),
64 'commonAttribs' => [ 'class' => 'licenseRadio' ],
65 ] ) .
66 $this->getCCChooser() .
67 $this->parent->getHelpBox( 'config-license-help' ) .
68
69 # E-mail
70 $this->getFieldsetStart( 'config-email-settings' ) .
71 $this->parent->getCheckBox( [
72 'var' => 'wgEnableEmail',
73 'label' => 'config-enable-email',
74 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ],
75 ] ) .
76 $this->parent->getHelpBox( 'config-enable-email-help' ) .
77 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
78 $this->parent->getTextBox( [
79 'var' => 'wgPasswordSender',
80 'label' => 'config-email-sender'
81 ] ) .
82 $this->parent->getHelpBox( 'config-email-sender-help' ) .
83 $this->parent->getCheckBox( [
84 'var' => 'wgEnableUserEmail',
85 'label' => 'config-email-user',
86 ] ) .
87 $this->parent->getHelpBox( 'config-email-user-help' ) .
88 $this->parent->getCheckBox( [
89 'var' => 'wgEnotifUserTalk',
90 'label' => 'config-email-usertalk',
91 ] ) .
92 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
93 $this->parent->getCheckBox( [
94 'var' => 'wgEnotifWatchlist',
95 'label' => 'config-email-watchlist',
96 ] ) .
97 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
98 $this->parent->getCheckBox( [
99 'var' => 'wgEmailAuthentication',
100 'label' => 'config-email-auth',
101 ] ) .
102 $this->parent->getHelpBox( 'config-email-auth-help' ) .
103 "</div>" .
104 $this->getFieldsetEnd()
105 );
106
107 $skins = $this->parent->findExtensions( 'skins' );
108 $skinHtml = $this->getFieldsetStart( 'config-skins' );
109
110 $skinNames = array_map( 'strtolower', array_keys( $skins ) );
111 $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
112
113 if ( $skins ) {
114 $radioButtons = $this->parent->getRadioElements( [
115 'var' => 'wgDefaultSkin',
116 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
117 'values' => $skinNames,
118 'value' => $chosenSkinName,
119 ] );
120
121 foreach ( $skins as $skin => $info ) {
122 if ( isset( $info['screenshots'] ) ) {
123 $screenshotText = $this->makeScreenshotsLink( $skin, $info['screenshots'] );
124 } else {
125 $screenshotText = htmlspecialchars( $skin );
126 }
127 $skinHtml .=
128 '<div class="config-skins-item">' .
129 $this->parent->getCheckBox( [
130 'var' => "skin-$skin",
131 'rawtext' => $screenshotText,
132 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
133 ] ) .
134 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
135 '</div>';
136 }
137 } else {
138 $skinHtml .=
139 $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
140 Html::hidden( 'config_wgDefaultSkin', $chosenSkinName );
141 }
142
143 $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
144 $this->getFieldsetEnd();
145 $this->addHTML( $skinHtml );
146
147 $extensions = $this->parent->findExtensions();
148 $dependencyMap = [];
149
150 if ( $extensions ) {
151 $extHtml = $this->getFieldsetStart( 'config-extensions' );
152
153 $extByType = [];
154 $types = SpecialVersion::getExtensionTypes();
155 // Sort by type first
156 foreach ( $extensions as $ext => $info ) {
157 if ( !isset( $info['type'] ) || !isset( $types[$info['type']] ) ) {
158 // We let extensions normally define custom types, but
159 // since we aren't loading extensions, we'll have to
160 // categorize them under other
161 $info['type'] = 'other';
162 }
163 $extByType[$info['type']][$ext] = $info;
164 }
165
166 foreach ( $types as $type => $message ) {
167 if ( !isset( $extByType[$type] ) ) {
168 continue;
169 }
170 $extHtml .= Html::element( 'h2', [], $message );
171 foreach ( $extByType[$type] as $ext => $info ) {
172 $urlText = '';
173 if ( isset( $info['url'] ) ) {
174 $urlText = ' ' . Html::element( 'a', [ 'href' => $info['url'] ], '(more information)' );
175 }
176 $attribs = [
177 'data-name' => $ext,
178 'class' => 'config-ext-input'
179 ];
180 $labelAttribs = [];
181 $fullDepList = [];
182 if ( isset( $info['requires']['extensions'] ) ) {
183 $dependencyMap[$ext]['extensions'] = $info['requires']['extensions'];
184 $labelAttribs['class'] = 'mw-ext-with-dependencies';
185 }
186 if ( isset( $info['requires']['skins'] ) ) {
187 $dependencyMap[$ext]['skins'] = $info['requires']['skins'];
188 $labelAttribs['class'] = 'mw-ext-with-dependencies';
189 }
190 if ( isset( $dependencyMap[$ext] ) ) {
191 $links = [];
192 // For each dependency, link to the checkbox for each
193 // extension/skin that is required
194 if ( isset( $dependencyMap[$ext]['extensions'] ) ) {
195 foreach ( $dependencyMap[$ext]['extensions'] as $name ) {
196 $links[] = Html::element(
197 'a',
198 [ 'href' => "#config_ext-$name" ],
199 $name
200 );
201 }
202 }
203 if ( isset( $dependencyMap[$ext]['skins'] ) ) {
204 foreach ( $dependencyMap[$ext]['skins'] as $name ) {
205 $links[] = Html::element(
206 'a',
207 [ 'href' => "#config_skin-$name" ],
208 $name
209 );
210 }
211 }
212
213 $text = wfMessage( 'config-extensions-requires' )
214 ->rawParams( $ext, $wgLang->commaList( $links ) )
215 ->escaped();
216 } else {
217 $text = $ext;
218 }
219 $extHtml .= $this->parent->getCheckBox( [
220 'var' => "ext-$ext",
221 'rawtext' => $text,
222 'attribs' => $attribs,
223 'labelAttribs' => $labelAttribs,
224 ] );
225 }
226 }
227
228 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
229 $this->getFieldsetEnd();
230 $this->addHTML( $extHtml );
231 // Push the dependency map to the client side
232 $this->addHTML( Html::inlineScript(
233 'var extDependencyMap = ' . Xml::encodeJsVar( $dependencyMap )
234 ) );
235 }
236
237 // Having / in paths in Windows looks funny :)
238 $this->setVar( 'wgDeletedDirectory',
239 str_replace(
240 '/', DIRECTORY_SEPARATOR,
241 $this->getVar( 'wgDeletedDirectory' )
242 )
243 );
244
245 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
246 $this->addHTML(
247 # Uploading
248 $this->getFieldsetStart( 'config-upload-settings' ) .
249 $this->parent->getCheckBox( [
250 'var' => 'wgEnableUploads',
251 'label' => 'config-upload-enable',
252 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ],
253 'help' => $this->parent->getHelpBox( 'config-upload-help' )
254 ] ) .
255 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
256 $this->parent->getTextBox( [
257 'var' => 'wgDeletedDirectory',
258 'label' => 'config-upload-deleted',
259 'attribs' => [ 'dir' => 'ltr' ],
260 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
261 ] ) .
262 '</div>' .
263 $this->parent->getTextBox( [
264 'var' => 'wgLogo',
265 'label' => 'config-logo',
266 'attribs' => [ 'dir' => 'ltr' ],
267 'help' => $this->parent->getHelpBox( 'config-logo-help' )
268 ] )
269 );
270 $this->addHTML(
271 $this->parent->getCheckBox( [
272 'var' => 'wgUseInstantCommons',
273 'label' => 'config-instantcommons',
274 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
275 ] ) .
276 $this->getFieldsetEnd()
277 );
278
279 $caches = [ 'none' ];
280 $cachevalDefault = 'none';
281
282 if ( count( $this->getVar( '_Caches' ) ) ) {
283 // A CACHE_ACCEL implementation is available
284 $caches[] = 'accel';
285 $cachevalDefault = 'accel';
286 }
287 $caches[] = 'memcached';
288
289 // We'll hide/show this on demand when the value changes, see config.js.
290 $cacheval = $this->getVar( '_MainCacheType' );
291 if ( !$cacheval ) {
292 // We need to set a default here; but don't hardcode it
293 // or we lose it every time we reload the page for validation
294 // or going back!
295 $cacheval = $cachevalDefault;
296 }
297 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
298 $this->addHTML(
299 # Advanced settings
300 $this->getFieldsetStart( 'config-advanced-settings' ) .
301 # Object cache settings
302 // getRadioSet() builds a set of labeled radio buttons.
303 // For grep: The following messages are used as the item labels:
304 // config-cache-none, config-cache-accel, config-cache-memcached
305 $this->parent->getRadioSet( [
306 'var' => '_MainCacheType',
307 'label' => 'config-cache-options',
308 'itemLabelPrefix' => 'config-cache-',
309 'values' => $caches,
310 'value' => $cacheval,
311 ] ) .
312 $this->parent->getHelpBox( 'config-cache-help' ) .
313 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
314 $this->parent->getTextArea( [
315 'var' => '_MemCachedServers',
316 'label' => 'config-memcached-servers',
317 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
318 ] ) .
319 '</div>' .
320 $this->getFieldsetEnd()
321 );
322 $this->endForm();
323
324 return null;
325 }
326
327 private function makeScreenshotsLink( $name, $screenshots ) {
328 global $wgLang;
329 if ( count( $screenshots ) > 1 ) {
330 $links = [];
331 $counter = 1;
332 foreach ( $screenshots as $shot ) {
333 $links[] = Html::element(
334 'a',
335 [ 'href' => $shot, 'target' => '_blank' ],
336 $wgLang->formatNum( $counter++ )
337 );
338 }
339 return wfMessage( 'config-skins-screenshots' )
340 ->rawParams( $name, $wgLang->commaList( $links ) )
341 ->escaped();
342 } else {
343 $link = Html::element(
344 'a',
345 [ 'href' => $screenshots[0], 'target' => '_blank' ],
346 wfMessage( 'config-screenshot' )->text()
347 );
348 return wfMessage( 'config-skins-screenshot', $name )->rawParams( $link )->escaped();
349 }
350 }
351
352 /**
353 * @return string
354 */
355 public function getCCPartnerUrl() {
356 $server = $this->getVar( 'wgServer' );
357 $exitUrl = $server . $this->parent->getUrl( [
358 'page' => 'Options',
359 'SubmitCC' => 'indeed',
360 'config__LicenseCode' => 'cc',
361 'config_wgRightsUrl' => '[license_url]',
362 'config_wgRightsText' => '[license_name]',
363 'config_wgRightsIcon' => '[license_button]',
364 ] );
365 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
366 '/mw-config/config-cc.css';
367 $iframeUrl = '//creativecommons.org/license/?' .
368 wfArrayToCgi( [
369 'partner' => 'MediaWiki',
370 'exit_url' => $exitUrl,
371 'lang' => $this->getVar( '_UserLang' ),
372 'stylesheet' => $styleUrl,
373 ] );
374
375 return $iframeUrl;
376 }
377
378 /**
379 * @return string
380 */
381 public function getCCChooser() {
382 $iframeAttribs = [
383 'class' => 'config-cc-iframe',
384 'name' => 'config-cc-iframe',
385 'id' => 'config-cc-iframe',
386 'frameborder' => 0,
387 'width' => '100%',
388 'height' => '100%',
389 ];
390 if ( $this->getVar( '_CCDone' ) ) {
391 $iframeAttribs['src'] = $this->parent->getUrl( [ 'ShowCC' => 'yes' ] );
392 } else {
393 $iframeAttribs['src'] = $this->getCCPartnerUrl();
394 }
395 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
396
397 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
398 Html::element( 'iframe', $iframeAttribs ) .
399 "</div>\n";
400 }
401
402 /**
403 * @return string
404 */
405 public function getCCDoneBox() {
406 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
407 // If you change this height, also change it in config.css
408 $expandJs = str_replace( '$1', '54em', $js );
409 $reduceJs = str_replace( '$1', '70px', $js );
410
411 return '<p>' .
412 Html::element( 'img', [ 'src' => $this->getVar( 'wgRightsIcon' ) ] ) .
413 "\u{00A0}\u{00A0}" .
414 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
415 "</p>\n" .
416 "<p style=\"text-align: center;\">" .
417 Html::element( 'a',
418 [
419 'href' => $this->getCCPartnerUrl(),
420 'onclick' => $expandJs,
421 ],
422 wfMessage( 'config-cc-again' )->text()
423 ) .
424 "</p>\n" .
425 "<script>\n" .
426 # Reduce the wrapper div height
427 htmlspecialchars( $reduceJs ) .
428 "\n" .
429 "</script>\n";
430 }
431
432 public function submitCC() {
433 $newValues = $this->parent->setVarsFromRequest(
434 [ 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ] );
435 if ( count( $newValues ) != 3 ) {
436 $this->parent->showError( 'config-cc-error' );
437
438 return;
439 }
440 $this->setVar( '_CCDone', true );
441 $this->addHTML( $this->getCCDoneBox() );
442 }
443
444 /**
445 * If the user skips this installer page, we still need to set up the default skins, but ignore
446 * everything else.
447 *
448 * @return bool
449 */
450 public function submitSkins() {
451 $skins = array_keys( $this->parent->findExtensions( 'skins' ) );
452 $this->parent->setVar( '_Skins', $skins );
453
454 if ( $skins ) {
455 $skinNames = array_map( 'strtolower', $skins );
456 $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
457 }
458
459 return true;
460 }
461
462 /**
463 * @return bool
464 */
465 public function submit() {
466 $this->parent->setVarsFromRequest( [ '_RightsProfile', '_LicenseCode',
467 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
468 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
469 'wgEmailAuthentication', '_MainCacheType', '_MemCachedServers',
470 'wgUseInstantCommons', 'wgDefaultSkin' ] );
471
472 $retVal = true;
473
474 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
475 reset( $this->parent->rightsProfiles );
476 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
477 }
478
479 $code = $this->getVar( '_LicenseCode' );
480 if ( $code == 'cc-choose' ) {
481 if ( !$this->getVar( '_CCDone' ) ) {
482 $this->parent->showError( 'config-cc-not-chosen' );
483 $retVal = false;
484 }
485 } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
486 // Messages:
487 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
488 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
489 // config-license-cc-choose
490 $entry = $this->parent->licenses[$code];
491 $this->setVar( 'wgRightsText',
492 $entry['text'] ?? wfMessage( 'config-license-' . $code )->text() );
493 $this->setVar( 'wgRightsUrl', $entry['url'] );
494 $this->setVar( 'wgRightsIcon', $entry['icon'] );
495 } else {
496 $this->setVar( 'wgRightsText', '' );
497 $this->setVar( 'wgRightsUrl', '' );
498 $this->setVar( 'wgRightsIcon', '' );
499 }
500
501 $skinsAvailable = array_keys( $this->parent->findExtensions( 'skins' ) );
502 $skinsToInstall = [];
503 foreach ( $skinsAvailable as $skin ) {
504 $this->parent->setVarsFromRequest( [ "skin-$skin" ] );
505 if ( $this->getVar( "skin-$skin" ) ) {
506 $skinsToInstall[] = $skin;
507 }
508 }
509 $this->parent->setVar( '_Skins', $skinsToInstall );
510
511 if ( !$skinsToInstall && $skinsAvailable ) {
512 $this->parent->showError( 'config-skins-must-enable-some' );
513 $retVal = false;
514 }
515 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
516 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
517 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
518 $this->parent->showError( 'config-skins-must-enable-default' );
519 $retVal = false;
520 }
521
522 $extsAvailable = array_keys( $this->parent->findExtensions() );
523 $extsToInstall = [];
524 foreach ( $extsAvailable as $ext ) {
525 $this->parent->setVarsFromRequest( [ "ext-$ext" ] );
526 if ( $this->getVar( "ext-$ext" ) ) {
527 $extsToInstall[] = $ext;
528 }
529 }
530 $this->parent->setVar( '_Extensions', $extsToInstall );
531
532 if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
533 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
534 if ( !$memcServers ) {
535 $this->parent->showError( 'config-memcache-needservers' );
536 $retVal = false;
537 }
538
539 foreach ( $memcServers as $server ) {
540 $memcParts = explode( ":", $server, 2 );
541 if ( !isset( $memcParts[0] )
542 || ( !IP::isValid( $memcParts[0] )
543 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
544 ) {
545 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
546 $retVal = false;
547 } elseif ( !isset( $memcParts[1] ) ) {
548 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
549 $retVal = false;
550 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
551 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
552 $retVal = false;
553 }
554 }
555 }
556
557 return $retVal;
558 }
559
560 }