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