* @ingroup Deployment
*/
+use MediaWiki\Installer\InstallException;
use MediaWiki\MediaWikiServices;
/**
/**
* @param string $siteName
* @param string|null $admin
- * @param array $option
+ * @param array $options
+ * @throws InstallException
*/
- function __construct( $siteName, $admin = null, array $option = [] ) {
+ function __construct( $siteName, $admin = null, array $options = [] ) {
global $wgContLang;
parent::__construct();
- if ( isset( $option['scriptpath'] ) ) {
+ if ( isset( $options['scriptpath'] ) ) {
$this->specifiedScriptPath = true;
}
foreach ( $this->optionMap as $opt => $global ) {
- if ( isset( $option[$opt] ) ) {
- $GLOBALS[$global] = $option[$opt];
- $this->setVar( $global, $option[$opt] );
+ if ( isset( $options[$opt] ) ) {
+ $GLOBALS[$global] = $options[$opt];
+ $this->setVar( $global, $options[$opt] );
}
}
- if ( isset( $option['lang'] ) ) {
+ if ( isset( $options['lang'] ) ) {
global $wgLang, $wgLanguageCode;
- $this->setVar( '_UserLang', $option['lang'] );
- $wgLanguageCode = $option['lang'];
+ $this->setVar( '_UserLang', $options['lang'] );
+ $wgLanguageCode = $options['lang'];
+ $this->setVar( 'wgLanguageCode', $wgLanguageCode );
$wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
- $wgLang = Language::factory( $option['lang'] );
+ $wgLang = Language::factory( $options['lang'] );
RequestContext::getMain()->setLanguage( $wgLang );
}
$this->setVar( '_AdminName', $admin );
}
- if ( !isset( $option['installdbuser'] ) ) {
+ if ( !isset( $options['installdbuser'] ) ) {
$this->setVar( '_InstallUser',
$this->getVar( 'wgDBuser' ) );
$this->setVar( '_InstallPassword',
$this->getVar( 'wgDBpassword' ) );
} else {
$this->setVar( '_InstallUser',
- $option['installdbuser'] );
+ $options['installdbuser'] );
$this->setVar( '_InstallPassword',
- $option['installdbpass'] ?? "" );
+ $options['installdbpass'] ?? "" );
// Assume that if we're given the installer user, we'll create the account.
$this->setVar( '_CreateDBAccount', true );
}
- if ( isset( $option['pass'] ) ) {
- $this->setVar( '_AdminPassword', $option['pass'] );
+ if ( isset( $options['pass'] ) ) {
+ $this->setVar( '_AdminPassword', $options['pass'] );
}
// Detect and inject any extension found
- if ( isset( $option['with-extensions'] ) ) {
- $this->setVar( '_Extensions', array_keys( $this->findExtensions() ) );
+ if ( isset( $options['extensions'] ) ) {
+ $status = $this->validateExtensions(
+ 'extension', 'extensions', $options['extensions'] );
+ if ( !$status->isOK() ) {
+ throw new InstallException( $status );
+ }
+ $this->setVar( '_Extensions', $status->value );
+ } elseif ( isset( $options['with-extensions'] ) ) {
+ $status = $this->findExtensions();
+ if ( !$status->isOK() ) {
+ throw new InstallException( $status );
+ }
+ $this->setVar( '_Extensions', array_keys( $status->value ) );
}
// Set up the default skins
- $skins = array_keys( $this->findExtensions( 'skins' ) );
+ if ( isset( $options['skins'] ) ) {
+ $status = $this->validateExtensions( 'skin', 'skins', $options['skins'] );
+ if ( !$status->isOK() ) {
+ throw new InstallException( $status );
+ }
+ $skins = $status->value;
+ } else {
+ $status = $this->findExtensions( 'skins' );
+ if ( !$status->isOK() ) {
+ throw new InstallException( $status );
+ }
+ $skins = array_keys( $status->value );
+ }
$this->setVar( '_Skins', $skins );
if ( $skins ) {
}
}
+ private function validateExtensions( $type, $directory, $nameLists ) {
+ $extensions = [];
+ $status = new Status;
+ foreach ( (array)$nameLists as $nameList ) {
+ foreach ( explode( ',', $nameList ) as $name ) {
+ $name = trim( $name );
+ if ( $name === '' ) {
+ continue;
+ }
+ $extStatus = $this->getExtensionInfo( $type, $directory, $name );
+ if ( $extStatus->isOK() ) {
+ $extensions[] = $name;
+ } else {
+ $status->merge( $extStatus );
+ }
+ }
+ }
+ $extensions = array_unique( $extensions );
+ $status->value = $extensions;
+ return $status;
+ }
+
/**
* Main entry point.
*/
public function execute() {
+ // If APC is available, use that as the MainCacheType, instead of nothing.
+ // This is hacky and should be consolidated with WebInstallerOptions.
+ // This is here instead of in __construct(), because it should run run after
+ // doEnvironmentChecks(), which populates '_Caches'.
+ if ( count( $this->getVar( '_Caches' ) ) ) {
+ // We detected a CACHE_ACCEL implementation, use it.
+ $this->setVar( '_MainCacheType', 'accel' );
+ }
+
$vars = Installer::getExistingLocalSettings();
if ( $vars ) {
- $this->showStatusMessage(
- Status::newFatal( "config-localsettings-cli-upgrade" )
- );
+ $status = Status::newFatal( "config-localsettings-cli-upgrade" );
+ $this->showStatusMessage( $status );
+ return $status;
}
- $this->performInstallation(
+ $result = $this->performInstallation(
[ $this, 'startStage' ],
[ $this, 'endStage' ]
);
+ // PerformInstallation bails on a fatal, so make sure the last item
+ // completed before giving 'next.' Likewise, only provide back on failure
+ $lastStepStatus = end( $result );
+ if ( $lastStepStatus->isOK() ) {
+ return Status::newGood();
+ } else {
+ return $lastStepStatus;
+ }
}
/**
$this->showMessage( 'config-install-step-done' );
}
- public function showMessage( $msg /*, ... */ ) {
- echo $this->getMessageText( func_get_args() ) . "\n";
+ public function showMessage( $msg, ...$params ) {
+ echo $this->getMessageText( $msg, $params ) . "\n";
flush();
}
- public function showError( $msg /*, ... */ ) {
- echo "***{$this->getMessageText( func_get_args() )}***\n";
+ public function showError( $msg, ...$params ) {
+ echo "***{$this->getMessageText( $msg, $params )}***\n";
flush();
}
/**
+ * @param string $msg
* @param array $params
*
* @return string
*/
- protected function getMessageText( $params ) {
- $msg = array_shift( $params );
-
+ protected function getMessageText( $msg, $params ) {
$text = wfMessage( $msg, $params )->parse();
$text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
$this->showMessage( ...$w );
}
}
-
- if ( !$status->isOK() ) {
- echo "\n";
- exit( 1 );
- }
}
public function envCheckPath() {