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
* @return bool
*/
public function isSlow() {
return false;
}
public function addHTML( $html ) {
$this->parent->output->addHTML( $html );
}
public function startForm() {
$this->addHTML(
"
\n";
$this->addHTML( $s );
}
public function getName() {
return str_replace( 'WebInstaller_', '', get_class( $this ) );
}
protected function getId() {
return array_search( $this->getName(), $this->parent->pageSequence );
}
public function getVar( $var ) {
return $this->parent->getVar( $var );
}
public function setVar( $name, $value ) {
$this->parent->setVar( $name, $value );
}
/**
* Get the starting tags of a fieldset.
*
* @param string $legend message name
*
* @return string
*/
protected function getFieldsetStart( $legend ) {
return "\n\n";
}
/**
* 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;
$userLang = $r->getVal( 'uselang' );
$contLang = $r->getVal( 'ContLang' );
$languages = Language::fetchLanguageNames();
$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 {
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( 'uselang', '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 "\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(
wfMessage( 'config-upgrade-key-missing', "
" )->plain()
) );
$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( wfMessage( 'config-localsettings-upgrade' )->plain() ).
' ' .
$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 array $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( wfMessage( 'config-welcome' )->plain() );
$status = $this->parent->doEnvironmentChecks();
if ( $status->isGood() ) {
$this->parent->output->addHTML( '' .
wfMessage( 'config-env-good' )->escaped() . '' );
$this->parent->output->addWikiText( wfMessage( 'config-copyright',
SpecialVersion::getCopyrightAndAuthorList() )->plain() );
$this->startForm();
$this->endForm();
} else {
$this->parent->showStatusMessage( $status );
}
return '';
}
}
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 = "
\n";
$settings = '';
$defaultType = $this->getVar( 'wgDBtype' );
$dbSupport = '';
foreach( $this->parent->getDBTypes() as $type ) {
$link = DatabaseBase::factory( $type )->getSoftwareLink();
$dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
}
$this->addHTML( $this->parent->getInfoBox(
wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
// It's possible that the library for the default DB type is not compiled in.
// In that case, instead select the first supported DB type in the list.
$compiledDBs = $this->parent->getCompiledDBs();
if ( !in_array( $defaultType, $compiledDBs ) ) {
$defaultType = $compiledDBs[0];
}
foreach ( $compiledDBs as $type ) {
$installer = $this->parent->getDBInstaller( $type );
$types .=
'
\n" .
Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
"
\n";
}
public function getCCDoneBox() {
$js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
// If you change this height, also change it in config.css
$expandJs = str_replace( '$1', '54em', $js );
$reduceJs = str_replace( '$1', '70px', $js );
return
'