Uncommented some used options; added the possibility to define $wgScriptPath
[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 'scriptpath' => 'wgScriptPath',
35 );
36
37 /**
38 * Constructor.
39 *
40 * @param $siteName
41 * @param $admin
42 * @param $option Array
43 */
44 function __construct( $siteName, $admin = null, array $option = array() ) {
45 parent::__construct();
46
47 foreach ( $this->optionMap as $opt => $global ) {
48 if ( isset( $option[$opt] ) ) {
49 $GLOBALS[$global] = $option[$opt];
50 $this->setVar( $global, $option[$opt] );
51 }
52 }
53
54 if ( isset( $option['lang'] ) ) {
55 global $wgLang, $wgContLang, $wgLanguageCode;
56 $this->setVar( '_UserLang', $option['lang'] );
57 $wgContLang = Language::factory( $option['lang'] );
58 $wgLang = Language::factory( $option['lang'] );
59 $wgLanguageCode = $option['lang'];
60 }
61
62 $this->setVar( 'wgSitename', $siteName );
63
64 if ( $admin ) {
65 $this->setVar( '_AdminName', $admin );
66 }
67
68 if ( !isset( $option['installdbuser'] ) ) {
69 $this->setVar( '_InstallUser',
70 $this->getVar( 'wgDBuser' ) );
71 $this->setVar( '_InstallPassword',
72 $this->getVar( 'wgDBpassword' ) );
73 }
74
75 if ( isset( $option['pass'] ) ) {
76 $this->setVar( '_AdminPassword', $option['pass'] );
77 }
78 }
79
80 /**
81 * Main entry point.
82 */
83 public function execute() {
84 $this->performInstallation(
85 array( $this, 'startStage' ),
86 array( $this, 'endStage' )
87 );
88
89 $ls = new LocalSettingsGenerator( $this );
90 file_put_contents( "LocalSettings.php", $ls->getText() );
91 }
92
93 public function startStage( $step ) {
94 $this->showMessage( wfMsg( "config-install-$step" ) .
95 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
96 }
97
98 public function endStage( $step, $status ) {
99 $warnings = $status->getWarningsArray();
100
101 if ( !$status->isOk() ) {
102 $this->showStatusMessage( $status );
103 echo "\n";
104 exit;
105 } elseif ( count( $warnings ) !== 0 ) {
106 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
107 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
108 wfMsg( 'word-separator' ) );
109 }
110 }
111
112 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
113 }
114
115 public function showMessage( $msg /*, ... */ ) {
116 echo html_entity_decode( strip_tags( $msg ), ENT_QUOTES );
117 flush();
118 }
119
120 public function showStatusMessage( Status $status ) {
121 $this->showMessage( $status->getWikiText() );
122 }
123 }