Support offsets in prefix searching
[mediawiki.git] / includes / installer / WebInstallerPage.php
blob9ecb24b7b79c810a65be8e2debb5de95de21014e
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 /**
40 * @return string
42 abstract public function execute();
44 /**
45 * @param WebInstaller $parent
47 public function __construct( WebInstaller $parent ) {
48 $this->parent = $parent;
51 /**
52 * Is this a slow-running page in the installer? If so, WebInstaller will
53 * set_time_limit(0) before calling execute(). Right now this only applies
54 * to Install and Upgrade pages
56 * @return bool Always false in this default implementation.
58 public function isSlow() {
59 return false;
62 /**
63 * @param string $html
65 public function addHTML( $html ) {
66 $this->parent->output->addHTML( $html );
69 public function startForm() {
70 $this->addHTML(
71 "<div class=\"config-section\">\n" .
72 Html::openElement(
73 'form',
74 array(
75 'method' => 'post',
76 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
78 ) . "\n"
82 /**
83 * @param string|bool $continue
84 * @param string|bool $back
86 public function endForm( $continue = 'continue', $back = 'back' ) {
87 $s = "<div class=\"config-submit\">\n";
88 $id = $this->getId();
90 if ( $id === false ) {
91 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
94 if ( $continue ) {
95 // Fake submit button for enter keypress (bug 26267)
96 // Messages: config-continue, config-restart, config-regenerate
97 $s .= Xml::submitButton(
98 wfMessage( "config-$continue" )->text(),
99 array(
100 'name' => "enter-$continue",
101 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0'
103 ) . "\n";
106 if ( $back ) {
107 // Message: config-back
108 $s .= Xml::submitButton(
109 wfMessage( "config-$back" )->text(),
110 array(
111 'name' => "submit-$back",
112 'tabindex' => $this->parent->nextTabIndex()
114 ) . "\n";
117 if ( $continue ) {
118 // Messages: config-continue, config-restart, config-regenerate
119 $s .= Xml::submitButton(
120 wfMessage( "config-$continue" )->text(),
121 array(
122 'name' => "submit-$continue",
123 'tabindex' => $this->parent->nextTabIndex(),
125 ) . "\n";
128 $s .= "</div></form></div>\n";
129 $this->addHTML( $s );
133 * @return string
135 public function getName() {
136 return str_replace( 'WebInstaller', '', get_class( $this ) );
140 * @return string
142 protected function getId() {
143 return array_search( $this->getName(), $this->parent->pageSequence );
147 * @param string $var
148 * @param mixed $default
150 * @return mixed
152 public function getVar( $var, $default = null ) {
153 return $this->parent->getVar( $var, $default );
157 * @param string $name
158 * @param mixed $value
160 public function setVar( $name, $value ) {
161 $this->parent->setVar( $name, $value );
165 * Get the starting tags of a fieldset.
167 * @param string $legend Message name
169 * @return string
171 protected function getFieldsetStart( $legend ) {
172 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
176 * Get the end tag of a fieldset.
178 * @return string
180 protected function getFieldsetEnd() {
181 return "</fieldset>\n";
185 * Opens a textarea used to display the progress of a long operation
187 protected function startLiveBox() {
188 $this->addHTML(
189 '<div id="config-spinner" style="display:none;">' .
190 '<img src="images/ajax-loader.gif" /></div>' .
191 '<script>jQuery( "#config-spinner" ).show();</script>' .
192 '<div id="config-live-log">' .
193 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
195 $this->parent->output->flush();
199 * Opposite to WebInstallerPage::startLiveBox
201 protected function endLiveBox() {
202 $this->addHTML( '</textarea></div>
203 <script>jQuery( "#config-spinner" ).hide()</script>' );
204 $this->parent->output->flush();
209 class WebInstallerLanguage extends WebInstallerPage {
212 * @return string|null
214 public function execute() {
215 global $wgLang;
216 $r = $this->parent->request;
217 $userLang = $r->getVal( 'uselang' );
218 $contLang = $r->getVal( 'ContLang' );
220 $languages = Language::fetchLanguageNames();
221 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
222 if ( !$lifetime ) {
223 $lifetime = 1440; // PHP default
226 if ( $r->wasPosted() ) {
227 # Do session test
228 if ( $this->parent->getSession( 'test' ) === null ) {
229 $requestTime = $r->getVal( 'LanguageRequestTime' );
230 if ( !$requestTime ) {
231 // The most likely explanation is that the user was knocked back
232 // from another page on POST due to session expiry
233 $msg = 'config-session-expired';
234 } elseif ( time() - $requestTime > $lifetime ) {
235 $msg = 'config-session-expired';
236 } else {
237 $msg = 'config-no-session';
239 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
240 } else {
241 if ( isset( $languages[$userLang] ) ) {
242 $this->setVar( '_UserLang', $userLang );
244 if ( isset( $languages[$contLang] ) ) {
245 $this->setVar( 'wgLanguageCode', $contLang );
248 return 'continue';
250 } elseif ( $this->parent->showSessionWarning ) {
251 # The user was knocked back from another page to the start
252 # This probably indicates a session expiry
253 $this->parent->showError( 'config-session-expired',
254 $wgLang->formatTimePeriod( $lifetime ) );
257 $this->parent->setSession( 'test', true );
259 if ( !isset( $languages[$userLang] ) ) {
260 $userLang = $this->getVar( '_UserLang', 'en' );
262 if ( !isset( $languages[$contLang] ) ) {
263 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
265 $this->startForm();
266 $s = Html::hidden( 'LanguageRequestTime', time() ) .
267 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
268 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
269 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
270 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
271 $this->addHTML( $s );
272 $this->endForm( 'continue', false );
274 return null;
278 * Get a "<select>" for selecting languages.
280 * @param string $name
281 * @param string $label
282 * @param string $selectedCode
283 * @param string $helpHtml
285 * @return string
287 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
288 global $wgDummyLanguageCodes;
290 $s = $helpHtml;
292 $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name,
293 'tabindex' => $this->parent->nextTabIndex() ) ) . "\n";
295 $languages = Language::fetchLanguageNames();
296 ksort( $languages );
297 foreach ( $languages as $code => $lang ) {
298 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
299 continue;
301 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
303 $s .= "\n</select>\n";
305 return $this->parent->label( $label, $name, $s );
310 class WebInstallerExistingWiki extends WebInstallerPage {
313 * @return string
315 public function execute() {
316 // If there is no LocalSettings.php, continue to the installer welcome page
317 $vars = Installer::getExistingLocalSettings();
318 if ( !$vars ) {
319 return 'skip';
322 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
323 if ( $vars['wgUpgradeKey'] !== false
324 && $this->getVar( '_UpgradeKeySupplied' )
325 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey']
327 // It's there, so the user is authorized
328 $status = $this->handleExistingUpgrade( $vars );
329 if ( $status->isOK() ) {
330 return 'skip';
331 } else {
332 $this->startForm();
333 $this->parent->showStatusBox( $status );
334 $this->endForm( 'continue' );
336 return 'output';
340 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
341 if ( $vars['wgUpgradeKey'] === false ) {
342 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
343 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
344 $this->parent->generateKeys();
345 $this->setVar( 'wgSecretKey', $secretKey );
346 $this->setVar( '_UpgradeKeySupplied', true );
348 $this->startForm();
349 $this->addHTML( $this->parent->getInfoBox(
350 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
351 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
352 ) );
353 $this->endForm( 'continue' );
355 return 'output';
358 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
360 $r = $this->parent->request;
361 if ( $r->wasPosted() ) {
362 $key = $r->getText( 'config_wgUpgradeKey' );
363 if ( !$key || $key !== $vars['wgUpgradeKey'] ) {
364 $this->parent->showError( 'config-localsettings-badkey' );
365 $this->showKeyForm();
367 return 'output';
369 // Key was OK
370 $status = $this->handleExistingUpgrade( $vars );
371 if ( $status->isOK() ) {
372 return 'continue';
373 } else {
374 $this->parent->showStatusBox( $status );
375 $this->showKeyForm();
377 return 'output';
379 } else {
380 $this->showKeyForm();
382 return 'output';
387 * Show the "enter key" form
389 protected function showKeyForm() {
390 $this->startForm();
391 $this->addHTML(
392 $this->parent->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
393 '<br />' .
394 $this->parent->getTextBox( array(
395 'var' => 'wgUpgradeKey',
396 'label' => 'config-localsettings-key',
397 'attribs' => array( 'autocomplete' => 'off' ),
400 $this->endForm( 'continue' );
404 * @param string[] $names
405 * @param mixed[] $vars
407 * @return Status
409 protected function importVariables( $names, $vars ) {
410 $status = Status::newGood();
411 foreach ( $names as $name ) {
412 if ( !isset( $vars[$name] ) ) {
413 $status->fatal( 'config-localsettings-incomplete', $name );
415 $this->setVar( $name, $vars[$name] );
418 return $status;
422 * Initiate an upgrade of the existing database
424 * @param mixed[] $vars Variables from LocalSettings.php
426 * @return Status
428 protected function handleExistingUpgrade( $vars ) {
429 // Check $wgDBtype
430 if ( !isset( $vars['wgDBtype'] ) ||
431 !in_array( $vars['wgDBtype'], Installer::getDBTypes() )
433 return Status::newFatal( 'config-localsettings-connection-error', '' );
436 // Set the relevant variables from LocalSettings.php
437 $requiredVars = array( 'wgDBtype' );
438 $status = $this->importVariables( $requiredVars, $vars );
439 $installer = $this->parent->getDBInstaller();
440 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
441 if ( !$status->isOK() ) {
442 return $status;
445 if ( isset( $vars['wgDBadminuser'] ) ) {
446 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
447 } else {
448 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
450 if ( isset( $vars['wgDBadminpassword'] ) ) {
451 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
452 } else {
453 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
456 // Test the database connection
457 $status = $installer->getConnection();
458 if ( !$status->isOK() ) {
459 // Adjust the error message to explain things correctly
460 $status->replaceMessage( 'config-connection-error',
461 'config-localsettings-connection-error' );
463 return $status;
466 // All good
467 $this->setVar( '_ExistingDBSettings', true );
469 return $status;
474 class WebInstallerWelcome extends WebInstallerPage {
477 * @return string
479 public function execute() {
480 if ( $this->parent->request->wasPosted() ) {
481 if ( $this->getVar( '_Environment' ) ) {
482 return 'continue';
485 $this->parent->output->addWikiText( wfMessage( 'config-welcome' )->plain() );
486 $status = $this->parent->doEnvironmentChecks();
487 if ( $status->isGood() ) {
488 $this->parent->output->addHTML( '<span class="success-message">' .
489 wfMessage( 'config-env-good' )->escaped() . '</span>' );
490 $this->parent->output->addWikiText( wfMessage( 'config-copyright',
491 SpecialVersion::getCopyrightAndAuthorList() )->plain() );
492 $this->startForm();
493 $this->endForm();
494 } else {
495 $this->parent->showStatusMessage( $status );
498 return '';
503 class WebInstallerDBConnect extends WebInstallerPage {
506 * @return string|null When string, "skip" or "continue"
508 public function execute() {
509 if ( $this->getVar( '_ExistingDBSettings' ) ) {
510 return 'skip';
513 $r = $this->parent->request;
514 if ( $r->wasPosted() ) {
515 $status = $this->submit();
517 if ( $status->isGood() ) {
518 $this->setVar( '_UpgradeDone', false );
520 return 'continue';
521 } else {
522 $this->parent->showStatusBox( $status );
526 $this->startForm();
528 $types = "<ul class=\"config-settings-block\">\n";
529 $settings = '';
530 $defaultType = $this->getVar( 'wgDBtype' );
532 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle,
533 // config-dbsupport-sqlite, config-dbsupport-mssql
534 $dbSupport = '';
535 foreach ( Installer::getDBTypes() as $type ) {
536 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
538 $this->addHTML( $this->parent->getInfoBox(
539 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
541 // It's possible that the library for the default DB type is not compiled in.
542 // In that case, instead select the first supported DB type in the list.
543 $compiledDBs = $this->parent->getCompiledDBs();
544 if ( !in_array( $defaultType, $compiledDBs ) ) {
545 $defaultType = $compiledDBs[0];
548 foreach ( $compiledDBs as $type ) {
549 $installer = $this->parent->getDBInstaller( $type );
550 $types .=
551 '<li>' .
552 Xml::radioLabel(
553 $installer->getReadableName(),
554 'DBType',
555 $type,
556 "DBType_$type",
557 $type == $defaultType,
558 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
560 "</li>\n";
562 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
563 // config-header-sqlite
564 $settings .= Html::openElement(
565 'div',
566 array(
567 'id' => 'DB_wrapper_' . $type,
568 'class' => 'dbWrapper'
571 Html::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
572 $installer->getConnectForm() .
573 "</div>\n";
576 $types .= "</ul><br style=\"clear: left\"/>\n";
578 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
579 $this->endForm();
581 return null;
585 * @return Status
587 public function submit() {
588 $r = $this->parent->request;
589 $type = $r->getVal( 'DBType' );
590 if ( !$type ) {
591 return Status::newFatal( 'config-invalid-db-type' );
593 $this->setVar( 'wgDBtype', $type );
594 $installer = $this->parent->getDBInstaller( $type );
595 if ( !$installer ) {
596 return Status::newFatal( 'config-invalid-db-type' );
599 return $installer->submitConnectForm();
604 class WebInstallerUpgrade extends WebInstallerPage {
607 * @return bool Always true.
609 public function isSlow() {
610 return true;
614 * @return string|null
616 public function execute() {
617 if ( $this->getVar( '_UpgradeDone' ) ) {
618 // Allow regeneration of LocalSettings.php, unless we are working
619 // from a pre-existing LocalSettings.php file and we want to avoid
620 // leaking its contents
621 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
622 // Done message acknowledged
623 return 'continue';
624 } else {
625 // Back button click
626 // Show the done message again
627 // Make them click back again if they want to do the upgrade again
628 $this->showDoneMessage();
630 return 'output';
634 // wgDBtype is generally valid here because otherwise the previous page
635 // (connect) wouldn't have declared its happiness
636 $type = $this->getVar( 'wgDBtype' );
637 $installer = $this->parent->getDBInstaller( $type );
639 if ( !$installer->needsUpgrade() ) {
640 return 'skip';
643 if ( $this->parent->request->wasPosted() ) {
644 $installer->preUpgrade();
646 $this->startLiveBox();
647 $result = $installer->doUpgrade();
648 $this->endLiveBox();
650 if ( $result ) {
651 // If they're going to possibly regenerate LocalSettings, we
652 // need to create the upgrade/secret keys. Bug 26481
653 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
654 $this->parent->generateKeys();
656 $this->setVar( '_UpgradeDone', true );
657 $this->showDoneMessage();
659 return 'output';
663 $this->startForm();
664 $this->addHTML( $this->parent->getInfoBox(
665 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
666 $this->endForm();
668 return null;
671 public function showDoneMessage() {
672 $this->startForm();
673 $regenerate = !$this->getVar( '_ExistingDBSettings' );
674 if ( $regenerate ) {
675 $msg = 'config-upgrade-done';
676 } else {
677 $msg = 'config-upgrade-done-no-regenerate';
679 $this->parent->disableLinkPopups();
680 $this->addHTML(
681 $this->parent->getInfoBox(
682 wfMessage( $msg,
683 $this->getVar( 'wgServer' ) .
684 $this->getVar( 'wgScriptPath' ) . '/index' .
685 $this->getVar( 'wgScriptExtension' )
686 )->plain(), 'tick-32.png'
689 $this->parent->restoreLinkPopups();
690 $this->endForm( $regenerate ? 'regenerate' : false, false );
695 class WebInstallerDBSettings extends WebInstallerPage {
698 * @return string|null
700 public function execute() {
701 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
703 $r = $this->parent->request;
704 if ( $r->wasPosted() ) {
705 $status = $installer->submitSettingsForm();
706 if ( $status === false ) {
707 return 'skip';
708 } elseif ( $status->isGood() ) {
709 return 'continue';
710 } else {
711 $this->parent->showStatusBox( $status );
715 $form = $installer->getSettingsForm();
716 if ( $form === false ) {
717 return 'skip';
720 $this->startForm();
721 $this->addHTML( $form );
722 $this->endForm();
724 return null;
729 class WebInstallerName extends WebInstallerPage {
732 * @return string
734 public function execute() {
735 $r = $this->parent->request;
736 if ( $r->wasPosted() ) {
737 if ( $this->submit() ) {
738 return 'continue';
742 $this->startForm();
744 // Encourage people to not name their site 'MediaWiki' by blanking the
745 // field. I think that was the intent with the original $GLOBALS['wgSitename']
746 // but these two always were the same so had the effect of making the
747 // installer forget $wgSitename when navigating back to this page.
748 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
749 $this->setVar( 'wgSitename', '' );
752 // Set wgMetaNamespace to something valid before we show the form.
753 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
754 $metaNS = $this->getVar( 'wgMetaNamespace' );
755 $this->setVar(
756 'wgMetaNamespace',
757 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
760 $this->addHTML(
761 $this->parent->getTextBox( array(
762 'var' => 'wgSitename',
763 'label' => 'config-site-name',
764 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
765 ) ) .
766 // getRadioSet() builds a set of labeled radio buttons.
767 // For grep: The following messages are used as the item labels:
768 // config-ns-site-name, config-ns-generic, config-ns-other
769 $this->parent->getRadioSet( array(
770 'var' => '_NamespaceType',
771 'label' => 'config-project-namespace',
772 'itemLabelPrefix' => 'config-ns-',
773 'values' => array( 'site-name', 'generic', 'other' ),
774 'commonAttribs' => array( 'class' => 'enableForOther',
775 'rel' => 'config_wgMetaNamespace' ),
776 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
777 ) ) .
778 $this->parent->getTextBox( array(
779 'var' => 'wgMetaNamespace',
780 'label' => '', // @todo Needs a label?
781 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' )
782 ) ) .
783 $this->getFieldSetStart( 'config-admin-box' ) .
784 $this->parent->getTextBox( array(
785 'var' => '_AdminName',
786 'label' => 'config-admin-name',
787 'help' => $this->parent->getHelpBox( 'config-admin-help' )
788 ) ) .
789 $this->parent->getPasswordBox( array(
790 'var' => '_AdminPassword',
791 'label' => 'config-admin-password',
792 ) ) .
793 $this->parent->getPasswordBox( array(
794 'var' => '_AdminPasswordConfirm',
795 'label' => 'config-admin-password-confirm'
796 ) ) .
797 $this->parent->getTextBox( array(
798 'var' => '_AdminEmail',
799 'attribs' => array(
800 'dir' => 'ltr',
802 'label' => 'config-admin-email',
803 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
804 ) ) .
805 $this->parent->getCheckBox( array(
806 'var' => '_Subscribe',
807 'label' => 'config-subscribe',
808 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
809 ) ) .
810 $this->getFieldSetEnd() .
811 $this->parent->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
812 // getRadioSet() builds a set of labeled radio buttons.
813 // For grep: The following messages are used as the item labels:
814 // config-optional-continue, config-optional-skip
815 $this->parent->getRadioSet( array(
816 'var' => '_SkipOptional',
817 'itemLabelPrefix' => 'config-optional-',
818 'values' => array( 'continue', 'skip' )
822 // Restore the default value
823 $this->setVar( 'wgMetaNamespace', $metaNS );
825 $this->endForm();
827 return 'output';
831 * @return bool
833 public function submit() {
834 $retVal = true;
835 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
836 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
837 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
839 // Validate site name
840 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
841 $this->parent->showError( 'config-site-name-blank' );
842 $retVal = false;
845 // Fetch namespace
846 $nsType = $this->getVar( '_NamespaceType' );
847 if ( $nsType == 'site-name' ) {
848 $name = $this->getVar( 'wgSitename' );
849 // Sanitize for namespace
850 // This algorithm should match the JS one in WebInstallerOutput.php
851 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
852 $name = str_replace( '&', '&amp;', $name );
853 $name = preg_replace( '/__+/', '_', $name );
854 $name = ucfirst( trim( $name, '_' ) );
855 } elseif ( $nsType == 'generic' ) {
856 $name = wfMessage( 'config-ns-generic' )->text();
857 } else { // other
858 $name = $this->getVar( 'wgMetaNamespace' );
861 // Validate namespace
862 if ( strpos( $name, ':' ) !== false ) {
863 $good = false;
864 } else {
865 // Title-style validation
866 $title = Title::newFromText( $name );
867 if ( !$title ) {
868 $good = $nsType == 'site-name';
869 } else {
870 $name = $title->getDBkey();
871 $good = true;
874 if ( !$good ) {
875 $this->parent->showError( 'config-ns-invalid', $name );
876 $retVal = false;
879 // Make sure it won't conflict with any existing namespaces
880 global $wgContLang;
881 $nsIndex = $wgContLang->getNsIndex( $name );
882 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
883 $this->parent->showError( 'config-ns-conflict', $name );
884 $retVal = false;
887 $this->setVar( 'wgMetaNamespace', $name );
889 // Validate username for creation
890 $name = $this->getVar( '_AdminName' );
891 if ( strval( $name ) === '' ) {
892 $this->parent->showError( 'config-admin-name-blank' );
893 $cname = $name;
894 $retVal = false;
895 } else {
896 $cname = User::getCanonicalName( $name, 'creatable' );
897 if ( $cname === false ) {
898 $this->parent->showError( 'config-admin-name-invalid', $name );
899 $retVal = false;
900 } else {
901 $this->setVar( '_AdminName', $cname );
905 // Validate password
906 $msg = false;
907 $pwd = $this->getVar( '_AdminPassword' );
908 $user = User::newFromName( $cname );
909 if ( $user ) {
910 $valid = $user->getPasswordValidity( $pwd );
911 } else {
912 $valid = 'config-admin-name-invalid';
914 if ( strval( $pwd ) === '' ) {
915 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
916 # This message is more specific and helpful.
917 $msg = 'config-admin-password-blank';
918 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
919 $msg = 'config-admin-password-mismatch';
920 } elseif ( $valid !== true ) {
921 $msg = $valid;
923 if ( $msg !== false ) {
924 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
925 $this->setVar( '_AdminPassword', '' );
926 $this->setVar( '_AdminPasswordConfirm', '' );
927 $retVal = false;
930 // Validate e-mail if provided
931 $email = $this->getVar( '_AdminEmail' );
932 if ( $email && !Sanitizer::validateEmail( $email ) ) {
933 $this->parent->showError( 'config-admin-error-bademail' );
934 $retVal = false;
936 // If they asked to subscribe to mediawiki-announce but didn't give
937 // an e-mail, show an error. Bug 29332
938 if ( !$email && $this->getVar( '_Subscribe' ) ) {
939 $this->parent->showError( 'config-subscribe-noemail' );
940 $retVal = false;
943 return $retVal;
948 class WebInstallerOptions extends WebInstallerPage {
951 * @return string|null
953 public function execute() {
954 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
955 $this->submitSkins();
956 return 'skip';
958 if ( $this->parent->request->wasPosted() ) {
959 if ( $this->submit() ) {
960 return 'continue';
964 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
965 $this->startForm();
966 $this->addHTML(
967 # User Rights
968 // getRadioSet() builds a set of labeled radio buttons.
969 // For grep: The following messages are used as the item labels:
970 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
971 $this->parent->getRadioSet( array(
972 'var' => '_RightsProfile',
973 'label' => 'config-profile',
974 'itemLabelPrefix' => 'config-profile-',
975 'values' => array_keys( $this->parent->rightsProfiles ),
976 ) ) .
977 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
979 # Licensing
980 // getRadioSet() builds a set of labeled radio buttons.
981 // For grep: The following messages are used as the item labels:
982 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
983 // config-license-cc-0, config-license-pd, config-license-gfdl,
984 // config-license-none, config-license-cc-choose
985 $this->parent->getRadioSet( array(
986 'var' => '_LicenseCode',
987 'label' => 'config-license',
988 'itemLabelPrefix' => 'config-license-',
989 'values' => array_keys( $this->parent->licenses ),
990 'commonAttribs' => array( 'class' => 'licenseRadio' ),
991 ) ) .
992 $this->getCCChooser() .
993 $this->parent->getHelpBox( 'config-license-help' ) .
995 # E-mail
996 $this->getFieldSetStart( 'config-email-settings' ) .
997 $this->parent->getCheckBox( array(
998 'var' => 'wgEnableEmail',
999 'label' => 'config-enable-email',
1000 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
1001 ) ) .
1002 $this->parent->getHelpBox( 'config-enable-email-help' ) .
1003 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
1004 $this->parent->getTextBox( array(
1005 'var' => 'wgPasswordSender',
1006 'label' => 'config-email-sender'
1007 ) ) .
1008 $this->parent->getHelpBox( 'config-email-sender-help' ) .
1009 $this->parent->getCheckBox( array(
1010 'var' => 'wgEnableUserEmail',
1011 'label' => 'config-email-user',
1012 ) ) .
1013 $this->parent->getHelpBox( 'config-email-user-help' ) .
1014 $this->parent->getCheckBox( array(
1015 'var' => 'wgEnotifUserTalk',
1016 'label' => 'config-email-usertalk',
1017 ) ) .
1018 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
1019 $this->parent->getCheckBox( array(
1020 'var' => 'wgEnotifWatchlist',
1021 'label' => 'config-email-watchlist',
1022 ) ) .
1023 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
1024 $this->parent->getCheckBox( array(
1025 'var' => 'wgEmailAuthentication',
1026 'label' => 'config-email-auth',
1027 ) ) .
1028 $this->parent->getHelpBox( 'config-email-auth-help' ) .
1029 "</div>" .
1030 $this->getFieldSetEnd()
1033 $skins = $this->parent->findExtensions( 'skins' );
1034 $skinHtml = $this->getFieldSetStart( 'config-skins' );
1036 if ( $skins ) {
1037 $skinNames = array_map( 'strtolower', $skins );
1039 $radioButtons = $this->parent->getRadioElements( array(
1040 'var' => 'wgDefaultSkin',
1041 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
1042 'values' => $skinNames,
1043 'value' => $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) ),
1044 ) );
1046 foreach ( $skins as $skin ) {
1047 $skinHtml .=
1048 '<div class="config-skins-item">' .
1049 $this->parent->getCheckBox( array(
1050 'var' => "skin-$skin",
1051 'rawtext' => $skin,
1052 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
1053 ) ) .
1054 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
1055 '</div>';
1057 } else {
1058 $skinHtml .= $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() );
1061 $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
1062 $this->getFieldSetEnd();
1063 $this->addHTML( $skinHtml );
1065 $extensions = $this->parent->findExtensions();
1067 if ( $extensions ) {
1068 $extHtml = $this->getFieldSetStart( 'config-extensions' );
1070 foreach ( $extensions as $ext ) {
1071 $extHtml .= $this->parent->getCheckBox( array(
1072 'var' => "ext-$ext",
1073 'rawtext' => $ext,
1074 ) );
1077 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
1078 $this->getFieldSetEnd();
1079 $this->addHTML( $extHtml );
1082 // Having / in paths in Windows looks funny :)
1083 $this->setVar( 'wgDeletedDirectory',
1084 str_replace(
1085 '/', DIRECTORY_SEPARATOR,
1086 $this->getVar( 'wgDeletedDirectory' )
1090 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
1091 $this->addHTML(
1092 # Uploading
1093 $this->getFieldSetStart( 'config-upload-settings' ) .
1094 $this->parent->getCheckBox( array(
1095 'var' => 'wgEnableUploads',
1096 'label' => 'config-upload-enable',
1097 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
1098 'help' => $this->parent->getHelpBox( 'config-upload-help' )
1099 ) ) .
1100 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
1101 $this->parent->getTextBox( array(
1102 'var' => 'wgDeletedDirectory',
1103 'label' => 'config-upload-deleted',
1104 'attribs' => array( 'dir' => 'ltr' ),
1105 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
1106 ) ) .
1107 '</div>' .
1108 $this->parent->getTextBox( array(
1109 'var' => 'wgLogo',
1110 'label' => 'config-logo',
1111 'attribs' => array( 'dir' => 'ltr' ),
1112 'help' => $this->parent->getHelpBox( 'config-logo-help' )
1115 $this->addHTML(
1116 $this->parent->getCheckBox( array(
1117 'var' => 'wgUseInstantCommons',
1118 'label' => 'config-instantcommons',
1119 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
1120 ) ) .
1121 $this->getFieldSetEnd()
1124 $caches = array( 'none' );
1125 if ( count( $this->getVar( '_Caches' ) ) ) {
1126 $caches[] = 'accel';
1128 $caches[] = 'memcached';
1130 // We'll hide/show this on demand when the value changes, see config.js.
1131 $cacheval = $this->getVar( 'wgMainCacheType' );
1132 if ( !$cacheval ) {
1133 // We need to set a default here; but don't hardcode it
1134 // or we lose it every time we reload the page for validation
1135 // or going back!
1136 $cacheval = 'none';
1138 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
1139 $this->addHTML(
1140 # Advanced settings
1141 $this->getFieldSetStart( 'config-advanced-settings' ) .
1142 # Object cache settings
1143 // getRadioSet() builds a set of labeled radio buttons.
1144 // For grep: The following messages are used as the item labels:
1145 // config-cache-none, config-cache-accel, config-cache-memcached
1146 $this->parent->getRadioSet( array(
1147 'var' => 'wgMainCacheType',
1148 'label' => 'config-cache-options',
1149 'itemLabelPrefix' => 'config-cache-',
1150 'values' => $caches,
1151 'value' => $cacheval,
1152 ) ) .
1153 $this->parent->getHelpBox( 'config-cache-help' ) .
1154 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1155 $this->parent->getTextArea( array(
1156 'var' => '_MemCachedServers',
1157 'label' => 'config-memcached-servers',
1158 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
1159 ) ) .
1160 '</div>' .
1161 $this->getFieldSetEnd()
1163 $this->endForm();
1165 return null;
1169 * @return string
1171 public function getCCPartnerUrl() {
1172 $server = $this->getVar( 'wgServer' );
1173 $exitUrl = $server . $this->parent->getUrl( array(
1174 'page' => 'Options',
1175 'SubmitCC' => 'indeed',
1176 'config__LicenseCode' => 'cc',
1177 'config_wgRightsUrl' => '[license_url]',
1178 'config_wgRightsText' => '[license_name]',
1179 'config_wgRightsIcon' => '[license_button]',
1180 ) );
1181 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
1182 '/mw-config/config-cc.css';
1183 $iframeUrl = 'http://creativecommons.org/license/?' .
1184 wfArrayToCgi( array(
1185 'partner' => 'MediaWiki',
1186 'exit_url' => $exitUrl,
1187 'lang' => $this->getVar( '_UserLang' ),
1188 'stylesheet' => $styleUrl,
1189 ) );
1191 return $iframeUrl;
1195 * @return string
1197 public function getCCChooser() {
1198 $iframeAttribs = array(
1199 'class' => 'config-cc-iframe',
1200 'name' => 'config-cc-iframe',
1201 'id' => 'config-cc-iframe',
1202 'frameborder' => 0,
1203 'width' => '100%',
1204 'height' => '100%',
1206 if ( $this->getVar( '_CCDone' ) ) {
1207 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1208 } else {
1209 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1211 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
1213 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1214 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1215 "</div>\n";
1219 * @return string
1221 public function getCCDoneBox() {
1222 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1223 // If you change this height, also change it in config.css
1224 $expandJs = str_replace( '$1', '54em', $js );
1225 $reduceJs = str_replace( '$1', '70px', $js );
1227 return '<p>' .
1228 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1229 '&#160;&#160;' .
1230 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1231 "</p>\n" .
1232 "<p style=\"text-align: center;\">" .
1233 Html::element( 'a',
1234 array(
1235 'href' => $this->getCCPartnerUrl(),
1236 'onclick' => $expandJs,
1238 wfMessage( 'config-cc-again' )->text()
1240 "</p>\n" .
1241 "<script>\n" .
1242 # Reduce the wrapper div height
1243 htmlspecialchars( $reduceJs ) .
1244 "\n" .
1245 "</script>\n";
1248 public function submitCC() {
1249 $newValues = $this->parent->setVarsFromRequest(
1250 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1251 if ( count( $newValues ) != 3 ) {
1252 $this->parent->showError( 'config-cc-error' );
1254 return;
1256 $this->setVar( '_CCDone', true );
1257 $this->addHTML( $this->getCCDoneBox() );
1261 * If the user skips this installer page, we still need to set up the default skins, but ignore
1262 * everything else.
1264 * @return bool
1266 public function submitSkins() {
1267 $skins = $this->parent->findExtensions( 'skins' );
1268 $this->parent->setVar( '_Skins', $skins );
1270 if ( $skins ) {
1271 $skinNames = array_map( 'strtolower', $skins );
1272 $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
1275 return true;
1279 * @return bool
1281 public function submit() {
1282 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1283 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1284 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1285 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1286 'wgUseInstantCommons', 'wgDefaultSkin' ) );
1288 $retVal = true;
1290 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
1291 reset( $this->parent->rightsProfiles );
1292 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1295 $code = $this->getVar( '_LicenseCode' );
1296 if ( $code == 'cc-choose' ) {
1297 if ( !$this->getVar( '_CCDone' ) ) {
1298 $this->parent->showError( 'config-cc-not-chosen' );
1299 $retVal = false;
1301 } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
1302 // Messages:
1303 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1304 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1305 // config-license-cc-choose
1306 $entry = $this->parent->licenses[$code];
1307 if ( isset( $entry['text'] ) ) {
1308 $this->setVar( 'wgRightsText', $entry['text'] );
1309 } else {
1310 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1312 $this->setVar( 'wgRightsUrl', $entry['url'] );
1313 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1314 } else {
1315 $this->setVar( 'wgRightsText', '' );
1316 $this->setVar( 'wgRightsUrl', '' );
1317 $this->setVar( 'wgRightsIcon', '' );
1320 $skinsAvailable = $this->parent->findExtensions( 'skins' );
1321 $skinsToInstall = array();
1322 foreach ( $skinsAvailable as $skin ) {
1323 $this->parent->setVarsFromRequest( array( "skin-$skin" ) );
1324 if ( $this->getVar( "skin-$skin" ) ) {
1325 $skinsToInstall[] = $skin;
1328 $this->parent->setVar( '_Skins', $skinsToInstall );
1330 if ( !$skinsToInstall && $skinsAvailable ) {
1331 $this->parent->showError( 'config-skins-must-enable-some' );
1332 $retVal = false;
1334 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
1335 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
1336 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
1337 $this->parent->showError( 'config-skins-must-enable-default' );
1338 $retVal = false;
1341 $extsAvailable = $this->parent->findExtensions();
1342 $extsToInstall = array();
1343 foreach ( $extsAvailable as $ext ) {
1344 $this->parent->setVarsFromRequest( array( "ext-$ext" ) );
1345 if ( $this->getVar( "ext-$ext" ) ) {
1346 $extsToInstall[] = $ext;
1349 $this->parent->setVar( '_Extensions', $extsToInstall );
1351 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1352 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1353 if ( !$memcServers ) {
1354 $this->parent->showError( 'config-memcache-needservers' );
1355 $retVal = false;
1358 foreach ( $memcServers as $server ) {
1359 $memcParts = explode( ":", $server, 2 );
1360 if ( !isset( $memcParts[0] )
1361 || ( !IP::isValid( $memcParts[0] )
1362 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1364 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1365 $retVal = false;
1366 } elseif ( !isset( $memcParts[1] ) ) {
1367 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1368 $retVal = false;
1369 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1370 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1371 $retVal = false;
1376 return $retVal;
1381 class WebInstallerInstall extends WebInstallerPage {
1384 * @return bool Always true.
1386 public function isSlow() {
1387 return true;
1391 * @return string|bool
1393 public function execute() {
1394 if ( $this->getVar( '_UpgradeDone' ) ) {
1395 return 'skip';
1396 } elseif ( $this->getVar( '_InstallDone' ) ) {
1397 return 'continue';
1398 } elseif ( $this->parent->request->wasPosted() ) {
1399 $this->startForm();
1400 $this->addHTML( "<ul>" );
1401 $results = $this->parent->performInstallation(
1402 array( $this, 'startStage' ),
1403 array( $this, 'endStage' )
1405 $this->addHTML( "</ul>" );
1406 // PerformInstallation bails on a fatal, so make sure the last item
1407 // completed before giving 'next.' Likewise, only provide back on failure
1408 $lastStep = end( $results );
1409 $continue = $lastStep->isOK() ? 'continue' : false;
1410 $back = $lastStep->isOK() ? false : 'back';
1411 $this->endForm( $continue, $back );
1412 } else {
1413 $this->startForm();
1414 $this->addHTML( $this->parent->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1415 $this->endForm();
1418 return true;
1422 * @param string $step
1424 public function startStage( $step ) {
1425 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1426 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1427 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1428 wfMessage( 'ellipsis' )->escaped() );
1430 if ( $step == 'extension-tables' ) {
1431 $this->startLiveBox();
1436 * @param string $step
1437 * @param Status $status
1439 public function endStage( $step, $status ) {
1440 if ( $step == 'extension-tables' ) {
1441 $this->endLiveBox();
1443 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1444 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1445 if ( !$status->isOk() ) {
1446 $html = "<span class=\"error\">$html</span>";
1448 $this->addHTML( $html . "</li>\n" );
1449 if ( !$status->isGood() ) {
1450 $this->parent->showStatusBox( $status );
1456 class WebInstallerComplete extends WebInstallerPage {
1458 public function execute() {
1459 // Pop up a dialog box, to make it difficult for the user to forget
1460 // to download the file
1461 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1462 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1463 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1465 // JS appears to be the only method that works consistently with IE7+
1466 $this->addHtml( "\n<script>jQuery( function () { location.href = " .
1467 Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1468 } else {
1469 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1472 $this->startForm();
1473 $this->parent->disableLinkPopups();
1474 $this->addHTML(
1475 $this->parent->getInfoBox(
1476 wfMessage( 'config-install-done',
1477 $lsUrl,
1478 $this->getVar( 'wgServer' ) .
1479 $this->getVar( 'wgScriptPath' ) . '/index' .
1480 $this->getVar( 'wgScriptExtension' ),
1481 '<downloadlink/>'
1482 )->plain(), 'tick-32.png'
1485 $this->addHTML( $this->parent->getInfoBox(
1486 wfMessage( 'config-extension-link' )->text() ) );
1488 $this->parent->restoreLinkPopups();
1489 $this->endForm( false, false );
1494 class WebInstallerRestart extends WebInstallerPage {
1497 * @return string|null
1499 public function execute() {
1500 $r = $this->parent->request;
1501 if ( $r->wasPosted() ) {
1502 $really = $r->getVal( 'submit-restart' );
1503 if ( $really ) {
1504 $this->parent->reset();
1507 return 'continue';
1510 $this->startForm();
1511 $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1512 $this->addHTML( $s );
1513 $this->endForm( 'restart' );
1515 return null;
1520 abstract class WebInstallerDocument extends WebInstallerPage {
1523 * @return string
1525 abstract protected function getFileName();
1527 public function execute() {
1528 $text = $this->getFileContents();
1529 $text = InstallDocFormatter::format( $text );
1530 $this->parent->output->addWikiText( $text );
1531 $this->startForm();
1532 $this->endForm( false );
1536 * @return string
1538 public function getFileContents() {
1539 $file = __DIR__ . '/../../' . $this->getFileName();
1540 if ( !file_exists( $file ) ) {
1541 return wfMessage( 'config-nofile', $file )->plain();
1544 return file_get_contents( $file );
1549 class WebInstallerReadme extends WebInstallerDocument {
1552 * @return string
1554 protected function getFileName() {
1555 return 'README';
1560 class WebInstallerReleaseNotes extends WebInstallerDocument {
1563 * @throws MWException
1564 * @return string
1566 protected function getFileName() {
1567 global $wgVersion;
1569 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1570 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1573 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1578 class WebInstallerUpgradeDoc extends WebInstallerDocument {
1581 * @return string
1583 protected function getFileName() {
1584 return 'UPGRADE';
1589 class WebInstallerCopying extends WebInstallerDocument {
1592 * @return string
1594 protected function getFileName() {
1595 return 'COPYING';