A few more ok -> done
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
index 9c56013..80c939b 100644 (file)
@@ -1,31 +1,46 @@
 <?php
+/**
+ * Base code for web installer pages.
+ *
+ * @file
+ * @ingroup Deployment
+ */
 
 /**
  * Abstract class to define pages for the web installer.
- * 
+ *
  * @ingroup Deployment
  * @since 1.17
  */
 abstract class WebInstallerPage {
-       
+
        /**
         * The WebInstaller object this WebInstallerPage belongs to.
-        * 
+        *
         * @var WebInstaller
         */
        public $parent;
-       
+
        public abstract function execute();
-       
+
        /**
         * Constructor.
-        * 
-        * @param WebInstaller $parent
-        */     
+        *
+        * @param $parent WebInstaller
+        */
        public function __construct( WebInstaller $parent ) {
                $this->parent = $parent;
        }
 
+       /**
+        * Is this a slow-running page in the installer? If so, WebInstaller will
+        * set_time_limit(0) before calling execute(). Right now this only applies
+        * to Install and Upgrade pages
+        */
+       public function isSlow() {
+               return false;
+       }
+
        public function addHTML( $html ) {
                $this->parent->output->addHTML( $html );
        }
@@ -33,7 +48,7 @@ abstract class WebInstallerPage {
        public function startForm() {
                $this->addHTML(
                        "<div class=\"config-section\">\n" .
-                       Xml::openElement(
+                       Html::openElement(
                                'form',
                                array(
                                        'method' => 'post',
@@ -43,29 +58,29 @@ abstract class WebInstallerPage {
                );
        }
 
-       public function endForm( $continue = 'continue' ) {
-               $this->parent->output->outputWarnings();
+       public function endForm( $continue = 'continue', $back = 'back' ) {
                $s = "<div class=\"config-submit\">\n";
                $id = $this->getId();
-               
+
                if ( $id === false ) {
-                       $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
+                       $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
                }
-               
+
                if ( $continue ) {
-                       // Fake submit button for enter keypress
+                       // Fake submit button for enter keypress (bug 26267)
                        $s .= Xml::submitButton( wfMsg( "config-$continue" ),
-                               array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
+                               array( 'name' => "enter-$continue", 'style' =>
+                                       'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
                }
-               
-               if ( $id !== 0 ) {
-                       $s .= Xml::submitButton( wfMsg( 'config-back' ),
+
+               if ( $back ) {
+                       $s .= Xml::submitButton( wfMsg( "config-$back" ),
                                array(
-                                       'name' => 'submit-back',
+                                       'name' => "submit-$back",
                                        'tabindex' => $this->parent->nextTabIndex()
                                ) ) . "\n";
                }
-               
+
                if ( $continue ) {
                        $s .= Xml::submitButton( wfMsg( "config-$continue" ),
                                array(
@@ -73,7 +88,7 @@ abstract class WebInstallerPage {
                                        'tabindex' => $this->parent->nextTabIndex(),
                                ) ) . "\n";
                }
-               
+
                $s .= "</div></form></div>\n";
                $this->addHTML( $s );
        }
@@ -82,7 +97,7 @@ abstract class WebInstallerPage {
                return str_replace( 'WebInstaller_', '', get_class( $this ) );
        }
 
-       public function getId() {
+       protected function getId() {
                return array_search( $this->getName(), $this->parent->pageSequence );
        }
 
@@ -93,15 +108,57 @@ abstract class WebInstallerPage {
        public function setVar( $name, $value ) {
                $this->parent->setVar( $name, $value );
        }
-       
+
+       /**
+        * Get the starting tags of a fieldset.
+        *
+        * @param $legend String: message name
+        *
+        * @return string
+        */
+       protected function getFieldsetStart( $legend ) {
+               return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
+       }
+
+       /**
+        * Get the end tag of a fieldset.
+        *
+        * @return string
+        */
+       protected function getFieldsetEnd() {
+               return "</fieldset>\n";
+       }
+
+       /**
+        * Opens a textarea used to display the progress of a long operation
+        */
+       protected function startLiveBox() {
+               $this->addHTML(
+                       '<div id="config-spinner" style="display:none;">' .
+                       '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
+                       '<script>jQuery( "#config-spinner" ).show();</script>' .
+                       '<div id="config-live-log">' .
+                       '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
+               );
+               $this->parent->output->flush();
+       }
+
+       /**
+        * Opposite to startLiveBox()
+        */
+       protected function endLiveBox() {
+               $this->addHTML( '</textarea></div>
+<script>jQuery( "#config-spinner" ).hide()</script>' );
+               $this->parent->output->flush();
+       }
 }
 
 class WebInstaller_Language extends WebInstallerPage {
-       
+
        public function execute() {
                global $wgLang;
                $r = $this->parent->request;
-               $userLang = $r->getVal( 'UserLang' );
+               $userLang = $r->getVal( 'userlang' );
                $contLang = $r->getVal( 'ContLang' );
 
                $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
@@ -136,7 +193,8 @@ class WebInstaller_Language extends WebInstallerPage {
                } 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->showError( 'config-session-expired',
+                               $wgLang->formatTimePeriod( $lifetime ) );
                }
 
                $this->parent->setSession( 'test', true );
@@ -148,40 +206,188 @@ class WebInstaller_Language extends WebInstallerPage {
                        $contLang = $this->getVar( 'wgLanguageCode', 'en' );
                }
                $this->startForm();
-               $s =
-                       Xml::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' );
-
-
+               $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();
+               $this->endForm( 'continue', false );
        }
 
        /**
         * Get a <select> for selecting languages.
+        *
+        * @param $name
+        * @param $label
+        * @param $selectedCode
+        * @param $helpHtml string
+        * @return string
         */
-       public function getLanguageSelector( $name, $label, $selectedCode ) {
+       public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
                global $wgDummyLanguageCodes;
-               $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
+
+               $s = $helpHtml;
+
+               $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name,
+                               'tabindex' => $this->parent->nextTabIndex() ) ) . "\n";
 
                $languages = Language::getLanguageNames();
                ksort( $languages );
-               $dummies = array_flip( $wgDummyLanguageCodes );
                foreach ( $languages as $code => $lang ) {
-                       if ( isset( $dummies[$code] ) ) continue;
+                       if ( isset( $wgDummyLanguageCodes[$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' ) ) {
@@ -190,21 +396,31 @@ class WebInstaller_Welcome extends WebInstallerPage {
                }
                $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
                $status = $this->parent->doEnvironmentChecks();
-               if ( $status ) {
-                       $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) );
+               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';
@@ -218,6 +434,15 @@ class WebInstaller_DBConnect extends WebInstallerPage {
                $types = "<ul class=\"config-settings-block\">\n";
                $settings = '';
                $defaultType = $this->getVar( 'wgDBtype' );
+
+               $dbSupport = '';
+               foreach( $this->parent->getDBTypes() as $type ) {
+                       $link = DatabaseBase::factory( $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 .=
@@ -233,12 +458,13 @@ class WebInstaller_DBConnect extends WebInstallerPage {
                                "</li>\n";
 
                        $settings .=
-                               Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
-                               Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
+                               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";
+               $types .= "</ul><br style=\"clear: left\"/>\n";
 
                $this->addHTML(
                        $this->parent->label( 'config-db-type', false, $types ) .
@@ -258,14 +484,20 @@ class WebInstaller_DBConnect extends WebInstallerPage {
                }
                return $installer->submitConnectForm();
        }
-       
+
 }
 
 class WebInstaller_Upgrade extends WebInstallerPage {
-       
+       public function isSlow() {
+               return true;
+       }
+
        public function execute() {
                if ( $this->getVar( '_UpgradeDone' ) ) {
-                       if ( $this->parent->request->wasPosted() ) {
+                       // 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 {
@@ -287,17 +519,18 @@ class WebInstaller_Upgrade extends WebInstallerPage {
                }
 
                if ( $this->parent->request->wasPosted() ) {
-                       $this->addHTML(
-                               '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
-                               '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
-                               '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
-                       );
-                       $this->parent->output->flush();
+                       $installer->preUpgrade();
+
+                       $this->startLiveBox();
                        $result = $installer->doUpgrade();
-                       $this->addHTML( '</textarea>
-<script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
-                       $this->parent->output->flush();
+                       $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';
@@ -312,22 +545,30 @@ class WebInstaller_Upgrade extends WebInstallerPage {
 
        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( 'config-upgrade-done',
-                                       $GLOBALS['wgServer'] .
+                               wfMsgNoTrans( $msg,
+                                       $this->getVar( 'wgServer' ) .
                                                $this->getVar( 'wgScriptPath' ) . '/index' .
                                                $this->getVar( 'wgScriptExtension' )
                                ), 'tick-32.png'
                        )
                );
-               $this->endForm( 'regenerate' );
+               $this->parent->restoreLinkPopups();
+               $this->endForm( $regenerate ? 'regenerate' : false, false );
        }
-       
+
 }
 
 class WebInstaller_DBSettings extends WebInstallerPage {
-       
+
        public function execute() {
                $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
 
@@ -356,7 +597,7 @@ class WebInstaller_DBSettings extends WebInstallerPage {
 }
 
 class WebInstaller_Name extends WebInstallerPage {
-       
+
        public function execute() {
                $r = $this->parent->request;
                if ( $r->wasPosted() ) {
@@ -367,7 +608,11 @@ class WebInstaller_Name extends WebInstallerPage {
 
                $this->startForm();
 
-               if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
+               // 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', '' );
                }
 
@@ -380,25 +625,28 @@ class WebInstaller_Name extends WebInstallerPage {
                        $this->parent->getTextBox( array(
                                'var' => 'wgSitename',
                                'label' => 'config-site-name',
+                         'help' => $this->parent->getHelpBox( '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' ),
+                               'commonAttribs' => array( 'class' => 'enableForOther',
+                                       'rel' => 'config_wgMetaNamespace' ),
+                               'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
                        ) ) .
                        $this->parent->getTextBox( array(
                                'var' => 'wgMetaNamespace',
-                               'label' => '',
-                               'attribs' => array( 'disabled' => '' ),
+                               'label' => '', //TODO: Needs a label?
+                               'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
+
                        ) ) .
-                       $this->parent->getHelpBox( 'config-project-namespace-help' ) .
-                       $this->parent->getFieldsetStart( 'config-admin-box' ) .
+                       $this->getFieldSetStart( 'config-admin-box' ) .
                        $this->parent->getTextBox( array(
                                'var' => '_AdminName',
-                               'label' => 'config-admin-name'
+                               'label' => 'config-admin-name',
+                               'help' => $this->parent->getHelpBox( 'config-admin-help' )
                        ) ) .
                        $this->parent->getPasswordBox( array(
                                'var' => '_AdminPassword',
@@ -408,18 +656,17 @@ class WebInstaller_Name extends WebInstallerPage {
                                'var' => '_AdminPassword2',
                                'label' => 'config-admin-password-confirm'
                        ) ) .
-                       $this->parent->getHelpBox( 'config-admin-help' ) .
                        $this->parent->getTextBox( array(
                                'var' => '_AdminEmail',
-                               'label' => 'config-admin-email'
+                               'label' => 'config-admin-email',
+                               'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-admin-email-help' ) .
                        $this->parent->getCheckBox( array(
                                'var' => '_Subscribe',
-                               'label' => 'config-subscribe'
+                               'label' => 'config-subscribe',
+                               'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-subscribe-help' ) .
-                       $this->parent->getFieldsetEnd() .
+                       $this->getFieldSetEnd() .
                        $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
                        $this->parent->getRadioSet( array(
                                'var' => '_SkipOptional',
@@ -439,7 +686,7 @@ class WebInstaller_Name extends WebInstallerPage {
                $retVal = true;
                $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
                        '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
-                       '_Subscribe', '_SkipOptional' ) );
+                       '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
 
                // Validate site name
                if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
@@ -470,7 +717,7 @@ class WebInstaller_Name extends WebInstallerPage {
                        // Title-style validation
                        $title = Title::newFromText( $name );
                        if ( !$title ) {
-                               $good = $nsType == 'site-name' ? true : false;
+                               $good = $nsType == 'site-name';
                        } else {
                                $name = $title->getDBkey();
                                $good = true;
@@ -480,6 +727,15 @@ class WebInstaller_Name extends WebInstallerPage {
                        $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
@@ -502,7 +758,7 @@ class WebInstaller_Name extends WebInstallerPage {
                $msg = false;
                $pwd = $this->getVar( '_AdminPassword' );
                $user = User::newFromName( $cname );
-               $valid = $user->getPasswordValidity( $pwd );
+               $valid = $user && $user->getPasswordValidity( $pwd );
                if ( strval( $pwd ) === '' ) {
                        # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
                        # This message is more specific and helpful.
@@ -515,18 +771,32 @@ class WebInstaller_Name extends WebInstallerPage {
                        $msg = $valid;
                }
                if ( $msg !== false ) {
-                       $this->parent->showError( $msg );
+                       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 && !Sanitizer::validateEmail( $email ) ) {
+                       $this->parent->showError( 'config-admin-error-bademail' );
+                       $retVal = false;
+               }
+               // If they asked to subscribe to mediawiki-announce but didn't give
+               // an e-mail, show an error. Bug 29332
+               if( !$email && $this->getVar( '_Subscribe' ) ) {
+                       $this->parent->showError( 'config-subscribe-noemail' );
+                       $retVal = false;
+               }
+
                return $retVal;
        }
-       
+
 }
 
 class WebInstaller_Options extends WebInstallerPage {
-       
+
        public function execute() {
                if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
                        return 'skip';
@@ -537,6 +807,7 @@ class WebInstaller_Options extends WebInstallerPage {
                        }
                }
 
+               $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
                $this->startForm();
                $this->addHTML(
                        # User Rights
@@ -546,7 +817,7 @@ class WebInstaller_Options extends WebInstallerPage {
                                'itemLabelPrefix' => 'config-profile-',
                                'values' => array_keys( $this->parent->rightsProfiles ),
                        ) ) .
-                       $this->parent->getHelpBox( 'config-profile-help' ) .
+                       $this->parent->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
 
                        # Licensing
                        $this->parent->getRadioSet( array(
@@ -560,14 +831,14 @@ class WebInstaller_Options extends WebInstallerPage {
                        $this->parent->getHelpBox( 'config-license-help' ) .
 
                        # E-mail
-                       $this->parent->getFieldsetStart( 'config-email-settings' ) .
+                       $this->getFieldSetStart( 'config-email-settings' ) .
                        $this->parent->getCheckBox( array(
                                'var' => 'wgEnableEmail',
                                'label' => 'config-enable-email',
                                'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
                        ) ) .
                        $this->parent->getHelpBox( 'config-enable-email-help' ) .
-                       "<div id=\"emailwrapper\">" .
+                       "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
                        $this->parent->getTextBox( array(
                                'var' => 'wgPasswordSender',
                                'label' => 'config-email-sender'
@@ -594,57 +865,66 @@ class WebInstaller_Options extends WebInstallerPage {
                        ) ) .
                        $this->parent->getHelpBox( 'config-email-auth-help' ) .
                        "</div>" .
-                       $this->parent->getFieldsetEnd()
+                       $this->getFieldSetEnd()
                );
 
                $extensions = $this->parent->findExtensions();
-               
+
                if( $extensions ) {
-                       $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
-                       
+                       $extHtml = $this->getFieldSetStart( 'config-extensions' );
+
                        foreach( $extensions as $ext ) {
                                $extHtml .= $this->parent->getCheckBox( array(
                                        'var' => "ext-$ext",
                                        'rawtext' => $ext,
                                ) );
                        }
-                       
+
                        $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
-                               $this->parent->getFieldsetEnd();
+                       $this->getFieldSetEnd();
                        $this->addHTML( $extHtml );
                }
 
+               // Having / in paths in Windows looks funny :)
+               $this->setVar( 'wgDeletedDirectory',
+                       str_replace(
+                               '/', DIRECTORY_SEPARATOR,
+                               $this->getVar( 'wgDeletedDirectory' )
+                       )
+               );
+
+               $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
                $this->addHTML(
                        # Uploading
-                       $this->parent->getFieldsetStart( 'config-upload-settings' ) .
-                       $this->parent->getCheckBox( array( 
+                       $this->getFieldSetStart( 'config-upload-settings' ) .
+                       $this->parent->getCheckBox( array(
                                'var' => 'wgEnableUploads',
                                'label' => 'config-upload-enable',
                                'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
+                               'help' => $this->parent->getHelpBox( 'config-upload-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-upload-help' ) .
-                       '<div id="uploadwrapper" style="display: none;">' .
-                       $this->parent->getTextBox( array( 
+                       '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
+                       $this->parent->getTextBox( array(
                                'var' => 'wgDeletedDirectory',
                                'label' => 'config-upload-deleted',
+                               'attribs' => array( 'dir' => 'ltr' ),
+                               'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
                        '</div>' .
                        $this->parent->getTextBox( array(
                                'var' => 'wgLogo',
-                               'label' => 'config-logo'
-                       ) ) .
-                       $this->parent->getHelpBox( 'config-logo-help' )
+                               'label' => 'config-logo',
+                               'attribs' => array( 'dir' => 'ltr' ),
+                               'help' => $this->parent->getHelpBox( 'config-logo-help' )
+                       ) )
                );
-               $canUse = $this->getVar( '_ExternalHTTP' ) ?
-                       'config-instantcommons-good' : 'config-instantcommons-bad';
                $this->addHTML(
                        $this->parent->getCheckBox( array(
                                'var' => 'wgUseInstantCommons',
                                'label' => 'config-instantcommons',
+                               'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
-                       $this->parent->getFieldsetEnd()
+                       $this->getFieldSetEnd()
                );
 
                $caches = array( 'none' );
@@ -653,32 +933,45 @@ class WebInstaller_Options extends WebInstallerPage {
                }
                $caches[] = 'memcached';
 
+               // We'll hide/show this on demand when the value changes, see config.js.
+               $cacheval = $this->getVar( 'wgMainCacheType' );
+               if (!$cacheval) {
+                       // We need to set a default here; but don't hardcode it
+                       // or we lose it every time we reload the page for validation
+                       // or going back!
+                       $cacheval = 'none';
+               }
+               $hidden = ($cacheval == 'memcached') ? '' : 'display: none';
                $this->addHTML(
                        # Advanced settings
-                       $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
+                       $this->getFieldSetStart( 'config-advanced-settings' ) .
                        # Object cache settings
                        $this->parent->getRadioSet( array(
                                'var' => 'wgMainCacheType',
                                'label' => 'config-cache-options',
                                'itemLabelPrefix' => 'config-cache-',
                                'values' => $caches,
-                               'value' => 'none',
+                               'value' => $cacheval,
                        ) ) .
                        $this->parent->getHelpBox( 'config-cache-help' ) .
-                       '<div id="config-memcachewrapper">' .
-                       $this->parent->getTextBox( array(
+                       "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
+                       $this->parent->getTextArea( array(
                                'var' => '_MemCachedServers',
                                'label' => 'config-memcached-servers',
+                               'help' => $this->parent->getHelpBox( 'config-memcached-help' )
                        ) ) .
-                       $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
-                       $this->parent->getFieldsetEnd()
+                       '</div>' .
+                       $this->getFieldSetEnd()
                );
                $this->endForm();
        }
 
+       /**
+        * @return string
+        */
        public function getCCPartnerUrl() {
-               global $wgServer;
-               $exitUrl = $wgServer . $this->parent->getUrl( array(
+               $server = $this->getVar( 'wgServer' );
+               $exitUrl = $server . $this->parent->getUrl( array(
                        'page' => 'Options',
                        'SubmitCC' => 'indeed',
                        'config__LicenseCode' => 'cc',
@@ -686,7 +979,7 @@ class WebInstaller_Options extends WebInstallerPage {
                        'config_wgRightsText' => '[license_name]',
                        'config_wgRightsIcon' => '[license_button]',
                ) );
-               $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
+               $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
                        '/skins/common/config-cc.css';
                $iframeUrl = 'http://creativecommons.org/license/?' .
                        wfArrayToCGI( array(
@@ -712,10 +1005,11 @@ class WebInstaller_Options extends WebInstallerPage {
                } else {
                        $iframeAttribs['src'] = $this->getCCPartnerUrl();
                }
+               $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ? '' : 'display: none';
 
                return
-                       "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
-                       Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
+                       "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
+                       Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
                        "</div>\n";
        }
 
@@ -726,12 +1020,12 @@ class WebInstaller_Options extends WebInstallerPage {
                $reduceJs = str_replace( '$1', '70px', $js );
                return
                        '<p>'.
-                       Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
+                       Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
                        '&#160;&#160;' .
                        htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
                        "</p>\n" .
                        "<p style=\"text-align: center\">" .
-                       Xml::element( 'a',
+                       Html::element( 'a',
                                array(
                                        'href' => $this->getCCPartnerUrl(),
                                        'onclick' => $expandJs,
@@ -800,39 +1094,82 @@ class WebInstaller_Options extends WebInstallerPage {
                        }
                }
                $this->parent->setVar( '_Extensions', $extsToInstall );
+
+               if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
+                       $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
+                       if( !$memcServers ) {
+                               $this->parent->showError( 'config-memcache-needservers' );
+                               return false;
+                       }
+
+                       foreach( $memcServers as $server ) {
+                               $memcParts = explode( ":", $server, 2 );
+                               if ( !isset( $memcParts[0] )
+                                               || ( !IP::isValid( $memcParts[0] )
+                                                       && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
+                                       $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
+                                       return false;
+                               } elseif( !isset( $memcParts[1] )  ) {
+                                       $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
+                                       return false;
+                               } elseif( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
+                                       $this->parent->showError( 'config-memcache-badport', 1, 65535 );
+                                       return false;
+                               }
+                       }
+               }
                return true;
        }
-       
+
 }
 
 class WebInstaller_Install extends WebInstallerPage {
+       public function isSlow() {
+               return true;
+       }
 
        public function execute() {
-               if( $this->parent->request->wasPosted() ) {
-                       return 'continue';
+               if( $this->getVar( '_UpgradeDone' ) ) {
+                       return 'skip';
                } elseif( $this->getVar( '_InstallDone' ) ) {
-                       $this->startForm();
-                       $status = new Status();
-                       $status->warning( 'config-install-alreadydone' );
-                       $this->parent->showStatusBox( $status );
-               } else {
+                       return 'continue';
+               } elseif( $this->parent->request->wasPosted() ) {
                        $this->startForm();
                        $this->addHTML("<ul>");
-                       $this->parent->performInstallation(
+                       $results = $this->parent->performInstallation(
                                array( $this, 'startStage'),
                                array( $this, 'endStage' )
                        );
                        $this->addHTML("</ul>");
+                       // PerformInstallation bails on a fatal, so make sure the last item
+                       // completed before giving 'next.' Likewise, only provide back on failure
+                       $lastStep = end( $results );
+                       $continue = $lastStep->isOK() ? 'continue' : false;
+                       $back = $lastStep->isOK() ? false : 'back';
+                       $this->endForm( $continue, $back );
+               } else {
+                       $this->startForm();
+                       $this->addHTML( $this->parent->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
+                       $this->endForm();
                }
-               $this->endForm();
                return true;
        }
 
        public function startStage( $step ) {
                $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
+               if ( $step == 'extension-tables' ) {
+                       $this->startLiveBox();
+               }
        }
 
+       /**
+        * @param $step
+        * @param $status Status
+        */
        public function endStage( $step, $status ) {
+               if ( $step == 'extension-tables' ) {
+                       $this->endLiveBox();
+               }
                $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
                $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
                if ( !$status->isOk() ) {
@@ -843,37 +1180,51 @@ class WebInstaller_Install extends WebInstallerPage {
                        $this->parent->showStatusBox( $status );
                }
        }
-       
+
 }
 
 class WebInstaller_Complete extends WebInstallerPage {
-       
+
        public function execute() {
+               // Pop up a dialog box, to make it difficult for the user to forget
+               // to download the file
+               $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
+               if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
+                        strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
+                       // JS appears the only method that works consistently with IE7+
+                       $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
+                               '">jQuery( document ).ready( function() { document.location=' .
+                               Xml::encodeJsVar( $lsUrl) . "; } );</script>\n" );
+               } else {
+                       $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
+               }
+
                $this->startForm();
+               $this->parent->disableLinkPopups();
                $this->addHTML(
                        $this->parent->getInfoBox(
                                wfMsgNoTrans( 'config-install-done',
-                                       $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ),
-                                       $GLOBALS['wgServer'] .
+                                       $lsUrl,
+                                       $this->getVar( 'wgServer' ) .
                                                $this->getVar( 'wgScriptPath' ) . '/index' .
-                                               $this->getVar( 'wgScriptExtension' )
+                                               $this->getVar( 'wgScriptExtension' ),
+                                       '<downloadlink/>'
                                ), 'tick-32.png'
                        )
                );
-               $this->endForm( false );
+               $this->parent->restoreLinkPopups();
+               $this->endForm( false, false );
        }
 }
 
 class WebInstaller_Restart extends WebInstallerPage {
-       
+
        public function execute() {
                $r = $this->parent->request;
                if ( $r->wasPosted() ) {
                        $really = $r->getVal( 'submit-restart' );
                        if ( $really ) {
-                               $this->parent->session = array();
-                               $this->parent->happyPages = array();
-                               $this->parent->settings = array();
+                               $this->parent->reset();
                        }
                        return 'continue';
                }
@@ -883,102 +1234,40 @@ class WebInstaller_Restart extends WebInstallerPage {
                $this->addHTML( $s );
                $this->endForm( 'restart' );
        }
-       
+
 }
 
 abstract class WebInstaller_Document extends WebInstallerPage {
-       
+
        protected abstract function getFileName();
 
        public  function execute() {
                $text = $this->getFileContents();
+               $text = InstallDocFormatter::format( $text );
                $this->parent->output->addWikiText( $text );
                $this->startForm();
                $this->endForm( false );
        }
 
-       public  function getFileContents() {
+       public function getFileContents() {
                return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
        }
 
-       protected function formatTextFile( $text ) {
-               $text = str_replace( array( '<', '{{', '[[' ),
-                       array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
-               // replace numbering with [1], [2], etc with MW-style numbering
-               $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
-               // join word-wrapped lines into one
-               do {
-                       $prev = $text;
-                       $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
-               } while ( $text != $prev );
-               // turn (bug nnnn) into links
-               $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
-               // add links to manual to every global variable mentioned
-               $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
-               // special case for <pre> - formatted links
-               do {
-                       $prev = $text;
-                       $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
-               } while ( $text != $prev );
-               return $text;
-       }
-
-       private function replaceBugLinks( $matches ) {
-               return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
-                       $matches[1] . ' bug ' . $matches[1] . ']</span>';
-       }
-
-       private function replaceConfigLinks( $matches ) {
-               return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
-                       $matches[1] . ' ' . $matches[1] . ']</span>';
-       }
-       
 }
 
 class WebInstaller_Readme extends WebInstaller_Document {
-       
        protected function getFileName() { return 'README'; }
-
-       public function getFileContents() {
-               return $this->formatTextFile( parent::getFileContents() );
-       }
-       
 }
 
 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
-       
        protected function getFileName() { return 'RELEASE-NOTES'; }
-
-       public function getFileContents() {
-               return $this->formatTextFile( parent::getFileContents() );
-       }
-       
 }
 
 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
-       
        protected function getFileName() { return 'UPGRADE'; }
-
-       public function getFileContents() {
-               return $this->formatTextFile( parent::getFileContents() );
-       }
-       
 }
 
 class WebInstaller_Copying extends WebInstaller_Document {
-       
        protected function getFileName() { return 'COPYING'; }
+}
 
-       public function getFileContents() {
-               $text = parent::getFileContents();
-               $text = str_replace( "\x0C", '', $text );
-               $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
-               $text = '<tt>' . nl2br( $text ) . '</tt>';
-               return $text;
-       }
-
-       private static function replaceLeadingSpaces( $matches ) {
-               return "\n" . str_repeat( '&#160;', strlen( $matches[0] ) );
-       }
-       
-}
\ No newline at end of file