4 * Base core installer class.
5 * Handles everything that is independent of user interface.
9 abstract class CoreInstaller
extends Installer
{
12 * MediaWiki configuration globals that will eventually be passed through
13 * to LocalSettings.php. The names only are given here, the defaults
14 * typically come from DefaultSettings.php.
18 protected $defaultVarNames = array(
30 'wgEmailAuthentication',
33 'wgImageMagickConvertCommand',
43 'wgUseInstantCommons',
47 * Variables that are stored alongside globals, and are used for any
48 * configuration of the installation process aside from the MediaWiki
49 * configuration. Map of names to defaults.
53 protected $internalDefaults = array(
55 '_Environment' => false,
56 '_CompiledDBs' => array(),
58 '_RaiseMemory' => false,
59 '_UpgradeDone' => false,
60 '_InstallDone' => false,
62 '_InstallUser' => 'root',
63 '_InstallPassword' => '',
64 '_SameAccount' => true,
65 '_CreateDBAccount' => false,
66 '_NamespaceType' => 'site-name',
67 '_AdminName' => '', // will be set later, when the user selects language
68 '_AdminPassword' => '',
69 '_AdminPassword2' => '',
71 '_Subscribe' => false,
72 '_SkipOptional' => 'continue',
73 '_RightsProfile' => 'wiki',
74 '_LicenseCode' => 'none',
76 '_Extensions' => array(),
77 '_MemCachedServers' => '',
78 '_ExternalHTTP' => false,
82 * Steps for installation.
86 protected $installSteps = array(
95 * Known object cache types and the functions used to test for their existence.
99 protected $objectCaches = array(
100 'xcache' => 'xcache_get',
101 'apc' => 'apc_fetch',
102 'eaccel' => 'eaccelerator_get',
103 'wincache' => 'wincache_ucache_get'
107 * User rights profiles.
111 public $rightsProfiles = array(
114 '*' => array( 'edit' => false )
118 'createaccount' => false,
124 'createaccount' => false,
136 public $licenses = array(
143 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
144 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
146 'cc-by-nc-sa' => array(
147 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
148 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
151 'url' => 'http://creativecommons.org/licenses/publicdomain/',
152 'icon' => '{$wgStylePath}/common/images/public-domain.png',
155 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
156 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
158 'gfdl-current' => array(
159 'url' => 'http://www.gnu.org/copyleft/fdl.html',
160 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
162 'cc-choose' => array(
163 // details will be filled in by the selector
171 * Constructor, always call this from child classes.
173 public function __construct() {
174 parent
::__construct();
176 global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
178 // Load the installer's i18n file.
179 $wgExtensionMessagesFiles['MediawikiInstaller'] =
180 './includes/installer/Installer.i18n.php';
182 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
183 $wgUser = User
::newFromId( 0 );
185 // Set our custom <doclink> hook.
186 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
188 $this->settings
= $this->internalDefaults
;
190 foreach ( $this->defaultVarNames
as $var ) {
191 $this->settings
[$var] = $GLOBALS[$var];
194 foreach ( $this->dbTypes
as $type ) {
195 $installer = $this->getDBInstaller( $type );
197 if ( !$installer->isCompiled() ) {
201 $defaults = $installer->getGlobalDefaults();
203 foreach ( $installer->getGlobalNames() as $var ) {
204 if ( isset( $defaults[$var] ) ) {
205 $this->settings
[$var] = $defaults[$var];
207 $this->settings
[$var] = $GLOBALS[$var];
212 $this->parserTitle
= Title
::newFromText( 'Installer' );
213 $this->parserOptions
= new ParserOptions
;
214 $this->parserOptions
->setEditSection( false );
218 * Register tag hook below.
220 * @param $parser Parser
222 public function registerDocLink( Parser
&$parser ) {
223 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
228 * Extension tag hook for a documentation link.
230 public function docLink( $linkText, $attribs, $parser ) {
231 $url = $this->getDocUrl( $attribs['href'] );
232 return '<a href="' . htmlspecialchars( $url ) . '">' .
233 htmlspecialchars( $linkText ) .
238 * Overridden by WebInstaller to provide lastPage parameters.
240 protected function getDocUrl( $page ) {
241 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
245 * Finds extensions that follow the format /extensions/Name/Name.php,
246 * and returns an array containing the value for 'Name' for each found extension.
250 public function findExtensions() {
251 if( $this->getVar( 'IP' ) === null ) {
256 $dir = $this->getVar( 'IP' ) . '/extensions';
257 $dh = opendir( $dir );
259 while ( ( $file = readdir( $dh ) ) !== false ) {
260 if( file_exists( "$dir/$file/$file.php" ) ) {
265 $this->setVar( '_Extensions', $exts );
271 * Installs the auto-detected extensions.
273 * TODO: this only requires them?
277 public function installExtensions() {
278 $exts = $this->getVar( '_Extensions' );
279 $path = $this->getVar( 'IP' ) . '/extensions';
281 foreach( $exts as $e ) {
282 require( "$path/$e/$e.php" );
285 return Status
::newGood();
288 public function getInstallSteps() {
289 if( $this->getVar( '_UpgradeDone' ) ) {
290 $this->installSteps
= array( 'localsettings' );
293 if( count( $this->getVar( '_Extensions' ) ) ) {
294 array_unshift( $this->installSteps
, 'extensions' );
297 return $this->installSteps
;
301 * Actually perform the installation.
303 * @param Array $startCB A callback array for the beginning of each step
304 * @param Array $endCB A callback array for the end of each step
306 * @return Array of Status objects
308 public function performInstallation( $startCB, $endCB ) {
309 $installResults = array();
310 $installer = $this->getDBInstaller();
312 foreach( $this->getInstallSteps() as $stepObj ) {
313 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
314 call_user_func_array( $startCB, array( $step ) );
317 # Call our working function
318 if ( is_array( $stepObj ) ) {
320 $callback = $stepObj['callback'];
321 $status = call_user_func_array( $callback, array( $installer ) );
323 # Boring implicitly named callback
324 $func = 'install' . ucfirst( $step );
325 $status = $this->{$func}( $installer );
328 call_user_func_array( $endCB, array( $step, $status ) );
329 $installResults[$step] = $status;
331 // If we've hit some sort of fatal, we need to bail.
332 // Callback already had a chance to do output above.
333 if( !$status->isOk() ) {
339 if( $status->isOk() ) {
340 $this->setVar( '_InstallDone', true );
343 return $installResults;
351 public function installSecretKey() {
352 if ( wfIsWindows() ) {
355 wfSuppressWarnings();
356 $file = fopen( "/dev/urandom", "r" );
360 $status = Status
::newGood();
363 $secretKey = bin2hex( fread( $file, 32 ) );
368 for ( $i=0; $i<8; $i++
) {
369 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
372 $status->warning( 'config-insecure-secretkey' );
375 $this->setVar( 'wgSecretKey', $secretKey );
385 public function installSysop() {
386 $name = $this->getVar( '_AdminName' );
387 $user = User
::newFromName( $name );
390 // We should've validated this earlier anyway!
391 return Status
::newFatal( 'config-admin-error-user', $name );
394 if ( $user->idForName() == 0 ) {
395 $user->addToDatabase();
398 $user->setPassword( $this->getVar( '_AdminPassword' ) );
399 } catch( PasswordError
$pwe ) {
400 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
403 $user->addGroup( 'sysop' );
404 $user->addGroup( 'bureaucrat' );
405 $user->saveSettings();
408 return Status
::newGood();
412 * Override the necessary bits of the config to run an installation.
414 public static function overrideConfig() {
415 define( 'MW_NO_SESSION', 1 );
417 // Don't access the database
418 $GLOBALS['wgUseDatabaseMessages'] = false;
420 $GLOBALS['wgShowExceptionDetails'] = true;
422 $GLOBALS['wgExternalLinkTarget'] = '_blank';
424 // Extended debugging. Maybe disable before release?
425 $GLOBALS['wgShowSQLErrors'] = true;
426 $GLOBALS['wgShowDBErrorBacktrace'] = true;
430 * Add an installation step following the given step.
432 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
433 * @param $callback array
435 public function addInstallStepFollowing( $findStep, $callback ) {
438 if( $findStep !== null ) {
439 $where = array_search( $findStep, $this->installSteps
);
442 array_splice( $this->installSteps
, $where, 0, $callback );