3 * Base code for MediaWiki installer.
10 * This documentation group collects source code files with deployment functionality.
12 * @defgroup Deployment Deployment
16 * Base installer class.
18 * This class provides the base for installation and update functionality
19 * for both MediaWiki core and extensions.
24 abstract class Installer
{
26 // This is the absolute minimum PHP version we can support
27 const MINIMUM_PHP_VERSION
= '5.2.3';
35 * Cached DB installer instances, access using getDBInstaller().
39 protected $dbInstallers = array();
42 * Minimum memory size in MB.
46 protected $minMemorySize = 50;
49 * Cached Title, used by parse().
53 protected $parserTitle;
56 * Cached ParserOptions, used by parse().
60 protected $parserOptions;
63 * Known database types. These correspond to the class names <type>Installer,
64 * and are also MediaWiki database types valid for $wgDBtype.
66 * To add a new type, create a <type>Installer class and a Database<type>
67 * class, and add a config-type-<type> message to MessagesEn.php.
71 protected static $dbTypes = array(
80 * A list of environment check methods called by doEnvironmentChecks().
81 * These may output warnings using showMessage(), and/or abort the
82 * installation process by returning false.
86 protected $envChecks = array(
88 'envCheckRegisterGlobals',
91 'envCheckMagicQuotes',
92 'envCheckMagicSybase',
104 'envCheckShellLocale',
105 'envCheckUploadsDirectory',
107 'envCheckSuhosinMaxValueLength',
111 * MediaWiki configuration globals that will eventually be passed through
112 * to LocalSettings.php. The names only are given here, the defaults
113 * typically come from DefaultSettings.php.
117 protected $defaultVarNames = array(
129 'wgEmailAuthentication',
132 'wgImageMagickConvertCommand',
137 'wgDeletedDirectory',
142 'wgUseInstantCommons',
145 'wgResourceLoaderMaxQueryLength',
149 * Variables that are stored alongside globals, and are used for any
150 * configuration of the installation process aside from the MediaWiki
151 * configuration. Map of names to defaults.
155 protected $internalDefaults = array(
157 '_Environment' => false,
158 '_CompiledDBs' => array(),
159 '_SafeMode' => false,
160 '_RaiseMemory' => false,
161 '_UpgradeDone' => false,
162 '_InstallDone' => false,
163 '_Caches' => array(),
164 '_InstallPassword' => '',
165 '_SameAccount' => true,
166 '_CreateDBAccount' => false,
167 '_NamespaceType' => 'site-name',
168 '_AdminName' => '', // will be set later, when the user selects language
169 '_AdminPassword' => '',
170 '_AdminPassword2' => '',
172 '_Subscribe' => false,
173 '_SkipOptional' => 'continue',
174 '_RightsProfile' => 'wiki',
175 '_LicenseCode' => 'none',
177 '_Extensions' => array(),
178 '_MemCachedServers' => '',
179 '_UpgradeKeySupplied' => false,
180 '_ExistingDBSettings' => false,
184 * The actual list of installation steps. This will be initialized by getInstallSteps()
188 private $installSteps = array();
191 * Extra steps for installation, for things like DatabaseInstallers to modify
195 protected $extraInstallSteps = array();
198 * Known object cache types and the functions used to test for their existence.
202 protected $objectCaches = array(
203 'xcache' => 'xcache_get',
204 'apc' => 'apc_fetch',
205 'eaccel' => 'eaccelerator_get',
206 'wincache' => 'wincache_ucache_get'
210 * User rights profiles.
214 public $rightsProfiles = array(
217 '*' => array( 'edit' => false )
221 'createaccount' => false,
227 'createaccount' => false,
239 public $licenses = array(
241 'url' => 'http://creativecommons.org/licenses/by/3.0/',
242 'icon' => '{$wgStylePath}/common/images/cc-by.png',
245 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
246 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
248 'cc-by-nc-sa' => array(
249 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
250 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
253 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
254 'icon' => '{$wgStylePath}/common/images/cc-0.png',
258 'icon' => '{$wgStylePath}/common/images/public-domain.png',
261 'url' => 'http://www.gnu.org/copyleft/fdl.html',
262 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
269 'cc-choose' => array(
270 // Details will be filled in by the selector.
278 * URL to mediawiki-announce subscription
280 protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
283 * Supported language codes for Mailman
285 protected $mediaWikiAnnounceLanguages = array(
286 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
287 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
288 'sl', 'sr', 'sv', 'tr', 'uk'
292 * UI interface for displaying a short message
293 * The parameters are like parameters to wfMsg().
294 * The messages will be in wikitext format, which will be converted to an
295 * output format such as HTML or text before being sent to the user.
297 public abstract function showMessage( $msg /*, ... */ );
300 * Same as showMessage(), but for displaying errors
302 public abstract function showError( $msg /*, ... */ );
305 * Show a message to the installing user by using a Status object
306 * @param $status Status
308 public abstract function showStatusMessage( Status
$status );
311 * Constructor, always call this from child classes.
313 public function __construct() {
314 global $wgExtensionMessagesFiles, $wgUser;
316 // Disable the i18n cache and LoadBalancer
317 Language
::getLocalisationCache()->disableBackend();
318 LBFactory
::disableBackend();
320 // Load the installer's i18n file.
321 $wgExtensionMessagesFiles['MediawikiInstaller'] =
322 dirname( __FILE__
) . '/Installer.i18n.php';
324 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
325 $wgUser = User
::newFromId( 0 );
327 $this->settings
= $this->internalDefaults
;
329 foreach ( $this->defaultVarNames
as $var ) {
330 $this->settings
[$var] = $GLOBALS[$var];
333 foreach ( self
::getDBTypes() as $type ) {
334 $installer = $this->getDBInstaller( $type );
336 if ( !$installer->isCompiled() ) {
340 $defaults = $installer->getGlobalDefaults();
342 foreach ( $installer->getGlobalNames() as $var ) {
343 if ( isset( $defaults[$var] ) ) {
344 $this->settings
[$var] = $defaults[$var];
346 $this->settings
[$var] = $GLOBALS[$var];
351 $this->parserTitle
= Title
::newFromText( 'Installer' );
352 $this->parserOptions
= new ParserOptions
; // language will be wrong :(
353 $this->parserOptions
->setEditSection( false );
357 * Get a list of known DB types.
361 public static function getDBTypes() {
362 return self
::$dbTypes;
366 * Do initial checks of the PHP environment. Set variables according to
367 * the observed environment.
369 * It's possible that this may be called under the CLI SAPI, not the SAPI
370 * that the wiki will primarily run under. In that case, the subclass should
371 * initialise variables such as wgScriptPath, before calling this function.
373 * Under the web subclass, it can already be assumed that PHP 5+ is in use
374 * and that sessions are working.
378 public function doEnvironmentChecks() {
379 $phpVersion = phpversion();
380 if( version_compare( $phpVersion, self
::MINIMUM_PHP_VERSION
, '>=' ) ) {
381 $this->showMessage( 'config-env-php', $phpVersion );
384 $this->showMessage( 'config-env-php-toolow', $phpVersion, self
::MINIMUM_PHP_VERSION
);
389 foreach ( $this->envChecks
as $check ) {
390 $status = $this->$check();
391 if ( $status === false ) {
397 $this->setVar( '_Environment', $good );
399 return $good ? Status
::newGood() : Status
::newFatal( 'config-env-bad' );
403 * Set a MW configuration variable, or internal installer configuration variable.
405 * @param $name String
406 * @param $value Mixed
408 public function setVar( $name, $value ) {
409 $this->settings
[$name] = $value;
413 * Get an MW configuration variable, or internal installer configuration variable.
414 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
415 * Installer variables are typically prefixed by an underscore.
417 * @param $name String
418 * @param $default Mixed
422 public function getVar( $name, $default = null ) {
423 if ( !isset( $this->settings
[$name] ) ) {
426 return $this->settings
[$name];
431 * Get an instance of DatabaseInstaller for the specified DB type.
433 * @param $type Mixed: DB installer for which is needed, false to use default.
435 * @return DatabaseInstaller
437 public function getDBInstaller( $type = false ) {
439 $type = $this->getVar( 'wgDBtype' );
442 $type = strtolower( $type );
444 if ( !isset( $this->dbInstallers
[$type] ) ) {
445 $class = ucfirst( $type ). 'Installer';
446 $this->dbInstallers
[$type] = new $class( $this );
449 return $this->dbInstallers
[$type];
453 * Determine if LocalSettings.php exists. If it does, return its variables,
454 * merged with those from AdminSettings.php, as an array.
458 public static function getExistingLocalSettings() {
461 wfSuppressWarnings();
462 $_lsExists = file_exists( "$IP/LocalSettings.php" );
470 require( "$IP/includes/DefaultSettings.php" );
471 require( "$IP/LocalSettings.php" );
472 if ( file_exists( "$IP/AdminSettings.php" ) ) {
473 require( "$IP/AdminSettings.php" );
475 return get_defined_vars();
479 * Get a fake password for sending back to the user in HTML.
480 * This is a security mechanism to avoid compromise of the password in the
481 * event of session ID compromise.
483 * @param $realPassword String
487 public function getFakePassword( $realPassword ) {
488 return str_repeat( '*', strlen( $realPassword ) );
492 * Set a variable which stores a password, except if the new value is a
493 * fake password in which case leave it as it is.
495 * @param $name String
496 * @param $value Mixed
498 public function setPassword( $name, $value ) {
499 if ( !preg_match( '/^\*+$/', $value ) ) {
500 $this->setVar( $name, $value );
505 * On POSIX systems return the primary group of the webserver we're running under.
506 * On other systems just returns null.
508 * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
509 * webserver user before he can install.
511 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
515 public static function maybeGetWebserverPrimaryGroup() {
516 if ( !function_exists( 'posix_getegid' ) ||
!function_exists( 'posix_getpwuid' ) ) {
517 # I don't know this, this isn't UNIX.
521 # posix_getegid() *not* getmygid() because we want the group of the webserver,
522 # not whoever owns the current script.
523 $gid = posix_getegid();
524 $getpwuid = posix_getpwuid( $gid );
525 $group = $getpwuid['name'];
531 * Convert wikitext $text to HTML.
533 * This is potentially error prone since many parser features require a complete
534 * installed MW database. The solution is to just not use those features when you
535 * write your messages. This appears to work well enough. Basic formatting and
536 * external links work just fine.
538 * But in case a translator decides to throw in a #ifexist or internal link or
539 * whatever, this function is guarded to catch the attempted DB access and to present
540 * some fallback text.
542 * @param $text String
543 * @param $lineStart Boolean
546 public function parse( $text, $lineStart = false ) {
550 $out = $wgParser->parse( $text, $this->parserTitle
, $this->parserOptions
, $lineStart );
551 $html = $out->getText();
552 } catch ( DBAccessError
$e ) {
553 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
555 if ( !empty( $this->debug
) ) {
556 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
564 * @return ParserOptions
566 public function getParserOptions() {
567 return $this->parserOptions
;
570 public function disableLinkPopups() {
571 $this->parserOptions
->setExternalLinkTarget( false );
574 public function restoreLinkPopups() {
575 global $wgExternalLinkTarget;
576 $this->parserOptions
->setExternalLinkTarget( $wgExternalLinkTarget );
580 * Install step which adds a row to the site_stats table with appropriate
583 * @param $installer DatabaseInstaller
587 public function populateSiteStats( DatabaseInstaller
$installer ) {
588 $status = $installer->getConnection();
589 if ( !$status->isOK() ) {
592 $status->value
->insert( 'site_stats', array(
594 'ss_total_views' => 0,
595 'ss_total_edits' => 0,
596 'ss_good_articles' => 0,
597 'ss_total_pages' => 0,
601 __METHOD__
, 'IGNORE' );
602 return Status
::newGood();
606 * Exports all wg* variables stored by the installer into global scope.
608 public function exportVars() {
609 foreach ( $this->settings
as $name => $value ) {
610 if ( substr( $name, 0, 2 ) == 'wg' ) {
611 $GLOBALS[$name] = $value;
617 * Environment check for DB types.
619 protected function envCheckDB() {
622 $compiledDBs = array();
625 foreach ( self
::getDBTypes() as $name ) {
626 if ( $this->getDBInstaller( $name )->isCompiled() ) {
627 $compiledDBs[] = $name;
629 $allNames[] = wfMsg( 'config-type-' . $name );
632 $this->setVar( '_CompiledDBs', $compiledDBs );
634 if ( !$compiledDBs ) {
635 $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
636 // @todo FIXME: This only works for the web installer!
640 // Check for FTS3 full-text search module
641 $sqlite = $this->getDBInstaller( 'sqlite' );
642 if ( $sqlite->isCompiled() ) {
643 if( DatabaseSqlite
::getFulltextSearchModule() != 'FTS3' ) {
644 $this->showMessage( 'config-no-fts3' );
650 * Environment check for register_globals.
652 protected function envCheckRegisterGlobals() {
653 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
654 $this->showMessage( 'config-register-globals' );
659 * Some versions of libxml+PHP break < and > encoding horribly
661 protected function envCheckBrokenXML() {
662 $test = new PhpXmlBugTester();
664 $this->showError( 'config-brokenlibxml' );
670 * Test PHP (probably 5.3.1, but it could regress again) to make sure that
671 * reference parameters to __call() are not converted to null
673 protected function envCheckPHP531() {
674 $test = new PhpRefCallBugTester
;
677 $this->showError( 'config-using531', phpversion() );
683 * Environment check for magic_quotes_runtime.
685 protected function envCheckMagicQuotes() {
686 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
687 $this->showError( 'config-magic-quotes-runtime' );
693 * Environment check for magic_quotes_sybase.
695 protected function envCheckMagicSybase() {
696 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
697 $this->showError( 'config-magic-quotes-sybase' );
703 * Environment check for mbstring.func_overload.
705 protected function envCheckMbstring() {
706 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
707 $this->showError( 'config-mbstring' );
713 * Environment check for zend.ze1_compatibility_mode.
715 protected function envCheckZE1() {
716 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
717 $this->showError( 'config-ze1' );
723 * Environment check for safe_mode.
725 protected function envCheckSafeMode() {
726 if ( wfIniGetBool( 'safe_mode' ) ) {
727 $this->setVar( '_SafeMode', true );
728 $this->showMessage( 'config-safe-mode' );
733 * Environment check for the XML module.
735 protected function envCheckXML() {
736 if ( !function_exists( "utf8_encode" ) ) {
737 $this->showError( 'config-xml-bad' );
743 * Environment check for the PCRE module.
745 protected function envCheckPCRE() {
746 if ( !function_exists( 'preg_match' ) ) {
747 $this->showError( 'config-pcre' );
750 wfSuppressWarnings();
751 $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
753 if ( $regexd != '--' ) {
754 $this->showError( 'config-pcre-no-utf8' );
760 * Environment check for available memory.
762 protected function envCheckMemory() {
763 $limit = ini_get( 'memory_limit' );
765 if ( !$limit ||
$limit == -1 ) {
769 $n = wfShorthandToInteger( $limit );
771 if( $n < $this->minMemorySize
* 1024 * 1024 ) {
772 $newLimit = "{$this->minMemorySize}M";
774 if( ini_set( "memory_limit", $newLimit ) === false ) {
775 $this->showMessage( 'config-memory-bad', $limit );
777 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
778 $this->setVar( '_RaiseMemory', true );
786 * Environment check for compiled object cache types.
788 protected function envCheckCache() {
790 foreach ( $this->objectCaches
as $name => $function ) {
791 if ( function_exists( $function ) ) {
792 $caches[$name] = true;
797 $this->showMessage( 'config-no-cache' );
800 $this->setVar( '_Caches', $caches );
804 * Search for GNU diff3.
806 protected function envCheckDiff3() {
807 $names = array( "gdiff3", "diff3", "diff3.exe" );
808 $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
810 $diff3 = self
::locateExecutableInDefaultPaths( $names, $versionInfo );
813 $this->setVar( 'wgDiff3', $diff3 );
815 $this->setVar( 'wgDiff3', false );
816 $this->showMessage( 'config-diff3-bad' );
821 * Environment check for ImageMagick and GD.
823 protected function envCheckGraphics() {
824 $names = array( wfIsWindows() ?
'convert.exe' : 'convert' );
825 $convert = self
::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
827 $this->setVar( 'wgImageMagickConvertCommand', '' );
829 $this->setVar( 'wgImageMagickConvertCommand', $convert );
830 $this->showMessage( 'config-imagemagick', $convert );
832 } elseif ( function_exists( 'imagejpeg' ) ) {
833 $this->showMessage( 'config-gd' );
836 $this->showMessage( 'config-no-scaling' );
841 * Environment check for setting $IP and $wgScriptPath.
843 protected function envCheckPath() {
845 $IP = dirname( dirname( dirname( __FILE__
) ) );
847 $this->setVar( 'IP', $IP );
849 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
850 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
851 // to get the path to the current script... hopefully it's reliable. SIGH
852 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
853 $path = $_SERVER['PHP_SELF'];
854 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
855 $path = $_SERVER['SCRIPT_NAME'];
856 } elseif ( $this->getVar( 'wgScriptPath' ) ) {
857 // Some kind soul has set it for us already (e.g. debconf)
860 $this->showError( 'config-no-uri' );
864 $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
865 $this->setVar( 'wgScriptPath', $uri );
869 * Environment check for setting the preferred PHP file extension.
871 protected function envCheckExtension() {
872 // @todo FIXME: Detect this properly
873 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
878 $this->setVar( 'wgScriptExtension', ".$ext" );
884 protected function envCheckShellLocale() {
885 $os = php_uname( 's' );
886 $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
888 if ( !in_array( $os, $supported ) ) {
892 # Get a list of available locales.
894 $lines = wfShellExec( '/usr/bin/locale -a', $ret );
900 $lines = wfArrayMap( 'trim', explode( "\n", $lines ) );
901 $candidatesByLocale = array();
902 $candidatesByLang = array();
904 foreach ( $lines as $line ) {
905 if ( $line === '' ) {
909 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
913 list( $all, $lang, $territory, $charset, $modifier ) = $m;
915 $candidatesByLocale[$m[0]] = $m;
916 $candidatesByLang[$lang][] = $m;
919 # Try the current value of LANG.
920 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
921 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
925 # Try the most common ones.
926 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
927 foreach ( $commonLocales as $commonLocale ) {
928 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
929 $this->setVar( 'wgShellLocale', $commonLocale );
934 # Is there an available locale in the Wiki's language?
935 $wikiLang = $this->getVar( 'wgLanguageCode' );
937 if ( isset( $candidatesByLang[$wikiLang] ) ) {
938 $m = reset( $candidatesByLang[$wikiLang] );
939 $this->setVar( 'wgShellLocale', $m[0] );
943 # Are there any at all?
944 if ( count( $candidatesByLocale ) ) {
945 $m = reset( $candidatesByLocale );
946 $this->setVar( 'wgShellLocale', $m[0] );
957 protected function envCheckUploadsDirectory() {
958 global $IP, $wgServer;
960 $dir = $IP . '/images/';
961 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
962 $safe = !$this->dirIsExecutable( $dir, $url );
967 $this->showMessage( 'config-uploads-not-safe', $dir );
972 * Checks if suhosin.get.max_value_length is set, and if so, sets
973 * $wgResourceLoaderMaxQueryLength to that value in the generated
976 protected function envCheckSuhosinMaxValueLength() {
977 $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
978 if ( $maxValueLength > 0 ) {
979 $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
981 $maxValueLength = -1;
983 $this->setVar( 'wgResourceLoaderMaxQueryLength', $maxValueLength );
987 * Convert a hex string representing a Unicode code point to that code point.
991 protected function unicodeChar( $c ) {
995 } else if ($c <= 0x7FF) {
996 return chr(0xC0 |
$c >> 6) . chr(0x80 |
$c & 0x3F);
997 } else if ($c <= 0xFFFF) {
998 return chr(0xE0 |
$c >> 12) . chr(0x80 |
$c >> 6 & 0x3F)
999 . chr(0x80 |
$c & 0x3F);
1000 } else if ($c <= 0x10FFFF) {
1001 return chr(0xF0 |
$c >> 18) . chr(0x80 |
$c >> 12 & 0x3F)
1002 . chr(0x80 |
$c >> 6 & 0x3F)
1003 . chr(0x80 |
$c & 0x3F);
1011 * Check the libicu version
1013 protected function envCheckLibicu() {
1014 $utf8 = function_exists( 'utf8_normalize' );
1015 $intl = function_exists( 'normalizer_normalize' );
1018 * This needs to be updated something that the latest libicu
1019 * will properly normalize. This normalization was found at
1020 * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
1021 * Note that we use the hex representation to create the code
1022 * points in order to avoid any Unicode-destroying during transit.
1024 $not_normal_c = $this->unicodeChar("FA6C");
1025 $normal_c = $this->unicodeChar("242EE");
1027 $useNormalizer = 'php';
1028 $needsUpdate = false;
1031 * We're going to prefer the pecl extension here unless
1032 * utf8_normalize is more up to date.
1035 $useNormalizer = 'utf8';
1036 $utf8 = utf8_normalize( $not_normal_c, UNORM_NFC
);
1037 if ( $utf8 !== $normal_c ) $needsUpdate = true;
1040 $useNormalizer = 'intl';
1041 $intl = normalizer_normalize( $not_normal_c, Normalizer
::FORM_C
);
1042 if ( $intl !== $normal_c ) $needsUpdate = true;
1045 // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
1046 if( $useNormalizer === 'php' ) {
1047 $this->showMessage( 'config-unicode-pure-php-warning' );
1049 $this->showMessage( 'config-unicode-using-' . $useNormalizer );
1050 if( $needsUpdate ) {
1051 $this->showMessage( 'config-unicode-update-warning' );
1057 * Get an array of likely places we can find executables. Check a bunch
1058 * of known Unix-like defaults, as well as the PATH environment variable
1059 * (which should maybe make it work for Windows?)
1063 protected static function getPossibleBinPaths() {
1065 array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
1066 '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
1067 explode( PATH_SEPARATOR
, getenv( 'PATH' ) )
1072 * Search a path for any of the given executable names. Returns the
1073 * executable name if found. Also checks the version string returned
1074 * by each executable.
1076 * Used only by environment checks.
1078 * @param $path String: path to search
1079 * @param $names Array of executable names
1080 * @param $versionInfo Boolean false or array with two members:
1081 * 0 => Command to run for version check, with $1 for the full executable name
1082 * 1 => String to compare the output with
1084 * If $versionInfo is not false, only executables with a version
1085 * matching $versionInfo[1] will be returned.
1087 public static function locateExecutable( $path, $names, $versionInfo = false ) {
1088 if ( !is_array( $names ) ) {
1089 $names = array( $names );
1092 foreach ( $names as $name ) {
1093 $command = $path . DIRECTORY_SEPARATOR
. $name;
1095 wfSuppressWarnings();
1096 $file_exists = file_exists( $command );
1097 wfRestoreWarnings();
1099 if ( $file_exists ) {
1100 if ( !$versionInfo ) {
1104 $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
1105 if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
1114 * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
1115 * @see locateExecutable()
1117 public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
1118 foreach( self
::getPossibleBinPaths() as $path ) {
1119 $exe = self
::locateExecutable( $path, $names, $versionInfo );
1120 if( $exe !== false ) {
1128 * Checks if scripts located in the given directory can be executed via the given URL.
1130 * Used only by environment checks.
1132 public function dirIsExecutable( $dir, $url ) {
1133 $scriptTypes = array(
1135 "<?php echo 'ex' . 'ec';",
1136 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
1140 // it would be good to check other popular languages here, but it'll be slow.
1142 wfSuppressWarnings();
1144 foreach ( $scriptTypes as $ext => $contents ) {
1145 foreach ( $contents as $source ) {
1146 $file = 'exectest.' . $ext;
1148 if ( !file_put_contents( $dir . $file, $source ) ) {
1153 $text = Http
::get( $url . $file, array( 'timeout' => 3 ) );
1155 catch( MWException
$e ) {
1156 // Http::get throws with allow_url_fopen = false and no curl extension.
1159 unlink( $dir . $file );
1161 if ( $text == 'exec' ) {
1162 wfRestoreWarnings();
1168 wfRestoreWarnings();
1174 * ParserOptions are constructed before we determined the language, so fix it
1176 * @param $lang Language
1178 public function setParserLanguage( $lang ) {
1179 $this->parserOptions
->setTargetLanguage( $lang );
1180 $this->parserOptions
->setUserLang( $lang->getCode() );
1184 * Overridden by WebInstaller to provide lastPage parameters.
1186 protected function getDocUrl( $page ) {
1187 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1191 * Finds extensions that follow the format /extensions/Name/Name.php,
1192 * and returns an array containing the value for 'Name' for each found extension.
1196 public function findExtensions() {
1197 if( $this->getVar( 'IP' ) === null ) {
1202 $extDir = $this->getVar( 'IP' ) . '/extensions';
1203 $dh = opendir( $extDir );
1205 while ( ( $file = readdir( $dh ) ) !== false ) {
1206 if( !is_dir( "$extDir/$file" ) ) {
1209 if( file_exists( "$extDir/$file/$file.php" ) ) {
1218 * Installs the auto-detected extensions.
1222 protected function includeExtensions() {
1224 $exts = $this->getVar( '_Extensions' );
1225 $IP = $this->getVar( 'IP' );
1228 * We need to include DefaultSettings before including extensions to avoid
1229 * warnings about unset variables. However, the only thing we really
1230 * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
1231 * if the extension has hidden hook registration in $wgExtensionFunctions,
1232 * but we're not opening that can of worms
1233 * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
1235 global $wgAutoloadClasses;
1236 $wgAutoloadClasses = array();
1238 require( "$IP/includes/DefaultSettings.php" );
1240 foreach( $exts as $e ) {
1241 require_once( "$IP/extensions/$e/$e.php" );
1244 $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
1245 $wgHooks['LoadExtensionSchemaUpdates'] : array();
1247 // Unset everyone else's hooks. Lord knows what someone might be doing
1248 // in ParserFirstCallInit (see bug 27171)
1249 $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
1251 return Status
::newGood();
1255 * Get an array of install steps. Should always be in the format of
1257 * 'name' => 'someuniquename',
1258 * 'callback' => array( $obj, 'method' ),
1260 * There must be a config-install-$name message defined per step, which will
1261 * be shown on install.
1263 * @param $installer DatabaseInstaller so we can make callbacks
1266 protected function getInstallSteps( DatabaseInstaller
$installer ) {
1267 $coreInstallSteps = array(
1268 array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
1269 array( 'name' => 'tables', 'callback' => array( $installer, 'createTables' ) ),
1270 array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
1271 array( 'name' => 'stats', 'callback' => array( $this, 'populateSiteStats' ) ),
1272 array( 'name' => 'keys', 'callback' => array( $this, 'generateKeys' ) ),
1273 array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
1274 array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
1277 // Build the array of install steps starting from the core install list,
1278 // then adding any callbacks that wanted to attach after a given step
1279 foreach( $coreInstallSteps as $step ) {
1280 $this->installSteps
[] = $step;
1281 if( isset( $this->extraInstallSteps
[ $step['name'] ] ) ) {
1282 $this->installSteps
= array_merge(
1283 $this->installSteps
,
1284 $this->extraInstallSteps
[ $step['name'] ]
1289 // Prepend any steps that want to be at the beginning
1290 if( isset( $this->extraInstallSteps
['BEGINNING'] ) ) {
1291 $this->installSteps
= array_merge(
1292 $this->extraInstallSteps
['BEGINNING'],
1297 // Extensions should always go first, chance to tie into hooks and such
1298 if( count( $this->getVar( '_Extensions' ) ) ) {
1299 array_unshift( $this->installSteps
,
1300 array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
1302 $this->installSteps
[] = array(
1303 'name' => 'extension-tables',
1304 'callback' => array( $installer, 'createExtensionTables' )
1307 return $this->installSteps
;
1311 * Actually perform the installation.
1313 * @param $startCB Array A callback array for the beginning of each step
1314 * @param $endCB Array A callback array for the end of each step
1316 * @return Array of Status objects
1318 public function performInstallation( $startCB, $endCB ) {
1319 $installResults = array();
1320 $installer = $this->getDBInstaller();
1321 $installer->preInstall();
1322 $steps = $this->getInstallSteps( $installer );
1323 foreach( $steps as $stepObj ) {
1324 $name = $stepObj['name'];
1325 call_user_func_array( $startCB, array( $name ) );
1327 // Perform the callback step
1328 $status = call_user_func( $stepObj['callback'], $installer );
1330 // Output and save the results
1331 call_user_func( $endCB, $name, $status );
1332 $installResults[$name] = $status;
1334 // If we've hit some sort of fatal, we need to bail.
1335 // Callback already had a chance to do output above.
1336 if( !$status->isOk() ) {
1340 if( $status->isOk() ) {
1341 $this->setVar( '_InstallDone', true );
1343 return $installResults;
1347 * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
1352 public function generateKeys() {
1353 $keys = array( 'wgSecretKey' => 64 );
1354 if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
1355 $keys['wgUpgradeKey'] = 16;
1357 return $this->doGenerateKeys( $keys );
1361 * Generate a secret value for variables using either
1362 * /dev/urandom or mt_rand(). Produce a warning in the later case.
1364 * @param $keys Array
1367 protected function doGenerateKeys( $keys ) {
1368 $status = Status
::newGood();
1370 wfSuppressWarnings();
1371 $file = fopen( "/dev/urandom", "r" );
1372 wfRestoreWarnings();
1374 foreach ( $keys as $name => $length ) {
1376 $secretKey = bin2hex( fread( $file, $length / 2 ) );
1380 for ( $i = 0; $i < $length / 8; $i++
) {
1381 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
1385 $this->setVar( $name, $secretKey );
1391 $names = array_keys ( $keys );
1392 $names = preg_replace( '/^(.*)$/', '\$$1', $names );
1394 $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
1401 * Create the first user account, grant it sysop and bureaucrat rights
1405 protected function createSysop() {
1406 $name = $this->getVar( '_AdminName' );
1407 $user = User
::newFromName( $name );
1410 // We should've validated this earlier anyway!
1411 return Status
::newFatal( 'config-admin-error-user', $name );
1414 if ( $user->idForName() == 0 ) {
1415 $user->addToDatabase();
1418 $user->setPassword( $this->getVar( '_AdminPassword' ) );
1419 } catch( PasswordError
$pwe ) {
1420 return Status
::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
1423 $user->addGroup( 'sysop' );
1424 $user->addGroup( 'bureaucrat' );
1425 if( $this->getVar( '_AdminEmail' ) ) {
1426 $user->setEmail( $this->getVar( '_AdminEmail' ) );
1428 $user->saveSettings();
1430 // Update user count
1431 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
1432 $ssUpdate->doUpdate();
1434 $status = Status
::newGood();
1436 if( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
1437 $this->subscribeToMediaWikiAnnounce( $status );
1443 private function subscribeToMediaWikiAnnounce( Status
$s ) {
1445 'email' => $this->getVar( '_AdminEmail' ),
1450 // Mailman doesn't support as many languages as we do, so check to make
1451 // sure their selected language is available
1452 $myLang = $this->getVar( '_UserLang' );
1453 if( in_array( $myLang, $this->mediaWikiAnnounceLanguages
) ) {
1454 $myLang = $myLang == 'pt-br' ?
'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
1455 $params['language'] = $myLang;
1458 $res = MWHttpRequest
::factory( $this->mediaWikiAnnounceUrl
,
1459 array( 'method' => 'POST', 'postData' => $params ) )->execute();
1460 if( !$res->isOK() ) {
1461 $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
1466 * Insert Main Page with default content.
1470 protected function createMainpage( DatabaseInstaller
$installer ) {
1471 $status = Status
::newGood();
1473 $article = new Article( Title
::newMainPage() );
1474 $article->doEdit( wfMsgForContent( 'mainpagetext' ) . "\n\n" .
1475 wfMsgForContent( 'mainpagedocfooter' ),
1479 User
::newFromName( 'MediaWiki default' ) );
1480 } catch (MWException
$e) {
1481 //using raw, because $wgShowExceptionDetails can not be set yet
1482 $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
1489 * Override the necessary bits of the config to run an installation.
1491 public static function overrideConfig() {
1492 define( 'MW_NO_SESSION', 1 );
1494 // Don't access the database
1495 $GLOBALS['wgUseDatabaseMessages'] = false;
1497 $GLOBALS['wgShowExceptionDetails'] = true;
1498 // Don't break forms
1499 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1501 // Extended debugging
1502 $GLOBALS['wgShowSQLErrors'] = true;
1503 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1505 // Allow multiple ob_flush() calls
1506 $GLOBALS['wgDisableOutputCompression'] = true;
1508 // Use a sensible cookie prefix (not my_wiki)
1509 $GLOBALS['wgCookiePrefix'] = 'mw_installer';
1511 // Some of the environment checks make shell requests, remove limits
1512 $GLOBALS['wgMaxShellMemory'] = 0;
1516 * Add an installation step following the given step.
1518 * @param $callback Array A valid installation callback array, in this form:
1519 * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
1520 * @param $findStep String the step to find. Omit to put the step at the beginning
1522 public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
1523 $this->extraInstallSteps
[$findStep][] = $callback;