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.
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.
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
22 class WebInstallerOptions
extends WebInstallerPage
{
27 public function execute() {
30 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
34 if ( $this->parent
->request
->wasPosted() && $this->submit() ) {
38 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
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
),
51 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
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' ],
66 $this->getCCChooser() .
67 $this->parent
->getHelpBox( 'config-license-help' ) .
70 $this->getFieldsetStart( 'config-email-settings' ) .
71 $this->parent
->getCheckBox( [
72 'var' => 'wgEnableEmail',
73 'label' => 'config-enable-email',
74 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ],
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'
82 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
83 $this->parent
->getCheckBox( [
84 'var' => 'wgEnableUserEmail',
85 'label' => 'config-email-user',
87 $this->parent
->getHelpBox( 'config-email-user-help' ) .
88 $this->parent
->getCheckBox( [
89 'var' => 'wgEnotifUserTalk',
90 'label' => 'config-email-usertalk',
92 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
93 $this->parent
->getCheckBox( [
94 'var' => 'wgEnotifWatchlist',
95 'label' => 'config-email-watchlist',
97 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
98 $this->parent
->getCheckBox( [
99 'var' => 'wgEmailAuthentication',
100 'label' => 'config-email-auth',
102 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
104 $this->getFieldsetEnd()
107 $skins = $this->parent
->findExtensions( 'skins' );
108 $skinHtml = $this->getFieldsetStart( 'config-skins' );
110 $skinNames = array_map( 'strtolower', array_keys( $skins ) );
111 $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent
->getDefaultSkin( $skinNames ) );
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,
121 foreach ( $skins as $skin => $info ) {
122 if ( isset( $info['screenshots'] ) ) {
123 $screenshotText = $this->makeScreenshotsLink( $skin, $info['screenshots'] );
125 $screenshotText = htmlspecialchars( $skin );
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
134 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
139 $this->parent
->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
140 Html
::hidden( 'config_wgDefaultSkin', $chosenSkinName );
143 $skinHtml .= $this->parent
->getHelpBox( 'config-skins-help' ) .
144 $this->getFieldsetEnd();
145 $this->addHTML( $skinHtml );
147 $extensions = $this->parent
->findExtensions();
151 $extHtml = $this->getFieldsetStart( 'config-extensions' );
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';
163 $extByType[$info['type']][$ext] = $info;
166 foreach ( $types as $type => $message ) {
167 if ( !isset( $extByType[$type] ) ) {
170 $extHtml .= Html
::element( 'h2', [], $message );
171 foreach ( $extByType[$type] as $ext => $info ) {
173 if ( isset( $info['url'] ) ) {
174 $urlText = ' ' . Html
::element( 'a', [ 'href' => $info['url'] ], '(more information)' );
178 'class' => 'config-ext-input'
182 if ( isset( $info['requires']['extensions'] ) ) {
183 $dependencyMap[$ext]['extensions'] = $info['requires']['extensions'];
184 $labelAttribs['class'] = 'mw-ext-with-dependencies';
186 if ( isset( $info['requires']['skins'] ) ) {
187 $dependencyMap[$ext]['skins'] = $info['requires']['skins'];
188 $labelAttribs['class'] = 'mw-ext-with-dependencies';
190 if ( isset( $dependencyMap[$ext] ) ) {
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(
198 [ 'href' => "#config_ext-$name" ],
203 if ( isset( $dependencyMap[$ext]['skins'] ) ) {
204 foreach ( $dependencyMap[$ext]['skins'] as $name ) {
205 $links[] = Html
::element(
207 [ 'href' => "#config_skin-$name" ],
213 $text = wfMessage( 'config-extensions-requires' )
214 ->rawParams( $ext, $wgLang->commaList( $links ) )
219 $extHtml .= $this->parent
->getCheckBox( [
222 'attribs' => $attribs,
223 'labelAttribs' => $labelAttribs,
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 )
237 // Having / in paths in Windows looks funny :)
238 $this->setVar( 'wgDeletedDirectory',
240 '/', DIRECTORY_SEPARATOR
,
241 $this->getVar( 'wgDeletedDirectory' )
245 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
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' )
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' )
263 $this->parent
->getTextBox( [
265 'label' => 'config-logo',
266 'attribs' => [ 'dir' => 'ltr' ],
267 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
271 $this->parent
->getCheckBox( [
272 'var' => 'wgUseInstantCommons',
273 'label' => 'config-instantcommons',
274 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
276 $this->getFieldsetEnd()
279 $caches = [ 'none' ];
280 $cachevalDefault = 'none';
282 if ( count( $this->getVar( '_Caches' ) ) ) {
283 // A CACHE_ACCEL implementation is available
285 $cachevalDefault = 'accel';
287 $caches[] = 'memcached';
289 // We'll hide/show this on demand when the value changes, see config.js.
290 $cacheval = $this->getVar( '_MainCacheType' );
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
295 $cacheval = $cachevalDefault;
297 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
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-',
310 'value' => $cacheval,
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' )
320 $this->getFieldsetEnd()
327 private function makeScreenshotsLink( $name, $screenshots ) {
329 if ( count( $screenshots ) > 1 ) {
332 foreach ( $screenshots as $shot ) {
333 $links[] = Html
::element(
335 [ 'href' => $shot, 'target' => '_blank' ],
336 $wgLang->formatNum( $counter++
)
339 return wfMessage( 'config-skins-screenshots' )
340 ->rawParams( $name, $wgLang->commaList( $links ) )
343 $link = Html
::element(
345 [ 'href' => $screenshots[0], 'target' => '_blank' ],
346 wfMessage( 'config-screenshot' )->text()
348 return wfMessage( 'config-skins-screenshot', $name )->rawParams( $link )->escaped();
355 public function getCCPartnerUrl() {
356 $server = $this->getVar( 'wgServer' );
357 $exitUrl = $server . $this->parent
->getUrl( [
359 'SubmitCC' => 'indeed',
360 'config__LicenseCode' => 'cc',
361 'config_wgRightsUrl' => '[license_url]',
362 'config_wgRightsText' => '[license_name]',
363 'config_wgRightsIcon' => '[license_button]',
365 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
366 '/mw-config/config-cc.css';
367 $iframeUrl = '//creativecommons.org/license/?' .
369 'partner' => 'MediaWiki',
370 'exit_url' => $exitUrl,
371 'lang' => $this->getVar( '_UserLang' ),
372 'stylesheet' => $styleUrl,
381 public function getCCChooser() {
383 'class' => 'config-cc-iframe',
384 'name' => 'config-cc-iframe',
385 'id' => 'config-cc-iframe',
390 if ( $this->getVar( '_CCDone' ) ) {
391 $iframeAttribs['src'] = $this->parent
->getUrl( [ 'ShowCC' => 'yes' ] );
393 $iframeAttribs['src'] = $this->getCCPartnerUrl();
395 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
397 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
398 Html
::element( 'iframe', $iframeAttribs ) .
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 );
412 Html
::element( 'img', [ 'src' => $this->getVar( 'wgRightsIcon' ) ] ) .
414 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
416 "<p style=\"text-align: center;\">" .
419 'href' => $this->getCCPartnerUrl(),
420 'onclick' => $expandJs,
422 wfMessage( 'config-cc-again' )->text()
426 # Reduce the wrapper div height
427 htmlspecialchars( $reduceJs ) .
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' );
440 $this->setVar( '_CCDone', true );
441 $this->addHTML( $this->getCCDoneBox() );
445 * If the user skips this installer page, we still need to set up the default skins, but ignore
450 public function submitSkins() {
451 $skins = array_keys( $this->parent
->findExtensions( 'skins' ) );
452 $this->parent
->setVar( '_Skins', $skins );
455 $skinNames = array_map( 'strtolower', $skins );
456 $this->parent
->setVar( 'wgDefaultSkin', $this->parent
->getDefaultSkin( $skinNames ) );
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' ] );
474 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent
->rightsProfiles
) ) {
475 reset( $this->parent
->rightsProfiles
);
476 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
479 $code = $this->getVar( '_LicenseCode' );
480 if ( $code == 'cc-choose' ) {
481 if ( !$this->getVar( '_CCDone' ) ) {
482 $this->parent
->showError( 'config-cc-not-chosen' );
485 } elseif ( array_key_exists( $code, $this->parent
->licenses
) ) {
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'] );
496 $this->setVar( 'wgRightsText', '' );
497 $this->setVar( 'wgRightsUrl', '' );
498 $this->setVar( 'wgRightsIcon', '' );
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;
509 $this->parent
->setVar( '_Skins', $skinsToInstall );
511 if ( !$skinsToInstall && $skinsAvailable ) {
512 $this->parent
->showError( 'config-skins-must-enable-some' );
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' );
522 $extsAvailable = array_keys( $this->parent
->findExtensions() );
524 foreach ( $extsAvailable as $ext ) {
525 $this->parent
->setVarsFromRequest( [ "ext-$ext" ] );
526 if ( $this->getVar( "ext-$ext" ) ) {
527 $extsToInstall[] = $ext;
530 $this->parent
->setVar( '_Extensions', $extsToInstall );
532 if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
533 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
534 if ( !$memcServers ) {
535 $this->parent
->showError( 'config-memcache-needservers' );
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] ) )
545 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
547 } elseif ( !isset( $memcParts[1] ) ) {
548 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
550 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
551 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );