X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Finstaller%2FCliInstaller.php;h=0ff34b086f63ea96d55539d3d698445ed4523ce0;hb=fbba262dc3b0627fb10b08d1c46f31d1599dfc91;hp=aee51e78cd1e3b5929fa0f03150524c17cc34a67;hpb=35f00337816ed66a7ca8bb6eeb5fccf422ee4e1a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/CliInstaller.php b/includes/installer/CliInstaller.php index aee51e78cd..0ff34b086f 100644 --- a/includes/installer/CliInstaller.php +++ b/includes/installer/CliInstaller.php @@ -21,6 +21,7 @@ * @ingroup Deployment */ +use MediaWiki\Installer\InstallException; use MediaWiki\MediaWikiServices; /** @@ -50,30 +51,32 @@ class CliInstaller extends Installer { /** * @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 ); } @@ -89,32 +92,55 @@ class CliInstaller extends Installer { $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 ) { @@ -123,21 +149,60 @@ class CliInstaller extends Installer { } } + 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; + } } /** @@ -162,24 +227,23 @@ class CliInstaller extends Installer { $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>/', '$2 <$1>', $text ); @@ -202,11 +266,6 @@ class CliInstaller extends Installer { $this->showMessage( ...$w ); } } - - if ( !$status->isOK() ) { - echo "\n"; - exit( 1 ); - } } public function envCheckPath() {