Skip install entirely if we did an upgrade
[mediawiki.git] / includes / installer / CliInstaller.php
blob666f835d198f18e891a3b2faf4a4caafe24d0e70
1 <?php
2 /**
3 * Core installer command line interface.
5 * @file
6 * @ingroup Deployment
7 */
9 /**
10 * Class for the core installer command line interface.
12 * @ingroup Deployment
13 * @since 1.17
15 class CliInstaller extends CoreInstaller {
17 private $optionMap = array(
18 'dbtype' => 'wgDBtype',
19 'dbserver' => 'wgDBserver',
20 'dbname' => 'wgDBname',
21 'dbuser' => 'wgDBuser',
22 'dbpass' => 'wgDBpassword',
23 'dbprefix' => 'wgDBprefix',
24 'dbtableoptions' => 'wgDBTableOptions',
25 'dbmysql5' => 'wgDBmysql5',
26 'dbserver' => 'wgDBserver',
27 'dbport' => 'wgDBport',
28 'dbname' => 'wgDBname',
29 'dbuser' => 'wgDBuser',
30 'dbpass' => 'wgDBpassword',
31 'dbschema' => 'wgDBmwschema',
32 'dbts2schema' => 'wgDBts2schema',
33 'dbpath' => 'wgSQLiteDataDir',
36 /**
37 * Constructor.
39 * @param $siteName
40 * @param $admin
41 * @param $option Array
43 function __construct( $siteName, $admin = null, array $option = array() ) {
44 parent::__construct();
46 foreach ( $this->optionMap as $opt => $global ) {
47 if ( isset( $option[$opt] ) ) {
48 $GLOBALS[$global] = $option[$opt];
49 $this->setVar( $global, $option[$opt] );
53 if ( isset( $option['lang'] ) ) {
54 global $wgLang, $wgContLang, $wgLanguageCode;
55 $this->setVar( '_UserLang', $option['lang'] );
56 $wgContLang = Language::factory( $option['lang'] );
57 $wgLang = Language::factory( $option['lang'] );
58 $wgLanguageCode = $option['lang'];
61 $this->setVar( 'wgSitename', $siteName );
63 if ( $admin ) {
64 $this->setVar( '_AdminName', $admin );
67 if ( !isset( $option['installdbuser'] ) ) {
68 $this->setVar( '_InstallUser',
69 $this->getVar( 'wgDBuser' ) );
70 $this->setVar( '_InstallPassword',
71 $this->getVar( 'wgDBpassword' ) );
74 if ( isset( $option['pass'] ) ) {
75 $this->setVar( '_AdminPassword', $option['pass'] );
79 /**
80 * Main entry point.
82 public function execute() {
83 $this->performInstallation(
84 array( $this, 'startStage' ),
85 array( $this, 'endStage' )
88 $ls = new LocalSettingsGenerator( $this );
89 file_put_contents( "LocalSettings.php", $ls->getText() );
92 public function startStage( $step ) {
93 $this->showMessage( wfMsg( "config-install-$step" ) .
94 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
97 public function endStage( $step, $status ) {
98 $warnings = $status->getWarningsArray();
100 if ( !$status->isOk() ) {
101 $this->showStatusMessage( $status );
102 echo "\n";
103 exit;
104 } elseif ( count($warnings) !== 0 ) {
105 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
106 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
107 wfMsg( 'word-separator' ) );
111 $this->showMessage( wfMsg( 'config-install-step-done' ) ."\n");
114 public function showMessage( $msg /*, ... */ ) {
115 echo html_entity_decode( strip_tags( $msg ), ENT_QUOTES );
116 flush();
119 public function showStatusMessage( Status $status ) {
120 $this->showMessage( $status->getWikiText() );