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 ( $this->dbTypes
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" ) ) {
274 $this->setVar( '_Extensions', $exts );
280 * Installs the auto-detected extensions.
282 * TODO: this only requires them?
286 public function installExtensions() {
287 $exts = $this->getVar( '_Extensions' );
288 $path = $this->getVar( 'IP' ) . '/extensions';
290 foreach( $exts as $e ) {
291 require( "$path/$e/$e.php" );
294 return Status
::newGood();
297 public function getInstallSteps() {
298 if( $this->getVar( '_UpgradeDone' ) ) {
299 $this->installSteps
= array( 'localsettings' );
302 if( count( $this->getVar( '_Extensions' ) ) ) {
303 array_unshift( $this->installSteps
, 'extensions' );
306 return $this->installSteps
;
310 * Actually perform the installation.
312 * @param Array $startCB A callback array for the beginning of each step
313 * @param Array $endCB A callback array for the end of each step
315 * @return Array of Status objects
317 public function performInstallation( $startCB, $endCB ) {
318 $installResults = array();
319 $installer = $this->getDBInstaller();
321 foreach( $this->getInstallSteps() as $stepObj ) {
322 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
323 call_user_func_array( $startCB, array( $step ) );
326 # Call our working function
327 if ( is_array( $stepObj ) ) {
329 $callback = $stepObj['callback'];
330 $status = call_user_func_array( $callback, array( $installer ) );
332 # Boring implicitly named callback
333 $func = 'install' . ucfirst( $step );
334 $status = $this->{$func}( $installer );
337 call_user_func_array( $endCB, array( $step, $status ) );
338 $installResults[$step] = $status;
340 // If we've hit some sort of fatal, we need to bail.
341 // Callback already had a chance to do output above.
342 if( !$status->isOk() ) {
348 if( $status->isOk() ) {
349 $this->setVar( '_InstallDone', true );
352 return $installResults;
360 public function installSecretKey() {
361 if ( wfIsWindows() ) {
364 wfSuppressWarnings();
365 $file = fopen( "/dev/urandom", "r" );
369 $status = Status
::newGood();
372 $secretKey = bin2hex( fread( $file, 32 ) );
377 for ( $i=0; $i<8; $i++
) {
378 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
381 $status->warning( 'config-insecure-secretkey' );
384 $this->setVar( 'wgSecretKey', $secretKey );
394 public function installSysop() {
395 $name = $this->getVar( '_AdminName' );
396 $user = User
::newFromName( $name );
399 // We should've validated this earlier anyway!
400 return Status
::newFatal( 'config-admin-error-user', $name );
403 if ( $user->idForName() == 0 ) {
404 $user->addToDatabase();
407 $user->setPassword( $this->getVar( '_AdminPassword' ) );
408 } catch( PasswordError
$pwe ) {
409 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
412 $user->addGroup( 'sysop' );
413 $user->addGroup( 'bureaucrat' );
414 $user->saveSettings();
417 return Status
::newGood();
421 * Override the necessary bits of the config to run an installation.
423 public static function overrideConfig() {
424 define( 'MW_NO_SESSION', 1 );
426 // Don't access the database
427 $GLOBALS['wgUseDatabaseMessages'] = false;
429 $GLOBALS['wgShowExceptionDetails'] = true;
431 $GLOBALS['wgExternalLinkTarget'] = '_blank';
433 // Extended debugging. Maybe disable before release?
434 $GLOBALS['wgShowSQLErrors'] = true;
435 $GLOBALS['wgShowDBErrorBacktrace'] = true;
439 * Add an installation step following the given step.
441 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
442 * @param $callback array
444 public function addInstallStepFollowing( $findStep, $callback ) {
447 if( $findStep !== null ) {
448 $where = array_search( $findStep, $this->installSteps
);
451 array_splice( $this->installSteps
, $where, 0, $callback );