5 * Handles everything that is independent of user interface
7 abstract class Installer
{
8 var $settings, $output;
11 * MediaWiki configuration globals that will eventually be passed through
12 * to LocalSettings.php. The names only are given here, the defaults
13 * typically come from DefaultSettings.php.
15 protected $defaultVarNames = array(
27 'wgEmailAuthentication',
30 'wgImageMagickConvertCommand',
43 * Variables that are stored alongside globals, and are used for any
44 * configuration of the installation process aside from the MediaWiki
45 * configuration. Map of names to defaults.
47 protected $internalDefaults = array(
49 '_Environment' => false,
50 '_CompiledDBs' => array(),
52 '_RaiseMemory' => false,
53 '_UpgradeDone' => false,
55 '_InstallUser' => 'root',
56 '_InstallPassword' => '',
57 '_SameAccount' => true,
58 '_CreateDBAccount' => false,
59 '_NamespaceType' => 'site-name',
60 '_AdminName' => null, // will be set later, when the user selects language
61 '_AdminPassword' => '',
62 '_AdminPassword2' => '',
64 '_Subscribe' => false,
65 '_SkipOptional' => 'continue',
66 '_RightsProfile' => 'wiki',
67 '_LicenseCode' => 'none',
69 '_Extensions' => array(),
70 '_MemCachedServers' => '',
74 * Known database types. These correspond to the class names <type>Installer,
75 * and are also MediaWiki database types valid for $wgDBtype.
77 * To add a new type, create a <type>Installer class and a Database<type>
78 * class, and add a config-type-<type> message to MessagesEn.php.
80 private $dbTypes = array(
88 * Minimum memory size in MB
90 private $minMemorySize = 50;
93 * Cached DB installer instances, access using getDBInstaller()
95 private $dbInstallers = array();
98 * A list of environment check methods called by doEnvironmentChecks().
99 * These may output warnings using showMessage(), and/or abort the
100 * installation process by returning false.
102 protected $envChecks = array(
105 'envCheckRegisterGlobals',
106 'envCheckMagicQuotes',
107 'envCheckMagicSybase',
118 'envCheckWriteableDir',
120 'envCheckShellLocale',
121 'envCheckUploadsDirectory',
125 * Steps for installation.
126 * @TODO Should be protected...
128 var $installSteps = array(
138 * Known object cache types and the functions used to test for their existence
140 protected $objectCaches = array(
141 'xcache' => 'xcache_get',
142 'apc' => 'apc_fetch',
143 'eaccel' => 'eaccelerator_get',
144 'wincache' => 'wincache_ucache_get'
148 * User rights profiles
150 var $rightsProfiles = array(
153 '*' => array( 'edit' => false )
157 'createaccount' => false,
163 'createaccount' => false,
173 var $licenses = array(
180 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
181 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
183 'cc-by-nc-sa' => array(
184 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
185 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
188 'url' => 'http://creativecommons.org/licenses/publicdomain/',
189 'icon' => '{$wgStylePath}/common/images/public-domain.png',
192 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
193 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
195 'gfdl-current' => array(
196 'url' => 'http://www.gnu.org/copyleft/fdl.html',
197 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
199 'cc-choose' => array(
200 // details will be filled in by the selector
207 * Cached Title and ParserOptions used by parse()
209 private $parserTitle, $parserOptions;
212 * Constructor, always call this from child classes
214 function __construct() {
215 // Disable the i18n cache and LoadBalancer
216 Language
::getLocalisationCache()->disableBackend();
217 LBFactory
::disableBackend();
219 // Load the installer's i18n file
220 global $wgExtensionMessagesFiles;
221 $wgExtensionMessagesFiles['MediawikiInstaller'] =
222 './includes/installer/Installer.i18n.php';
225 $wgUser = User
::newFromId( 0 );
226 // Having a user with id = 0 safeguards us from DB access via User::loadOptions()
228 // Set our custom <doclink> hook
230 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
232 $this->settings
= $this->internalDefaults
;
233 foreach ( $this->defaultVarNames
as $var ) {
234 $this->settings
[$var] = $GLOBALS[$var];
236 foreach ( $this->dbTypes
as $type ) {
237 $installer = $this->getDBInstaller( $type );
241 $defaults = $installer->getGlobalDefaults();
242 foreach ( $installer->getGlobalNames() as $var ) {
243 if ( isset( $defaults[$var] ) ) {
244 $this->settings
[$var] = $defaults[$var];
246 $this->settings
[$var] = $GLOBALS[$var];
251 $this->parserTitle
= Title
::newFromText( 'Installer' );
252 $this->parserOptions
= new ParserOptions
;
253 $this->parserOptions
->setEditSection( false );
257 * UI interface for displaying a short message
258 * The parameters are like parameters to wfMsg().
259 * The messages will be in wikitext format, which will be converted to an
260 * output format such as HTML or text before being sent to the user.
262 abstract function showMessage( $msg /*, ... */ );
264 abstract function showStatusMessage( $status );
267 * Get a list of known DB types
269 function getDBTypes() {
270 return $this->dbTypes
;
274 * Get an instance of InstallerDBType for the specified DB type
275 * @param $type Mixed: DB installer for which is needed, false to use default
277 function getDBInstaller( $type = false ) {
279 $type = $this->getVar( 'wgDBtype' );
281 $type = strtolower($type);
283 if ( !isset( $this->dbInstallers
[$type] ) ) {
284 $class = ucfirst( $type ). 'Installer';
285 if ($class::isCompiled()) {
286 $this->dbInstallers
[$type] = new $class( $this );
288 $this->dbInstallers
[$type] = false;
291 return $this->dbInstallers
[$type];
295 * Do initial checks of the PHP environment. Set variables according to
296 * the observed environment.
298 * It's possible that this may be called under the CLI SAPI, not the SAPI
299 * that the wiki will primarily run under. In that case, the subclass should
300 * initialise variables such as wgScriptPath, before calling this function.
302 * Under the web subclass, it can already be assumed that PHP 5+ is in use
303 * and that sessions are working.
305 function doEnvironmentChecks() {
306 $this->showMessage( 'config-env-php', phpversion() );
309 foreach ( $this->envChecks
as $check ) {
310 $status = $this->$check();
311 if ( $status === false ) {
315 $this->setVar( '_Environment', $good );
317 $this->showMessage( 'config-env-good' );
319 $this->showMessage( 'config-env-bad' );
325 * Get an MW configuration variable, or internal installer configuration variable.
326 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
327 * Installer variables are typically prefixed by an underscore.
329 function getVar( $name, $default = null ) {
330 if ( !isset( $this->settings
[$name] ) ) {
333 return $this->settings
[$name];
338 * Set a MW configuration variable, or internal installer configuration variable.
340 function setVar( $name, $value ) {
341 $this->settings
[$name] = $value;
345 * Exports all wg* variables stored by the installer into global scope
347 function exportVars() {
348 foreach ( $this->settings
as $name => $value ) {
349 if ( substr( $name, 0, 2 ) == 'wg' ) {
350 $GLOBALS[$name] = $value;
356 * Get a fake password for sending back to the user in HTML.
357 * This is a security mechanism to avoid compromise of the password in the
358 * event of session ID compromise.
360 function getFakePassword( $realPassword ) {
361 return str_repeat( '*', strlen( $realPassword ) );
365 * Set a variable which stores a password, except if the new value is a
366 * fake password in which case leave it as it is.
368 function setPassword( $name, $value ) {
369 if ( !preg_match( '/^\*+$/', $value ) ) {
370 $this->setVar( $name, $value );
374 /** Check if we're installing the latest version */
375 function envLatestVersion() {
377 $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json';
378 $latestInfo = Http
::get( $latestInfoUrl );
380 $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
383 $latestInfo = FormatJson
::decode($latestInfo);
384 if ($latestInfo === false ||
!isset( $latestInfo->mwreleases
) ) {
385 # For when the request is successful but there's e.g. some silly man in
386 # the middle firewall blocking us, e.g. one of those annoying airport ones
387 $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
390 foreach( $latestInfo->mwreleases
as $rel ) {
391 if( isset( $rel->current
) )
392 $currentVersion = $rel->version
;
394 if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
395 $this->showMessage( 'config-env-latest-old' );
396 $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
397 } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
398 $this->showMessage( 'config-env-latest-new' );
400 $this->showMessage( 'config-env-latest-ok' );
403 /** Environment check for DB types */
404 function envCheckDB() {
405 $compiledDBs = array();
406 $goodNames = array();
408 foreach ( $this->dbTypes
as $name ) {
409 $db = $this->getDBInstaller( $name );
410 $readableName = wfMsg( 'config-type-' . $name );
412 $compiledDBs[] = $name;
413 $goodNames[] = $readableName;
415 $allNames[] = $readableName;
417 $this->setVar( '_CompiledDBs', $compiledDBs );
420 if ( !$compiledDBs ) {
421 $this->showMessage( 'config-no-db' );
422 $this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
425 $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
428 /** Environment check for register_globals */
429 function envCheckRegisterGlobals() {
430 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
431 $this->showMessage( 'config-register-globals' );
435 /** Environment check for magic_quotes_runtime */
436 function envCheckMagicQuotes() {
437 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
438 $this->showMessage( 'config-magic-quotes-runtime' );
443 /** Environment check for magic_quotes_sybase */
444 function envCheckMagicSybase() {
445 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
446 $this->showMessage( 'config-magic-quotes-sybase' );
451 /* Environment check for mbstring.func_overload */
452 function envCheckMbstring() {
453 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
454 $this->showMessage( 'config-mbstring' );
459 /** Environment check for zend.ze1_compatibility_mode */
460 function envCheckZE1() {
461 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
462 $this->showMessage( 'config-ze1' );
467 /** Environment check for safe_mode */
468 function envCheckSafeMode() {
469 if ( wfIniGetBool( 'safe_mode' ) ) {
470 $this->setVar( '_SafeMode', true );
471 $this->showMessage( 'config-safe-mode' );
475 /** Environment check for the XML module */
476 function envCheckXML() {
477 if ( !function_exists( "utf8_encode" ) ) {
478 $this->showMessage( 'config-xml-bad' );
481 $this->showMessage( 'config-xml-good' );
484 /** Environment check for the PCRE module */
485 function envCheckPCRE() {
486 if ( !function_exists( 'preg_match' ) ) {
487 $this->showMessage( 'config-pcre' );
492 /** Environment check for available memory */
493 function envCheckMemory() {
494 $limit = ini_get( 'memory_limit' );
495 if ( !$limit ||
$limit == -1 ) {
496 $this->showMessage( 'config-memory-none' );
499 $n = intval( $limit );
500 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
501 $n = intval( $m[1] * (1024*1024) );
503 if( $n < $this->minMemorySize
*1024*1024 ) {
504 $newLimit = "{$this->minMemorySize}M";
505 if( false === ini_set( "memory_limit", $newLimit ) ) {
506 $this->showMessage( 'config-memory-bad', $limit );
508 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
509 $this->setVar( '_RaiseMemory', true );
512 $this->showMessage( 'config-memory-ok', $limit );
516 /** Environment check for compiled object cache types */
517 function envCheckCache() {
519 foreach ( $this->objectCaches
as $name => $function ) {
520 if ( function_exists( $function ) ) {
521 $caches[$name] = true;
522 $this->showMessage( 'config-' . $name );
526 $this->showMessage( 'config-no-cache' );
528 $this->setVar( '_Caches', $caches );
531 /** Search for GNU diff3 */
532 function envCheckDiff3() {
533 $paths = array_merge(
540 explode( PATH_SEPARATOR
, getenv( "PATH" ) ) );
541 $names = array( "gdiff3", "diff3", "diff3.exe" );
543 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
545 foreach ( $paths as $path ) {
546 $exe = $this->locateExecutable( $path, $names, $versionInfo );
547 if ($exe !== false) {
548 $this->setVar( 'wgDiff3', $exe );
554 $this->showMessage( 'config-diff3-good', $exe );
556 $this->setVar( 'wgDiff3', false );
557 $this->showMessage( 'config-diff3-bad' );
562 * Search a path for any of the given executable names. Returns the
563 * executable name if found. Also checks the version string returned
566 * @param $path String: path to search
567 * @param $names Array of executable names
568 * @param $versionInfo Boolean false or array with two members:
569 * 0 => Command to run for version check, with $1 for the path
570 * 1 => String to compare the output with
572 * If $versionInfo is not false, only executables with a version
573 * matching $versionInfo[1] will be returned.
575 function locateExecutable( $path, $names, $versionInfo = false ) {
576 if (!is_array($names))
577 $names = array($names);
579 foreach ($names as $name) {
580 $command = "$path/$name";
581 if ( @file_exists
( $command ) ) {
585 $file = str_replace( '$1', $command, $versionInfo[0] );
586 # Should maybe be wfShellExec( $file), but runs into a ulimit, see
587 # http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
588 if ( strstr( `
$file`
, $versionInfo[1]) !== false )
595 /** Environment check for ImageMagick and GD */
596 function envCheckGraphics() {
597 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
598 foreach( $imcheck as $dir ) {
599 $im = "$dir/convert";
600 if( @file_exists
( $im ) ) {
601 $this->showMessage( 'config-imagemagick', $im );
602 $this->setVar( 'wgImageMagickConvertCommand', $im );
606 if ( function_exists( 'imagejpeg' ) ) {
607 $this->showMessage( 'config-gd' );
610 $this->showMessage( 'no-scaling' );
613 /** Environment check for setting $IP and $wgScriptPath */
614 function envCheckPath() {
615 $IP = dirname( dirname( dirname( __FILE__
) ) );
616 $this->setVar( 'IP', $IP );
617 $this->showMessage( 'config-dir', $IP );
619 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
620 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
621 // to get the path to the current script... hopefully it's reliable. SIGH
622 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
623 $path = $_SERVER['PHP_SELF'];
624 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
625 $path = $_SERVER['SCRIPT_NAME'];
626 } elseif ( $this->getVar( 'wgScriptPath' ) ) {
627 // Some kind soul has set it for us already (e.g. debconf)
630 $this->showMessage( 'config-no-uri' );
633 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
634 $this->setVar( 'wgScriptPath', $uri );
635 $this->showMessage( 'config-uri', $uri );
638 /** Environment check for writable config/ directory */
639 function envCheckWriteableDir() {
640 $ipDir = $this->getVar( 'IP' );
641 $configDir = $ipDir . '/config';
642 if( !is_writeable( $configDir ) ) {
643 $webserverGroup = self
::maybeGetWebserverPrimaryGroup();
644 if ( $webserverGroup !== null ) {
645 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
647 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
653 /** Environment check for setting the preferred PHP file extension */
654 function envCheckExtension() {
655 // FIXME: detect this properly
656 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
661 $this->setVar( 'wgScriptExtension', ".$ext" );
662 $this->showMessage( 'config-file-extension', $ext );
665 function envCheckShellLocale() {
666 # Give up now if we're in safe mode or open_basedir
667 # It's theoretically possible but tricky to work with
668 if ( wfIniGetBool( "safe_mode" ) ||
ini_get( 'open_basedir' ) ||
!function_exists( 'exec' ) ) {
672 $os = php_uname( 's' );
673 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
674 if ( !in_array( $os, $supported ) ) {
678 # Get a list of available locales
679 $lines = $ret = false;
680 exec( '/usr/bin/locale -a', $lines, $ret );
685 $lines = wfArrayMap( 'trim', $lines );
686 $candidatesByLocale = array();
687 $candidatesByLang = array();
688 foreach ( $lines as $line ) {
689 if ( $line === '' ) {
692 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
695 list( $all, $lang, $territory, $charset, $modifier ) = $m;
696 $candidatesByLocale[$m[0]] = $m;
697 $candidatesByLang[$lang][] = $m;
700 # Try the current value of LANG
701 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
702 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
703 $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
707 # Try the most common ones
708 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
709 foreach ( $commonLocales as $commonLocale ) {
710 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
711 $this->setVar( 'wgShellLocale', $commonLocale );
712 $this->showMessage( 'config-shell-locale', $commonLocale );
717 # Is there an available locale in the Wiki's language?
718 $wikiLang = $this->getVar( 'wgLanguageCode' );
719 if ( isset( $candidatesByLang[$wikiLang] ) ) {
720 $m = reset( $candidatesByLang[$wikiLang] );
721 $this->setVar( 'wgShellLocale', $m[0] );
722 $this->showMessage( 'config-shell-locale', $m[0] );
726 # Are there any at all?
727 if ( count( $candidatesByLocale ) ) {
728 $m = reset( $candidatesByLocale );
729 $this->setVar( 'wgShellLocale', $m[0] );
730 $this->showMessage( 'config-shell-locale', $m[0] );
738 function envCheckUploadsDirectory() {
739 global $IP, $wgServer;
740 $dir = $IP . '/images/';
741 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
742 $safe = !$this->dirIsExecutable( $dir, $url );
744 $this->showMessage( 'config-uploads-safe' );
746 $this->showMessage( 'config-uploads-not-safe', $dir );
751 * Checks if scripts located in the given directory can be executed via the given URL
753 function dirIsExecutable( $dir, $url ) {
754 $scriptTypes = array(
756 "<?php echo 'ex' . 'ec';",
757 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
760 // it would be good to check other popular languages here, but it'll be slow
762 wfSuppressWarnings();
763 foreach ( $scriptTypes as $ext => $contents ) {
764 foreach ( $contents as $source ) {
765 $file = 'exectest.' . $ext;
766 if ( !file_put_contents( $dir . $file, $source ) ) {
769 $text = Http
::get( $url . $file );
770 unlink( $dir . $file );
771 if ( $text == 'exec' ) {
782 * Convert wikitext $text to HTML.
784 * This is potentially error prone since many parser features require a complete
785 * installed MW database. The solution is to just not use those features when you
786 * write your messages. This appears to work well enough. Basic formatting and
787 * external links work just fine.
789 * But in case a translator decides to throw in a #ifexist or internal link or
790 * whatever, this function is guarded to catch attempted DB access and to present
791 * some fallback text.
793 * @param $text String
794 * @param $lineStart Boolean
797 function parse( $text, $lineStart = false ) {
800 $out = $wgParser->parse( $text, $this->parserTitle
, $this->parserOptions
, $lineStart );
801 $html = $out->getText();
802 } catch ( DBAccessError
$e ) {
803 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
804 if ( !empty( $this->debug
) ) {
805 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
812 * Register tag hook below
814 function registerDocLink( &$parser ) {
815 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
820 * Extension tag hook for a documentation link
822 function docLink( $linkText, $attribs, $parser ) {
823 $url = $this->getDocUrl( $attribs['href'] );
824 return '<a href="' . htmlspecialchars( $url ) . '">' .
825 htmlspecialchars( $linkText ) .
830 * Overridden by WebInstaller to provide lastPage parameters
832 protected function getDocUrl( $page ) {
833 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
836 public function findExtensions() {
837 if( $this->getVar( 'IP' ) === null ) {
841 $dir = $this->getVar( 'IP' ) . '/extensions';
842 $dh = opendir( $dir );
843 while ( ( $file = readdir( $dh ) ) !== false ) {
844 if( file_exists( "$dir/$file/$file.php" ) ) {
848 $this->setVar( '_Extensions', $exts );
852 public function getInstallSteps() {
853 if( $this->getVar( '_UpgradeDone' ) ) {
854 $this->installSteps
= array( 'localsettings' );
856 if( count( $this->getVar( '_Extensions' ) ) ) {
857 array_unshift( $this->installSteps
, 'extensions' );
859 return $this->installSteps
;
863 * Actually perform the installation
864 * @param Array $startCB A callback array for the beginning of each step
865 * @param Array $endCB A callback array for the end of each step
866 * @return Array of Status objects
868 public function performInstallation( $startCB, $endCB ) {
869 $installResults = array();
870 foreach( $this->getInstallSteps() as $stepObj ) {
871 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
872 call_user_func_array( $startCB, array( $step ) );
875 # Call our working function
876 if ( is_array( $step ) ) {
878 $callback = $stepObj['callback'];
879 $status = call_user_func_array( $callback, array() );
881 # Boring implicitly named callback
882 $func = 'install' . ucfirst( $step );
883 $status = $this->{$func}();
885 call_user_func_array( $endCB, array( $step, $status ) );
886 $installResults[$step] = $status;
888 // If we've hit some sort of fatal, we need to bail. Callback
889 // already had a chance to do output above.
890 if( !$status->isOk() )
893 return $installResults;
896 public function installExtensions() {
897 global $wgHooks, $wgAutoloadClasses;
898 $exts = $this->getVar( '_Extensions' );
899 $path = $this->getVar( 'IP' ) . '/extensions';
900 foreach( $exts as $e ) {
901 require( "$path/$e/$e.php" );
903 return Status
::newGood();
906 public function installDatabase() {
907 $type = $this->getVar( 'wgDBtype' );
908 $installer = $this->getDBInstaller( $type );
910 $status = Status
::newFatal( "config-no-db", $type );
912 $status = $installer->setupDatabase();
917 public function installUser() {
918 $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
919 $status = $installer->setupUser();
923 public function installTables() {
924 $installer = $this->getDBInstaller();
925 $status = $installer->createTables();
926 if( $status->isOK() ) {
927 LBFactory
::enableBackend();
932 public function installInterwiki() {
933 $installer = $this->getDBInstaller();
934 return $installer->populateInterwikiTable();
937 public function installSecretKey() {
938 if ( wfIsWindows() ) {
941 wfSuppressWarnings();
942 $file = fopen( "/dev/urandom", "r" );
946 $status = Status
::newGood();
949 $secretKey = bin2hex( fread( $file, 32 ) );
953 for ( $i=0; $i<8; $i++
) {
954 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
956 $status->warning( 'config-insecure-secretkey' );
958 $this->setVar( 'wgSecretKey', $secretKey );
963 public function installSysop() {
964 $name = $this->getVar( '_AdminName' );
965 $user = User
::newFromName( $name );
967 // we should've validated this earlier anyway!
968 return Status
::newFatal( 'config-admin-error-user', $name );
970 if ( $user->idForName() == 0 ) {
971 $user->addToDatabase();
973 $user->setPassword( $this->getVar( '_AdminPassword' ) );
974 } catch( PasswordError
$pwe ) {
975 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
977 $user->addGroup( 'sysop' );
978 $user->addGroup( 'bureaucrat' );
979 $user->saveSettings();
981 return Status
::newGood();
984 public function installLocalsettings() {
985 $localSettings = new LocalSettingsGenerator( $this );
986 return $localSettings->writeLocalSettings();
990 * Determine if LocalSettings exists. If it does, return an appropriate
991 * status for whether we should can upgrade or not
994 function getLocalSettingsStatus() {
997 $status = Status
::newGood();
999 wfSuppressWarnings();
1000 $ls = file_exists( "$IP/LocalSettings.php" );
1001 wfRestoreWarnings();
1004 if( $this->getDBInstaller()->needsUpgrade() ) {
1005 $status->warning( 'config-localsettings-upgrade' );
1008 $status->fatal( 'config-localsettings-noupgrade' );
1015 * On POSIX systems return the primary group of the webserver we're running under.
1016 * On other systems just returns null.
1018 * This is used to advice the user that he should chgrp his config/data/images directory as the
1019 * webserver user before he can install.
1021 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
1025 public static function maybeGetWebserverPrimaryGroup() {
1026 if ( ! function_exists('posix_getegid') ||
! function_exists('posix_getpwuid') ) {
1027 # I don't know this, this isn't UNIX
1031 # posix_getegid() *not* getmygid() because we want the group of the webserver,
1032 # not whoever owns the current script
1033 $gid = posix_getegid();
1034 $getpwuid = posix_getpwuid( $gid );
1035 $group = $getpwuid["name"];
1041 * Override the necessary bits of the config to run an installation
1043 public static function overrideConfig() {
1044 define( 'MW_NO_SESSION', 1 );
1046 // Don't access the database
1047 $GLOBALS['wgUseDatabaseMessages'] = false;
1049 $GLOBALS['wgShowExceptionDetails'] = true;
1050 // Don't break forms
1051 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1053 // Extended debugging. Maybe disable before release?
1054 $GLOBALS['wgShowSQLErrors'] = true;
1055 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1059 * Add an installation step following the given step.
1060 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
1061 * @param $callback array
1063 function addInstallStepFollowing( $findStep, $callback ) {
1065 if( $findStep !== null ) $where = array_search( $findStep, $this->installSteps
);
1067 array_splice( $this->installSteps
, $where, 0, $callback );