bbb43fbfe03425f94f8a2efda4d513d24d86a4f9
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
1 <?php
2
3 /**
4 * Class for the core installer command line interface.
5 *
6 * @since 1.17
7 */
8 class CliInstaller extends CoreInstaller {
9
10 /* The maintenance class in effect */
11 private $maint;
12
13 private $optionMap = array(
14 'dbtype' => 'wgDBtype',
15 'dbserver' => 'wgDBserver',
16 'dbname' => 'wgDBname',
17 'dbuser' => 'wgDBuser',
18 'dbpass' => 'wgDBpassword',
19 'dbprefix' => 'wgDBprefix',
20 'dbtableoptions' => 'wgDBTableOptions',
21 'dbmysql5' => 'wgDBmysql5',
22 'dbserver' => 'wgDBserver',
23 'dbport' => 'wgDBport',
24 'dbname' => 'wgDBname',
25 'dbuser' => 'wgDBuser',
26 'dbpass' => 'wgDBpassword',
27 'dbschema' => 'wgDBmwschema',
28 'dbts2schema' => 'wgDBts2schema',
29 'dbpath' => 'wgSQLiteDataDir',
30 );
31
32 /** Constructor */
33 function __construct( $siteName, $admin = null, $option = array() ) {
34 parent::__construct();
35
36 foreach ( $this->optionMap as $opt => $global ) {
37 if ( isset( $option[$opt] ) ) {
38 $GLOBALS[$global] = $option[$opt];
39 $this->setVar( $global, $option[$opt] );
40 }
41 }
42
43 if ( isset( $option['lang'] ) ) {
44 global $wgLang, $wgContLang, $wgLanguageCode;
45 $this->setVar( '_UserLang', $option['lang'] );
46 $wgContLang = Language::factory( $option['lang'] );
47 $wgLang = Language::factory( $option['lang'] );
48 $wgLanguageCode = $option['lang'];
49 }
50
51 $this->setVar( 'wgSitename', $siteName );
52 if ( $admin ) {
53 $this->setVar( '_AdminName', $admin );
54 }
55
56 if ( !isset( $option['installdbuser'] ) ) {
57 $this->setVar( '_InstallUser',
58 $this->getVar( 'wgDBuser' ) );
59 $this->setVar( '_InstallPassword',
60 $this->getVar( 'wgDBpassword' ) );
61 }
62
63 if ( isset( $option['pass'] ) ) {
64 $this->setVar( '_AdminPassword', $option['pass'] );
65 }
66 }
67
68 /**
69 * Main entry point.
70 */
71 public function execute() {
72 $this->performInstallation(
73 array( $this, 'startStage'),
74 array( $this, 'endStage' )
75 );
76 }
77
78 public function startStage( $step ) {
79 $this->showMessage( wfMsg( "config-install-$step") .
80 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
81 }
82
83 public function endStage( $step, $status ) {
84 $warnings = $status->getWarningsArray();
85 if ( !$status->isOk() ) {
86 $this->showStatusMessage( $status );
87 echo "\n";
88 exit;
89 } elseif ( count($warnings) !== 0 ) {
90 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
91 $this->showMessage( $w . wfMsg( 'ellipsis') .
92 wfMsg( 'word-separator' ) );
93 }
94 }
95 $this->showMessage( wfMsg( 'config-install-step-done' ) ."\n");
96 }
97
98 public function showMessage( $msg /*, ... */ ) {
99 echo html_entity_decode( strip_tags( $msg ), ENT_QUOTES );
100 flush();
101 }
102
103 public function showStatusMessage( $status ) {
104 $this->showMessage( $status->getWikiText() );
105 }
106
107 }