X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Finstaller%2FWebInstallerPage.php;h=d35046d720bb34031d7ac1b374b7acaf2ab1003a;hb=253d3b7d6a5c5ea7ab74b69490b48674d828c5e9;hp=be2a780b351253e2e0d6ab9531e9a89cfcf289b7;hpb=4f8f4bf675c87af99cfe96b7d91a1c097900bc43;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index be2a780b35..d35046d720 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -20,9 +20,9 @@ abstract class WebInstallerPage { * @var WebInstaller */ public $parent; - + public abstract function execute(); - + /** * Constructor. * @@ -49,28 +49,28 @@ abstract class WebInstallerPage { ); } - public function endForm( $continue = 'continue' ) { + public function endForm( $continue = 'continue', $back = 'back' ) { $s = "
\n"; $id = $this->getId(); - + if ( $id === false ) { $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) ); } - + if ( $continue ) { // Fake submit button for enter keypress (bug 26267) $s .= Xml::submitButton( wfMsg( "config-$continue" ), 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( @@ -78,7 +78,7 @@ abstract class WebInstallerPage { 'tabindex' => $this->parent->nextTabIndex(), ) ) . "\n"; } - + $s .= "
\n"; $this->addHTML( $s ); } @@ -103,6 +103,8 @@ abstract class WebInstallerPage { * Get the starting tags of a fieldset. * * @param $legend String: message name + * + * @return string */ protected function getFieldsetStart( $legend ) { return "\n
" . wfMsgHtml( $legend ) . "\n"; @@ -110,64 +112,37 @@ abstract class WebInstallerPage { /** * Get the end tag of a fieldset. + * + * @returns string */ protected function getFieldsetEnd() { return "
\n"; } -} - -class WebInstaller_Locked extends WebInstallerPage { - // The status of Installer::getLocalSettingsStatus() - private $status; - - public function setLocalSettingsStatus( Status $s ) { - $this->status = $s; - } - - protected function getId() { - return 0; - } - public function execute() { - $r = $this->parent->request; - if( !$r->wasPosted() || !$this->status->isOK() ) { - $this->display(); - return 'output'; - } else { - $key = $r->getText( 'config_wpUpgradeKey' ); - if( !$key || $key !== $this->getVar( '_UpgradeKey' ) ) { - $this->parent->showError( 'config-localsettings-badkey' ); - $this->display(); - return 'output'; - } else { - $this->setVar( '_LocalSettingsLocked', false ); - return 'continue'; - } - } + /** + * Opens a textarea used to display the progress of a long operation + */ + protected function startLiveBox() { + $this->addHTML( + '' . + '' . + ' +' ); + $this->parent->output->flush(); } } class WebInstaller_Language extends WebInstallerPage { - + public function execute() { global $wgLang; $r = $this->parent->request; @@ -201,7 +176,6 @@ class WebInstaller_Language extends WebInstallerPage { if ( isset( $languages[$contLang] ) ) { $this->setVar( 'wgLanguageCode', $contLang ); } - $this->setVar( '_ExternalHTTP', $r->getBool( 'config__ExternalHTTP' ) ); return 'continue'; } } elseif ( $this->parent->showSessionWarning ) { @@ -221,21 +195,15 @@ class WebInstaller_Language extends WebInstallerPage { $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->parent->getCheckBox( - array( - 'var' => '_ExternalHTTP', - 'label' => 'config-allow-requests', - 'help' => $this->parent->getHelpBox( 'config-allow-requests-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 \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 = $this->parent->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', + "
\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';
" ) + ) ); + $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' ) ). + '
' . + $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' ) ) { @@ -264,22 +373,31 @@ class WebInstaller_Welcome extends WebInstallerPage { } $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) ); $status = $this->parent->doEnvironmentChecks(); - if ( $status ) { + if ( $status->isGood() ) { + $this->parent->output->addHTML( '' . + wfMsgHtml( 'config-env-good' ) . '' ); $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'; @@ -296,9 +414,8 @@ class WebInstaller_DBConnect extends WebInstallerPage { $dbSupport = ''; foreach( $this->parent->getDBTypes() as $type ) { - $db = 'Database' . ucfirst( $type ); - $dbSupport .= wfMsgNoTrans( "config-support-$type", - call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n"; + $link = DatabaseBase::newFromType( $type )->getSoftwareLink(); + $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n"; } $this->addHTML( $this->parent->getInfoBox( wfMsg( 'config-support-info', $dbSupport ) ) ); @@ -343,14 +460,17 @@ class WebInstaller_DBConnect extends WebInstallerPage { } return $installer->submitConnectForm(); } - + } class WebInstaller_Upgrade extends WebInstallerPage { - + 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 { @@ -373,17 +493,17 @@ class WebInstaller_Upgrade extends WebInstallerPage { if ( $this->parent->request->wasPosted() ) { $installer->preUpgrade(); - $this->addHTML( - '' . - '' . - ' -' ); - $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'; @@ -398,22 +518,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', + wfMsgNoTrans( $msg, $GLOBALS['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' ) ); @@ -442,7 +570,7 @@ class WebInstaller_DBSettings extends WebInstallerPage { } class WebInstaller_Name extends WebInstallerPage { - + public function execute() { $r = $this->parent->request; if ( $r->wasPosted() ) { @@ -453,7 +581,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', '' ); } @@ -480,7 +612,7 @@ class WebInstaller_Name extends WebInstallerPage { 'var' => 'wgMetaNamespace', 'label' => '', //TODO: Needs a label? 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ), - + ) ) . $this->getFieldSetStart( 'config-admin-box' ) . $this->parent->getTextBox( array( @@ -499,12 +631,12 @@ class WebInstaller_Name extends WebInstallerPage { $this->parent->getTextBox( array( 'var' => '_AdminEmail', 'label' => 'config-admin-email', - 'help' => $this->parent->getHelpBox( 'config-admin-email-help' ) + 'help' => $this->parent->getHelpBox( 'config-admin-email-help' ) ) ) . $this->parent->getCheckBox( array( 'var' => '_Subscribe', 'label' => 'config-subscribe', - 'help' => $this->parent->getHelpBox( 'config-subscribe-help' ) + 'help' => $this->parent->getHelpBox( 'config-subscribe-help' ) ) ) . $this->getFieldSetEnd() . $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) . @@ -526,7 +658,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' ) ) === '' ) { @@ -567,6 +699,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 @@ -603,18 +744,26 @@ 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 && !User::isValidEmailAddr( $email ) ) { + $this->parent->showError( 'config-admin-error-bademail' ); + $retVal = false; + } + return $retVal; } - + } class WebInstaller_Options extends WebInstallerPage { - + public function execute() { if ( $this->getVar( '_SkipOptional' ) == 'skip' ) { return 'skip'; @@ -625,6 +774,7 @@ class WebInstaller_Options extends WebInstallerPage { } } + $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none'; $this->startForm(); $this->addHTML( # User Rights @@ -634,7 +784,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( @@ -655,7 +805,7 @@ class WebInstaller_Options extends WebInstallerPage { 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ), ) ) . $this->parent->getHelpBox( 'config-enable-email-help' ) . - "
" . + "
" . $this->parent->getTextBox( array( 'var' => 'wgPasswordSender', 'label' => 'config-email-sender' @@ -686,22 +836,31 @@ class WebInstaller_Options extends WebInstallerPage { ); $extensions = $this->parent->findExtensions(); - + if( $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->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->getFieldSetStart( 'config-upload-settings' ) . @@ -709,28 +868,26 @@ class WebInstaller_Options extends WebInstallerPage { 'var' => 'wgEnableUploads', 'label' => 'config-upload-enable', 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ), - 'help' => $this->parent->getHelpBox( 'config-upload-help' ) + 'help' => $this->parent->getHelpBox( 'config-upload-help' ) ) ) . - '