2024418fe28070ec08ae6e0796c0c32ff5b99ef7
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(
103 * Known object cache types and the functions used to test for their existence.
107 protected $objectCaches = array(
108 'xcache' => 'xcache_get',
109 'apc' => 'apc_fetch',
110 'eaccel' => 'eaccelerator_get',
111 'wincache' => 'wincache_ucache_get'
115 * User rights profiles.
119 public $rightsProfiles = array(
122 '*' => array( 'edit' => false )
126 'createaccount' => false,
132 'createaccount' => false,
144 public $licenses = array(
146 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
147 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
149 'cc-by-nc-sa' => array(
150 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
151 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
154 'url' => 'http://creativecommons.org/licenses/publicdomain/',
155 'icon' => '{$wgStylePath}/common/images/public-domain.png',
158 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
159 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
161 'gfdl-current' => array(
162 'url' => 'http://www.gnu.org/copyleft/fdl.html',
163 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
170 'cc-choose' => array(
171 // Details will be filled in by the selector.
181 * @param $status Status
183 public abstract function showStatusMessage( Status
$status );
187 * Constructor, always call this from child classes.
189 public function __construct() {
190 parent
::__construct();
192 global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
194 // Load the installer's i18n file.
195 $wgExtensionMessagesFiles['MediawikiInstaller'] =
196 dirname( __FILE__
) . '/Installer.i18n.php';
198 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
199 $wgUser = User
::newFromId( 0 );
201 // Set our custom <doclink> hook.
202 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
204 $this->settings
= $this->internalDefaults
;
206 foreach ( $this->defaultVarNames
as $var ) {
207 $this->settings
[$var] = $GLOBALS[$var];
210 foreach ( self
::getDBTypes() as $type ) {
211 $installer = $this->getDBInstaller( $type );
213 if ( !$installer->isCompiled() ) {
217 $defaults = $installer->getGlobalDefaults();
219 foreach ( $installer->getGlobalNames() as $var ) {
220 if ( isset( $defaults[$var] ) ) {
221 $this->settings
[$var] = $defaults[$var];
223 $this->settings
[$var] = $GLOBALS[$var];
228 $this->parserTitle
= Title
::newFromText( 'Installer' );
229 $this->parserOptions
= new ParserOptions
;
230 $this->parserOptions
->setEditSection( false );
234 * Register tag hook below.
236 * @todo Move this to WebInstaller with the two things below?
238 * @param $parser Parser
240 public function registerDocLink( Parser
&$parser ) {
241 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
246 * Extension tag hook for a documentation link.
248 public function docLink( $linkText, $attribs, $parser ) {
249 $url = $this->getDocUrl( $attribs['href'] );
250 return '<a href="' . htmlspecialchars( $url ) . '">' .
251 htmlspecialchars( $linkText ) .
256 * Overridden by WebInstaller to provide lastPage parameters.
258 protected function getDocUrl( $page ) {
259 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
263 * Finds extensions that follow the format /extensions/Name/Name.php,
264 * and returns an array containing the value for 'Name' for each found extension.
268 public function findExtensions() {
269 if( $this->getVar( 'IP' ) === null ) {
274 $dir = $this->getVar( 'IP' ) . '/extensions';
275 $dh = opendir( $dir );
277 while ( ( $file = readdir( $dh ) ) !== false ) {
278 if( file_exists( "$dir/$file/$file.php" ) ) {
287 * Installs the auto-detected extensions.
289 * @TODO: this only requires them? That's all it's supposed to do. Poorly
294 protected function installExtensions() {
295 $exts = $this->getVar( '_Extensions' );
296 $path = $this->getVar( 'IP' ) . '/extensions';
298 foreach( $exts as $e ) {
299 require( "$path/$e/$e.php" );
302 return Status
::newGood();
306 * Get an array of install steps. These could be a plain key like the defaults
307 * in $installSteps, or could be an array with a name and a specific callback
311 protected function getInstallSteps() {
312 if( $this->getVar( '_UpgradeDone' ) ) {
313 $this->installSteps
= array( 'localsettings' );
316 if( count( $this->getVar( '_Extensions' ) ) ) {
317 array_unshift( $this->installSteps
, 'extensions' );
320 return $this->installSteps
;
324 * Actually perform the installation.
326 * @param $startCB A callback array for the beginning of each step
327 * @param $endCB A callback array for the end of each step
329 * @return Array of Status objects
331 public function performInstallation( $startCB, $endCB ) {
332 $installResults = array();
333 $installer = $this->getDBInstaller();
334 $installer->preInstall();
336 foreach( $this->getInstallSteps() as $stepObj ) {
337 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
338 call_user_func_array( $startCB, array( $step ) );
340 # Call our working function
341 if ( is_array( $stepObj ) ) {
343 $callback = $stepObj['callback'];
344 $status = call_user_func_array( $callback, array( $installer ) );
346 # Boring implicitly named callback
347 $func = 'install' . ucfirst( $step );
348 $status = $this->{$func}( $installer );
351 call_user_func_array( $endCB, array( $step, $status ) );
352 $installResults[$step] = $status;
354 // If we've hit some sort of fatal, we need to bail.
355 // Callback already had a chance to do output above.
356 if( !$status->isOk() ) {
362 if( $status->isOk() ) {
363 $this->setVar( '_InstallDone', true );
366 return $installResults;
370 * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
375 protected function installSecretKey() {
376 if ( wfIsWindows() ) {
379 wfSuppressWarnings();
380 $file = fopen( "/dev/urandom", "r" );
384 $status = Status
::newGood();
387 $secretKey = bin2hex( fread( $file, 32 ) );
392 for ( $i=0; $i<8; $i++
) {
393 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
396 $status->warning( 'config-insecure-secretkey' );
399 $this->setVar( 'wgSecretKey', $secretKey );
405 * Create the first user account, grant it sysop and bureaucrat rights
409 protected function installSysop() {
410 $name = $this->getVar( '_AdminName' );
411 $user = User
::newFromName( $name );
414 // We should've validated this earlier anyway!
415 return Status
::newFatal( 'config-admin-error-user', $name );
418 if ( $user->idForName() == 0 ) {
419 $user->addToDatabase();
422 $user->setPassword( $this->getVar( '_AdminPassword' ) );
423 } catch( PasswordError
$pwe ) {
424 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
427 $user->addGroup( 'sysop' );
428 $user->addGroup( 'bureaucrat' );
429 $user->saveSettings();
432 return Status
::newGood();
436 * Override the necessary bits of the config to run an installation.
438 public static function overrideConfig() {
439 define( 'MW_NO_SESSION', 1 );
441 // Don't access the database
442 $GLOBALS['wgUseDatabaseMessages'] = false;
444 $GLOBALS['wgShowExceptionDetails'] = true;
446 $GLOBALS['wgExternalLinkTarget'] = '_blank';
448 // Extended debugging. Maybe disable before release?
449 $GLOBALS['wgShowSQLErrors'] = true;
450 $GLOBALS['wgShowDBErrorBacktrace'] = true;
452 // Allow multiple ob_flush() calls
453 $GLOBALS['wgDisableOutputCompression'] = true;
455 // Some of the environment checks make shell requests, remove limits
456 $GLOBALS['wgMaxShellMemory'] = 0;
460 * Add an installation step following the given step.
462 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
463 * @param $callback array
465 public function addInstallStepFollowing( $findStep, $callback ) {
468 if( $findStep !== null ) {
469 $where = array_search( $findStep, $this->installSteps
);
472 array_splice( $this->installSteps
, $where, 0, $callback );