Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / installer / WebInstallerPage.php
blob87c4a8f063aa4956dc97ededc0f2fefa472dbfe4
1 <?php
2 /**
3 * Base code for web installer pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Deployment
24 /**
25 * Abstract class to define pages for the web installer.
27 * @ingroup Deployment
28 * @since 1.17
30 abstract class WebInstallerPage {
32 /**
33 * The WebInstaller object this WebInstallerPage belongs to.
35 * @var WebInstaller
37 public $parent;
39 abstract public function execute();
41 /**
42 * Constructor.
44 * @param $parent WebInstaller
46 public function __construct( WebInstaller $parent ) {
47 $this->parent = $parent;
50 /**
51 * Is this a slow-running page in the installer? If so, WebInstaller will
52 * set_time_limit(0) before calling execute(). Right now this only applies
53 * to Install and Upgrade pages
54 * @return bool
56 public function isSlow() {
57 return false;
60 public function addHTML( $html ) {
61 $this->parent->output->addHTML( $html );
64 public function startForm() {
65 $this->addHTML(
66 "<div class=\"config-section\">\n" .
67 Html::openElement(
68 'form',
69 array(
70 'method' => 'post',
71 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
73 ) . "\n"
77 public function endForm( $continue = 'continue', $back = 'back' ) {
78 $s = "<div class=\"config-submit\">\n";
79 $id = $this->getId();
81 if ( $id === false ) {
82 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
85 if ( $continue ) {
86 // Fake submit button for enter keypress (bug 26267)
87 // Give grep a chance to find the usages: config-continue
88 $s .= Xml::submitButton( wfMessage( "config-$continue" )->text(),
89 array( 'name' => "enter-$continue", 'style' =>
90 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
93 if ( $back ) {
94 // Give grep a chance to find the usages: config-back
95 $s .= Xml::submitButton( wfMessage( "config-$back" )->text(),
96 array(
97 'name' => "submit-$back",
98 'tabindex' => $this->parent->nextTabIndex()
99 ) ) . "\n";
102 if ( $continue ) {
103 // Give grep a chance to find the usages: config-continue
104 $s .= Xml::submitButton( wfMessage( "config-$continue" )->text(),
105 array(
106 'name' => "submit-$continue",
107 'tabindex' => $this->parent->nextTabIndex(),
108 ) ) . "\n";
111 $s .= "</div></form></div>\n";
112 $this->addHTML( $s );
115 public function getName() {
116 return str_replace( 'WebInstaller_', '', get_class( $this ) );
119 protected function getId() {
120 return array_search( $this->getName(), $this->parent->pageSequence );
123 public function getVar( $var ) {
124 return $this->parent->getVar( $var );
127 public function setVar( $name, $value ) {
128 $this->parent->setVar( $name, $value );
132 * Get the starting tags of a fieldset.
134 * @param string $legend message name
136 * @return string
138 protected function getFieldsetStart( $legend ) {
139 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
143 * Get the end tag of a fieldset.
145 * @return string
147 protected function getFieldsetEnd() {
148 return "</fieldset>\n";
152 * Opens a textarea used to display the progress of a long operation
154 protected function startLiveBox() {
155 $this->addHTML(
156 '<div id="config-spinner" style="display:none;">' .
157 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
158 '<script>jQuery( "#config-spinner" ).show();</script>' .
159 '<div id="config-live-log">' .
160 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
162 $this->parent->output->flush();
166 * Opposite to startLiveBox()
168 protected function endLiveBox() {
169 $this->addHTML( '</textarea></div>
170 <script>jQuery( "#config-spinner" ).hide()</script>' );
171 $this->parent->output->flush();
175 class WebInstaller_Language extends WebInstallerPage {
177 public function execute() {
178 global $wgLang;
179 $r = $this->parent->request;
180 $userLang = $r->getVal( 'uselang' );
181 $contLang = $r->getVal( 'ContLang' );
183 $languages = Language::fetchLanguageNames();
184 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
185 if ( !$lifetime ) {
186 $lifetime = 1440; // PHP default
189 if ( $r->wasPosted() ) {
190 # Do session test
191 if ( $this->parent->getSession( 'test' ) === null ) {
192 $requestTime = $r->getVal( 'LanguageRequestTime' );
193 if ( !$requestTime ) {
194 // The most likely explanation is that the user was knocked back
195 // from another page on POST due to session expiry
196 $msg = 'config-session-expired';
197 } elseif ( time() - $requestTime > $lifetime ) {
198 $msg = 'config-session-expired';
199 } else {
200 $msg = 'config-no-session';
202 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
203 } else {
204 if ( isset( $languages[$userLang] ) ) {
205 $this->setVar( '_UserLang', $userLang );
207 if ( isset( $languages[$contLang] ) ) {
208 $this->setVar( 'wgLanguageCode', $contLang );
210 return 'continue';
212 } elseif ( $this->parent->showSessionWarning ) {
213 # The user was knocked back from another page to the start
214 # This probably indicates a session expiry
215 $this->parent->showError( 'config-session-expired',
216 $wgLang->formatTimePeriod( $lifetime ) );
219 $this->parent->setSession( 'test', true );
221 if ( !isset( $languages[$userLang] ) ) {
222 $userLang = $this->getVar( '_UserLang', 'en' );
224 if ( !isset( $languages[$contLang] ) ) {
225 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
227 $this->startForm();
228 $s = Html::hidden( 'LanguageRequestTime', time() ) .
229 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
230 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
231 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
232 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
233 $this->addHTML( $s );
234 $this->endForm( 'continue', false );
238 * Get a "<select>" for selecting languages.
240 * @param $name
241 * @param $label
242 * @param $selectedCode
243 * @param $helpHtml string
244 * @return string
246 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
247 global $wgDummyLanguageCodes;
249 $s = $helpHtml;
251 $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name,
252 'tabindex' => $this->parent->nextTabIndex() ) ) . "\n";
254 $languages = Language::fetchLanguageNames();
255 ksort( $languages );
256 foreach ( $languages as $code => $lang ) {
257 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
258 continue;
260 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
262 $s .= "\n</select>\n";
263 return $this->parent->label( $label, $name, $s );
268 class WebInstaller_ExistingWiki extends WebInstallerPage {
269 public function execute() {
270 // If there is no LocalSettings.php, continue to the installer welcome page
271 $vars = Installer::getExistingLocalSettings();
272 if ( !$vars ) {
273 return 'skip';
276 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
277 if ( $vars['wgUpgradeKey'] !== false
278 && $this->getVar( '_UpgradeKeySupplied' )
279 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
281 // It's there, so the user is authorized
282 $status = $this->handleExistingUpgrade( $vars );
283 if ( $status->isOK() ) {
284 return 'skip';
285 } else {
286 $this->startForm();
287 $this->parent->showStatusBox( $status );
288 $this->endForm( 'continue' );
289 return 'output';
293 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
294 if ( $vars['wgUpgradeKey'] === false ) {
295 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
296 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
297 $this->parent->generateKeys();
298 $this->setVar( 'wgSecretKey', $secretKey );
299 $this->setVar( '_UpgradeKeySupplied', true );
301 $this->startForm();
302 $this->addHTML( $this->parent->getInfoBox(
303 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
304 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
305 ) );
306 $this->endForm( 'continue' );
307 return 'output';
310 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
312 $r = $this->parent->request;
313 if ( $r->wasPosted() ) {
314 $key = $r->getText( 'config_wgUpgradeKey' );
315 if ( !$key || $key !== $vars['wgUpgradeKey'] ) {
316 $this->parent->showError( 'config-localsettings-badkey' );
317 $this->showKeyForm();
318 return 'output';
320 // Key was OK
321 $status = $this->handleExistingUpgrade( $vars );
322 if ( $status->isOK() ) {
323 return 'continue';
324 } else {
325 $this->parent->showStatusBox( $status );
326 $this->showKeyForm();
327 return 'output';
329 } else {
330 $this->showKeyForm();
331 return 'output';
336 * Show the "enter key" form
338 protected function showKeyForm() {
339 $this->startForm();
340 $this->addHTML(
341 $this->parent->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
342 '<br />' .
343 $this->parent->getTextBox( array(
344 'var' => 'wgUpgradeKey',
345 'label' => 'config-localsettings-key',
346 'attribs' => array( 'autocomplete' => 'off' ),
349 $this->endForm( 'continue' );
352 protected function importVariables( $names, $vars ) {
353 $status = Status::newGood();
354 foreach ( $names as $name ) {
355 if ( !isset( $vars[$name] ) ) {
356 $status->fatal( 'config-localsettings-incomplete', $name );
358 $this->setVar( $name, $vars[$name] );
360 return $status;
364 * Initiate an upgrade of the existing database
365 * @param array $vars Variables from LocalSettings.php and AdminSettings.php
366 * @return Status
368 protected function handleExistingUpgrade( $vars ) {
369 // Check $wgDBtype
370 if ( !isset( $vars['wgDBtype'] ) ||
371 !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
372 return Status::newFatal( 'config-localsettings-connection-error', '' );
375 // Set the relevant variables from LocalSettings.php
376 $requiredVars = array( 'wgDBtype' );
377 $status = $this->importVariables( $requiredVars, $vars );
378 $installer = $this->parent->getDBInstaller();
379 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
380 if ( !$status->isOK() ) {
381 return $status;
384 if ( isset( $vars['wgDBadminuser'] ) ) {
385 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
386 } else {
387 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
389 if ( isset( $vars['wgDBadminpassword'] ) ) {
390 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
391 } else {
392 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
395 // Test the database connection
396 $status = $installer->getConnection();
397 if ( !$status->isOK() ) {
398 // Adjust the error message to explain things correctly
399 $status->replaceMessage( 'config-connection-error',
400 'config-localsettings-connection-error' );
401 return $status;
404 // All good
405 $this->setVar( '_ExistingDBSettings', true );
406 return $status;
410 class WebInstaller_Welcome extends WebInstallerPage {
412 public function execute() {
413 if ( $this->parent->request->wasPosted() ) {
414 if ( $this->getVar( '_Environment' ) ) {
415 return 'continue';
418 $this->parent->output->addWikiText( wfMessage( 'config-welcome' )->plain() );
419 $status = $this->parent->doEnvironmentChecks();
420 if ( $status->isGood() ) {
421 $this->parent->output->addHTML( '<span class="success-message">' .
422 wfMessage( 'config-env-good' )->escaped() . '</span>' );
423 $this->parent->output->addWikiText( wfMessage( 'config-copyright',
424 SpecialVersion::getCopyrightAndAuthorList() )->plain() );
425 $this->startForm();
426 $this->endForm();
427 } else {
428 $this->parent->showStatusMessage( $status );
430 return '';
435 class WebInstaller_DBConnect extends WebInstallerPage {
437 public function execute() {
438 if ( $this->getVar( '_ExistingDBSettings' ) ) {
439 return 'skip';
442 $r = $this->parent->request;
443 if ( $r->wasPosted() ) {
444 $status = $this->submit();
446 if ( $status->isGood() ) {
447 $this->setVar( '_UpgradeDone', false );
448 return 'continue';
449 } else {
450 $this->parent->showStatusBox( $status );
454 $this->startForm();
456 $types = "<ul class=\"config-settings-block\">\n";
457 $settings = '';
458 $defaultType = $this->getVar( 'wgDBtype' );
460 // Give grep a chance to find the usages:
461 // config-support-mysql, config-support-postgres, config-support-oracle, config-support-sqlite
462 $dbSupport = '';
463 foreach ( $this->parent->getDBTypes() as $type ) {
464 $link = DatabaseBase::factory( $type )->getSoftwareLink();
465 $dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
467 $this->addHTML( $this->parent->getInfoBox(
468 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
470 // It's possible that the library for the default DB type is not compiled in.
471 // In that case, instead select the first supported DB type in the list.
472 $compiledDBs = $this->parent->getCompiledDBs();
473 if ( !in_array( $defaultType, $compiledDBs ) ) {
474 $defaultType = $compiledDBs[0];
477 foreach ( $compiledDBs as $type ) {
478 $installer = $this->parent->getDBInstaller( $type );
479 $types .=
480 '<li>' .
481 Xml::radioLabel(
482 $installer->getReadableName(),
483 'DBType',
484 $type,
485 "DBType_$type",
486 $type == $defaultType,
487 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
489 "</li>\n";
491 // Give grep a chance to find the usages:
492 // config-header-mysql, config-header-postgres, config-header-oracle, config-header-sqlite
493 $settings .=
494 Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
495 'class' => 'dbWrapper' ) ) .
496 Html::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
497 $installer->getConnectForm() .
498 "</div>\n";
500 $types .= "</ul><br style=\"clear: left\"/>\n";
502 $this->addHTML(
503 $this->parent->label( 'config-db-type', false, $types ) .
504 $settings
507 $this->endForm();
510 public function submit() {
511 $r = $this->parent->request;
512 $type = $r->getVal( 'DBType' );
513 if ( !$type ) {
514 return Status::newFatal( 'config-invalid-db-type' );
516 $this->setVar( 'wgDBtype', $type );
517 $installer = $this->parent->getDBInstaller( $type );
518 if ( !$installer ) {
519 return Status::newFatal( 'config-invalid-db-type' );
521 return $installer->submitConnectForm();
526 class WebInstaller_Upgrade extends WebInstallerPage {
527 public function isSlow() {
528 return true;
531 public function execute() {
532 if ( $this->getVar( '_UpgradeDone' ) ) {
533 // Allow regeneration of LocalSettings.php, unless we are working
534 // from a pre-existing LocalSettings.php file and we want to avoid
535 // leaking its contents
536 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
537 // Done message acknowledged
538 return 'continue';
539 } else {
540 // Back button click
541 // Show the done message again
542 // Make them click back again if they want to do the upgrade again
543 $this->showDoneMessage();
544 return 'output';
548 // wgDBtype is generally valid here because otherwise the previous page
549 // (connect) wouldn't have declared its happiness
550 $type = $this->getVar( 'wgDBtype' );
551 $installer = $this->parent->getDBInstaller( $type );
553 if ( !$installer->needsUpgrade() ) {
554 return 'skip';
557 if ( $this->parent->request->wasPosted() ) {
558 $installer->preUpgrade();
560 $this->startLiveBox();
561 $result = $installer->doUpgrade();
562 $this->endLiveBox();
564 if ( $result ) {
565 // If they're going to possibly regenerate LocalSettings, we
566 // need to create the upgrade/secret keys. Bug 26481
567 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
568 $this->parent->generateKeys();
570 $this->setVar( '_UpgradeDone', true );
571 $this->showDoneMessage();
572 return 'output';
576 $this->startForm();
577 $this->addHTML( $this->parent->getInfoBox(
578 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
579 $this->endForm();
582 public function showDoneMessage() {
583 $this->startForm();
584 $regenerate = !$this->getVar( '_ExistingDBSettings' );
585 if ( $regenerate ) {
586 $msg = 'config-upgrade-done';
587 } else {
588 $msg = 'config-upgrade-done-no-regenerate';
590 $this->parent->disableLinkPopups();
591 $this->addHTML(
592 $this->parent->getInfoBox(
593 wfMessage( $msg,
594 $this->getVar( 'wgServer' ) .
595 $this->getVar( 'wgScriptPath' ) . '/index' .
596 $this->getVar( 'wgScriptExtension' )
597 )->plain(), 'tick-32.png'
600 $this->parent->restoreLinkPopups();
601 $this->endForm( $regenerate ? 'regenerate' : false, false );
606 class WebInstaller_DBSettings extends WebInstallerPage {
608 public function execute() {
609 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
611 $r = $this->parent->request;
612 if ( $r->wasPosted() ) {
613 $status = $installer->submitSettingsForm();
614 if ( $status === false ) {
615 return 'skip';
616 } elseif ( $status->isGood() ) {
617 return 'continue';
618 } else {
619 $this->parent->showStatusBox( $status );
623 $form = $installer->getSettingsForm();
624 if ( $form === false ) {
625 return 'skip';
628 $this->startForm();
629 $this->addHTML( $form );
630 $this->endForm();
635 class WebInstaller_Name extends WebInstallerPage {
637 public function execute() {
638 $r = $this->parent->request;
639 if ( $r->wasPosted() ) {
640 if ( $this->submit() ) {
641 return 'continue';
645 $this->startForm();
647 // Encourage people to not name their site 'MediaWiki' by blanking the
648 // field. I think that was the intent with the original $GLOBALS['wgSitename']
649 // but these two always were the same so had the effect of making the
650 // installer forget $wgSitename when navigating back to this page.
651 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
652 $this->setVar( 'wgSitename', '' );
655 // Set wgMetaNamespace to something valid before we show the form.
656 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
657 $metaNS = $this->getVar( 'wgMetaNamespace' );
658 $this->setVar(
659 'wgMetaNamespace',
660 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
663 $this->addHTML(
664 $this->parent->getTextBox( array(
665 'var' => 'wgSitename',
666 'label' => 'config-site-name',
667 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
668 ) ) .
669 // getRadioSet() builds a set of labeled radio buttons.
670 // For grep: The following messages are used as the item labels:
671 // config-ns-site-name, config-ns-generic, config-ns-other
672 $this->parent->getRadioSet( array(
673 'var' => '_NamespaceType',
674 'label' => 'config-project-namespace',
675 'itemLabelPrefix' => 'config-ns-',
676 'values' => array( 'site-name', 'generic', 'other' ),
677 'commonAttribs' => array( 'class' => 'enableForOther',
678 'rel' => 'config_wgMetaNamespace' ),
679 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
680 ) ) .
681 $this->parent->getTextBox( array(
682 'var' => 'wgMetaNamespace',
683 'label' => '', //TODO: Needs a label?
684 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
686 ) ) .
687 $this->getFieldSetStart( 'config-admin-box' ) .
688 $this->parent->getTextBox( array(
689 'var' => '_AdminName',
690 'label' => 'config-admin-name',
691 'help' => $this->parent->getHelpBox( 'config-admin-help' )
692 ) ) .
693 $this->parent->getPasswordBox( array(
694 'var' => '_AdminPassword',
695 'label' => 'config-admin-password',
696 ) ) .
697 $this->parent->getPasswordBox( array(
698 'var' => '_AdminPassword2',
699 'label' => 'config-admin-password-confirm'
700 ) ) .
701 $this->parent->getTextBox( array(
702 'var' => '_AdminEmail',
703 'label' => 'config-admin-email',
704 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
705 ) ) .
706 $this->parent->getCheckBox( array(
707 'var' => '_Subscribe',
708 'label' => 'config-subscribe',
709 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
710 ) ) .
711 $this->getFieldSetEnd() .
712 $this->parent->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
713 // getRadioSet() builds a set of labeled radio buttons.
714 // For grep: The following messages are used as the item labels:
715 // config-optional-continue, config-optional-skip
716 $this->parent->getRadioSet( array(
717 'var' => '_SkipOptional',
718 'itemLabelPrefix' => 'config-optional-',
719 'values' => array( 'continue', 'skip' )
723 // Restore the default value
724 $this->setVar( 'wgMetaNamespace', $metaNS );
726 $this->endForm();
727 return 'output';
730 public function submit() {
731 $retVal = true;
732 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
733 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
734 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
736 // Validate site name
737 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
738 $this->parent->showError( 'config-site-name-blank' );
739 $retVal = false;
742 // Fetch namespace
743 $nsType = $this->getVar( '_NamespaceType' );
744 if ( $nsType == 'site-name' ) {
745 $name = $this->getVar( 'wgSitename' );
746 // Sanitize for namespace
747 // This algorithm should match the JS one in WebInstallerOutput.php
748 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
749 $name = str_replace( '&', '&amp;', $name );
750 $name = preg_replace( '/__+/', '_', $name );
751 $name = ucfirst( trim( $name, '_' ) );
752 } elseif ( $nsType == 'generic' ) {
753 $name = wfMessage( 'config-ns-generic' )->text();
754 } else { // other
755 $name = $this->getVar( 'wgMetaNamespace' );
758 // Validate namespace
759 if ( strpos( $name, ':' ) !== false ) {
760 $good = false;
761 } else {
762 // Title-style validation
763 $title = Title::newFromText( $name );
764 if ( !$title ) {
765 $good = $nsType == 'site-name';
766 } else {
767 $name = $title->getDBkey();
768 $good = true;
771 if ( !$good ) {
772 $this->parent->showError( 'config-ns-invalid', $name );
773 $retVal = false;
776 // Make sure it won't conflict with any existing namespaces
777 global $wgContLang;
778 $nsIndex = $wgContLang->getNsIndex( $name );
779 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
780 $this->parent->showError( 'config-ns-conflict', $name );
781 $retVal = false;
784 $this->setVar( 'wgMetaNamespace', $name );
786 // Validate username for creation
787 $name = $this->getVar( '_AdminName' );
788 if ( strval( $name ) === '' ) {
789 $this->parent->showError( 'config-admin-name-blank' );
790 $cname = $name;
791 $retVal = false;
792 } else {
793 $cname = User::getCanonicalName( $name, 'creatable' );
794 if ( $cname === false ) {
795 $this->parent->showError( 'config-admin-name-invalid', $name );
796 $retVal = false;
797 } else {
798 $this->setVar( '_AdminName', $cname );
802 // Validate password
803 $msg = false;
804 $pwd = $this->getVar( '_AdminPassword' );
805 $user = User::newFromName( $cname );
806 $valid = $user && $user->getPasswordValidity( $pwd );
807 if ( strval( $pwd ) === '' ) {
808 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
809 # This message is more specific and helpful.
810 $msg = 'config-admin-password-blank';
811 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
812 $msg = 'config-admin-password-mismatch';
813 } elseif ( $valid !== true ) {
814 # As of writing this will only catch the username being e.g. 'FOO' and
815 # the password 'foo'
816 $msg = $valid;
818 if ( $msg !== false ) {
819 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
820 $this->setVar( '_AdminPassword', '' );
821 $this->setVar( '_AdminPassword2', '' );
822 $retVal = false;
825 // Validate e-mail if provided
826 $email = $this->getVar( '_AdminEmail' );
827 if ( $email && !Sanitizer::validateEmail( $email ) ) {
828 $this->parent->showError( 'config-admin-error-bademail' );
829 $retVal = false;
831 // If they asked to subscribe to mediawiki-announce but didn't give
832 // an e-mail, show an error. Bug 29332
833 if ( !$email && $this->getVar( '_Subscribe' ) ) {
834 $this->parent->showError( 'config-subscribe-noemail' );
835 $retVal = false;
838 return $retVal;
843 class WebInstaller_Options extends WebInstallerPage {
845 public function execute() {
846 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
847 return 'skip';
849 if ( $this->parent->request->wasPosted() ) {
850 if ( $this->submit() ) {
851 return 'continue';
855 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
856 $this->startForm();
857 $this->addHTML(
858 # User Rights
859 // getRadioSet() builds a set of labeled radio buttons.
860 // For grep: The following messages are used as the item labels:
861 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
862 $this->parent->getRadioSet( array(
863 'var' => '_RightsProfile',
864 'label' => 'config-profile',
865 'itemLabelPrefix' => 'config-profile-',
866 'values' => array_keys( $this->parent->rightsProfiles ),
867 ) ) .
868 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
870 # Licensing
871 // getRadioSet() builds a set of labeled radio buttons.
872 // For grep: The following messages are used as the item labels:
873 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
874 // config-license-cc-0, config-license-pd, config-license-gfdl,
875 // config-license-none, config-license-cc-choose
876 $this->parent->getRadioSet( array(
877 'var' => '_LicenseCode',
878 'label' => 'config-license',
879 'itemLabelPrefix' => 'config-license-',
880 'values' => array_keys( $this->parent->licenses ),
881 'commonAttribs' => array( 'class' => 'licenseRadio' ),
882 ) ) .
883 $this->getCCChooser() .
884 $this->parent->getHelpBox( 'config-license-help' ) .
886 # E-mail
887 $this->getFieldSetStart( 'config-email-settings' ) .
888 $this->parent->getCheckBox( array(
889 'var' => 'wgEnableEmail',
890 'label' => 'config-enable-email',
891 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
892 ) ) .
893 $this->parent->getHelpBox( 'config-enable-email-help' ) .
894 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
895 $this->parent->getTextBox( array(
896 'var' => 'wgPasswordSender',
897 'label' => 'config-email-sender'
898 ) ) .
899 $this->parent->getHelpBox( 'config-email-sender-help' ) .
900 $this->parent->getCheckBox( array(
901 'var' => 'wgEnableUserEmail',
902 'label' => 'config-email-user',
903 ) ) .
904 $this->parent->getHelpBox( 'config-email-user-help' ) .
905 $this->parent->getCheckBox( array(
906 'var' => 'wgEnotifUserTalk',
907 'label' => 'config-email-usertalk',
908 ) ) .
909 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
910 $this->parent->getCheckBox( array(
911 'var' => 'wgEnotifWatchlist',
912 'label' => 'config-email-watchlist',
913 ) ) .
914 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
915 $this->parent->getCheckBox( array(
916 'var' => 'wgEmailAuthentication',
917 'label' => 'config-email-auth',
918 ) ) .
919 $this->parent->getHelpBox( 'config-email-auth-help' ) .
920 "</div>" .
921 $this->getFieldSetEnd()
924 $extensions = $this->parent->findExtensions();
926 if ( $extensions ) {
927 $extHtml = $this->getFieldSetStart( 'config-extensions' );
929 foreach ( $extensions as $ext ) {
930 $extHtml .= $this->parent->getCheckBox( array(
931 'var' => "ext-$ext",
932 'rawtext' => $ext,
933 ) );
936 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
937 $this->getFieldSetEnd();
938 $this->addHTML( $extHtml );
941 // Having / in paths in Windows looks funny :)
942 $this->setVar( 'wgDeletedDirectory',
943 str_replace(
944 '/', DIRECTORY_SEPARATOR,
945 $this->getVar( 'wgDeletedDirectory' )
948 // If we're using the default, let the user set it relative to $wgScriptPath
949 $curLogo = $this->getVar( 'wgLogo' );
950 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
951 '$wgStylePath/common/images/wiki.png' : $curLogo;
953 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
954 $this->addHTML(
955 # Uploading
956 $this->getFieldSetStart( 'config-upload-settings' ) .
957 $this->parent->getCheckBox( array(
958 'var' => 'wgEnableUploads',
959 'label' => 'config-upload-enable',
960 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
961 'help' => $this->parent->getHelpBox( 'config-upload-help' )
962 ) ) .
963 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
964 $this->parent->getTextBox( array(
965 'var' => 'wgDeletedDirectory',
966 'label' => 'config-upload-deleted',
967 'attribs' => array( 'dir' => 'ltr' ),
968 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
969 ) ) .
970 '</div>' .
971 $this->parent->getTextBox( array(
972 'var' => 'wgLogo',
973 'value' => $logoString,
974 'label' => 'config-logo',
975 'attribs' => array( 'dir' => 'ltr' ),
976 'help' => $this->parent->getHelpBox( 'config-logo-help' )
979 $this->addHTML(
980 $this->parent->getCheckBox( array(
981 'var' => 'wgUseInstantCommons',
982 'label' => 'config-instantcommons',
983 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
984 ) ) .
985 $this->getFieldSetEnd()
988 $caches = array( 'none' );
989 if ( count( $this->getVar( '_Caches' ) ) ) {
990 $caches[] = 'accel';
992 $caches[] = 'memcached';
994 // We'll hide/show this on demand when the value changes, see config.js.
995 $cacheval = $this->getVar( 'wgMainCacheType' );
996 if ( !$cacheval ) {
997 // We need to set a default here; but don't hardcode it
998 // or we lose it every time we reload the page for validation
999 // or going back!
1000 $cacheval = 'none';
1002 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
1003 $this->addHTML(
1004 # Advanced settings
1005 $this->getFieldSetStart( 'config-advanced-settings' ) .
1006 # Object cache settings
1007 // getRadioSet() builds a set of labeled radio buttons.
1008 // For grep: The following messages are used as the item labels:
1009 // config-cache-none, config-cache-accel, config-cache-memcached
1010 $this->parent->getRadioSet( array(
1011 'var' => 'wgMainCacheType',
1012 'label' => 'config-cache-options',
1013 'itemLabelPrefix' => 'config-cache-',
1014 'values' => $caches,
1015 'value' => $cacheval,
1016 ) ) .
1017 $this->parent->getHelpBox( 'config-cache-help' ) .
1018 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1019 $this->parent->getTextArea( array(
1020 'var' => '_MemCachedServers',
1021 'label' => 'config-memcached-servers',
1022 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
1023 ) ) .
1024 '</div>' .
1025 $this->getFieldSetEnd()
1027 $this->endForm();
1031 * @return string
1033 public function getCCPartnerUrl() {
1034 $server = $this->getVar( 'wgServer' );
1035 $exitUrl = $server . $this->parent->getUrl( array(
1036 'page' => 'Options',
1037 'SubmitCC' => 'indeed',
1038 'config__LicenseCode' => 'cc',
1039 'config_wgRightsUrl' => '[license_url]',
1040 'config_wgRightsText' => '[license_name]',
1041 'config_wgRightsIcon' => '[license_button]',
1042 ) );
1043 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
1044 '/skins/common/config-cc.css';
1045 $iframeUrl = 'http://creativecommons.org/license/?' .
1046 wfArrayToCgi( array(
1047 'partner' => 'MediaWiki',
1048 'exit_url' => $exitUrl,
1049 'lang' => $this->getVar( '_UserLang' ),
1050 'stylesheet' => $styleUrl,
1051 ) );
1052 return $iframeUrl;
1055 public function getCCChooser() {
1056 $iframeAttribs = array(
1057 'class' => 'config-cc-iframe',
1058 'name' => 'config-cc-iframe',
1059 'id' => 'config-cc-iframe',
1060 'frameborder' => 0,
1061 'width' => '100%',
1062 'height' => '100%',
1064 if ( $this->getVar( '_CCDone' ) ) {
1065 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1066 } else {
1067 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1069 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
1071 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1072 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1073 "</div>\n";
1076 public function getCCDoneBox() {
1077 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1078 // If you change this height, also change it in config.css
1079 $expandJs = str_replace( '$1', '54em', $js );
1080 $reduceJs = str_replace( '$1', '70px', $js );
1081 return '<p>' .
1082 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1083 '&#160;&#160;' .
1084 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1085 "</p>\n" .
1086 "<p style=\"text-align: center;\">" .
1087 Html::element( 'a',
1088 array(
1089 'href' => $this->getCCPartnerUrl(),
1090 'onclick' => $expandJs,
1092 wfMessage( 'config-cc-again' )->text()
1094 "</p>\n" .
1095 "<script>\n" .
1096 # Reduce the wrapper div height
1097 htmlspecialchars( $reduceJs ) .
1098 "\n" .
1099 "</script>\n";
1102 public function submitCC() {
1103 $newValues = $this->parent->setVarsFromRequest(
1104 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1105 if ( count( $newValues ) != 3 ) {
1106 $this->parent->showError( 'config-cc-error' );
1107 return;
1109 $this->setVar( '_CCDone', true );
1110 $this->addHTML( $this->getCCDoneBox() );
1113 public function submit() {
1114 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1115 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1116 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1117 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1118 'wgUseInstantCommons' ) );
1120 if ( !in_array( $this->getVar( '_RightsProfile' ),
1121 array_keys( $this->parent->rightsProfiles ) ) )
1123 reset( $this->parent->rightsProfiles );
1124 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1127 $code = $this->getVar( '_LicenseCode' );
1128 if ( $code == 'cc-choose' ) {
1129 if ( !$this->getVar( '_CCDone' ) ) {
1130 $this->parent->showError( 'config-cc-not-chosen' );
1131 return false;
1133 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
1134 // Give grep a chance to find the usages:
1135 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1136 // config-license-cc-0, config-license-pd, config-license-gfdl,
1137 // config-license-none, config-license-cc-choose
1138 $entry = $this->parent->licenses[$code];
1139 if ( isset( $entry['text'] ) ) {
1140 $this->setVar( 'wgRightsText', $entry['text'] );
1141 } else {
1142 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1144 $this->setVar( 'wgRightsUrl', $entry['url'] );
1145 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1146 } else {
1147 $this->setVar( 'wgRightsText', '' );
1148 $this->setVar( 'wgRightsUrl', '' );
1149 $this->setVar( 'wgRightsIcon', '' );
1152 $extsAvailable = $this->parent->findExtensions();
1153 $extsToInstall = array();
1154 foreach ( $extsAvailable as $ext ) {
1155 if ( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
1156 $extsToInstall[] = $ext;
1159 $this->parent->setVar( '_Extensions', $extsToInstall );
1161 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1162 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1163 if ( !$memcServers ) {
1164 $this->parent->showError( 'config-memcache-needservers' );
1165 return false;
1168 foreach ( $memcServers as $server ) {
1169 $memcParts = explode( ":", $server, 2 );
1170 if ( !isset( $memcParts[0] )
1171 || ( !IP::isValid( $memcParts[0] )
1172 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1173 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1174 return false;
1175 } elseif ( !isset( $memcParts[1] ) ) {
1176 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1177 return false;
1178 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1179 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1180 return false;
1184 return true;
1189 class WebInstaller_Install extends WebInstallerPage {
1190 public function isSlow() {
1191 return true;
1194 public function execute() {
1195 if ( $this->getVar( '_UpgradeDone' ) ) {
1196 return 'skip';
1197 } elseif ( $this->getVar( '_InstallDone' ) ) {
1198 return 'continue';
1199 } elseif ( $this->parent->request->wasPosted() ) {
1200 $this->startForm();
1201 $this->addHTML( "<ul>" );
1202 $results = $this->parent->performInstallation(
1203 array( $this, 'startStage' ),
1204 array( $this, 'endStage' )
1206 $this->addHTML( "</ul>" );
1207 // PerformInstallation bails on a fatal, so make sure the last item
1208 // completed before giving 'next.' Likewise, only provide back on failure
1209 $lastStep = end( $results );
1210 $continue = $lastStep->isOK() ? 'continue' : false;
1211 $back = $lastStep->isOK() ? false : 'back';
1212 $this->endForm( $continue, $back );
1213 } else {
1214 $this->startForm();
1215 $this->addHTML( $this->parent->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1216 $this->endForm();
1218 return true;
1221 public function startStage( $step ) {
1222 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1223 if ( $step == 'extension-tables' ) {
1224 $this->startLiveBox();
1229 * @param $step
1230 * @param $status Status
1232 public function endStage( $step, $status ) {
1233 if ( $step == 'extension-tables' ) {
1234 $this->endLiveBox();
1236 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1237 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1238 if ( !$status->isOk() ) {
1239 $html = "<span class=\"error\">$html</span>";
1241 $this->addHTML( $html . "</li>\n" );
1242 if ( !$status->isGood() ) {
1243 $this->parent->showStatusBox( $status );
1249 class WebInstaller_Complete extends WebInstallerPage {
1251 public function execute() {
1252 // Pop up a dialog box, to make it difficult for the user to forget
1253 // to download the file
1254 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1255 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1256 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1257 // JS appears to be the only method that works consistently with IE7+
1258 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1259 Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1260 } else {
1261 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1264 $this->startForm();
1265 $this->parent->disableLinkPopups();
1266 $this->addHTML(
1267 $this->parent->getInfoBox(
1268 wfMessage( 'config-install-done',
1269 $lsUrl,
1270 $this->getVar( 'wgServer' ) .
1271 $this->getVar( 'wgScriptPath' ) . '/index' .
1272 $this->getVar( 'wgScriptExtension' ),
1273 '<downloadlink/>'
1274 )->plain(), 'tick-32.png'
1277 $this->addHTML( $this->parent->getInfoBox(
1278 wfMessage( 'config-extension-link' )->text() ) );
1280 $this->parent->restoreLinkPopups();
1281 $this->endForm( false, false );
1285 class WebInstaller_Restart extends WebInstallerPage {
1287 public function execute() {
1288 $r = $this->parent->request;
1289 if ( $r->wasPosted() ) {
1290 $really = $r->getVal( 'submit-restart' );
1291 if ( $really ) {
1292 $this->parent->reset();
1294 return 'continue';
1297 $this->startForm();
1298 $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1299 $this->addHTML( $s );
1300 $this->endForm( 'restart' );
1305 abstract class WebInstaller_Document extends WebInstallerPage {
1307 abstract protected function getFileName();
1309 public function execute() {
1310 $text = $this->getFileContents();
1311 $text = InstallDocFormatter::format( $text );
1312 $this->parent->output->addWikiText( $text );
1313 $this->startForm();
1314 $this->endForm( false );
1317 public function getFileContents() {
1318 $file = __DIR__ . '/../../' . $this->getFileName();
1319 if ( ! file_exists( $file ) ) {
1320 return wfMessage( 'config-nofile', $file )->plain();
1322 return file_get_contents( $file );
1327 class WebInstaller_Readme extends WebInstaller_Document {
1328 protected function getFileName() {
1329 return 'README';
1333 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1334 protected function getFileName() {
1335 global $wgVersion;
1337 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1338 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1341 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1345 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1346 protected function getFileName() {
1347 return 'UPGRADE';
1351 class WebInstaller_Copying extends WebInstaller_Document {
1352 protected function getFileName() {
1353 return 'COPYING';