9fdee766e66e3b3f2e8da7b782e90b4e17591f86
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
25 * Abstract class to define pages for the web installer.
30 abstract class WebInstallerPage
{
33 * The WebInstaller object this WebInstallerPage belongs to.
42 abstract public function execute();
45 * @param WebInstaller $parent
47 public function __construct( WebInstaller
$parent ) {
48 $this->parent
= $parent;
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() {
65 public function addHTML( $html ) {
66 $this->parent
->output
->addHTML( $html );
69 public function startForm() {
71 "<div class=\"config-section\">\n" .
76 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
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";
90 if ( $id === false ) {
91 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
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(),
100 'name' => "enter-$continue",
101 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0'
107 // Message: config-back
108 $s .= Xml
::submitButton(
109 wfMessage( "config-$back" )->text(),
111 'name' => "submit-$back",
112 'tabindex' => $this->parent
->nextTabIndex()
118 // Messages: config-continue, config-restart, config-regenerate
119 $s .= Xml
::submitButton(
120 wfMessage( "config-$continue" )->text(),
122 'name' => "submit-$continue",
123 'tabindex' => $this->parent
->nextTabIndex(),
128 $s .= "</div></form></div>\n";
129 $this->addHTML( $s );
135 public function getName() {
136 return str_replace( 'WebInstaller', '', get_class( $this ) );
142 protected function getId() {
143 return array_search( $this->getName(), $this->parent
->pageSequence
);
148 * @param mixed $default
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
171 protected function getFieldsetStart( $legend ) {
172 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
176 * Get the end tag of a fieldset.
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() {
189 '<div id="config-spinner" style="display:none;">' .
190 '<img src="../skins/common/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() {
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' ) );
223 $lifetime = 1440; // PHP default
226 if ( $r->wasPosted() ) {
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';
237 $msg = 'config-no-session';
239 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
241 if ( isset( $languages[$userLang] ) ) {
242 $this->setVar( '_UserLang', $userLang );
244 if ( isset( $languages[$contLang] ) ) {
245 $this->setVar( 'wgLanguageCode', $contLang );
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' );
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 );
278 * Get a "<select>" for selecting languages.
280 * @param string $name
281 * @param string $label
282 * @param string $selectedCode
283 * @param string $helpHtml
287 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
288 global $wgDummyLanguageCodes;
292 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
293 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
295 $languages = Language
::fetchLanguageNames();
297 foreach ( $languages as $code => $lang ) {
298 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
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
{
315 public function execute() {
316 // If there is no LocalSettings.php, continue to the installer welcome page
317 $vars = Installer
::getExistingLocalSettings();
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() ) {
333 $this->parent
->showStatusBox( $status );
334 $this->endForm( 'continue' );
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 );
349 $this->addHTML( $this->parent
->getInfoBox(
350 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
351 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
353 $this->endForm( 'continue' );
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();
370 $status = $this->handleExistingUpgrade( $vars );
371 if ( $status->isOK() ) {
374 $this->parent
->showStatusBox( $status );
375 $this->showKeyForm();
380 $this->showKeyForm();
387 * Show the "enter key" form
389 protected function showKeyForm() {
392 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
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
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] );
422 * Initiate an upgrade of the existing database
424 * @param mixed[] $vars Variables from LocalSettings.php
428 protected function handleExistingUpgrade( $vars ) {
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() ) {
445 if ( isset( $vars['wgDBadminuser'] ) ) {
446 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
448 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
450 if ( isset( $vars['wgDBadminpassword'] ) ) {
451 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
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' );
467 $this->setVar( '_ExistingDBSettings', true );
474 class WebInstallerWelcome
extends WebInstallerPage
{
479 public function execute() {
480 if ( $this->parent
->request
->wasPosted() ) {
481 if ( $this->getVar( '_Environment' ) ) {
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() );
495 $this->parent
->showStatusMessage( $status );
503 class WebInstallerDBConnect
extends WebInstallerPage
{
506 * @return string|null When string, "skip" or "continue"
508 public function execute() {
509 if ( $this->getVar( '_ExistingDBSettings' ) ) {
513 $r = $this->parent
->request
;
514 if ( $r->wasPosted() ) {
515 $status = $this->submit();
517 if ( $status->isGood() ) {
518 $this->setVar( '_UpgradeDone', false );
522 $this->parent
->showStatusBox( $status );
528 $types = "<ul class=\"config-settings-block\">\n";
530 $defaultType = $this->getVar( 'wgDBtype' );
532 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle,
533 // config-dbsupport-sqlite, config-dbsupport-mssql
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 );
553 $installer->getReadableName(),
557 $type == $defaultType,
558 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
562 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
563 // config-header-sqlite
564 $settings .= Html
::openElement(
567 'id' => 'DB_wrapper_' . $type,
568 'class' => 'dbWrapper'
571 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
572 $installer->getConnectForm() .
576 $types .= "</ul><br style=\"clear: left\"/>\n";
578 $this->addHTML( $this->parent
->label( 'config-db-type', false, $types ) . $settings );
587 public function submit() {
588 $r = $this->parent
->request
;
589 $type = $r->getVal( 'DBType' );
591 return Status
::newFatal( 'config-invalid-db-type' );
593 $this->setVar( 'wgDBtype', $type );
594 $installer = $this->parent
->getDBInstaller( $type );
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() {
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
626 // Show the done message again
627 // Make them click back again if they want to do the upgrade again
628 $this->showDoneMessage();
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() ) {
643 if ( $this->parent
->request
->wasPosted() ) {
644 $installer->preUpgrade();
646 $this->startLiveBox();
647 $result = $installer->doUpgrade();
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();
664 $this->addHTML( $this->parent
->getInfoBox(
665 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
671 public function showDoneMessage() {
673 $regenerate = !$this->getVar( '_ExistingDBSettings' );
675 $msg = 'config-upgrade-done';
677 $msg = 'config-upgrade-done-no-regenerate';
679 $this->parent
->disableLinkPopups();
681 $this->parent
->getInfoBox(
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 ) {
708 } elseif ( $status->isGood() ) {
711 $this->parent
->showStatusBox( $status );
715 $form = $installer->getSettingsForm();
716 if ( $form === false ) {
721 $this->addHTML( $form );
729 class WebInstallerName
extends WebInstallerPage
{
734 public function execute() {
735 $r = $this->parent
->request
;
736 if ( $r->wasPosted() ) {
737 if ( $this->submit() ) {
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' );
757 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
761 $this->parent
->getTextBox( array(
762 'var' => 'wgSitename',
763 'label' => 'config-site-name',
764 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
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' )
778 $this->parent
->getTextBox( array(
779 'var' => 'wgMetaNamespace',
780 'label' => '', // @todo Needs a label?
781 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' )
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' )
789 $this->parent
->getPasswordBox( array(
790 'var' => '_AdminPassword',
791 'label' => 'config-admin-password',
793 $this->parent
->getPasswordBox( array(
794 'var' => '_AdminPasswordConfirm',
795 'label' => 'config-admin-password-confirm'
797 $this->parent
->getTextBox( array(
798 'var' => '_AdminEmail',
799 'label' => 'config-admin-email',
800 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
802 $this->parent
->getCheckBox( array(
803 'var' => '_Subscribe',
804 'label' => 'config-subscribe',
805 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
807 $this->getFieldSetEnd() .
808 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
809 // getRadioSet() builds a set of labeled radio buttons.
810 // For grep: The following messages are used as the item labels:
811 // config-optional-continue, config-optional-skip
812 $this->parent
->getRadioSet( array(
813 'var' => '_SkipOptional',
814 'itemLabelPrefix' => 'config-optional-',
815 'values' => array( 'continue', 'skip' )
819 // Restore the default value
820 $this->setVar( 'wgMetaNamespace', $metaNS );
830 public function submit() {
832 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
833 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
834 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
836 // Validate site name
837 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
838 $this->parent
->showError( 'config-site-name-blank' );
843 $nsType = $this->getVar( '_NamespaceType' );
844 if ( $nsType == 'site-name' ) {
845 $name = $this->getVar( 'wgSitename' );
846 // Sanitize for namespace
847 // This algorithm should match the JS one in WebInstallerOutput.php
848 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
849 $name = str_replace( '&', '&', $name );
850 $name = preg_replace( '/__+/', '_', $name );
851 $name = ucfirst( trim( $name, '_' ) );
852 } elseif ( $nsType == 'generic' ) {
853 $name = wfMessage( 'config-ns-generic' )->text();
855 $name = $this->getVar( 'wgMetaNamespace' );
858 // Validate namespace
859 if ( strpos( $name, ':' ) !== false ) {
862 // Title-style validation
863 $title = Title
::newFromText( $name );
865 $good = $nsType == 'site-name';
867 $name = $title->getDBkey();
872 $this->parent
->showError( 'config-ns-invalid', $name );
876 // Make sure it won't conflict with any existing namespaces
878 $nsIndex = $wgContLang->getNsIndex( $name );
879 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
880 $this->parent
->showError( 'config-ns-conflict', $name );
884 $this->setVar( 'wgMetaNamespace', $name );
886 // Validate username for creation
887 $name = $this->getVar( '_AdminName' );
888 if ( strval( $name ) === '' ) {
889 $this->parent
->showError( 'config-admin-name-blank' );
893 $cname = User
::getCanonicalName( $name, 'creatable' );
894 if ( $cname === false ) {
895 $this->parent
->showError( 'config-admin-name-invalid', $name );
898 $this->setVar( '_AdminName', $cname );
904 $pwd = $this->getVar( '_AdminPassword' );
905 $user = User
::newFromName( $cname );
907 $valid = $user->getPasswordValidity( $pwd );
909 $valid = 'config-admin-name-invalid';
911 if ( strval( $pwd ) === '' ) {
912 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
913 # This message is more specific and helpful.
914 $msg = 'config-admin-password-blank';
915 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
916 $msg = 'config-admin-password-mismatch';
917 } elseif ( $valid !== true ) {
920 if ( $msg !== false ) {
921 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
922 $this->setVar( '_AdminPassword', '' );
923 $this->setVar( '_AdminPasswordConfirm', '' );
927 // Validate e-mail if provided
928 $email = $this->getVar( '_AdminEmail' );
929 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
930 $this->parent
->showError( 'config-admin-error-bademail' );
933 // If they asked to subscribe to mediawiki-announce but didn't give
934 // an e-mail, show an error. Bug 29332
935 if ( !$email && $this->getVar( '_Subscribe' ) ) {
936 $this->parent
->showError( 'config-subscribe-noemail' );
945 class WebInstallerOptions
extends WebInstallerPage
{
948 * @return string|null
950 public function execute() {
951 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
952 $this->submitSkins();
955 if ( $this->parent
->request
->wasPosted() ) {
956 if ( $this->submit() ) {
961 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
965 // getRadioSet() builds a set of labeled radio buttons.
966 // For grep: The following messages are used as the item labels:
967 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
968 $this->parent
->getRadioSet( array(
969 'var' => '_RightsProfile',
970 'label' => 'config-profile',
971 'itemLabelPrefix' => 'config-profile-',
972 'values' => array_keys( $this->parent
->rightsProfiles
),
974 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
977 // getRadioSet() builds a set of labeled radio buttons.
978 // For grep: The following messages are used as the item labels:
979 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
980 // config-license-cc-0, config-license-pd, config-license-gfdl,
981 // config-license-none, config-license-cc-choose
982 $this->parent
->getRadioSet( array(
983 'var' => '_LicenseCode',
984 'label' => 'config-license',
985 'itemLabelPrefix' => 'config-license-',
986 'values' => array_keys( $this->parent
->licenses
),
987 'commonAttribs' => array( 'class' => 'licenseRadio' ),
989 $this->getCCChooser() .
990 $this->parent
->getHelpBox( 'config-license-help' ) .
993 $this->getFieldSetStart( 'config-email-settings' ) .
994 $this->parent
->getCheckBox( array(
995 'var' => 'wgEnableEmail',
996 'label' => 'config-enable-email',
997 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
999 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
1000 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
1001 $this->parent
->getTextBox( array(
1002 'var' => 'wgPasswordSender',
1003 'label' => 'config-email-sender'
1005 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
1006 $this->parent
->getCheckBox( array(
1007 'var' => 'wgEnableUserEmail',
1008 'label' => 'config-email-user',
1010 $this->parent
->getHelpBox( 'config-email-user-help' ) .
1011 $this->parent
->getCheckBox( array(
1012 'var' => 'wgEnotifUserTalk',
1013 'label' => 'config-email-usertalk',
1015 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
1016 $this->parent
->getCheckBox( array(
1017 'var' => 'wgEnotifWatchlist',
1018 'label' => 'config-email-watchlist',
1020 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
1021 $this->parent
->getCheckBox( array(
1022 'var' => 'wgEmailAuthentication',
1023 'label' => 'config-email-auth',
1025 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
1027 $this->getFieldSetEnd()
1030 $skins = $this->parent
->findExtensions( 'skins' );
1031 $skinHtml = $this->getFieldSetStart( 'config-skins' );
1034 $skinNames = array_map( 'strtolower', $skins );
1036 $radioButtons = $this->parent
->getRadioElements( array(
1037 'var' => 'wgDefaultSkin',
1038 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
1039 'values' => $skinNames,
1040 'value' => $this->getVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) ),
1043 foreach ( $skins as $skin ) {
1045 '<div class="config-skins-item">' .
1046 $this->parent
->getCheckBox( array(
1047 'var' => "skin-$skin",
1049 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
1051 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
1055 $skinHtml .= $this->parent
->getWarningBox( wfMessage( 'config-skins-missing' )->plain() );
1058 $skinHtml .= $this->parent
->getHelpBox( 'config-skins-help' ) .
1059 $this->getFieldSetEnd();
1060 $this->addHTML( $skinHtml );
1062 $extensions = $this->parent
->findExtensions();
1064 if ( $extensions ) {
1065 $extHtml = $this->getFieldSetStart( 'config-extensions' );
1067 foreach ( $extensions as $ext ) {
1068 $extHtml .= $this->parent
->getCheckBox( array(
1069 'var' => "ext-$ext",
1074 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
1075 $this->getFieldSetEnd();
1076 $this->addHTML( $extHtml );
1079 // Having / in paths in Windows looks funny :)
1080 $this->setVar( 'wgDeletedDirectory',
1082 '/', DIRECTORY_SEPARATOR
,
1083 $this->getVar( 'wgDeletedDirectory' )
1087 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
1090 $this->getFieldSetStart( 'config-upload-settings' ) .
1091 $this->parent
->getCheckBox( array(
1092 'var' => 'wgEnableUploads',
1093 'label' => 'config-upload-enable',
1094 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
1095 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
1097 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
1098 $this->parent
->getTextBox( array(
1099 'var' => 'wgDeletedDirectory',
1100 'label' => 'config-upload-deleted',
1101 'attribs' => array( 'dir' => 'ltr' ),
1102 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
1105 $this->parent
->getTextBox( array(
1107 'label' => 'config-logo',
1108 'attribs' => array( 'dir' => 'ltr' ),
1109 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
1113 $this->parent
->getCheckBox( array(
1114 'var' => 'wgUseInstantCommons',
1115 'label' => 'config-instantcommons',
1116 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
1118 $this->getFieldSetEnd()
1121 $caches = array( 'none' );
1122 if ( count( $this->getVar( '_Caches' ) ) ) {
1123 $caches[] = 'accel';
1125 $caches[] = 'memcached';
1127 // We'll hide/show this on demand when the value changes, see config.js.
1128 $cacheval = $this->getVar( 'wgMainCacheType' );
1130 // We need to set a default here; but don't hardcode it
1131 // or we lose it every time we reload the page for validation
1135 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
1138 $this->getFieldSetStart( 'config-advanced-settings' ) .
1139 # Object cache settings
1140 // getRadioSet() builds a set of labeled radio buttons.
1141 // For grep: The following messages are used as the item labels:
1142 // config-cache-none, config-cache-accel, config-cache-memcached
1143 $this->parent
->getRadioSet( array(
1144 'var' => 'wgMainCacheType',
1145 'label' => 'config-cache-options',
1146 'itemLabelPrefix' => 'config-cache-',
1147 'values' => $caches,
1148 'value' => $cacheval,
1150 $this->parent
->getHelpBox( 'config-cache-help' ) .
1151 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1152 $this->parent
->getTextArea( array(
1153 'var' => '_MemCachedServers',
1154 'label' => 'config-memcached-servers',
1155 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1158 $this->getFieldSetEnd()
1168 public function getCCPartnerUrl() {
1169 $server = $this->getVar( 'wgServer' );
1170 $exitUrl = $server . $this->parent
->getUrl( array(
1171 'page' => 'Options',
1172 'SubmitCC' => 'indeed',
1173 'config__LicenseCode' => 'cc',
1174 'config_wgRightsUrl' => '[license_url]',
1175 'config_wgRightsText' => '[license_name]',
1176 'config_wgRightsIcon' => '[license_button]',
1178 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1179 '/skins/common/config-cc.css';
1180 $iframeUrl = 'http://creativecommons.org/license/?' .
1181 wfArrayToCgi( array(
1182 'partner' => 'MediaWiki',
1183 'exit_url' => $exitUrl,
1184 'lang' => $this->getVar( '_UserLang' ),
1185 'stylesheet' => $styleUrl,
1194 public function getCCChooser() {
1195 $iframeAttribs = array(
1196 'class' => 'config-cc-iframe',
1197 'name' => 'config-cc-iframe',
1198 'id' => 'config-cc-iframe',
1203 if ( $this->getVar( '_CCDone' ) ) {
1204 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1206 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1208 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
1210 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1211 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1218 public function getCCDoneBox() {
1219 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1220 // If you change this height, also change it in config.css
1221 $expandJs = str_replace( '$1', '54em', $js );
1222 $reduceJs = str_replace( '$1', '70px', $js );
1225 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1227 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1229 "<p style=\"text-align: center;\">" .
1232 'href' => $this->getCCPartnerUrl(),
1233 'onclick' => $expandJs,
1235 wfMessage( 'config-cc-again' )->text()
1239 # Reduce the wrapper div height
1240 htmlspecialchars( $reduceJs ) .
1245 public function submitCC() {
1246 $newValues = $this->parent
->setVarsFromRequest(
1247 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1248 if ( count( $newValues ) != 3 ) {
1249 $this->parent
->showError( 'config-cc-error' );
1253 $this->setVar( '_CCDone', true );
1254 $this->addHTML( $this->getCCDoneBox() );
1258 * Returns a default value to be used for $wgDefaultSkin: the preferred skin, if available among
1259 * the installed skins, or any other one otherwise.
1261 * @param string[] $skinNames Names of installed skins.
1264 public function getDefaultSkin( array $skinNames ) {
1265 $defaultSkin = $GLOBALS['wgDefaultSkin'];
1266 if ( in_array( $defaultSkin, $skinNames ) ) {
1267 return $defaultSkin;
1269 return $skinNames[0];
1274 * If the user skips this installer page, we still need to set up the default skins, but ignore
1279 public function submitSkins() {
1280 $skins = $this->parent
->findExtensions( 'skins' );
1281 $this->parent
->setVar( '_Skins', $skins );
1284 $skinNames = array_map( 'strtolower', $skins );
1285 $this->parent
->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) );
1294 public function submit() {
1295 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1296 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1297 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1298 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1299 'wgUseInstantCommons', 'wgDefaultSkin' ) );
1303 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent
->rightsProfiles
)
1305 reset( $this->parent
->rightsProfiles
);
1306 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1309 $code = $this->getVar( '_LicenseCode' );
1310 if ( $code == 'cc-choose' ) {
1311 if ( !$this->getVar( '_CCDone' ) ) {
1312 $this->parent
->showError( 'config-cc-not-chosen' );
1315 } elseif ( array_key_exists( $code, $this->parent
->licenses
) ) {
1317 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1318 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1319 // config-license-cc-choose
1320 $entry = $this->parent
->licenses
[$code];
1321 if ( isset( $entry['text'] ) ) {
1322 $this->setVar( 'wgRightsText', $entry['text'] );
1324 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1326 $this->setVar( 'wgRightsUrl', $entry['url'] );
1327 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1329 $this->setVar( 'wgRightsText', '' );
1330 $this->setVar( 'wgRightsUrl', '' );
1331 $this->setVar( 'wgRightsIcon', '' );
1334 $skinsAvailable = $this->parent
->findExtensions( 'skins' );
1335 $skinsToInstall = array();
1336 foreach ( $skinsAvailable as $skin ) {
1337 $this->parent
->setVarsFromRequest( array( "skin-$skin" ) );
1338 if ( $this->getVar( "skin-$skin" ) ) {
1339 $skinsToInstall[] = $skin;
1342 $this->parent
->setVar( '_Skins', $skinsToInstall );
1344 if ( !$skinsToInstall && $skinsAvailable ) {
1345 $this->parent
->showError( 'config-skins-must-enable-some' );
1348 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
1349 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
1350 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
1351 $this->parent
->showError( 'config-skins-must-enable-default' );
1355 $extsAvailable = $this->parent
->findExtensions();
1356 $extsToInstall = array();
1357 foreach ( $extsAvailable as $ext ) {
1358 $this->parent
->setVarsFromRequest( array( "ext-$ext" ) );
1359 if ( $this->getVar( "ext-$ext" ) ) {
1360 $extsToInstall[] = $ext;
1363 $this->parent
->setVar( '_Extensions', $extsToInstall );
1365 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1366 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1367 if ( !$memcServers ) {
1368 $this->parent
->showError( 'config-memcache-needservers' );
1372 foreach ( $memcServers as $server ) {
1373 $memcParts = explode( ":", $server, 2 );
1374 if ( !isset( $memcParts[0] )
1375 ||
( !IP
::isValid( $memcParts[0] )
1376 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1378 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1380 } elseif ( !isset( $memcParts[1] ) ) {
1381 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1383 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1384 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1395 class WebInstallerInstall
extends WebInstallerPage
{
1398 * @return bool Always true.
1400 public function isSlow() {
1405 * @return string|bool
1407 public function execute() {
1408 if ( $this->getVar( '_UpgradeDone' ) ) {
1410 } elseif ( $this->getVar( '_InstallDone' ) ) {
1412 } elseif ( $this->parent
->request
->wasPosted() ) {
1414 $this->addHTML( "<ul>" );
1415 $results = $this->parent
->performInstallation(
1416 array( $this, 'startStage' ),
1417 array( $this, 'endStage' )
1419 $this->addHTML( "</ul>" );
1420 // PerformInstallation bails on a fatal, so make sure the last item
1421 // completed before giving 'next.' Likewise, only provide back on failure
1422 $lastStep = end( $results );
1423 $continue = $lastStep->isOK() ?
'continue' : false;
1424 $back = $lastStep->isOK() ?
false : 'back';
1425 $this->endForm( $continue, $back );
1428 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1436 * @param string $step
1438 public function startStage( $step ) {
1439 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1440 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1441 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1442 wfMessage( 'ellipsis' )->escaped() );
1444 if ( $step == 'extension-tables' ) {
1445 $this->startLiveBox();
1450 * @param string $step
1451 * @param Status $status
1453 public function endStage( $step, $status ) {
1454 if ( $step == 'extension-tables' ) {
1455 $this->endLiveBox();
1457 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1458 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1459 if ( !$status->isOk() ) {
1460 $html = "<span class=\"error\">$html</span>";
1462 $this->addHTML( $html . "</li>\n" );
1463 if ( !$status->isGood() ) {
1464 $this->parent
->showStatusBox( $status );
1470 class WebInstallerComplete
extends WebInstallerPage
{
1472 public function execute() {
1473 // Pop up a dialog box, to make it difficult for the user to forget
1474 // to download the file
1475 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1476 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1477 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1479 // JS appears to be the only method that works consistently with IE7+
1480 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1481 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1483 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1487 $this->parent
->disableLinkPopups();
1489 $this->parent
->getInfoBox(
1490 wfMessage( 'config-install-done',
1492 $this->getVar( 'wgServer' ) .
1493 $this->getVar( 'wgScriptPath' ) . '/index' .
1494 $this->getVar( 'wgScriptExtension' ),
1496 )->plain(), 'tick-32.png'
1499 $this->addHTML( $this->parent
->getInfoBox(
1500 wfMessage( 'config-extension-link' )->text() ) );
1502 $this->parent
->restoreLinkPopups();
1503 $this->endForm( false, false );
1508 class WebInstallerRestart
extends WebInstallerPage
{
1511 * @return string|null
1513 public function execute() {
1514 $r = $this->parent
->request
;
1515 if ( $r->wasPosted() ) {
1516 $really = $r->getVal( 'submit-restart' );
1518 $this->parent
->reset();
1525 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1526 $this->addHTML( $s );
1527 $this->endForm( 'restart' );
1534 abstract class WebInstallerDocument
extends WebInstallerPage
{
1539 abstract protected function getFileName();
1541 public function execute() {
1542 $text = $this->getFileContents();
1543 $text = InstallDocFormatter
::format( $text );
1544 $this->parent
->output
->addWikiText( $text );
1546 $this->endForm( false );
1552 public function getFileContents() {
1553 $file = __DIR__
. '/../../' . $this->getFileName();
1554 if ( !file_exists( $file ) ) {
1555 return wfMessage( 'config-nofile', $file )->plain();
1558 return file_get_contents( $file );
1563 class WebInstallerReadme
extends WebInstallerDocument
{
1568 protected function getFileName() {
1574 class WebInstallerReleaseNotes
extends WebInstallerDocument
{
1577 * @throws MWException
1580 protected function getFileName() {
1583 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1584 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1587 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1592 class WebInstallerUpgradeDoc
extends WebInstallerDocument
{
1597 protected function getFileName() {
1603 class WebInstallerCopying
extends WebInstallerDocument
{
1608 protected function getFileName() {