]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/installer/CliInstaller.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.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                 } else {
81                         $this->setVar( '_InstallUser',
82                                 $option['installdbuser'] );
83                         $this->setVar( '_InstallPassword',
84                                 $option['installdbpass'] );
85                 }
86
87                 if ( isset( $option['pass'] ) ) {
88                         $this->setVar( '_AdminPassword', $option['pass'] );
89                 }
90         }
91
92         /**
93          * Main entry point.
94          */
95         public function execute() {
96                 $vars = Installer::getExistingLocalSettings();
97                 if( $vars ) {
98                         $this->showStatusMessage(
99                                 Status::newFatal( "config-localsettings-cli-upgrade" )
100                         );
101                 }
102
103                 $this->performInstallation(
104                         array( $this, 'startStage' ),
105                         array( $this, 'endStage' )
106                 );
107         }
108
109         /**
110          * Write LocalSettings.php to a given path
111          *
112          * @param $path String Full path to write LocalSettings.php to
113          */
114         public function writeConfigurationFile( $path ) {
115                 $ls = new LocalSettingsGenerator( $this );
116                 $ls->writeFile( "$path/LocalSettings.php" );
117         }
118
119         public function startStage( $step ) {
120                 $this->showMessage( "config-install-$step" );
121         }
122
123         public function endStage( $step, $status ) {
124                 $this->showStatusMessage( $status );
125                 $this->showMessage( 'config-install-step-done' );
126         }
127
128         public function showMessage( $msg /*, ... */ ) {
129                 echo $this->getMessageText( func_get_args() ) . "\n";
130                 flush();
131         }
132
133         public function showError( $msg /*, ... */ ) {
134                 echo "***{$this->getMessageText( func_get_args() )}***\n";
135                 flush();
136         }
137
138         /**
139          * @return string
140          */
141         protected function getMessageText( $params ) {
142                 $msg = array_shift( $params );
143
144                 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
145
146                 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
147                 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
148         }
149
150         /**
151          * Dummy
152          */
153         public function showHelpBox( $msg /*, ... */ ) {
154         }
155
156         public function showStatusMessage( Status $status ) {
157                 $warnings = array_merge( $status->getWarningsArray(),
158                         $status->getErrorsArray() );
159
160                 if ( count( $warnings ) !== 0 ) {
161                         foreach ( $warnings as $w ) {
162                                 call_user_func_array( array( $this, 'showMessage' ), $w );
163                         }
164                 }
165
166                 if ( !$status->isOk() ) {
167                         echo "\n";
168                         exit;
169                 }
170         }
171 }