20a43b4c0b303dd3dcbcec533335fddc68b54502
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',
35 // 'wgDeletedDirectory',
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.
127 protected $installSteps = array(
137 * Known object cache types and the functions used to test for their existence
139 protected $objectCaches = array(
140 'xcache' => 'xcache_get',
141 'apc' => 'apc_fetch',
142 'eaccel' => 'eaccelerator_get',
143 'wincache' => 'wincache_ucache_get'
147 * User rights profiles
149 var $rightsProfiles = array(
152 '*' => array( 'edit' => false )
156 'createaccount' => false,
162 'createaccount' => false,
172 var $licenses = array(
179 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
180 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
182 'cc-by-nc-sa' => array(
183 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
184 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
187 'url' => 'http://creativecommons.org/licenses/publicdomain/',
188 'icon' => '{$wgStylePath}/common/images/public-domain.png',
191 'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
192 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
194 'gfdl-current' => array(
195 'url' => 'http://www.gnu.org/copyleft/fdl.html',
196 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
198 'cc-choose' => array(
199 // details will be filled in by the selector
206 * Cached Title and ParserOptions used by parse()
208 private $parserTitle, $parserOptions;
211 * Constructor, always call this from child classes
213 function __construct() {
214 // Disable the i18n cache and LoadBalancer
215 Language
::getLocalisationCache()->disableBackend();
216 LBFactory
::disableBackend();
218 // Load the installer's i18n file
219 global $wgExtensionMessagesFiles;
220 $wgExtensionMessagesFiles['MediawikiInstaller'] =
221 './includes/installer/Installer.i18n.php';
224 $wgUser = User
::newFromId( 0 );
225 // Having a user with id = 0 safeguards us from DB access via User::loadOptions()
227 // Set our custom <doclink> hook
229 $wgHooks['ParserFirstCallInit'][] = array( $this, 'registerDocLink' );
231 $this->settings
= $this->internalDefaults
;
232 foreach ( $this->defaultVarNames
as $var ) {
233 $this->settings
[$var] = $GLOBALS[$var];
235 foreach ( $this->dbTypes
as $type ) {
236 $installer = $this->getDBInstaller( $type );
237 if ( !$installer->isCompiled() ) {
240 $defaults = $installer->getGlobalDefaults();
241 foreach ( $installer->getGlobalNames() as $var ) {
242 if ( isset( $defaults[$var] ) ) {
243 $this->settings
[$var] = $defaults[$var];
245 $this->settings
[$var] = $GLOBALS[$var];
250 $this->parserTitle
= Title
::newFromText( 'Installer' );
251 $this->parserOptions
= new ParserOptions
;
252 $this->parserOptions
->setEditSection( false );
256 * UI interface for displaying a short message
257 * The parameters are like parameters to wfMsg().
258 * The messages will be in wikitext format, which will be converted to an
259 * output format such as HTML or text before being sent to the user.
261 abstract function showMessage( $msg /*, ... */ );
263 abstract function showStatusMessage( $status );
266 * Get a list of known DB types
268 function getDBTypes() {
269 return $this->dbTypes
;
273 * Get an instance of InstallerDBType for the specified DB type
274 * @param $type Mixed: DB installer for which is needed, false to use default
276 function getDBInstaller( $type = false ) {
278 $type = $this->getVar( 'wgDBtype' );
280 if ( !isset( $this->dbInstallers
[$type] ) ) {
281 $class = ucfirst( $type ). 'Installer';
282 $this->dbInstallers
[$type] = new $class( $this );
284 return $this->dbInstallers
[$type];
288 * Do initial checks of the PHP environment. Set variables according to
289 * the observed environment.
291 * It's possible that this may be called under the CLI SAPI, not the SAPI
292 * that the wiki will primarily run under. In that case, the subclass should
293 * initialise variables such as wgScriptPath, before calling this function.
295 * Under the web subclass, it can already be assumed that PHP 5+ is in use
296 * and that sessions are working.
298 function doEnvironmentChecks() {
299 $this->showMessage( 'config-env-php', phpversion() );
302 foreach ( $this->envChecks
as $check ) {
303 $status = $this->$check();
304 if ( $status === false ) {
308 $this->setVar( '_Environment', $good );
310 $this->showMessage( 'config-env-good' );
312 $this->showMessage( 'config-env-bad' );
318 * Get an MW configuration variable, or internal installer configuration variable.
319 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
320 * Installer variables are typically prefixed by an underscore.
322 function getVar( $name, $default = null ) {
323 if ( !isset( $this->settings
[$name] ) ) {
326 return $this->settings
[$name];
331 * Set a MW configuration variable, or internal installer configuration variable.
333 function setVar( $name, $value ) {
334 $this->settings
[$name] = $value;
338 * Exports all wg* variables stored by the installer into global scope
340 function exportVars() {
341 foreach ( $this->settings
as $name => $value ) {
342 if ( substr( $name, 0, 2 ) == 'wg' ) {
343 $GLOBALS[$name] = $value;
349 * Get a fake password for sending back to the user in HTML.
350 * This is a security mechanism to avoid compromise of the password in the
351 * event of session ID compromise.
353 function getFakePassword( $realPassword ) {
354 return str_repeat( '*', strlen( $realPassword ) );
358 * Set a variable which stores a password, except if the new value is a
359 * fake password in which case leave it as it is.
361 function setPassword( $name, $value ) {
362 if ( !preg_match( '/^\*+$/', $value ) ) {
363 $this->setVar( $name, $value );
367 /** Check if we're installing the latest version */
368 function envLatestVersion() {
370 $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json';
371 $latestInfo = Http
::get( $latestInfoUrl );
373 $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
376 $latestInfo = FormatJson
::decode($latestInfo);
377 if ($latestInfo === false ||
!isset( $latestInfo->mwreleases
) ) {
378 # For when the request is successful but there's e.g. some silly man in
379 # the middle firewall blocking us, e.g. one of those annoying airport ones
380 $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
383 foreach( $latestInfo->mwreleases
as $rel ) {
384 if( isset( $rel->current
) )
385 $currentVersion = $rel->version
;
387 if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
388 $this->showMessage( 'config-env-latest-old' );
389 $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
390 } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
391 $this->showMessage( 'config-env-latest-new' );
393 $this->showMessage( 'config-env-latest-ok' );
396 /** Environment check for DB types */
397 function envCheckDB() {
398 $compiledDBs = array();
399 $goodNames = array();
401 foreach ( $this->dbTypes
as $name ) {
402 $db = $this->getDBInstaller( $name );
403 $readableName = wfMsg( 'config-type-' . $name );
404 if ( $db->isCompiled() ) {
405 $compiledDBs[] = $name;
406 $goodNames[] = $readableName;
408 $allNames[] = $readableName;
410 $this->setVar( '_CompiledDBs', $compiledDBs );
413 if ( !$compiledDBs ) {
414 $this->showMessage( 'config-no-db' );
415 $this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
418 $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
421 /** Environment check for register_globals */
422 function envCheckRegisterGlobals() {
423 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
424 $this->showMessage( 'config-register-globals' );
428 /** Environment check for magic_quotes_runtime */
429 function envCheckMagicQuotes() {
430 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
431 $this->showMessage( 'config-magic-quotes-runtime' );
436 /** Environment check for magic_quotes_sybase */
437 function envCheckMagicSybase() {
438 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
439 $this->showMessage( 'config-magic-quotes-sybase' );
444 /* Environment check for mbstring.func_overload */
445 function envCheckMbstring() {
446 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
447 $this->showMessage( 'config-mbstring' );
452 /** Environment check for zend.ze1_compatibility_mode */
453 function envCheckZE1() {
454 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
455 $this->showMessage( 'config-ze1' );
460 /** Environment check for safe_mode */
461 function envCheckSafeMode() {
462 if ( wfIniGetBool( 'safe_mode' ) ) {
463 $this->setVar( '_SafeMode', true );
464 $this->showMessage( 'config-safe-mode' );
468 /** Environment check for the XML module */
469 function envCheckXML() {
470 if ( !function_exists( "utf8_encode" ) ) {
471 $this->showMessage( 'config-xml-bad' );
474 $this->showMessage( 'config-xml-good' );
477 /** Environment check for the PCRE module */
478 function envCheckPCRE() {
479 if ( !function_exists( 'preg_match' ) ) {
480 $this->showMessage( 'config-pcre' );
485 /** Environment check for available memory */
486 function envCheckMemory() {
487 $limit = ini_get( 'memory_limit' );
488 if ( !$limit ||
$limit == -1 ) {
489 $this->showMessage( 'config-memory-none' );
492 $n = intval( $limit );
493 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
494 $n = intval( $m[1] * (1024*1024) );
496 if( $n < $this->minMemorySize
*1024*1024 ) {
497 $newLimit = "{$this->minMemorySize}M";
498 if( false === ini_set( "memory_limit", $newLimit ) ) {
499 $this->showMessage( 'config-memory-bad', $limit );
501 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
502 $this->setVar( '_RaiseMemory', true );
505 $this->showMessage( 'config-memory-ok', $limit );
509 /** Environment check for compiled object cache types */
510 function envCheckCache() {
512 foreach ( $this->objectCaches
as $name => $function ) {
513 if ( function_exists( $function ) ) {
514 $caches[$name] = true;
515 $this->showMessage( 'config-' . $name );
519 $this->showMessage( 'config-no-cache' );
521 $this->setVar( '_Caches', $caches );
524 /** Search for GNU diff3 */
525 function envCheckDiff3() {
526 $paths = array_merge(
533 explode( PATH_SEPARATOR
, getenv( "PATH" ) ) );
534 $names = array( "gdiff3", "diff3", "diff3.exe" );
536 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
538 foreach ( $paths as $path ) {
539 $exe = $this->locateExecutable( $path, $names, $versionInfo );
540 if ($exe !== false) {
541 $this->setVar( 'wgDiff3', $exe );
547 $this->showMessage( 'config-diff3-good', $exe );
549 $this->setVar( 'wgDiff3', false );
550 $this->showMessage( 'config-diff3-bad' );
555 * Search a path for any of the given executable names. Returns the
556 * executable name if found. Also checks the version string returned
559 * @param $path String: path to search
560 * @param $names Array of executable names
561 * @param $versionInfo Boolean false or array with two members:
562 * 0 => Command to run for version check, with $1 for the path
563 * 1 => String to compare the output with
565 * If $versionInfo is not false, only executables with a version
566 * matching $versionInfo[1] will be returned.
568 function locateExecutable( $path, $names, $versionInfo = false ) {
569 if (!is_array($names))
570 $names = array($names);
572 foreach ($names as $name) {
573 $command = "$path/$name";
574 if ( @file_exists
( $command ) ) {
578 $file = str_replace( '$1', $command, $versionInfo[0] );
579 # Should maybe be wfShellExec( $file), but runs into a ulimit, see
580 # http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
581 if ( strstr( `
$file`
, $versionInfo[1]) !== false )
588 /** Environment check for ImageMagick and GD */
589 function envCheckGraphics() {
590 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
591 foreach( $imcheck as $dir ) {
592 $im = "$dir/convert";
593 if( @file_exists
( $im ) ) {
594 $this->showMessage( 'config-imagemagick', $im );
595 $this->setVar( 'wgImageMagickConvertCommand', $im );
599 if ( function_exists( 'imagejpeg' ) ) {
600 $this->showMessage( 'config-gd' );
603 $this->showMessage( 'no-scaling' );
606 /** Environment check for setting $IP and $wgScriptPath */
607 function envCheckPath() {
608 $IP = dirname( dirname( dirname( __FILE__
) ) );
609 $this->setVar( 'IP', $IP );
610 $this->showMessage( 'config-dir', $IP );
612 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
613 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
614 // to get the path to the current script... hopefully it's reliable. SIGH
615 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
616 $path = $_SERVER['PHP_SELF'];
617 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
618 $path = $_SERVER['SCRIPT_NAME'];
619 } elseif ( $this->getVar( 'wgScriptPath' ) ) {
620 // Some kind soul has set it for us already (e.g. debconf)
623 $this->showMessage( 'config-no-uri' );
626 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
627 $this->setVar( 'wgScriptPath', $uri );
628 $this->showMessage( 'config-uri', $uri );
631 /** Environment check for writable config/ directory */
632 function envCheckWriteableDir() {
633 $ipDir = $this->getVar( 'IP' );
634 $configDir = $ipDir . '/config';
635 if( !is_writeable( $configDir ) ) {
636 $webserverGroup = self
::maybeGetWebserverPrimaryGroup();
637 if ( $webserverGroup !== null ) {
638 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
640 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
646 /** Environment check for setting the preferred PHP file extension */
647 function envCheckExtension() {
648 // FIXME: detect this properly
649 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
654 $this->setVar( 'wgScriptExtension', ".$ext" );
655 $this->showMessage( 'config-file-extension', $ext );
658 function envCheckShellLocale() {
659 # Give up now if we're in safe mode or open_basedir
660 # It's theoretically possible but tricky to work with
661 if ( wfIniGetBool( "safe_mode" ) ||
ini_get( 'open_basedir' ) ||
!function_exists( 'exec' ) ) {
665 $os = php_uname( 's' );
666 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
667 if ( !in_array( $os, $supported ) ) {
671 # Get a list of available locales
672 $lines = $ret = false;
673 exec( '/usr/bin/locale -a', $lines, $ret );
678 $lines = wfArrayMap( 'trim', $lines );
679 $candidatesByLocale = array();
680 $candidatesByLang = array();
681 foreach ( $lines as $line ) {
682 if ( $line === '' ) {
685 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
688 list( $all, $lang, $territory, $charset, $modifier ) = $m;
689 $candidatesByLocale[$m[0]] = $m;
690 $candidatesByLang[$lang][] = $m;
693 # Try the current value of LANG
694 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
695 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
696 $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
700 # Try the most common ones
701 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
702 foreach ( $commonLocales as $commonLocale ) {
703 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
704 $this->setVar( 'wgShellLocale', $commonLocale );
705 $this->showMessage( 'config-shell-locale', $commonLocale );
710 # Is there an available locale in the Wiki's language?
711 $wikiLang = $this->getVar( 'wgLanguageCode' );
712 if ( isset( $candidatesByLang[$wikiLang] ) ) {
713 $m = reset( $candidatesByLang[$wikiLang] );
714 $this->setVar( 'wgShellLocale', $m[0] );
715 $this->showMessage( 'config-shell-locale', $m[0] );
719 # Are there any at all?
720 if ( count( $candidatesByLocale ) ) {
721 $m = reset( $candidatesByLocale );
722 $this->setVar( 'wgShellLocale', $m[0] );
723 $this->showMessage( 'config-shell-locale', $m[0] );
731 function envCheckUploadsDirectory() {
732 global $IP, $wgServer;
733 $dir = $IP . '/images/';
734 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
735 $safe = !$this->dirIsExecutable( $dir, $url );
737 $this->showMessage( 'config-uploads-safe' );
739 $this->showMessage( 'config-uploads-not-safe', $dir );
744 * Checks if scripts located in the given directory can be executed via the given URL
746 function dirIsExecutable( $dir, $url ) {
747 $scriptTypes = array(
749 "<?php echo 'ex' . 'ec';",
750 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
753 // it would be good to check other popular languages here, but it'll be slow
755 wfSuppressWarnings();
756 foreach ( $scriptTypes as $ext => $contents ) {
757 foreach ( $contents as $source ) {
758 $file = 'exectest.' . $ext;
759 if ( !file_put_contents( $dir . $file, $source ) ) {
762 $text = Http
::get( $url . $file );
763 unlink( $dir . $file );
764 if ( $text == 'exec' ) {
775 * Convert wikitext $text to HTML.
777 * This is potentially error prone since many parser features require a complete
778 * installed MW database. The solution is to just not use those features when you
779 * write your messages. This appears to work well enough. Basic formatting and
780 * external links work just fine.
782 * But in case a translator decides to throw in a #ifexist or internal link or
783 * whatever, this function is guarded to catch attempted DB access and to present
784 * some fallback text.
786 * @param $text String
787 * @param $lineStart Boolean
790 function parse( $text, $lineStart = false ) {
793 $out = $wgParser->parse( $text, $this->parserTitle
, $this->parserOptions
, $lineStart );
794 $html = $out->getText();
795 } catch ( DBAccessError
$e ) {
796 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
797 if ( !empty( $this->debug
) ) {
798 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
805 * Register tag hook below
807 function registerDocLink( &$parser ) {
808 $parser->setHook( 'doclink', array( $this, 'docLink' ) );
813 * Extension tag hook for a documentation link
815 function docLink( $linkText, $attribs, $parser ) {
816 $url = $this->getDocUrl( $attribs['href'] );
817 return '<a href="' . htmlspecialchars( $url ) . '">' .
818 htmlspecialchars( $linkText ) .
823 * Overridden by WebInstaller to provide lastPage parameters
825 protected function getDocUrl( $page ) {
826 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $attribs['href'] );
829 public function findExtensions() {
830 if( $this->getVar( 'IP' ) === null ) {
834 $dir = $this->getVar( 'IP' ) . '/extensions';
835 $dh = opendir( $dir );
836 while ( ( $file = readdir( $dh ) ) !== false ) {
837 if( file_exists( "$dir/$file/$file.php" ) ) {
841 $this->setVar( '_Extensions', $exts );
845 public function getInstallSteps() {
846 if( $this->getVar( '_UpgradeDone' ) ) {
847 $this->installSteps
= array( 'localsettings' );
849 if( count( $this->getVar( '_Extensions' ) ) ) {
850 array_unshift( $this->installSteps
, 'extensions' );
852 return $this->installSteps
;
855 public function installExtensions() {
856 global $wgHooks, $wgAutoloadClasses;
857 $exts = $this->getVar( '_Extensions' );
858 $path = $this->getVar( 'IP' ) . '/extensions';
859 foreach( $exts as $e ) {
860 require( "$path/$e/$e.php" );
862 return Status
::newGood();
865 public function installDatabase() {
866 $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
867 $status = $installer->setupDatabase();
871 public function installUser() {
872 $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
873 $status = $installer->setupUser();
877 public function installTables() {
878 $installer = $this->getDBInstaller();
879 $status = $installer->createTables();
880 if( $status->isOK() ) {
881 LBFactory
::enableBackend();
886 public function installInterwiki() {
887 $installer = $this->getDBInstaller();
888 return $installer->populateInterwikiTable();
891 public function installSecretKey() {
892 if ( wfIsWindows() ) {
895 wfSuppressWarnings();
896 $file = fopen( "/dev/urandom", "r" );
900 $status = Status
::newGood();
903 $secretKey = bin2hex( fread( $file, 32 ) );
907 for ( $i=0; $i<8; $i++
) {
908 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
910 $status->warning( 'config-insecure-secretkey' );
912 $this->setVar( 'wgSecretKey', $secretKey );
917 public function installSysop() {
918 $name = $this->getVar( '_AdminName' );
919 $user = User
::newFromName( $name );
921 // we should've validated this earlier anyway!
922 return Status
::newFatal( 'config-admin-error-user', $name );
924 if ( $user->idForName() == 0 ) {
925 $user->addToDatabase();
927 $user->setPassword( $this->getVar( '_AdminPassword' ) );
928 } catch( PasswordError
$pwe ) {
929 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
931 $user->addGroup( 'sysop' );
932 $user->addGroup( 'bureaucrat' );
933 $user->saveSettings();
935 return Status
::newGood();
938 public function installLocalsettings() {
939 $localSettings = new LocalSettingsGenerator( $this );
940 return $localSettings->writeLocalSettings();
944 * Determine if LocalSettings exists. If it does, return an appropriate
945 * status for whether we should can upgrade or not
948 function getLocalSettingsStatus() {
951 $status = Status
::newGood();
953 wfSuppressWarnings();
954 $ls = file_exists( "$IP/LocalSettings.php" );
958 if( $this->getDBInstaller()->needsUpgrade() ) {
959 $status->warning( 'config-localsettings-upgrade' );
962 $status->fatal( 'config-localsettings-noupgrade' );
969 * On POSIX systems return the primary group of the webserver we're running under.
970 * On other systems just returns null.
972 * This is used to advice the user that he should chgrp his config/data/images directory as the
973 * webserver user before he can install.
975 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
979 public static function maybeGetWebserverPrimaryGroup() {
980 if ( ! function_exists('posix_getegid') ||
! function_exists('posix_getpwuid') ) {
981 # I don't know this, this isn't UNIX
985 # posix_getegid() *not* getmygid() because we want the group of the webserver,
986 # not whoever owns the current script
987 $gid = posix_getegid();
988 $getpwuid = posix_getpwuid( $gid );
989 $group = $getpwuid["name"];
995 * Override the necessary bits of the config to run an installation
997 public static function overrideConfig() {
998 define( 'MW_NO_SESSION', 1 );
1000 // Don't access the database
1001 $GLOBALS['wgUseDatabaseMessages'] = false;
1003 $GLOBALS['wgShowExceptionDetails'] = true;
1004 // Don't break forms
1005 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1007 // Extended debugging. Maybe disable before release?
1008 $GLOBALS['wgShowSQLErrors'] = true;
1009 $GLOBALS['wgShowDBErrorBacktrace'] = true;