Merge "Move section ID fallbacks into headers themselves"
[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 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
29 $this->submitSkins();
30 return 'skip';
31 }
32 if ( $this->parent->request->wasPosted() ) {
33 if ( $this->submit() ) {
34 return 'continue';
35 }
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
149 if ( $extensions ) {
150 $extHtml = $this->getFieldsetStart( 'config-extensions' );
151
152 foreach ( $extensions as $ext => $info ) {
153 $extHtml .= $this->parent->getCheckBox( [
154 'var' => "ext-$ext",
155 'rawtext' => $ext,
156 ] );
157 }
158
159 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
160 $this->getFieldsetEnd();
161 $this->addHTML( $extHtml );
162 }
163
164 // Having / in paths in Windows looks funny :)
165 $this->setVar( 'wgDeletedDirectory',
166 str_replace(
167 '/', DIRECTORY_SEPARATOR,
168 $this->getVar( 'wgDeletedDirectory' )
169 )
170 );
171
172 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
173 $this->addHTML(
174 # Uploading
175 $this->getFieldsetStart( 'config-upload-settings' ) .
176 $this->parent->getCheckBox( [
177 'var' => 'wgEnableUploads',
178 'label' => 'config-upload-enable',
179 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ],
180 'help' => $this->parent->getHelpBox( 'config-upload-help' )
181 ] ) .
182 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
183 $this->parent->getTextBox( [
184 'var' => 'wgDeletedDirectory',
185 'label' => 'config-upload-deleted',
186 'attribs' => [ 'dir' => 'ltr' ],
187 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
188 ] ) .
189 '</div>' .
190 $this->parent->getTextBox( [
191 'var' => 'wgLogo',
192 'label' => 'config-logo',
193 'attribs' => [ 'dir' => 'ltr' ],
194 'help' => $this->parent->getHelpBox( 'config-logo-help' )
195 ] )
196 );
197 $this->addHTML(
198 $this->parent->getCheckBox( [
199 'var' => 'wgUseInstantCommons',
200 'label' => 'config-instantcommons',
201 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
202 ] ) .
203 $this->getFieldsetEnd()
204 );
205
206 $caches = [ 'none' ];
207 $cachevalDefault = 'none';
208
209 if ( count( $this->getVar( '_Caches' ) ) ) {
210 // A CACHE_ACCEL implementation is available
211 $caches[] = 'accel';
212 $cachevalDefault = 'accel';
213 }
214 $caches[] = 'memcached';
215
216 // We'll hide/show this on demand when the value changes, see config.js.
217 $cacheval = $this->getVar( '_MainCacheType' );
218 if ( !$cacheval ) {
219 // We need to set a default here; but don't hardcode it
220 // or we lose it every time we reload the page for validation
221 // or going back!
222 $cacheval = $cachevalDefault;
223 }
224 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
225 $this->addHTML(
226 # Advanced settings
227 $this->getFieldsetStart( 'config-advanced-settings' ) .
228 # Object cache settings
229 // getRadioSet() builds a set of labeled radio buttons.
230 // For grep: The following messages are used as the item labels:
231 // config-cache-none, config-cache-accel, config-cache-memcached
232 $this->parent->getRadioSet( [
233 'var' => '_MainCacheType',
234 'label' => 'config-cache-options',
235 'itemLabelPrefix' => 'config-cache-',
236 'values' => $caches,
237 'value' => $cacheval,
238 ] ) .
239 $this->parent->getHelpBox( 'config-cache-help' ) .
240 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
241 $this->parent->getTextArea( [
242 'var' => '_MemCachedServers',
243 'label' => 'config-memcached-servers',
244 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
245 ] ) .
246 '</div>' .
247 $this->getFieldsetEnd()
248 );
249 $this->endForm();
250
251 return null;
252 }
253
254 private function makeScreenshotsLink( $name, $screenshots ) {
255 global $wgLang;
256 if ( count( $screenshots ) > 1 ) {
257 $links = [];
258 $counter = 1;
259 foreach ( $screenshots as $shot ) {
260 $links[] = Html::element(
261 'a',
262 [ 'href' => $shot ],
263 $wgLang->formatNum( $counter++ )
264 );
265 }
266 return wfMessage( 'config-skins-screenshots' )
267 ->rawParams( $name, $wgLang->commaList( $links ) )
268 ->escaped();
269 } else {
270 $link = Html::element(
271 'a',
272 [ 'href' => $screenshots[0] ],
273 wfMessage( 'config-screenshot' )->text()
274 );
275 return wfMessage( 'config-skins-screenshot', $name )->rawParams( $link )->escaped();
276 }
277 }
278
279 /**
280 * @return string
281 */
282 public function getCCPartnerUrl() {
283 $server = $this->getVar( 'wgServer' );
284 $exitUrl = $server . $this->parent->getUrl( [
285 'page' => 'Options',
286 'SubmitCC' => 'indeed',
287 'config__LicenseCode' => 'cc',
288 'config_wgRightsUrl' => '[license_url]',
289 'config_wgRightsText' => '[license_name]',
290 'config_wgRightsIcon' => '[license_button]',
291 ] );
292 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
293 '/mw-config/config-cc.css';
294 $iframeUrl = '//creativecommons.org/license/?' .
295 wfArrayToCgi( [
296 'partner' => 'MediaWiki',
297 'exit_url' => $exitUrl,
298 'lang' => $this->getVar( '_UserLang' ),
299 'stylesheet' => $styleUrl,
300 ] );
301
302 return $iframeUrl;
303 }
304
305 /**
306 * @return string
307 */
308 public function getCCChooser() {
309 $iframeAttribs = [
310 'class' => 'config-cc-iframe',
311 'name' => 'config-cc-iframe',
312 'id' => 'config-cc-iframe',
313 'frameborder' => 0,
314 'width' => '100%',
315 'height' => '100%',
316 ];
317 if ( $this->getVar( '_CCDone' ) ) {
318 $iframeAttribs['src'] = $this->parent->getUrl( [ 'ShowCC' => 'yes' ] );
319 } else {
320 $iframeAttribs['src'] = $this->getCCPartnerUrl();
321 }
322 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
323
324 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
325 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
326 "</div>\n";
327 }
328
329 /**
330 * @return string
331 */
332 public function getCCDoneBox() {
333 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
334 // If you change this height, also change it in config.css
335 $expandJs = str_replace( '$1', '54em', $js );
336 $reduceJs = str_replace( '$1', '70px', $js );
337
338 return '<p>' .
339 Html::element( 'img', [ 'src' => $this->getVar( 'wgRightsIcon' ) ] ) .
340 '&#160;&#160;' .
341 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
342 "</p>\n" .
343 "<p style=\"text-align: center;\">" .
344 Html::element( 'a',
345 [
346 'href' => $this->getCCPartnerUrl(),
347 'onclick' => $expandJs,
348 ],
349 wfMessage( 'config-cc-again' )->text()
350 ) .
351 "</p>\n" .
352 "<script>\n" .
353 # Reduce the wrapper div height
354 htmlspecialchars( $reduceJs ) .
355 "\n" .
356 "</script>\n";
357 }
358
359 public function submitCC() {
360 $newValues = $this->parent->setVarsFromRequest(
361 [ 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ] );
362 if ( count( $newValues ) != 3 ) {
363 $this->parent->showError( 'config-cc-error' );
364
365 return;
366 }
367 $this->setVar( '_CCDone', true );
368 $this->addHTML( $this->getCCDoneBox() );
369 }
370
371 /**
372 * If the user skips this installer page, we still need to set up the default skins, but ignore
373 * everything else.
374 *
375 * @return bool
376 */
377 public function submitSkins() {
378 $skins = array_keys( $this->parent->findExtensions( 'skins' ) );
379 $this->parent->setVar( '_Skins', $skins );
380
381 if ( $skins ) {
382 $skinNames = array_map( 'strtolower', $skins );
383 $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
384 }
385
386 return true;
387 }
388
389 /**
390 * @return bool
391 */
392 public function submit() {
393 $this->parent->setVarsFromRequest( [ '_RightsProfile', '_LicenseCode',
394 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
395 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
396 'wgEmailAuthentication', '_MainCacheType', '_MemCachedServers',
397 'wgUseInstantCommons', 'wgDefaultSkin' ] );
398
399 $retVal = true;
400
401 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
402 reset( $this->parent->rightsProfiles );
403 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
404 }
405
406 $code = $this->getVar( '_LicenseCode' );
407 if ( $code == 'cc-choose' ) {
408 if ( !$this->getVar( '_CCDone' ) ) {
409 $this->parent->showError( 'config-cc-not-chosen' );
410 $retVal = false;
411 }
412 } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
413 // Messages:
414 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
415 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
416 // config-license-cc-choose
417 $entry = $this->parent->licenses[$code];
418 if ( isset( $entry['text'] ) ) {
419 $this->setVar( 'wgRightsText', $entry['text'] );
420 } else {
421 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
422 }
423 $this->setVar( 'wgRightsUrl', $entry['url'] );
424 $this->setVar( 'wgRightsIcon', $entry['icon'] );
425 } else {
426 $this->setVar( 'wgRightsText', '' );
427 $this->setVar( 'wgRightsUrl', '' );
428 $this->setVar( 'wgRightsIcon', '' );
429 }
430
431 $skinsAvailable = array_keys( $this->parent->findExtensions( 'skins' ) );
432 $skinsToInstall = [];
433 foreach ( $skinsAvailable as $skin ) {
434 $this->parent->setVarsFromRequest( [ "skin-$skin" ] );
435 if ( $this->getVar( "skin-$skin" ) ) {
436 $skinsToInstall[] = $skin;
437 }
438 }
439 $this->parent->setVar( '_Skins', $skinsToInstall );
440
441 if ( !$skinsToInstall && $skinsAvailable ) {
442 $this->parent->showError( 'config-skins-must-enable-some' );
443 $retVal = false;
444 }
445 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
446 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
447 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
448 $this->parent->showError( 'config-skins-must-enable-default' );
449 $retVal = false;
450 }
451
452 $extsAvailable = array_keys( $this->parent->findExtensions() );
453 $extsToInstall = [];
454 foreach ( $extsAvailable as $ext ) {
455 $this->parent->setVarsFromRequest( [ "ext-$ext" ] );
456 if ( $this->getVar( "ext-$ext" ) ) {
457 $extsToInstall[] = $ext;
458 }
459 }
460 $this->parent->setVar( '_Extensions', $extsToInstall );
461
462 if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
463 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
464 if ( !$memcServers ) {
465 $this->parent->showError( 'config-memcache-needservers' );
466 $retVal = false;
467 }
468
469 foreach ( $memcServers as $server ) {
470 $memcParts = explode( ":", $server, 2 );
471 if ( !isset( $memcParts[0] )
472 || ( !IP::isValid( $memcParts[0] )
473 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
474 ) {
475 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
476 $retVal = false;
477 } elseif ( !isset( $memcParts[1] ) ) {
478 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
479 $retVal = false;
480 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
481 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
482 $retVal = false;
483 }
484 }
485 }
486
487 return $retVal;
488 }
489
490 }