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() {
28 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
32 if ( $this->parent
->request
->wasPosted() ) {
33 if ( $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( array(
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( array(
60 'var' => '_LicenseCode',
61 'label' => 'config-license',
62 'itemLabelPrefix' => 'config-license-',
63 'values' => array_keys( $this->parent
->licenses
),
64 'commonAttribs' => array( 'class' => 'licenseRadio' ),
66 $this->getCCChooser() .
67 $this->parent
->getHelpBox( 'config-license-help' ) .
70 $this->getFieldSetStart( 'config-email-settings' ) .
71 $this->parent
->getCheckBox( array(
72 'var' => 'wgEnableEmail',
73 'label' => 'config-enable-email',
74 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
76 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
77 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
78 $this->parent
->getTextBox( array(
79 'var' => 'wgPasswordSender',
80 'label' => 'config-email-sender'
82 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
83 $this->parent
->getCheckBox( array(
84 'var' => 'wgEnableUserEmail',
85 'label' => 'config-email-user',
87 $this->parent
->getHelpBox( 'config-email-user-help' ) .
88 $this->parent
->getCheckBox( array(
89 'var' => 'wgEnotifUserTalk',
90 'label' => 'config-email-usertalk',
92 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
93 $this->parent
->getCheckBox( array(
94 'var' => 'wgEnotifWatchlist',
95 'label' => 'config-email-watchlist',
97 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
98 $this->parent
->getCheckBox( array(
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', $skins );
111 $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent
->getDefaultSkin( $skinNames ) );
114 $radioButtons = $this->parent
->getRadioElements( array(
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 ) {
123 '<div class="config-skins-item">' .
124 $this->parent
->getCheckBox( array(
125 'var' => "skin-$skin",
127 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
129 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
134 $this->parent
->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
135 Html
::hidden( 'config_wgDefaultSkin', $chosenSkinName );
138 $skinHtml .= $this->parent
->getHelpBox( 'config-skins-help' ) .
139 $this->getFieldSetEnd();
140 $this->addHTML( $skinHtml );
142 $extensions = $this->parent
->findExtensions();
145 $extHtml = $this->getFieldSetStart( 'config-extensions' );
147 foreach ( $extensions as $ext ) {
148 $extHtml .= $this->parent
->getCheckBox( array(
154 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
155 $this->getFieldSetEnd();
156 $this->addHTML( $extHtml );
159 // Having / in paths in Windows looks funny :)
160 $this->setVar( 'wgDeletedDirectory',
162 '/', DIRECTORY_SEPARATOR
,
163 $this->getVar( 'wgDeletedDirectory' )
167 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
170 $this->getFieldSetStart( 'config-upload-settings' ) .
171 $this->parent
->getCheckBox( array(
172 'var' => 'wgEnableUploads',
173 'label' => 'config-upload-enable',
174 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
175 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
177 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
178 $this->parent
->getTextBox( array(
179 'var' => 'wgDeletedDirectory',
180 'label' => 'config-upload-deleted',
181 'attribs' => array( 'dir' => 'ltr' ),
182 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
185 $this->parent
->getTextBox( array(
187 'label' => 'config-logo',
188 'attribs' => array( 'dir' => 'ltr' ),
189 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
193 $this->parent
->getCheckBox( array(
194 'var' => 'wgUseInstantCommons',
195 'label' => 'config-instantcommons',
196 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
198 $this->getFieldSetEnd()
201 $caches = array( 'none' );
202 $cachevalDefault = 'none';
204 if ( count( $this->getVar( '_Caches' ) ) ) {
205 // A CACHE_ACCEL implementation is available
207 $cachevalDefault = 'accel';
209 $caches[] = 'memcached';
211 // We'll hide/show this on demand when the value changes, see config.js.
212 $cacheval = $this->getVar( '_MainCacheType' );
214 // We need to set a default here; but don't hardcode it
215 // or we lose it every time we reload the page for validation
217 $cacheval = $cachevalDefault;
219 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
222 $this->getFieldSetStart( 'config-advanced-settings' ) .
223 # Object cache settings
224 // getRadioSet() builds a set of labeled radio buttons.
225 // For grep: The following messages are used as the item labels:
226 // config-cache-none, config-cache-accel, config-cache-memcached
227 $this->parent
->getRadioSet( array(
228 'var' => '_MainCacheType',
229 'label' => 'config-cache-options',
230 'itemLabelPrefix' => 'config-cache-',
232 'value' => $cacheval,
234 $this->parent
->getHelpBox( 'config-cache-help' ) .
235 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
236 $this->parent
->getTextArea( array(
237 'var' => '_MemCachedServers',
238 'label' => 'config-memcached-servers',
239 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
242 $this->getFieldSetEnd()
252 public function getCCPartnerUrl() {
253 $server = $this->getVar( 'wgServer' );
254 $exitUrl = $server . $this->parent
->getUrl( array(
256 'SubmitCC' => 'indeed',
257 'config__LicenseCode' => 'cc',
258 'config_wgRightsUrl' => '[license_url]',
259 'config_wgRightsText' => '[license_name]',
260 'config_wgRightsIcon' => '[license_button]',
262 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
263 '/mw-config/config-cc.css';
264 $iframeUrl = '//creativecommons.org/license/?' .
266 'partner' => 'MediaWiki',
267 'exit_url' => $exitUrl,
268 'lang' => $this->getVar( '_UserLang' ),
269 'stylesheet' => $styleUrl,
278 public function getCCChooser() {
279 $iframeAttribs = array(
280 'class' => 'config-cc-iframe',
281 'name' => 'config-cc-iframe',
282 'id' => 'config-cc-iframe',
287 if ( $this->getVar( '_CCDone' ) ) {
288 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
290 $iframeAttribs['src'] = $this->getCCPartnerUrl();
292 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
294 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
295 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
302 public function getCCDoneBox() {
303 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
304 // If you change this height, also change it in config.css
305 $expandJs = str_replace( '$1', '54em', $js );
306 $reduceJs = str_replace( '$1', '70px', $js );
309 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
311 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
313 "<p style=\"text-align: center;\">" .
316 'href' => $this->getCCPartnerUrl(),
317 'onclick' => $expandJs,
319 wfMessage( 'config-cc-again' )->text()
323 # Reduce the wrapper div height
324 htmlspecialchars( $reduceJs ) .
329 public function submitCC() {
330 $newValues = $this->parent
->setVarsFromRequest(
331 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
332 if ( count( $newValues ) != 3 ) {
333 $this->parent
->showError( 'config-cc-error' );
337 $this->setVar( '_CCDone', true );
338 $this->addHTML( $this->getCCDoneBox() );
342 * If the user skips this installer page, we still need to set up the default skins, but ignore
347 public function submitSkins() {
348 $skins = $this->parent
->findExtensions( 'skins' );
349 $this->parent
->setVar( '_Skins', $skins );
352 $skinNames = array_map( 'strtolower', $skins );
353 $this->parent
->setVar( 'wgDefaultSkin', $this->parent
->getDefaultSkin( $skinNames ) );
362 public function submit() {
363 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
364 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
365 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
366 'wgEmailAuthentication', '_MainCacheType', '_MemCachedServers',
367 'wgUseInstantCommons', 'wgDefaultSkin' ) );
371 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent
->rightsProfiles
) ) {
372 reset( $this->parent
->rightsProfiles
);
373 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
376 $code = $this->getVar( '_LicenseCode' );
377 if ( $code == 'cc-choose' ) {
378 if ( !$this->getVar( '_CCDone' ) ) {
379 $this->parent
->showError( 'config-cc-not-chosen' );
382 } elseif ( array_key_exists( $code, $this->parent
->licenses
) ) {
384 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
385 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
386 // config-license-cc-choose
387 $entry = $this->parent
->licenses
[$code];
388 if ( isset( $entry['text'] ) ) {
389 $this->setVar( 'wgRightsText', $entry['text'] );
391 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
393 $this->setVar( 'wgRightsUrl', $entry['url'] );
394 $this->setVar( 'wgRightsIcon', $entry['icon'] );
396 $this->setVar( 'wgRightsText', '' );
397 $this->setVar( 'wgRightsUrl', '' );
398 $this->setVar( 'wgRightsIcon', '' );
401 $skinsAvailable = $this->parent
->findExtensions( 'skins' );
402 $skinsToInstall = array();
403 foreach ( $skinsAvailable as $skin ) {
404 $this->parent
->setVarsFromRequest( array( "skin-$skin" ) );
405 if ( $this->getVar( "skin-$skin" ) ) {
406 $skinsToInstall[] = $skin;
409 $this->parent
->setVar( '_Skins', $skinsToInstall );
411 if ( !$skinsToInstall && $skinsAvailable ) {
412 $this->parent
->showError( 'config-skins-must-enable-some' );
415 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
416 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
417 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
418 $this->parent
->showError( 'config-skins-must-enable-default' );
422 $extsAvailable = $this->parent
->findExtensions();
423 $extsToInstall = array();
424 foreach ( $extsAvailable as $ext ) {
425 $this->parent
->setVarsFromRequest( array( "ext-$ext" ) );
426 if ( $this->getVar( "ext-$ext" ) ) {
427 $extsToInstall[] = $ext;
430 $this->parent
->setVar( '_Extensions', $extsToInstall );
432 if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
433 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
434 if ( !$memcServers ) {
435 $this->parent
->showError( 'config-memcache-needservers' );
439 foreach ( $memcServers as $server ) {
440 $memcParts = explode( ":", $server, 2 );
441 if ( !isset( $memcParts[0] )
442 ||
( !IP
::isValid( $memcParts[0] )
443 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
445 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
447 } elseif ( !isset( $memcParts[1] ) ) {
448 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
450 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
451 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );