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 );
238 if ( !$installer->isCompiled() ) {
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 $this->dbInstallers
[$type] = new $class( $this );
287 return $this->dbInstallers
[$type];
291 * Do initial checks of the PHP environment. Set variables according to
292 * the observed environment.
294 * It's possible that this may be called under the CLI SAPI, not the SAPI
295 * that the wiki will primarily run under. In that case, the subclass should
296 * initialise variables such as wgScriptPath, before calling this function.
298 * Under the web subclass, it can already be assumed that PHP 5+ is in use
299 * and that sessions are working.
301 function doEnvironmentChecks() {
302 $this->showMessage( 'config-env-php', phpversion() );
305 foreach ( $this->envChecks
as $check ) {
306 $status = $this->$check();
307 if ( $status === false ) {
311 $this->setVar( '_Environment', $good );
313 $this->showMessage( 'config-env-good' );
315 $this->showMessage( 'config-env-bad' );
321 * Get an MW configuration variable, or internal installer configuration variable.
322 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
323 * Installer variables are typically prefixed by an underscore.
325 function getVar( $name, $default = null ) {
326 if ( !isset( $this->settings
[$name] ) ) {
329 return $this->settings
[$name];
334 * Set a MW configuration variable, or internal installer configuration variable.
336 function setVar( $name, $value ) {
337 $this->settings
[$name] = $value;
341 * Exports all wg* variables stored by the installer into global scope
343 function exportVars() {
344 foreach ( $this->settings
as $name => $value ) {
345 if ( substr( $name, 0, 2 ) == 'wg' ) {
346 $GLOBALS[$name] = $value;
352 * Get a fake password for sending back to the user in HTML.
353 * This is a security mechanism to avoid compromise of the password in the
354 * event of session ID compromise.
356 function getFakePassword( $realPassword ) {
357 return str_repeat( '*', strlen( $realPassword ) );
361 * Set a variable which stores a password, except if the new value is a
362 * fake password in which case leave it as it is.
364 function setPassword( $name, $value ) {
365 if ( !preg_match( '/^\*+$/', $value ) ) {
366 $this->setVar( $name, $value );
370 /** Check if we're installing the latest version */
371 function envLatestVersion() {
373 $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json';
374 $latestInfo = Http
::get( $latestInfoUrl );
376 $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
379 $latestInfo = FormatJson
::decode($latestInfo);
380 if ($latestInfo === false ||
!isset( $latestInfo->mwreleases
) ) {
381 # For when the request is successful but there's e.g. some silly man in
382 # the middle firewall blocking us, e.g. one of those annoying airport ones
383 $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
386 foreach( $latestInfo->mwreleases
as $rel ) {
387 if( isset( $rel->current
) )
388 $currentVersion = $rel->version
;
390 if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
391 $this->showMessage( 'config-env-latest-old' );
392 $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
393 } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
394 $this->showMessage( 'config-env-latest-new' );
396 $this->showMessage( 'config-env-latest-ok' );
399 /** Environment check for DB types */
400 function envCheckDB() {
401 $compiledDBs = array();
402 $goodNames = array();
404 foreach ( $this->dbTypes
as $name ) {
405 $db = $this->getDBInstaller( $name );
406 $readableName = wfMsg( 'config-type-' . $name );
408 $compiledDBs[] = $name;
409 $goodNames[] = $readableName;
411 $allNames[] = $readableName;
413 $this->setVar( '_CompiledDBs', $compiledDBs );
416 if ( !$compiledDBs ) {
417 $this->showMessage( 'config-no-db' );
418 $this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
421 $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
424 /** Environment check for register_globals */
425 function envCheckRegisterGlobals() {
426 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
427 $this->showMessage( 'config-register-globals' );
431 /** Environment check for magic_quotes_runtime */
432 function envCheckMagicQuotes() {
433 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
434 $this->showMessage( 'config-magic-quotes-runtime' );
439 /** Environment check for magic_quotes_sybase */
440 function envCheckMagicSybase() {
441 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
442 $this->showMessage( 'config-magic-quotes-sybase' );
447 /* Environment check for mbstring.func_overload */
448 function envCheckMbstring() {
449 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
450 $this->showMessage( 'config-mbstring' );
455 /** Environment check for zend.ze1_compatibility_mode */
456 function envCheckZE1() {
457 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
458 $this->showMessage( 'config-ze1' );
463 /** Environment check for safe_mode */
464 function envCheckSafeMode() {
465 if ( wfIniGetBool( 'safe_mode' ) ) {
466 $this->setVar( '_SafeMode', true );
467 $this->showMessage( 'config-safe-mode' );
471 /** Environment check for the XML module */
472 function envCheckXML() {
473 if ( !function_exists( "utf8_encode" ) ) {
474 $this->showMessage( 'config-xml-bad' );
477 $this->showMessage( 'config-xml-good' );
480 /** Environment check for the PCRE module */
481 function envCheckPCRE() {
482 if ( !function_exists( 'preg_match' ) ) {
483 $this->showMessage( 'config-pcre' );
488 /** Environment check for available memory */
489 function envCheckMemory() {
490 $limit = ini_get( 'memory_limit' );
491 if ( !$limit ||
$limit == -1 ) {
492 $this->showMessage( 'config-memory-none' );
495 $n = intval( $limit );
496 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
497 $n = intval( $m[1] * (1024*1024) );
499 if( $n < $this->minMemorySize
*1024*1024 ) {
500 $newLimit = "{$this->minMemorySize}M";
501 if( false === ini_set( "memory_limit", $newLimit ) ) {
502 $this->showMessage( 'config-memory-bad', $limit );
504 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
505 $this->setVar( '_RaiseMemory', true );
508 $this->showMessage( 'config-memory-ok', $limit );
512 /** Environment check for compiled object cache types */
513 function envCheckCache() {
515 foreach ( $this->objectCaches
as $name => $function ) {
516 if ( function_exists( $function ) ) {
517 $caches[$name] = true;
518 $this->showMessage( 'config-' . $name );
522 $this->showMessage( 'config-no-cache' );
524 $this->setVar( '_Caches', $caches );
527 /** Search for GNU diff3 */
528 function envCheckDiff3() {
529 $paths = array_merge(
536 explode( PATH_SEPARATOR
, getenv( "PATH" ) ) );
537 $names = array( "gdiff3", "diff3", "diff3.exe" );
539 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
541 foreach ( $paths as $path ) {
542 $exe = $this->locateExecutable( $path, $names, $versionInfo );
543 if ($exe !== false) {
544 $this->setVar( 'wgDiff3', $exe );
550 $this->showMessage( 'config-diff3-good', $exe );
552 $this->setVar( 'wgDiff3', false );
553 $this->showMessage( 'config-diff3-bad' );
558 * Search a path for any of the given executable names. Returns the
559 * executable name if found. Also checks the version string returned
562 * @param $path String: path to search
563 * @param $names Array of executable names
564 * @param $versionInfo Boolean false or array with two members:
565 * 0 => Command to run for version check, with $1 for the path
566 * 1 => String to compare the output with
568 * If $versionInfo is not false, only executables with a version
569 * matching $versionInfo[1] will be returned.
571 function locateExecutable( $path, $names, $versionInfo = false ) {
572 if (!is_array($names))
573 $names = array($names);
575 foreach ($names as $name) {
576 $command = "$path/$name";
577 if ( @file_exists
( $command ) ) {
581 $file = str_replace( '$1', $command, $versionInfo[0] );
582 # Should maybe be wfShellExec( $file), but runs into a ulimit, see
583 # http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
584 if ( strstr( `
$file`
, $versionInfo[1]) !== false )
591 /** Environment check for ImageMagick and GD */
592 function envCheckGraphics() {
593 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
594 foreach( $imcheck as $dir ) {
595 $im = "$dir/convert";
596 if( @file_exists
( $im ) ) {
597 $this->showMessage( 'config-imagemagick', $im );
598 $this->setVar( 'wgImageMagickConvertCommand', $im );
602 if ( function_exists( 'imagejpeg' ) ) {
603 $this->showMessage( 'config-gd' );
606 $this->showMessage( 'no-scaling' );
609 /** Environment check for setting $IP and $wgScriptPath */
610 function envCheckPath() {
611 $IP = dirname( dirname( dirname( __FILE__
) ) );
612 $this->setVar( 'IP', $IP );
613 $this->showMessage( 'config-dir', $IP );
615 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
616 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
617 // to get the path to the current script... hopefully it's reliable. SIGH
618 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
619 $path = $_SERVER['PHP_SELF'];
620 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
621 $path = $_SERVER['SCRIPT_NAME'];
622 } elseif ( $this->getVar( 'wgScriptPath' ) ) {
623 // Some kind soul has set it for us already (e.g. debconf)
626 $this->showMessage( 'config-no-uri' );
629 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
630 $this->setVar( 'wgScriptPath', $uri );
631 $this->showMessage( 'config-uri', $uri );
634 /** Environment check for writable config/ directory */
635 function envCheckWriteableDir() {
636 $ipDir = $this->getVar( 'IP' );
637 $configDir = $ipDir . '/config';
638 if( !is_writeable( $configDir ) ) {
639 $webserverGroup = self
::maybeGetWebserverPrimaryGroup();
640 if ( $webserverGroup !== null ) {
641 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
643 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
649 /** Environment check for setting the preferred PHP file extension */
650 function envCheckExtension() {
651 // FIXME: detect this properly
652 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
657 $this->setVar( 'wgScriptExtension', ".$ext" );
658 $this->showMessage( 'config-file-extension', $ext );
661 function envCheckShellLocale() {
662 # Give up now if we're in safe mode or open_basedir
663 # It's theoretically possible but tricky to work with
664 if ( wfIniGetBool( "safe_mode" ) ||
ini_get( 'open_basedir' ) ||
!function_exists( 'exec' ) ) {
668 $os = php_uname( 's' );
669 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
670 if ( !in_array( $os, $supported ) ) {
674 # Get a list of available locales
675 $lines = $ret = false;
676 exec( '/usr/bin/locale -a', $lines, $ret );
681 $lines = wfArrayMap( 'trim', $lines );
682 $candidatesByLocale = array();
683 $candidatesByLang = array();
684 foreach ( $lines as $line ) {
685 if ( $line === '' ) {
688 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
691 list( $all, $lang, $territory, $charset, $modifier ) = $m;
692 $candidatesByLocale[$m[0]] = $m;
693 $candidatesByLang[$lang][] = $m;
696 # Try the current value of LANG
697 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
698 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
699 $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
703 # Try the most common ones
704 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
705 foreach ( $commonLocales as $commonLocale ) {
706 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
707 $this->setVar( 'wgShellLocale', $commonLocale );
708 $this->showMessage( 'config-shell-locale', $commonLocale );
713 # Is there an available locale in the Wiki's language?
714 $wikiLang = $this->getVar( 'wgLanguageCode' );
715 if ( isset( $candidatesByLang[$wikiLang] ) ) {
716 $m = reset( $candidatesByLang[$wikiLang] );
717 $this->setVar( 'wgShellLocale', $m[0] );
718 $this->showMessage( 'config-shell-locale', $m[0] );
722 # Are there any at all?
723 if ( count( $candidatesByLocale ) ) {
724 $m = reset( $candidatesByLocale );
725 $this->setVar( 'wgShellLocale', $m[0] );
726 $this->showMessage( 'config-shell-locale', $m[0] );
734 function envCheckUploadsDirectory() {
735 global $IP, $wgServer;
736 $dir = $IP . '/images/';
737 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
738 $safe = !$this->dirIsExecutable( $dir, $url );
740 $this->showMessage( 'config-uploads-safe' );
742 $this->showMessage( 'config-uploads-not-safe', $dir );
747 * Checks if scripts located in the given directory can be executed via the given URL
749 function dirIsExecutable( $dir, $url ) {
750 $scriptTypes = array(
752 "<?php echo 'ex' . 'ec';",
753 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
756 // it would be good to check other popular languages here, but it'll be slow
758 wfSuppressWarnings();
759 foreach ( $scriptTypes as $ext => $contents ) {
760 foreach ( $contents as $source ) {
761 $file = 'exectest.' . $ext;
762 if ( !file_put_contents( $dir . $file, $source ) ) {
765 $text = Http
::get( $url . $file );
766 unlink( $dir . $file );
767 if ( $text == 'exec' ) {
778 * Convert wikitext $text to HTML.
780 * This is potentially error prone since many parser features require a complete
781 * installed MW database. The solution is to just not use those features when you
782 * write your messages. This appears to work well enough. Basic formatting and
783 * external links work just fine.
785 * But in case a translator decides to throw in a #ifexist or internal link or
786 * whatever, this function is guarded to catch attempted DB access and to present
787 * some fallback text.
789 * @param $text String
790 * @param $lineStart Boolean
793 function parse( $text, $lineStart = false ) {
796 $out = $wgParser->parse( $text, $this->parserTitle
, $this->parserOptions
, $lineStart );
797 $html = $out->getText();
798 } catch ( DBAccessError
$e ) {
799 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
800 if ( !empty( $this->debug
) ) {
801 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
808 * Register tag hook below
810 function registerDocLink( &$parser ) {
811 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
816 * Extension tag hook for a documentation link
818 function docLink( $linkText, $attribs, $parser ) {
819 $url = $this->getDocUrl( $attribs['href'] );
820 return '<a href="' . htmlspecialchars( $url ) . '">' .
821 htmlspecialchars( $linkText ) .
826 * Overridden by WebInstaller to provide lastPage parameters
828 protected function getDocUrl( $page ) {
829 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
832 public function findExtensions() {
833 if( $this->getVar( 'IP' ) === null ) {
837 $dir = $this->getVar( 'IP' ) . '/extensions';
838 $dh = opendir( $dir );
839 while ( ( $file = readdir( $dh ) ) !== false ) {
840 if( file_exists( "$dir/$file/$file.php" ) ) {
844 $this->setVar( '_Extensions', $exts );
848 public function getInstallSteps() {
849 if( $this->getVar( '_UpgradeDone' ) ) {
850 $this->installSteps
= array( 'localsettings' );
852 if( count( $this->getVar( '_Extensions' ) ) ) {
853 array_unshift( $this->installSteps
, 'extensions' );
855 return $this->installSteps
;
859 * Actually perform the installation
860 * @param Array $startCB A callback array for the beginning of each step
861 * @param Array $endCB A callback array for the end of each step
862 * @return Array of Status objects
864 public function performInstallation( $startCB, $endCB ) {
865 $installResults = array();
866 $installer = $this->getDBInstaller();
867 foreach( $this->getInstallSteps() as $stepObj ) {
868 $step = is_array( $stepObj ) ?
$stepObj['name'] : $stepObj;
869 call_user_func_array( $startCB, array( $step ) );
872 # Call our working function
873 if ( is_array( $stepObj ) ) {
875 $callback = $stepObj['callback'];
876 $status = call_user_func_array( $callback, array( $installer ) );
878 # Boring implicitly named callback
879 $func = 'install' . ucfirst( $step );
880 $status = $this->{$func}( $installer );
882 call_user_func_array( $endCB, array( $step, $status ) );
883 $installResults[$step] = $status;
885 // If we've hit some sort of fatal, we need to bail. Callback
886 // already had a chance to do output above.
887 if( !$status->isOk() )
890 return $installResults;
893 public function installExtensions() {
894 global $wgHooks, $wgAutoloadClasses;
895 $exts = $this->getVar( '_Extensions' );
896 $path = $this->getVar( 'IP' ) . '/extensions';
897 foreach( $exts as $e ) {
898 require( "$path/$e/$e.php" );
900 return Status
::newGood();
903 public function installDatabase( &$installer ) {
905 $type = $this->getVar( 'wgDBtype' );
906 $status = Status
::newFatal( "config-no-db", $type );
908 $status = $installer->setupDatabase();
913 public function installTables( &$installer ) {
914 $status = $installer->createTables();
915 if( $status->isOK() ) {
916 LBFactory
::enableBackend();
921 public function installInterwiki( &$installer ) {
922 return $installer->populateInterwikiTable();
925 public function installSecretKey() {
926 if ( wfIsWindows() ) {
929 wfSuppressWarnings();
930 $file = fopen( "/dev/urandom", "r" );
934 $status = Status
::newGood();
937 $secretKey = bin2hex( fread( $file, 32 ) );
941 for ( $i=0; $i<8; $i++
) {
942 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
944 $status->warning( 'config-insecure-secretkey' );
946 $this->setVar( 'wgSecretKey', $secretKey );
951 public function installSysop() {
952 $name = $this->getVar( '_AdminName' );
953 $user = User
::newFromName( $name );
955 // we should've validated this earlier anyway!
956 return Status
::newFatal( 'config-admin-error-user', $name );
958 if ( $user->idForName() == 0 ) {
959 $user->addToDatabase();
961 $user->setPassword( $this->getVar( '_AdminPassword' ) );
962 } catch( PasswordError
$pwe ) {
963 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
965 $user->addGroup( 'sysop' );
966 $user->addGroup( 'bureaucrat' );
967 $user->saveSettings();
969 return Status
::newGood();
972 public function installLocalsettings() {
973 $localSettings = new LocalSettingsGenerator( $this );
974 return $localSettings->writeLocalSettings();
978 * Determine if LocalSettings exists. If it does, return an appropriate
979 * status for whether we should can upgrade or not
982 function getLocalSettingsStatus() {
985 $status = Status
::newGood();
987 wfSuppressWarnings();
988 $ls = file_exists( "$IP/LocalSettings.php" );
992 if( $this->getDBInstaller()->needsUpgrade() ) {
993 $status->warning( 'config-localsettings-upgrade' );
996 $status->fatal( 'config-localsettings-noupgrade' );
1003 * On POSIX systems return the primary group of the webserver we're running under.
1004 * On other systems just returns null.
1006 * This is used to advice the user that he should chgrp his config/data/images directory as the
1007 * webserver user before he can install.
1009 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
1013 public static function maybeGetWebserverPrimaryGroup() {
1014 if ( ! function_exists('posix_getegid') ||
! function_exists('posix_getpwuid') ) {
1015 # I don't know this, this isn't UNIX
1019 # posix_getegid() *not* getmygid() because we want the group of the webserver,
1020 # not whoever owns the current script
1021 $gid = posix_getegid();
1022 $getpwuid = posix_getpwuid( $gid );
1023 $group = $getpwuid["name"];
1029 * Override the necessary bits of the config to run an installation
1031 public static function overrideConfig() {
1032 define( 'MW_NO_SESSION', 1 );
1034 // Don't access the database
1035 $GLOBALS['wgUseDatabaseMessages'] = false;
1037 $GLOBALS['wgShowExceptionDetails'] = true;
1038 // Don't break forms
1039 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1041 // Extended debugging. Maybe disable before release?
1042 $GLOBALS['wgShowSQLErrors'] = true;
1043 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1047 * Add an installation step following the given step.
1048 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
1049 * @param $callback array
1051 function addInstallStepFollowing( $findStep, $callback ) {
1053 if( $findStep !== null ) $where = array_search( $findStep, $this->installSteps
);
1055 array_splice( $this->installSteps
, $where, 0, $callback );