3bc45b98394790c01e42b695ab979bbaab8e24fe
[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 'wikiroot' => 'wgScriptPath',
36 'upgrade' => 'cliUpgrade', /* As long as it isn't $confItems
37 * in LocalSettingsGenerator, we
38 * should be fine. */
39 );
40
41 /**
42 * Constructor.
43 *
44 * @param $siteName
45 * @param $admin
46 * @param $option Array
47 */
48 function __construct( $siteName, $admin = null, array $option = array() ) {
49 parent::__construct();
50
51 foreach ( $this->optionMap as $opt => $global ) {
52 if ( isset( $option[$opt] ) ) {
53 $GLOBALS[$global] = $option[$opt];
54 $this->setVar( $global, $option[$opt] );
55 }
56 }
57
58 if ( isset( $option['lang'] ) ) {
59 global $wgLang, $wgContLang, $wgLanguageCode;
60 $this->setVar( '_UserLang', $option['lang'] );
61 $wgContLang = Language::factory( $option['lang'] );
62 $wgLang = Language::factory( $option['lang'] );
63 $wgLanguageCode = $option['lang'];
64 }
65
66 $this->setVar( 'wgSitename', $siteName );
67
68 if ( $admin ) {
69 $this->setVar( '_AdminName', $admin );
70 }
71
72 if ( !isset( $option['installdbuser'] ) ) {
73 $this->setVar( '_InstallUser',
74 $this->getVar( 'wgDBuser' ) );
75 $this->setVar( '_InstallPassword',
76 $this->getVar( 'wgDBpassword' ) );
77 }
78
79 if ( isset( $option['pass'] ) ) {
80 $this->setVar( '_AdminPassword', $option['pass'] );
81 }
82 }
83
84 /**
85 * Main entry point.
86 */
87 public function execute() {
88 global $cliUpgrade;
89
90 $vars = $this->getExistingLocalSettings();
91 if( $vars && ( !isset( $cliUpgrade ) || $cliUpgrade !== "yes" ) ) {
92 $this->showStatusMessage(
93 Status::newFatal( "config-localsettings-cli-upgrade" )
94 );
95 }
96
97 $this->performInstallation(
98 array( $this, 'startStage' ),
99 array( $this, 'endStage' )
100 );
101 }
102
103 /**
104 * Write LocalSettings.php to a given path
105 *
106 * @param $path String Full path to write LocalSettings.php to
107 */
108 public function writeConfigurationFile( $path ) {
109 $ls = new LocalSettingsGenerator( $this );
110 $ls->writeFile( "$path/LocalSettings.php" );
111 }
112
113 public function startStage( $step ) {
114 $this->showMessage( wfMsg( "config-install-$step" ) .
115 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
116 }
117
118 public function endStage( $step, $status ) {
119 $this->showStatusMessage( $status );
120 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
121 }
122
123 public function showMessage( $msg /*, ... */ ) {
124 $params = func_get_args();
125 array_shift( $params );
126
127 /* parseinline has the nasty side-effect of putting encoded
128 * angle brackets, around the message, so the substr removes
129 * them. */
130 $text = substr( wfMsgExt( $msg, array( 'parseinline' ), $params ), 4, -4 );
131 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
132 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES ) . "\n";
133 flush();
134 }
135
136 public function showStatusMessage( Status $status ) {
137 $warnings = array_merge( $status->getWarningsArray(),
138 $status->getErrorsArray() );
139
140 if ( count( $warnings ) !== 0 ) {
141 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
142 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
143 wfMsg( 'word-separator' ) );
144 }
145 }
146
147 if ( !$status->isOk() ) {
148 echo "\n";
149 exit;
150 }
151 }
152 }