-}
-
-class WebInstaller_Language extends WebInstallerPage {
-
- public function execute() {
- global $wgLang;
- $r = $this->parent->request;
- $userLang = $r->getVal( 'UserLang' );
- $contLang = $r->getVal( 'ContLang' );
-
- $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
- if ( !$lifetime ) {
- $lifetime = 1440; // PHP default
- }
-
- if ( $r->wasPosted() ) {
- # Do session test
- if ( $this->parent->getSession( 'test' ) === null ) {
- $requestTime = $r->getVal( 'LanguageRequestTime' );
- if ( !$requestTime ) {
- // The most likely explanation is that the user was knocked back
- // from another page on POST due to session expiry
- $msg = 'config-session-expired';
- } elseif ( time() - $requestTime > $lifetime ) {
- $msg = 'config-session-expired';
- } else {
- $msg = 'config-no-session';
- }
- $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
- } else {
- $languages = Language::getLanguageNames();
- if ( isset( $languages[$userLang] ) ) {
- $this->setVar( '_UserLang', $userLang );
- }
- if ( isset( $languages[$contLang] ) ) {
- $this->setVar( 'wgLanguageCode', $contLang );
- }
- return 'continue';
- }
- } elseif ( $this->parent->showSessionWarning ) {
- # The user was knocked back from another page to the start
- # This probably indicates a session expiry
- $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
- }
-
- $this->parent->setSession( 'test', true );
-
- if ( !isset( $languages[$userLang] ) ) {
- $userLang = $this->getVar( '_UserLang', 'en' );
- }
- if ( !isset( $languages[$contLang] ) ) {
- $contLang = $this->getVar( 'wgLanguageCode', 'en' );
- }
- $this->startForm();
- $s = Html::hidden( 'LanguageRequestTime', time() ) .
- $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent->getHelpBox( 'config-your-language-help' ) ) .
- $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent->getHelpBox( 'config-wiki-language-help' ) );
- $this->addHTML( $s );
- $this->endForm( 'continue', false );
- }
-
- /**
- * Get a <select> for selecting languages.
- */
- public function getLanguageSelector( $name, $label, $selectedCode ) {
- global $wgDummyLanguageCodes;
- $s = Html::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
-
- $languages = Language::getLanguageNames();
- ksort( $languages );
- $dummies = array_flip( $wgDummyLanguageCodes );
- foreach ( $languages as $code => $lang ) {
- if ( isset( $dummies[$code] ) ) continue;
- $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
- }
- $s .= "\n</select>\n";
- return $this->parent->label( $label, $name, $s );
- }
-
-}
-
-class WebInstaller_ExistingWiki extends WebInstallerPage {
- public function execute() {
- // If there is no LocalSettings.php, continue to the installer welcome page
- $vars = Installer::getExistingLocalSettings();
- if ( !$vars ) {
- return 'skip';
- }
-
- // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
- if ( $vars['wgUpgradeKey'] !== false
- && $this->getVar( '_UpgradeKeySupplied' )
- && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
- {
- // It's there, so the user is authorized
- $status = $this->handleExistingUpgrade( $vars );
- if ( $status->isOK() ) {
- return 'skip';
- } else {
- $this->startForm();
- $this->parent->showStatusBox( $status );
- $this->endForm( 'continue' );
- return 'output';
- }
- }
-
- // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
- if ( $vars['wgUpgradeKey'] === false ) {
- if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
- $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
- $this->parent->generateKeys();
- $this->setVar( 'wgSecretKey', $secretKey );
- $this->setVar( '_UpgradeKeySupplied', true );
- }
- $this->startForm();
- $this->addHTML( $this->parent->getInfoBox(
- wfMsgNoTrans( 'config-upgrade-key-missing',
- "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
- ) );
- $this->endForm( 'continue' );
- return 'output';
- }
-
- // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
-
- $r = $this->parent->request;
- if ( $r->wasPosted() ) {
- $key = $r->getText( 'config_wgUpgradeKey' );
- if( !$key || $key !== $vars['wgUpgradeKey'] ) {
- $this->parent->showError( 'config-localsettings-badkey' );
- $this->showKeyForm();
- return 'output';
- }
- // Key was OK
- $status = $this->handleExistingUpgrade( $vars );
- if ( $status->isOK() ) {
- return 'continue';
- } else {
- $this->parent->showStatusBox( $status );
- $this->showKeyForm();
- return 'output';
- }
- } else {
- $this->showKeyForm();
- return 'output';
- }
- }
-
- /**
- * Show the "enter key" form
- */
- protected function showKeyForm() {
- $this->startForm();
- $this->addHTML(
- $this->parent->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
- '<br />' .
- $this->parent->getTextBox( array(
- 'var' => 'wgUpgradeKey',
- 'label' => 'config-localsettings-key',
- 'attribs' => array( 'autocomplete' => 'off' ),
- ) )
- );
- $this->endForm( 'continue' );
- }
-
- protected function importVariables( $names, $vars ) {
- $status = Status::newGood();
- foreach ( $names as $name ) {
- if ( !isset( $vars[$name] ) ) {
- $status->fatal( 'config-localsettings-incomplete', $name );
- }
- $this->setVar( $name, $vars[$name] );
- }
- return $status;
- }
-
- /**
- * Initiate an upgrade of the existing database
- * @param $vars Variables from LocalSettings.php and AdminSettings.php
- * @return Status
- */
- protected function handleExistingUpgrade( $vars ) {
- // Check $wgDBtype
- if ( !isset( $vars['wgDBtype'] ) || !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
- return Status::newFatal( 'config-localsettings-connection-error', '' );
- }
-
- // Set the relevant variables from LocalSettings.php
- $requiredVars = array( 'wgDBtype' );
- $status = $this->importVariables( $requiredVars , $vars );
- $installer = $this->parent->getDBInstaller();
- $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
- if ( !$status->isOK() ) {
- return $status;
- }
-
- if ( isset( $vars['wgDBadminuser'] ) ) {
- $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
- } else {
- $this->setVar( '_InstallUser', $vars['wgDBuser'] );
- }
- if ( isset( $vars['wgDBadminpassword'] ) ) {
- $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
- } else {
- $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
- }
-
- // Test the database connection
- $status = $installer->getConnection();
- if ( !$status->isOK() ) {
- // Adjust the error message to explain things correctly
- $status->replaceMessage( 'config-connection-error',
- 'config-localsettings-connection-error' );
- return $status;
- }
-
- // All good
- $this->setVar( '_ExistingDBSettings', true );
- return $status;
- }
-}
-
-class WebInstaller_Welcome extends WebInstallerPage {
-
- public function execute() {
- if ( $this->parent->request->wasPosted() ) {
- if ( $this->getVar( '_Environment' ) ) {
- return 'continue';
- }
- }
- $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
- $status = $this->parent->doEnvironmentChecks();
- if ( $status->isGood() ) {
- $this->parent->output->addHTML( '<span class="success-message">' .
- wfMsgHtml( 'config-env-good' ) . '</span>' );
- $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright',
- SpecialVersion::getCopyrightAndAuthorList() ) );
- $this->startForm();
- $this->endForm();
- } else {
- $this->parent->showStatusMessage( $status );
- }
- }
-
-}
-
-class WebInstaller_DBConnect extends WebInstallerPage {
-
- public function execute() {
- if ( $this->getVar( '_ExistingDBSettings' ) ) {
- return 'skip';
- }
-
- $r = $this->parent->request;
- if ( $r->wasPosted() ) {
- $status = $this->submit();
-
- if ( $status->isGood() ) {
- $this->setVar( '_UpgradeDone', false );
- return 'continue';
- } else {
- $this->parent->showStatusBox( $status );
- }
- }
-
- $this->startForm();
-
- $types = "<ul class=\"config-settings-block\">\n";
- $settings = '';
- $defaultType = $this->getVar( 'wgDBtype' );
-
- $dbSupport = '';
- foreach( $this->parent->getDBTypes() as $type ) {
- $link = DatabaseBase::newFromType( $type )->getSoftwareLink();
- $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
- }
- $this->addHTML( $this->parent->getInfoBox(
- wfMsg( 'config-support-info', $dbSupport ) ) );
-
- foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
- $installer = $this->parent->getDBInstaller( $type );
- $types .=
- '<li>' .
- Xml::radioLabel(
- $installer->getReadableName(),
- 'DBType',
- $type,
- "DBType_$type",
- $type == $defaultType,
- array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
- ) .
- "</li>\n";
-
- $settings .=
- Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
- Html::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
- $installer->getConnectForm() .
- "</div>\n";
- }
- $types .= "</ul><br clear=\"left\"/>\n";
-
- $this->addHTML(
- $this->parent->label( 'config-db-type', false, $types ) .
- $settings
- );
-
- $this->endForm();
- }
-
- public function submit() {
- $r = $this->parent->request;
- $type = $r->getVal( 'DBType' );
- $this->setVar( 'wgDBtype', $type );
- $installer = $this->parent->getDBInstaller( $type );
- if ( !$installer ) {
- return Status::newFatal( 'config-invalid-db-type' );
- }
- return $installer->submitConnectForm();
- }
-
-}
-
-class WebInstaller_Upgrade extends WebInstallerPage {
-
- public function execute() {
- if ( $this->getVar( '_UpgradeDone' ) ) {
- // Allow regeneration of LocalSettings.php, unless we are working
- // from a pre-existing LocalSettings.php file and we want to avoid
- // leaking its contents
- if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
- // Done message acknowledged
- return 'continue';
- } else {
- // Back button click
- // Show the done message again
- // Make them click back again if they want to do the upgrade again
- $this->showDoneMessage();
- return 'output';
- }
- }
-
- // wgDBtype is generally valid here because otherwise the previous page
- // (connect) wouldn't have declared its happiness
- $type = $this->getVar( 'wgDBtype' );
- $installer = $this->parent->getDBInstaller( $type );
-
- if ( !$installer->needsUpgrade() ) {
- return 'skip';
- }
-
- if ( $this->parent->request->wasPosted() ) {
- $installer->preUpgrade();
-
- $this->startLiveBox();
- $result = $installer->doUpgrade();
- $this->endLiveBox();
-
- if ( $result ) {
- // If they're going to possibly regenerate LocalSettings, we
- // need to create the upgrade/secret keys. Bug 26481
- if( !$this->getVar( '_ExistingDBSettings' ) ) {
- $this->parent->generateKeys();
- }
- $this->setVar( '_UpgradeDone', true );
- $this->showDoneMessage();
- return 'output';
- }
- }
-
- $this->startForm();
- $this->addHTML( $this->parent->getInfoBox(
- wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
- $this->endForm();
- }
-
- public function showDoneMessage() {
- $this->startForm();
- $regenerate = !$this->getVar( '_ExistingDBSettings' );
- if ( $regenerate ) {
- $msg = 'config-upgrade-done';
- } else {
- $msg = 'config-upgrade-done-no-regenerate';
- }
- $this->parent->disableLinkPopups();
- $this->addHTML(
- $this->parent->getInfoBox(
- wfMsgNoTrans( $msg,
- $GLOBALS['wgServer'] .
- $this->getVar( 'wgScriptPath' ) . '/index' .
- $this->getVar( 'wgScriptExtension' )
- ), 'tick-32.png'
- )
- );
- $this->parent->restoreLinkPopups();
- $this->endForm( $regenerate ? 'regenerate' : false, false );
- }
-
-}
-
-class WebInstaller_DBSettings extends WebInstallerPage {
-
- public function execute() {
- $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
-
- $r = $this->parent->request;
- if ( $r->wasPosted() ) {
- $status = $installer->submitSettingsForm();
- if ( $status === false ) {
- return 'skip';
- } elseif ( $status->isGood() ) {
- return 'continue';
- } else {
- $this->parent->showStatusBox( $status );
- }
- }
-
- $form = $installer->getSettingsForm();
- if ( $form === false ) {
- return 'skip';
- }
-
- $this->startForm();
- $this->addHTML( $form );
- $this->endForm();
- }
-
-}
-
-class WebInstaller_Name extends WebInstallerPage {
-
- public function execute() {
- $r = $this->parent->request;
- if ( $r->wasPosted() ) {
- if ( $this->submit() ) {
- return 'continue';
- }
- }
-
- $this->startForm();
-
- // Encourage people to not name their site 'MediaWiki' by blanking the
- // field. I think that was the intent with the original $GLOBALS['wgSitename']
- // but these two always were the same so had the effect of making the
- // installer forget $wgSitename when navigating back to this page.
- if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
- $this->setVar( 'wgSitename', '' );
- }
-
- // Set wgMetaNamespace to something valid before we show the form.
- // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
- $metaNS = $this->getVar( 'wgMetaNamespace' );
- $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
-
- $this->addHTML(
- $this->parent->getTextBox( array(
- 'var' => 'wgSitename',
- 'label' => 'config-site-name',
- 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
- ) ) .
- $this->parent->getRadioSet( array(
- 'var' => '_NamespaceType',
- 'label' => 'config-project-namespace',
- 'itemLabelPrefix' => 'config-ns-',
- 'values' => array( 'site-name', 'generic', 'other' ),
- 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
- 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
- ) ) .
- $this->parent->getTextBox( array(
- 'var' => 'wgMetaNamespace',
- 'label' => '', //TODO: Needs a label?
- 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
-
- ) ) .
- $this->getFieldSetStart( 'config-admin-box' ) .
- $this->parent->getTextBox( array(
- 'var' => '_AdminName',
- 'label' => 'config-admin-name',
- 'help' => $this->parent->getHelpBox( 'config-admin-help' )
- ) ) .
- $this->parent->getPasswordBox( array(
- 'var' => '_AdminPassword',
- 'label' => 'config-admin-password',
- ) ) .
- $this->parent->getPasswordBox( array(
- 'var' => '_AdminPassword2',
- 'label' => 'config-admin-password-confirm'
- ) ) .
- $this->parent->getTextBox( array(
- 'var' => '_AdminEmail',
- 'label' => 'config-admin-email',
- 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
- ) ) .
- $this->parent->getCheckBox( array(
- 'var' => '_Subscribe',
- 'label' => 'config-subscribe',
- 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
- ) ) .
- $this->getFieldSetEnd() .
- $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
- $this->parent->getRadioSet( array(
- 'var' => '_SkipOptional',
- 'itemLabelPrefix' => 'config-optional-',
- 'values' => array( 'continue', 'skip' )
- ) )
- );
-
- // Restore the default value
- $this->setVar( 'wgMetaNamespace', $metaNS );
-
- $this->endForm();
- return 'output';
- }
-
- public function submit() {
- $retVal = true;
- $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
- '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
- '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
-
- // Validate site name
- if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
- $this->parent->showError( 'config-site-name-blank' );
- $retVal = false;
- }
-
- // Fetch namespace
- $nsType = $this->getVar( '_NamespaceType' );
- if ( $nsType == 'site-name' ) {
- $name = $this->getVar( 'wgSitename' );
- // Sanitize for namespace
- // This algorithm should match the JS one in WebInstallerOutput.php
- $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
- $name = str_replace( '&', '&', $name );
- $name = preg_replace( '/__+/', '_', $name );
- $name = ucfirst( trim( $name, '_' ) );
- } elseif ( $nsType == 'generic' ) {
- $name = wfMsg( 'config-ns-generic' );
- } else { // other
- $name = $this->getVar( 'wgMetaNamespace' );
- }
-
- // Validate namespace
- if ( strpos( $name, ':' ) !== false ) {
- $good = false;
- } else {
- // Title-style validation
- $title = Title::newFromText( $name );
- if ( !$title ) {
- $good = $nsType == 'site-name';
- } else {
- $name = $title->getDBkey();
- $good = true;
- }
- }
- if ( !$good ) {
- $this->parent->showError( 'config-ns-invalid', $name );
- $retVal = false;
- }
-
- // Make sure it won't conflict with any existing namespaces
- global $wgContLang;
- $nsIndex = $wgContLang->getNsIndex( $name );
- if( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
- $this->parent->showError( 'config-ns-conflict', $name );
- $retVal = false;
- }
-
- $this->setVar( 'wgMetaNamespace', $name );
-
- // Validate username for creation
- $name = $this->getVar( '_AdminName' );
- if ( strval( $name ) === '' ) {
- $this->parent->showError( 'config-admin-name-blank' );
- $cname = $name;
- $retVal = false;
- } else {
- $cname = User::getCanonicalName( $name, 'creatable' );
- if ( $cname === false ) {
- $this->parent->showError( 'config-admin-name-invalid', $name );
- $retVal = false;
- } else {
- $this->setVar( '_AdminName', $cname );
- }
- }
-
- // Validate password
- $msg = false;
- $valid = false;
- $pwd = $this->getVar( '_AdminPassword' );
- $user = User::newFromName( $cname );
- $valid = $user && $user->getPasswordValidity( $pwd );
- if ( strval( $pwd ) === '' ) {
- # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
- # This message is more specific and helpful.
- $msg = 'config-admin-password-blank';
- } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
- $msg = 'config-admin-password-mismatch';
- } elseif ( $valid !== true ) {
- # As of writing this will only catch the username being e.g. 'FOO' and
- # the password 'foo'
- $msg = $valid;
- }
- if ( $msg !== false ) {
- call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
- $this->setVar( '_AdminPassword', '' );
- $this->setVar( '_AdminPassword2', '' );
- $retVal = false;
- }
-
- // Validate e-mail if provided
- $email = $this->getVar( '_AdminEmail' );
- if( $email && !User::isValidEmailAddr( $email ) ) {
- $this->parent->showError( 'config-admin-error-bademail' );
- $retVal = false;
- }
-
- return $retVal;
- }