10 * Base core installer class.
11 * Handles everything that is independent of user interface.
16 abstract class CoreInstaller
extends Installer
{
19 * MediaWiki configuration globals that will eventually be passed through
20 * to LocalSettings.php. The names only are given here, the defaults
21 * typically come from DefaultSettings.php.
25 protected $defaultVarNames = array(
37 'wgEmailAuthentication',
40 'wgImageMagickConvertCommand',
50 'wgUseInstantCommons',
54 * Variables that are stored alongside globals, and are used for any
55 * configuration of the installation process aside from the MediaWiki
56 * configuration. Map of names to defaults.
60 protected $internalDefaults = array(
62 '_Environment' => false,
63 '_CompiledDBs' => array(),
65 '_RaiseMemory' => false,
66 '_UpgradeDone' => false,
67 '_InstallDone' => false,
69 '_InstallUser' => 'root',
70 '_InstallPassword' => '',
71 '_SameAccount' => true,
72 '_CreateDBAccount' => false,
73 '_NamespaceType' => 'site-name',
74 '_AdminName' => '', // will be set later, when the user selects language
75 '_AdminPassword' => '',
76 '_AdminPassword2' => '',
78 '_Subscribe' => false,
79 '_SkipOptional' => 'continue',
80 '_RightsProfile' => 'wiki',
81 '_LicenseCode' => 'none',
83 '_Extensions' => array(),
84 '_MemCachedServers' => '',
85 '_ExternalHTTP' => false,
89 * Steps for installation.
93 protected $installSteps = array(
102 * Known object cache types and the functions used to test for their existence.
106 protected $objectCaches = array(
107 'xcache' => 'xcache_get',
108 'apc' => 'apc_fetch',
109 'eaccel' => 'eaccelerator_get',
110 'wincache' => 'wincache_ucache_get'
114 * User rights profiles.
118 public $rightsProfiles = array(
121 '*' => array( 'edit' => false )
125 'createaccount' => false,
131 'createaccount' => false,
143 public $licenses = array(
145 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
146 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
148 'cc-by-nc-sa' => array(
149 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
150 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
153 'url' => 'http://creativecommons.org/licenses/publicdomain/',
154 'icon' => '{$wgStylePath}/common/images/public-domain.png',
157 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
158 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
160 'gfdl-current' => array(
161 'url' => 'http://www.gnu.org/copyleft/fdl.html',
162 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
169 'cc-choose' => array(
170 // Details will be filled in by the selector.
180 * @param $status Status
182 public abstract function showStatusMessage( Status
$status );
186 * Constructor, always call this from child classes.
188 public function __construct() {
189 parent
::__construct();
191 global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
193 // Load the installer's i18n file.
194 $wgExtensionMessagesFiles['MediawikiInstaller'] =
195 dirname( __FILE__
) . '/Installer.i18n.php';
197 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
198 $wgUser = User
::newFromId( 0 );
200 // Set our custom <doclink> hook.
201 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
203 $this->settings
= $this->internalDefaults
;
205 foreach ( $this->defaultVarNames
as $var ) {
206 $this->settings
[$var] = $GLOBALS[$var];
209 foreach ( self
::getDBTypes() as $type ) {
210 $installer = $this->getDBInstaller( $type );
212 if ( !$installer->isCompiled() ) {
216 $defaults = $installer->getGlobalDefaults();
218 foreach ( $installer->getGlobalNames() as $var ) {
219 if ( isset( $defaults[$var] ) ) {
220 $this->settings
[$var] = $defaults[$var];
222 $this->settings
[$var] = $GLOBALS[$var];
227 $this->parserTitle
= Title
::newFromText( 'Installer' );
228 $this->parserOptions
= new ParserOptions
;
229 $this->parserOptions
->setEditSection( false );
233 * Register tag hook below.
235 * @param $parser Parser
237 public function registerDocLink( Parser
&$parser ) {
238 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
243 * Extension tag hook for a documentation link.
245 public function docLink( $linkText, $attribs, $parser ) {
246 $url = $this->getDocUrl( $attribs['href'] );
247 return '<a href="' . htmlspecialchars( $url ) . '">' .
248 htmlspecialchars( $linkText ) .
253 * Overridden by WebInstaller to provide lastPage parameters.
255 protected function getDocUrl( $page ) {
256 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
260 * Finds extensions that follow the format /extensions/Name/Name.php,
261 * and returns an array containing the value for 'Name' for each found extension.
265 public function findExtensions() {
266 if( $this->getVar( 'IP' ) === null ) {
271 $dir = $this->getVar( 'IP' ) . '/extensions';
272 $dh = opendir( $dir );
274 while ( ( $file = readdir( $dh ) ) !== false ) {
275 if( file_exists( "$dir/$file/$file.php" ) ) {
284 * Installs the auto-detected extensions.
286 * @TODO: this only requires them? That's all it's supposed to do. Poorly
291 public function installExtensions() {
292 $exts = $this->getVar( '_Extensions' );
293 $path = $this->getVar( 'IP' ) . '/extensions';
295 foreach( $exts as $e ) {
296 require( "$path/$e/$e.php" );
299 return Status
::newGood();
303 * Get an array of install steps. These could be a plain key like the defaults
304 * in $installSteps, or could be an array with a name and a specific callback
308 public function getInstallSteps() {
309 if( $this->getVar( '_UpgradeDone' ) ) {
310 $this->installSteps
= array( 'localsettings' );
313 if( count( $this->getVar( '_Extensions' ) ) ) {
314 array_unshift( $this->installSteps
, 'extensions' );
317 return $this->installSteps
;
321 * Actually perform the installation.
323 * @param $startCB A callback array for the beginning of each step
324 * @param $endCB A callback array for the end of each step
326 * @return Array of Status objects
328 public function performInstallation( $startCB, $endCB ) {
329 $installResults = array();
330 $installer = $this->getDBInstaller();
332 foreach( $this->getInstallSteps() as $stepObj ) {
333 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
334 call_user_func_array( $startCB, array( $step ) );
336 # Call our working function
337 if ( is_array( $stepObj ) ) {
339 $callback = $stepObj['callback'];
340 $status = call_user_func_array( $callback, array( $installer ) );
342 # Boring implicitly named callback
343 $func = 'install' . ucfirst( $step );
344 $status = $this->{$func}( $installer );
347 call_user_func_array( $endCB, array( $step, $status ) );
348 $installResults[$step] = $status;
350 // If we've hit some sort of fatal, we need to bail.
351 // Callback already had a chance to do output above.
352 if( !$status->isOk() ) {
358 if( $status->isOk() ) {
359 $this->setVar( '_InstallDone', true );
362 return $installResults;
366 * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
371 public function installSecretKey() {
372 if ( wfIsWindows() ) {
375 wfSuppressWarnings();
376 $file = fopen( "/dev/urandom", "r" );
380 $status = Status
::newGood();
383 $secretKey = bin2hex( fread( $file, 32 ) );
388 for ( $i=0; $i<8; $i++
) {
389 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
392 $status->warning( 'config-insecure-secretkey' );
395 $this->setVar( 'wgSecretKey', $secretKey );
401 * Create the first user account, grant it sysop and bureaucrat rights
405 public function installSysop() {
406 $name = $this->getVar( '_AdminName' );
407 $user = User
::newFromName( $name );
410 // We should've validated this earlier anyway!
411 return Status
::newFatal( 'config-admin-error-user', $name );
414 if ( $user->idForName() == 0 ) {
415 $user->addToDatabase();
418 $user->setPassword( $this->getVar( '_AdminPassword' ) );
419 } catch( PasswordError
$pwe ) {
420 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
423 $user->addGroup( 'sysop' );
424 $user->addGroup( 'bureaucrat' );
425 $user->saveSettings();
428 return Status
::newGood();
432 * Override the necessary bits of the config to run an installation.
434 public static function overrideConfig() {
435 define( 'MW_NO_SESSION', 1 );
437 // Don't access the database
438 $GLOBALS['wgUseDatabaseMessages'] = false;
440 $GLOBALS['wgShowExceptionDetails'] = true;
442 $GLOBALS['wgExternalLinkTarget'] = '_blank';
444 // Extended debugging. Maybe disable before release?
445 $GLOBALS['wgShowSQLErrors'] = true;
446 $GLOBALS['wgShowDBErrorBacktrace'] = true;
448 // Allow multiple ob_flush() calls
449 $GLOBALS['wgDisableOutputCompression'] = true;
453 * Add an installation step following the given step.
455 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
456 * @param $callback array
458 public function addInstallStepFollowing( $findStep, $callback ) {
461 if( $findStep !== null ) {
462 $where = array_search( $findStep, $this->installSteps
);
465 array_splice( $this->installSteps
, $where, 0, $callback );