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 * @todo Move this to WebInstaller with the two things below?
237 * @param $parser Parser
239 public function registerDocLink( Parser
&$parser ) {
240 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
245 * Extension tag hook for a documentation link.
247 public function docLink( $linkText, $attribs, $parser ) {
248 $url = $this->getDocUrl( $attribs['href'] );
249 return '<a href="' . htmlspecialchars( $url ) . '">' .
250 htmlspecialchars( $linkText ) .
255 * Overridden by WebInstaller to provide lastPage parameters.
257 protected function getDocUrl( $page ) {
258 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
262 * Finds extensions that follow the format /extensions/Name/Name.php,
263 * and returns an array containing the value for 'Name' for each found extension.
267 public function findExtensions() {
268 if( $this->getVar( 'IP' ) === null ) {
273 $dir = $this->getVar( 'IP' ) . '/extensions';
274 $dh = opendir( $dir );
276 while ( ( $file = readdir( $dh ) ) !== false ) {
277 if( file_exists( "$dir/$file/$file.php" ) ) {
286 * Installs the auto-detected extensions.
288 * @TODO: this only requires them? That's all it's supposed to do. Poorly
293 protected function installExtensions() {
294 $exts = $this->getVar( '_Extensions' );
295 $path = $this->getVar( 'IP' ) . '/extensions';
297 foreach( $exts as $e ) {
298 require( "$path/$e/$e.php" );
301 return Status
::newGood();
305 * Get an array of install steps. These could be a plain key like the defaults
306 * in $installSteps, or could be an array with a name and a specific callback
310 protected function getInstallSteps() {
311 if( $this->getVar( '_UpgradeDone' ) ) {
312 $this->installSteps
= array( 'localsettings' );
315 if( count( $this->getVar( '_Extensions' ) ) ) {
316 array_unshift( $this->installSteps
, 'extensions' );
319 return $this->installSteps
;
323 * Actually perform the installation.
325 * @param $startCB A callback array for the beginning of each step
326 * @param $endCB A callback array for the end of each step
328 * @return Array of Status objects
330 public function performInstallation( $startCB, $endCB ) {
331 $installResults = array();
332 $installer = $this->getDBInstaller();
333 $installer->preInstall();
335 foreach( $this->getInstallSteps() as $stepObj ) {
336 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
337 call_user_func_array( $startCB, array( $step ) );
339 # Call our working function
340 if ( is_array( $stepObj ) ) {
342 $callback = $stepObj['callback'];
343 $status = call_user_func_array( $callback, array( $installer ) );
345 # Boring implicitly named callback
346 $func = 'install' . ucfirst( $step );
347 $status = $this->{$func}( $installer );
350 call_user_func_array( $endCB, array( $step, $status ) );
351 $installResults[$step] = $status;
353 // If we've hit some sort of fatal, we need to bail.
354 // Callback already had a chance to do output above.
355 if( !$status->isOk() ) {
361 if( $status->isOk() ) {
362 $this->setVar( '_InstallDone', true );
365 return $installResults;
369 * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
374 protected function installSecretKey() {
375 if ( wfIsWindows() ) {
378 wfSuppressWarnings();
379 $file = fopen( "/dev/urandom", "r" );
383 $status = Status
::newGood();
386 $secretKey = bin2hex( fread( $file, 32 ) );
391 for ( $i=0; $i<8; $i++
) {
392 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
395 $status->warning( 'config-insecure-secretkey' );
398 $this->setVar( 'wgSecretKey', $secretKey );
404 * Create the first user account, grant it sysop and bureaucrat rights
408 protected function installSysop() {
409 $name = $this->getVar( '_AdminName' );
410 $user = User
::newFromName( $name );
413 // We should've validated this earlier anyway!
414 return Status
::newFatal( 'config-admin-error-user', $name );
417 if ( $user->idForName() == 0 ) {
418 $user->addToDatabase();
421 $user->setPassword( $this->getVar( '_AdminPassword' ) );
422 } catch( PasswordError
$pwe ) {
423 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
426 $user->addGroup( 'sysop' );
427 $user->addGroup( 'bureaucrat' );
428 $user->saveSettings();
431 return Status
::newGood();
435 * Override the necessary bits of the config to run an installation.
437 public static function overrideConfig() {
438 define( 'MW_NO_SESSION', 1 );
440 // Don't access the database
441 $GLOBALS['wgUseDatabaseMessages'] = false;
443 $GLOBALS['wgShowExceptionDetails'] = true;
445 $GLOBALS['wgExternalLinkTarget'] = '_blank';
447 // Extended debugging. Maybe disable before release?
448 $GLOBALS['wgShowSQLErrors'] = true;
449 $GLOBALS['wgShowDBErrorBacktrace'] = true;
451 // Allow multiple ob_flush() calls
452 $GLOBALS['wgDisableOutputCompression'] = true;
454 // Some of the environment checks make shell requests, remove limits
455 $GLOBALS['wgMaxShellMemory'] = 0;
459 * Add an installation step following the given step.
461 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
462 * @param $callback array
464 public function addInstallStepFollowing( $findStep, $callback ) {
467 if( $findStep !== null ) {
468 $where = array_search( $findStep, $this->installSteps
);
471 array_splice( $this->installSteps
, $where, 0, $callback );