Removed comment that's no longer relevant
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
1 <?php
2 /**
3 * Core installer command line interface.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Class for the core installer command line interface.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 class CliInstaller extends CoreInstaller {
16
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',
34 );
35
36 /**
37 * Constructor.
38 *
39 * @param $siteName
40 * @param $admin
41 * @param $option Array
42 */
43 function __construct( $siteName, $admin = null, array $option = array() ) {
44 parent::__construct();
45
46 foreach ( $this->optionMap as $opt => $global ) {
47 if ( isset( $option[$opt] ) ) {
48 $GLOBALS[$global] = $option[$opt];
49 $this->setVar( $global, $option[$opt] );
50 }
51 }
52
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'];
59 }
60
61 $this->setVar( 'wgSitename', $siteName );
62
63 if ( $admin ) {
64 $this->setVar( '_AdminName', $admin );
65 }
66
67 if ( !isset( $option['installdbuser'] ) ) {
68 $this->setVar( '_InstallUser',
69 $this->getVar( 'wgDBuser' ) );
70 $this->setVar( '_InstallPassword',
71 $this->getVar( 'wgDBpassword' ) );
72 }
73
74 if ( isset( $option['pass'] ) ) {
75 $this->setVar( '_AdminPassword', $option['pass'] );
76 }
77 }
78
79 /**
80 * Main entry point.
81 */
82 public function execute() {
83 $this->performInstallation(
84 array( $this, 'startStage' ),
85 array( $this, 'endStage' )
86 );
87
88 $ls = new LocalSettingsGenerator( $this );
89 file_put_contents( "LocalSettings.php", $ls->getText() );
90 }
91
92 public function startStage( $step ) {
93 $this->showMessage( wfMsg( "config-install-$step" ) .
94 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
95 }
96
97 public function endStage( $step, $status ) {
98 $warnings = $status->getWarningsArray();
99
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' ) );
108 }
109 }
110
111 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
112 }
113
114 public function showMessage( $msg /*, ... */ ) {
115 echo html_entity_decode( strip_tags( $msg ), ENT_QUOTES );
116 flush();
117 }
118
119 public function showStatusMessage( Status $status ) {
120 $this->showMessage( $status->getWikiText() );
121 }
122 }