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