Added --env-checks parameter to install.php that checks for prerequisites instead...
[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
90 /**
91 * Write LocalSettings.php to a given path
92 *
93 * @param $path String Full path to write LocalSettings.php to
94 */
95 public function writeConfigurationFile( $path ) {
96 $ls = new LocalSettingsGenerator( $this );
97 $ls->writeFile( "$path/LocalSettings.php" );
98 }
99
100 public function startStage( $step ) {
101 $this->showMessage( wfMsg( "config-install-$step" ) .
102 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
103 }
104
105 public function endStage( $step, $status ) {
106 $warnings = $status->getWarningsArray();
107
108 if ( !$status->isOk() ) {
109 $this->showStatusMessage( $status );
110 echo "\n";
111 exit;
112 } elseif ( count( $warnings ) !== 0 ) {
113 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
114 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
115 wfMsg( 'word-separator' ) );
116 }
117 }
118
119 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
120 }
121
122 public function showMessage( $msg /*, ... */ ) {
123 $params = func_get_args();
124 array_shift( $params );
125 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
126 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
127 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES ) . "\n";
128 flush();
129 }
130
131 public function showStatusMessage( Status $status ) {
132 $this->showMessage( $status->getWikiText() );
133 }
134 }