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(
150 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
151 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
153 'cc-by-nc-sa' => array(
154 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
155 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
158 'url' => 'http://creativecommons.org/licenses/publicdomain/',
159 'icon' => '{$wgStylePath}/common/images/public-domain.png',
162 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
163 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
165 'gfdl-current' => array(
166 'url' => 'http://www.gnu.org/copyleft/fdl.html',
167 '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?
290 public function installExtensions() {
291 $exts = $this->getVar( '_Extensions' );
292 $path = $this->getVar( 'IP' ) . '/extensions';
294 foreach( $exts as $e ) {
295 require( "$path/$e/$e.php" );
298 return Status
::newGood();
301 public function getInstallSteps() {
302 if( $this->getVar( '_UpgradeDone' ) ) {
303 $this->installSteps
= array( 'localsettings' );
306 if( count( $this->getVar( '_Extensions' ) ) ) {
307 array_unshift( $this->installSteps
, 'extensions' );
310 return $this->installSteps
;
314 * Actually perform the installation.
316 * @param $startCB A callback array for the beginning of each step
317 * @param $endCB A callback array for the end of each step
319 * @return Array of Status objects
321 public function performInstallation( $startCB, $endCB ) {
322 $installResults = array();
323 $installer = $this->getDBInstaller();
325 foreach( $this->getInstallSteps() as $stepObj ) {
326 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
327 call_user_func_array( $startCB, array( $step ) );
330 # Call our working function
331 if ( is_array( $stepObj ) ) {
333 $callback = $stepObj['callback'];
334 $status = call_user_func_array( $callback, array( $installer ) );
336 # Boring implicitly named callback
337 $func = 'install' . ucfirst( $step );
338 $status = $this->{$func}( $installer );
341 call_user_func_array( $endCB, array( $step, $status ) );
342 $installResults[$step] = $status;
344 // If we've hit some sort of fatal, we need to bail.
345 // Callback already had a chance to do output above.
346 if( !$status->isOk() ) {
352 if( $status->isOk() ) {
353 $this->setVar( '_InstallDone', true );
356 return $installResults;
364 public function installSecretKey() {
365 if ( wfIsWindows() ) {
368 wfSuppressWarnings();
369 $file = fopen( "/dev/urandom", "r" );
373 $status = Status
::newGood();
376 $secretKey = bin2hex( fread( $file, 32 ) );
381 for ( $i=0; $i<8; $i++
) {
382 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
385 $status->warning( 'config-insecure-secretkey' );
388 $this->setVar( 'wgSecretKey', $secretKey );
398 public function installSysop() {
399 $name = $this->getVar( '_AdminName' );
400 $user = User
::newFromName( $name );
403 // We should've validated this earlier anyway!
404 return Status
::newFatal( 'config-admin-error-user', $name );
407 if ( $user->idForName() == 0 ) {
408 $user->addToDatabase();
411 $user->setPassword( $this->getVar( '_AdminPassword' ) );
412 } catch( PasswordError
$pwe ) {
413 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
416 $user->addGroup( 'sysop' );
417 $user->addGroup( 'bureaucrat' );
418 $user->saveSettings();
421 return Status
::newGood();
425 * Override the necessary bits of the config to run an installation.
427 public static function overrideConfig() {
428 define( 'MW_NO_SESSION', 1 );
430 // Don't access the database
431 $GLOBALS['wgUseDatabaseMessages'] = false;
433 $GLOBALS['wgShowExceptionDetails'] = true;
435 $GLOBALS['wgExternalLinkTarget'] = '_blank';
437 // Extended debugging. Maybe disable before release?
438 $GLOBALS['wgShowSQLErrors'] = true;
439 $GLOBALS['wgShowDBErrorBacktrace'] = true;
441 // Allow multiple ob_flush() calls
442 $GLOBALS['wgDisableOutputCompression'] = true;
446 * Add an installation step following the given step.
448 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
449 * @param $callback array
451 public function addInstallStepFollowing( $findStep, $callback ) {
454 if( $findStep !== null ) {
455 $where = array_search( $findStep, $this->installSteps
);
458 array_splice( $this->installSteps
, $where, 0, $callback );