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