MediaWiki REL1_27
CliInstaller.php
Go to the documentation of this file.
1<?php
30class CliInstaller extends Installer {
31 private $specifiedScriptPath = false;
32
33 private $optionMap = [
34 'dbtype' => 'wgDBtype',
35 'dbserver' => 'wgDBserver',
36 'dbname' => 'wgDBname',
37 'dbuser' => 'wgDBuser',
38 'dbpass' => 'wgDBpassword',
39 'dbprefix' => 'wgDBprefix',
40 'dbtableoptions' => 'wgDBTableOptions',
41 'dbmysql5' => 'wgDBmysql5',
42 'dbport' => 'wgDBport',
43 'dbschema' => 'wgDBmwschema',
44 'dbpath' => 'wgSQLiteDataDir',
45 'server' => 'wgServer',
46 'scriptpath' => 'wgScriptPath',
47 ];
48
56 function __construct( $siteName, $admin = null, array $option = [] ) {
58
59 parent::__construct();
60
61 if ( isset( $option['scriptpath'] ) ) {
62 $this->specifiedScriptPath = true;
63 }
64
65 foreach ( $this->optionMap as $opt => $global ) {
66 if ( isset( $option[$opt] ) ) {
67 $GLOBALS[$global] = $option[$opt];
68 $this->setVar( $global, $option[$opt] );
69 }
70 }
71
72 if ( isset( $option['lang'] ) ) {
74 $this->setVar( '_UserLang', $option['lang'] );
75 $wgContLang = Language::factory( $option['lang'] );
76 $wgLang = Language::factory( $option['lang'] );
77 $wgLanguageCode = $option['lang'];
78 RequestContext::getMain()->setLanguage( $wgLang );
79 }
80
81 $this->setVar( 'wgSitename', $siteName );
82
83 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
84 if ( $metaNS == 'MediaWiki' ) {
85 $metaNS = 'Project';
86 }
87 $this->setVar( 'wgMetaNamespace', $metaNS );
88
89 if ( $admin ) {
90 $this->setVar( '_AdminName', $admin );
91 }
92
93 if ( !isset( $option['installdbuser'] ) ) {
94 $this->setVar( '_InstallUser',
95 $this->getVar( 'wgDBuser' ) );
96 $this->setVar( '_InstallPassword',
97 $this->getVar( 'wgDBpassword' ) );
98 } else {
99 $this->setVar( '_InstallUser',
100 $option['installdbuser'] );
101 $this->setVar( '_InstallPassword',
102 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" );
103
104 // Assume that if we're given the installer user, we'll create the account.
105 $this->setVar( '_CreateDBAccount', true );
106 }
107
108 if ( isset( $option['pass'] ) ) {
109 $this->setVar( '_AdminPassword', $option['pass'] );
110 }
111
112 // Detect and inject any extension found
113 if ( isset( $option['with-extensions'] ) ) {
114 $this->setVar( '_Extensions', $this->findExtensions() );
115 }
116
117 // Set up the default skins
118 $skins = $this->findExtensions( 'skins' );
119 $this->setVar( '_Skins', $skins );
120
121 if ( $skins ) {
122 $skinNames = array_map( 'strtolower', $skins );
123 $this->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) );
124 }
125 }
126
130 public function execute() {
132 if ( $vars ) {
133 $this->showStatusMessage(
134 Status::newFatal( "config-localsettings-cli-upgrade" )
135 );
136 }
137
138 $this->performInstallation(
139 [ $this, 'startStage' ],
140 [ $this, 'endStage' ]
141 );
142 }
143
149 public function writeConfigurationFile( $path ) {
151 $ls->writeFile( "$path/LocalSettings.php" );
152 }
153
154 public function startStage( $step ) {
155 // Messages: config-install-database, config-install-tables, config-install-interwiki,
156 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage,
157 // config-install-extensions
158 $this->showMessage( "config-install-$step" );
159 }
160
161 public function endStage( $step, $status ) {
162 $this->showStatusMessage( $status );
163 $this->showMessage( 'config-install-step-done' );
164 }
165
166 public function showMessage( $msg /*, ... */ ) {
167 echo $this->getMessageText( func_get_args() ) . "\n";
168 flush();
169 }
170
171 public function showError( $msg /*, ... */ ) {
172 echo "***{$this->getMessageText( func_get_args() )}***\n";
173 flush();
174 }
175
181 protected function getMessageText( $params ) {
182 $msg = array_shift( $params );
183
184 $text = wfMessage( $msg, $params )->parse();
185
186 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
187
188 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
189 }
190
194 public function showHelpBox( $msg /*, ... */ ) {
195 }
196
197 public function showStatusMessage( Status $status ) {
198 $warnings = array_merge( $status->getWarningsArray(),
199 $status->getErrorsArray() );
200
201 if ( count( $warnings ) !== 0 ) {
202 foreach ( $warnings as $w ) {
203 call_user_func_array( [ $this, 'showMessage' ], $w );
204 }
205 }
206
207 if ( !$status->isOK() ) {
208 echo "\n";
209 exit( 1 );
210 }
211 }
212
213 public function envCheckPath() {
214 if ( !$this->specifiedScriptPath ) {
215 $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) );
216 }
217
218 return parent::envCheckPath();
219 }
220
221 protected function envGetDefaultServer() {
222 return null; // Do not guess if installing from CLI
223 }
224
225 public function dirIsExecutable( $dir, $url ) {
226 $this->showMessage( 'config-no-cli-uploads-check', $dir );
227
228 return false;
229 }
230}
$GLOBALS['IP']
$wgLanguageCode
Site language code.
Class for the core installer command line interface.
showError( $msg)
Same as showMessage(), but for displaying errors.
__construct( $siteName, $admin=null, array $option=[])
Constructor.
execute()
Main entry point.
showHelpBox( $msg)
Dummy.
showStatusMessage(Status $status)
Show a message to the installing user by using a Status object.
getMessageText( $params)
writeConfigurationFile( $path)
Write LocalSettings.php to a given path.
dirIsExecutable( $dir, $url)
Checks if scripts located in the given directory can be executed via the given URL.
envGetDefaultServer()
Helper function to be called from envPrepServer()
envCheckPath()
Environment check to inform user which paths we've assumed.
startStage( $step)
endStage( $step, $status)
showMessage( $msg)
UI interface for displaying a short message The parameters are like parameters to wfMessage().
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
Base installer class.
Definition Installer.php:42
getDefaultSkin(array $skinNames)
Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings,...
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
performInstallation( $startCB, $endCB)
Actually perform the installation.
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
findExtensions( $directory='extensions')
Finds extensions that follow the format /$directory/Name/Name.php, and returns an array containing th...
static getMain()
Static methods.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition design.txt:56
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1007
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:1999
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
if(count( $args)==0) $dir
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params