4 * Base core installer class.
5 * Handles everything that is independent of user interface.
10 abstract class CoreInstaller
extends Installer
{
13 * MediaWiki configuration globals that will eventually be passed through
14 * to LocalSettings.php. The names only are given here, the defaults
15 * typically come from DefaultSettings.php.
19 protected $defaultVarNames = array(
31 'wgEmailAuthentication',
34 'wgImageMagickConvertCommand',
44 'wgUseInstantCommons',
48 * Variables that are stored alongside globals, and are used for any
49 * configuration of the installation process aside from the MediaWiki
50 * configuration. Map of names to defaults.
54 protected $internalDefaults = array(
56 '_Environment' => false,
57 '_CompiledDBs' => array(),
59 '_RaiseMemory' => false,
60 '_UpgradeDone' => false,
61 '_InstallDone' => false,
63 '_InstallUser' => 'root',
64 '_InstallPassword' => '',
65 '_SameAccount' => true,
66 '_CreateDBAccount' => false,
67 '_NamespaceType' => 'site-name',
68 '_AdminName' => '', // will be set later, when the user selects language
69 '_AdminPassword' => '',
70 '_AdminPassword2' => '',
72 '_Subscribe' => false,
73 '_SkipOptional' => 'continue',
74 '_RightsProfile' => 'wiki',
75 '_LicenseCode' => 'none',
77 '_Extensions' => array(),
78 '_MemCachedServers' => '',
79 '_ExternalHTTP' => false,
83 * Steps for installation.
87 protected $installSteps = array(
96 * Known object cache types and the functions used to test for their existence.
100 protected $objectCaches = array(
101 'xcache' => 'xcache_get',
102 'apc' => 'apc_fetch',
103 'eaccel' => 'eaccelerator_get',
104 'wincache' => 'wincache_ucache_get'
108 * User rights profiles.
112 public $rightsProfiles = array(
115 '*' => array( 'edit' => false )
119 'createaccount' => false,
125 'createaccount' => false,
137 public $licenses = array(
144 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
145 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
147 'cc-by-nc-sa' => array(
148 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
149 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
152 'url' => 'http://creativecommons.org/licenses/publicdomain/',
153 'icon' => '{$wgStylePath}/common/images/public-domain.png',
156 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
157 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
159 'gfdl-current' => array(
160 'url' => 'http://www.gnu.org/copyleft/fdl.html',
161 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
163 'cc-choose' => array(
164 // Details will be filled in by the selector.
174 * @param Status $status
176 public abstract function showStatusMessage( Status
$status );
180 * Constructor, always call this from child classes.
182 public function __construct() {
183 parent
::__construct();
185 global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
187 // Load the installer's i18n file.
188 $wgExtensionMessagesFiles['MediawikiInstaller'] =
189 './includes/installer/Installer.i18n.php';
191 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
192 $wgUser = User
::newFromId( 0 );
194 // Set our custom <doclink> hook.
195 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
197 $this->settings
= $this->internalDefaults
;
199 foreach ( $this->defaultVarNames
as $var ) {
200 $this->settings
[$var] = $GLOBALS[$var];
203 foreach ( self
::getDBTypes() as $type ) {
204 $installer = $this->getDBInstaller( $type );
206 if ( !$installer->isCompiled() ) {
210 $defaults = $installer->getGlobalDefaults();
212 foreach ( $installer->getGlobalNames() as $var ) {
213 if ( isset( $defaults[$var] ) ) {
214 $this->settings
[$var] = $defaults[$var];
216 $this->settings
[$var] = $GLOBALS[$var];
221 $this->parserTitle
= Title
::newFromText( 'Installer' );
222 $this->parserOptions
= new ParserOptions
;
223 $this->parserOptions
->setEditSection( false );
227 * Register tag hook below.
229 * @param $parser Parser
231 public function registerDocLink( Parser
&$parser ) {
232 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
237 * Extension tag hook for a documentation link.
239 public function docLink( $linkText, $attribs, $parser ) {
240 $url = $this->getDocUrl( $attribs['href'] );
241 return '<a href="' . htmlspecialchars( $url ) . '">' .
242 htmlspecialchars( $linkText ) .
247 * Overridden by WebInstaller to provide lastPage parameters.
249 protected function getDocUrl( $page ) {
250 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
254 * Finds extensions that follow the format /extensions/Name/Name.php,
255 * and returns an array containing the value for 'Name' for each found extension.
259 public function findExtensions() {
260 if( $this->getVar( 'IP' ) === null ) {
265 $dir = $this->getVar( 'IP' ) . '/extensions';
266 $dh = opendir( $dir );
268 while ( ( $file = readdir( $dh ) ) !== false ) {
269 if( file_exists( "$dir/$file/$file.php" ) ) {
278 * Installs the auto-detected extensions.
280 * TODO: this only requires them?
284 public function installExtensions() {
285 $exts = $this->getVar( '_Extensions' );
286 $path = $this->getVar( 'IP' ) . '/extensions';
288 foreach( $exts as $e ) {
289 require( "$path/$e/$e.php" );
292 return Status
::newGood();
295 public function getInstallSteps() {
296 if( $this->getVar( '_UpgradeDone' ) ) {
297 $this->installSteps
= array( 'localsettings' );
300 if( count( $this->getVar( '_Extensions' ) ) ) {
301 array_unshift( $this->installSteps
, 'extensions' );
304 return $this->installSteps
;
308 * Actually perform the installation.
310 * @param Array $startCB A callback array for the beginning of each step
311 * @param Array $endCB A callback array for the end of each step
313 * @return Array of Status objects
315 public function performInstallation( $startCB, $endCB ) {
316 $installResults = array();
317 $installer = $this->getDBInstaller();
319 foreach( $this->getInstallSteps() as $stepObj ) {
320 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
321 call_user_func_array( $startCB, array( $step ) );
324 # Call our working function
325 if ( is_array( $stepObj ) ) {
327 $callback = $stepObj['callback'];
328 $status = call_user_func_array( $callback, array( $installer ) );
330 # Boring implicitly named callback
331 $func = 'install' . ucfirst( $step );
332 $status = $this->{$func}( $installer );
335 call_user_func_array( $endCB, array( $step, $status ) );
336 $installResults[$step] = $status;
338 // If we've hit some sort of fatal, we need to bail.
339 // Callback already had a chance to do output above.
340 if( !$status->isOk() ) {
346 if( $status->isOk() ) {
347 $this->setVar( '_InstallDone', true );
350 return $installResults;
358 public function installSecretKey() {
359 if ( wfIsWindows() ) {
362 wfSuppressWarnings();
363 $file = fopen( "/dev/urandom", "r" );
367 $status = Status
::newGood();
370 $secretKey = bin2hex( fread( $file, 32 ) );
375 for ( $i=0; $i<8; $i++
) {
376 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
379 $status->warning( 'config-insecure-secretkey' );
382 $this->setVar( 'wgSecretKey', $secretKey );
392 public function installSysop() {
393 $name = $this->getVar( '_AdminName' );
394 $user = User
::newFromName( $name );
397 // We should've validated this earlier anyway!
398 return Status
::newFatal( 'config-admin-error-user', $name );
401 if ( $user->idForName() == 0 ) {
402 $user->addToDatabase();
405 $user->setPassword( $this->getVar( '_AdminPassword' ) );
406 } catch( PasswordError
$pwe ) {
407 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
410 $user->addGroup( 'sysop' );
411 $user->addGroup( 'bureaucrat' );
412 $user->saveSettings();
415 return Status
::newGood();
419 * Override the necessary bits of the config to run an installation.
421 public static function overrideConfig() {
422 define( 'MW_NO_SESSION', 1 );
424 // Don't access the database
425 $GLOBALS['wgUseDatabaseMessages'] = false;
427 $GLOBALS['wgShowExceptionDetails'] = true;
429 $GLOBALS['wgExternalLinkTarget'] = '_blank';
431 // Extended debugging. Maybe disable before release?
432 $GLOBALS['wgShowSQLErrors'] = true;
433 $GLOBALS['wgShowDBErrorBacktrace'] = true;
437 * Add an installation step following the given step.
439 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
440 * @param $callback array
442 public function addInstallStepFollowing( $findStep, $callback ) {
445 if( $findStep !== null ) {
446 $where = array_search( $findStep, $this->installSteps
);
449 array_splice( $this->installSteps
, $where, 0, $callback );