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