Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / installer / Installer.php
blobd887a13a163d55fc5b3e468caeb0d85d81c8ed1b
1 <?php
2 /**
3 * Base code for MediaWiki installer.
5 * DO NOT PATCH THIS FILE IF YOU NEED TO CHANGE INSTALLER BEHAVIOR IN YOUR PACKAGE!
6 * See mw-config/overrides/README for details.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
24 * @ingroup Deployment
26 use MediaWiki\MediaWikiServices;
28 /**
29 * This documentation group collects source code files with deployment functionality.
31 * @defgroup Deployment Deployment
34 /**
35 * Base installer class.
37 * This class provides the base for installation and update functionality
38 * for both MediaWiki core and extensions.
40 * @ingroup Deployment
41 * @since 1.17
43 abstract class Installer {
45 /**
46 * The oldest version of PCRE we can support.
48 * Defining this is necessary because PHP may be linked with a system version
49 * of PCRE, which may be older than that bundled with the minimum PHP version.
51 const MINIMUM_PCRE_VERSION = '7.2';
53 /**
54 * @var array
56 protected $settings;
58 /**
59 * List of detected DBs, access using getCompiledDBs().
61 * @var array
63 protected $compiledDBs;
65 /**
66 * Cached DB installer instances, access using getDBInstaller().
68 * @var array
70 protected $dbInstallers = [];
72 /**
73 * Minimum memory size in MB.
75 * @var int
77 protected $minMemorySize = 50;
79 /**
80 * Cached Title, used by parse().
82 * @var Title
84 protected $parserTitle;
86 /**
87 * Cached ParserOptions, used by parse().
89 * @var ParserOptions
91 protected $parserOptions;
93 /**
94 * Known database types. These correspond to the class names <type>Installer,
95 * and are also MediaWiki database types valid for $wgDBtype.
97 * To add a new type, create a <type>Installer class and a Database<type>
98 * class, and add a config-type-<type> message to MessagesEn.php.
100 * @var array
102 protected static $dbTypes = [
103 'mysql',
104 'postgres',
105 'oracle',
106 'mssql',
107 'sqlite',
111 * A list of environment check methods called by doEnvironmentChecks().
112 * These may output warnings using showMessage(), and/or abort the
113 * installation process by returning false.
115 * For the WebInstaller these are only called on the Welcome page,
116 * if these methods have side-effects that should affect later page loads
117 * (as well as the generated stylesheet), use envPreps instead.
119 * @var array
121 protected $envChecks = [
122 'envCheckDB',
123 'envCheckBrokenXML',
124 'envCheckPCRE',
125 'envCheckMemory',
126 'envCheckCache',
127 'envCheckModSecurity',
128 'envCheckDiff3',
129 'envCheckGraphics',
130 'envCheckGit',
131 'envCheckServer',
132 'envCheckPath',
133 'envCheckShellLocale',
134 'envCheckUploadsDirectory',
135 'envCheckLibicu',
136 'envCheckSuhosinMaxValueLength',
140 * A list of environment preparation methods called by doEnvironmentPreps().
142 * @var array
144 protected $envPreps = [
145 'envPrepServer',
146 'envPrepPath',
150 * MediaWiki configuration globals that will eventually be passed through
151 * to LocalSettings.php. The names only are given here, the defaults
152 * typically come from DefaultSettings.php.
154 * @var array
156 protected $defaultVarNames = [
157 'wgSitename',
158 'wgPasswordSender',
159 'wgLanguageCode',
160 'wgRightsIcon',
161 'wgRightsText',
162 'wgRightsUrl',
163 'wgEnableEmail',
164 'wgEnableUserEmail',
165 'wgEnotifUserTalk',
166 'wgEnotifWatchlist',
167 'wgEmailAuthentication',
168 'wgDBname',
169 'wgDBtype',
170 'wgDiff3',
171 'wgImageMagickConvertCommand',
172 'wgGitBin',
173 'IP',
174 'wgScriptPath',
175 'wgMetaNamespace',
176 'wgDeletedDirectory',
177 'wgEnableUploads',
178 'wgShellLocale',
179 'wgSecretKey',
180 'wgUseInstantCommons',
181 'wgUpgradeKey',
182 'wgDefaultSkin',
183 'wgPingback',
187 * Variables that are stored alongside globals, and are used for any
188 * configuration of the installation process aside from the MediaWiki
189 * configuration. Map of names to defaults.
191 * @var array
193 protected $internalDefaults = [
194 '_UserLang' => 'en',
195 '_Environment' => false,
196 '_RaiseMemory' => false,
197 '_UpgradeDone' => false,
198 '_InstallDone' => false,
199 '_Caches' => [],
200 '_InstallPassword' => '',
201 '_SameAccount' => true,
202 '_CreateDBAccount' => false,
203 '_NamespaceType' => 'site-name',
204 '_AdminName' => '', // will be set later, when the user selects language
205 '_AdminPassword' => '',
206 '_AdminPasswordConfirm' => '',
207 '_AdminEmail' => '',
208 '_Subscribe' => false,
209 '_SkipOptional' => 'continue',
210 '_RightsProfile' => 'wiki',
211 '_LicenseCode' => 'none',
212 '_CCDone' => false,
213 '_Extensions' => [],
214 '_Skins' => [],
215 '_MemCachedServers' => '',
216 '_UpgradeKeySupplied' => false,
217 '_ExistingDBSettings' => false,
219 // $wgLogo is probably wrong (bug 48084); set something that will work.
220 // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped.
221 'wgLogo' => '$wgResourceBasePath/resources/assets/wiki.png',
222 'wgAuthenticationTokenVersion' => 1,
226 * The actual list of installation steps. This will be initialized by getInstallSteps()
228 * @var array
230 private $installSteps = [];
233 * Extra steps for installation, for things like DatabaseInstallers to modify
235 * @var array
237 protected $extraInstallSteps = [];
240 * Known object cache types and the functions used to test for their existence.
242 * @var array
244 protected $objectCaches = [
245 'xcache' => 'xcache_get',
246 'apc' => 'apc_fetch',
247 'apcu' => 'apcu_fetch',
248 'wincache' => 'wincache_ucache_get'
252 * User rights profiles.
254 * @var array
256 public $rightsProfiles = [
257 'wiki' => [],
258 'no-anon' => [
259 '*' => [ 'edit' => false ]
261 'fishbowl' => [
262 '*' => [
263 'createaccount' => false,
264 'edit' => false,
267 'private' => [
268 '*' => [
269 'createaccount' => false,
270 'edit' => false,
271 'read' => false,
277 * License types.
279 * @var array
281 public $licenses = [
282 'cc-by' => [
283 'url' => 'https://creativecommons.org/licenses/by/4.0/',
284 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by.png',
286 'cc-by-sa' => [
287 'url' => 'https://creativecommons.org/licenses/by-sa/4.0/',
288 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png',
290 'cc-by-nc-sa' => [
291 'url' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/',
292 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-nc-sa.png',
294 'cc-0' => [
295 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
296 'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-0.png',
298 'gfdl' => [
299 'url' => 'https://www.gnu.org/copyleft/fdl.html',
300 'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png',
302 'none' => [
303 'url' => '',
304 'icon' => '',
305 'text' => ''
307 'cc-choose' => [
308 // Details will be filled in by the selector.
309 'url' => '',
310 'icon' => '',
311 'text' => '',
316 * URL to mediawiki-announce subscription
318 protected $mediaWikiAnnounceUrl =
319 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
322 * Supported language codes for Mailman
324 protected $mediaWikiAnnounceLanguages = [
325 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
326 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
327 'sl', 'sr', 'sv', 'tr', 'uk'
331 * UI interface for displaying a short message
332 * The parameters are like parameters to wfMessage().
333 * The messages will be in wikitext format, which will be converted to an
334 * output format such as HTML or text before being sent to the user.
335 * @param string $msg
337 abstract public function showMessage( $msg /*, ... */ );
340 * Same as showMessage(), but for displaying errors
341 * @param string $msg
343 abstract public function showError( $msg /*, ... */ );
346 * Show a message to the installing user by using a Status object
347 * @param Status $status
349 abstract public function showStatusMessage( Status $status );
352 * Constructs a Config object that contains configuration settings that should be
353 * overwritten for the installation process.
355 * @since 1.27
357 * @param Config $baseConfig
359 * @return Config The config to use during installation.
361 public static function getInstallerConfig( Config $baseConfig ) {
362 $configOverrides = new HashConfig();
364 // disable (problematic) object cache types explicitly, preserving all other (working) ones
365 // bug T113843
366 $emptyCache = [ 'class' => 'EmptyBagOStuff' ];
368 $objectCaches = [
369 CACHE_NONE => $emptyCache,
370 CACHE_DB => $emptyCache,
371 CACHE_ANYTHING => $emptyCache,
372 CACHE_MEMCACHED => $emptyCache,
373 ] + $baseConfig->get( 'ObjectCaches' );
375 $configOverrides->set( 'ObjectCaches', $objectCaches );
377 // Load the installer's i18n.
378 $messageDirs = $baseConfig->get( 'MessagesDirs' );
379 $messageDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
381 $configOverrides->set( 'MessagesDirs', $messageDirs );
383 $installerConfig = new MultiConfig( [ $configOverrides, $baseConfig ] );
385 // make sure we use the installer config as the main config
386 $configRegistry = $baseConfig->get( 'ConfigRegistry' );
387 $configRegistry['main'] = function() use ( $installerConfig ) {
388 return $installerConfig;
391 $configOverrides->set( 'ConfigRegistry', $configRegistry );
393 return $installerConfig;
397 * Constructor, always call this from child classes.
399 public function __construct() {
400 global $wgMemc, $wgUser, $wgObjectCaches;
402 $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php
403 $installerConfig = self::getInstallerConfig( $defaultConfig );
405 // Reset all services and inject config overrides
406 MediaWiki\MediaWikiServices::resetGlobalInstance( $installerConfig );
408 // Don't attempt to load user language options (T126177)
409 // This will be overridden in the web installer with the user-specified language
410 RequestContext::getMain()->setLanguage( 'en' );
412 // Disable the i18n cache
413 // TODO: manage LocalisationCache singleton in MediaWikiServices
414 Language::getLocalisationCache()->disableBackend();
416 // Disable all global services, since we don't have any configuration yet!
417 MediaWiki\MediaWikiServices::disableStorageBackend();
419 // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
420 // SqlBagOStuff will then throw since we just disabled wfGetDB)
421 $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get( 'ObjectCaches' );
422 $wgMemc = ObjectCache::getInstance( CACHE_NONE );
424 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
425 $wgUser = User::newFromId( 0 );
426 RequestContext::getMain()->setUser( $wgUser );
428 $this->settings = $this->internalDefaults;
430 foreach ( $this->defaultVarNames as $var ) {
431 $this->settings[$var] = $GLOBALS[$var];
434 $this->doEnvironmentPreps();
436 $this->compiledDBs = [];
437 foreach ( self::getDBTypes() as $type ) {
438 $installer = $this->getDBInstaller( $type );
440 if ( !$installer->isCompiled() ) {
441 continue;
443 $this->compiledDBs[] = $type;
446 $this->parserTitle = Title::newFromText( 'Installer' );
447 $this->parserOptions = new ParserOptions( $wgUser ); // language will be wrong :(
448 $this->parserOptions->setEditSection( false );
452 * Get a list of known DB types.
454 * @return array
456 public static function getDBTypes() {
457 return self::$dbTypes;
461 * Do initial checks of the PHP environment. Set variables according to
462 * the observed environment.
464 * It's possible that this may be called under the CLI SAPI, not the SAPI
465 * that the wiki will primarily run under. In that case, the subclass should
466 * initialise variables such as wgScriptPath, before calling this function.
468 * Under the web subclass, it can already be assumed that PHP 5+ is in use
469 * and that sessions are working.
471 * @return Status
473 public function doEnvironmentChecks() {
474 // Php version has already been checked by entry scripts
475 // Show message here for information purposes
476 if ( wfIsHHVM() ) {
477 $this->showMessage( 'config-env-hhvm', HHVM_VERSION );
478 } else {
479 $this->showMessage( 'config-env-php', PHP_VERSION );
482 $good = true;
483 // Must go here because an old version of PCRE can prevent other checks from completing
484 list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
485 if ( version_compare( $pcreVersion, self::MINIMUM_PCRE_VERSION, '<' ) ) {
486 $this->showError( 'config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion );
487 $good = false;
488 } else {
489 foreach ( $this->envChecks as $check ) {
490 $status = $this->$check();
491 if ( $status === false ) {
492 $good = false;
497 $this->setVar( '_Environment', $good );
499 return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
502 public function doEnvironmentPreps() {
503 foreach ( $this->envPreps as $prep ) {
504 $this->$prep();
509 * Set a MW configuration variable, or internal installer configuration variable.
511 * @param string $name
512 * @param mixed $value
514 public function setVar( $name, $value ) {
515 $this->settings[$name] = $value;
519 * Get an MW configuration variable, or internal installer configuration variable.
520 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
521 * Installer variables are typically prefixed by an underscore.
523 * @param string $name
524 * @param mixed $default
526 * @return mixed
528 public function getVar( $name, $default = null ) {
529 if ( !isset( $this->settings[$name] ) ) {
530 return $default;
531 } else {
532 return $this->settings[$name];
537 * Get a list of DBs supported by current PHP setup
539 * @return array
541 public function getCompiledDBs() {
542 return $this->compiledDBs;
546 * Get an instance of DatabaseInstaller for the specified DB type.
548 * @param mixed $type DB installer for which is needed, false to use default.
550 * @return DatabaseInstaller
552 public function getDBInstaller( $type = false ) {
553 if ( !$type ) {
554 $type = $this->getVar( 'wgDBtype' );
557 $type = strtolower( $type );
559 if ( !isset( $this->dbInstallers[$type] ) ) {
560 $class = ucfirst( $type ) . 'Installer';
561 $this->dbInstallers[$type] = new $class( $this );
564 return $this->dbInstallers[$type];
568 * Determine if LocalSettings.php exists. If it does, return its variables.
570 * @return array|false
572 public static function getExistingLocalSettings() {
573 global $IP;
575 // You might be wondering why this is here. Well if you don't do this
576 // then some poorly-formed extensions try to call their own classes
577 // after immediately registering them. We really need to get extension
578 // registration out of the global scope and into a real format.
579 // @see https://phabricator.wikimedia.org/T69440
580 global $wgAutoloadClasses;
581 $wgAutoloadClasses = [];
583 // @codingStandardsIgnoreStart
584 // LocalSettings.php should not call functions, except wfLoadSkin/wfLoadExtensions
585 // Define the required globals here, to ensure, the functions can do it work correctly.
586 global $wgExtensionDirectory, $wgStyleDirectory;
587 // @codingStandardsIgnoreEnd
589 MediaWiki\suppressWarnings();
590 $_lsExists = file_exists( "$IP/LocalSettings.php" );
591 MediaWiki\restoreWarnings();
593 if ( !$_lsExists ) {
594 return false;
596 unset( $_lsExists );
598 require "$IP/includes/DefaultSettings.php";
599 require "$IP/LocalSettings.php";
601 return get_defined_vars();
605 * Get a fake password for sending back to the user in HTML.
606 * This is a security mechanism to avoid compromise of the password in the
607 * event of session ID compromise.
609 * @param string $realPassword
611 * @return string
613 public function getFakePassword( $realPassword ) {
614 return str_repeat( '*', strlen( $realPassword ) );
618 * Set a variable which stores a password, except if the new value is a
619 * fake password in which case leave it as it is.
621 * @param string $name
622 * @param mixed $value
624 public function setPassword( $name, $value ) {
625 if ( !preg_match( '/^\*+$/', $value ) ) {
626 $this->setVar( $name, $value );
631 * On POSIX systems return the primary group of the webserver we're running under.
632 * On other systems just returns null.
634 * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
635 * webserver user before he can install.
637 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
639 * @return mixed
641 public static function maybeGetWebserverPrimaryGroup() {
642 if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
643 # I don't know this, this isn't UNIX.
644 return null;
647 # posix_getegid() *not* getmygid() because we want the group of the webserver,
648 # not whoever owns the current script.
649 $gid = posix_getegid();
650 $group = posix_getpwuid( $gid )['name'];
652 return $group;
656 * Convert wikitext $text to HTML.
658 * This is potentially error prone since many parser features require a complete
659 * installed MW database. The solution is to just not use those features when you
660 * write your messages. This appears to work well enough. Basic formatting and
661 * external links work just fine.
663 * But in case a translator decides to throw in a "#ifexist" or internal link or
664 * whatever, this function is guarded to catch the attempted DB access and to present
665 * some fallback text.
667 * @param string $text
668 * @param bool $lineStart
669 * @return string
671 public function parse( $text, $lineStart = false ) {
672 global $wgParser;
674 try {
675 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
676 $html = $out->getText();
677 } catch ( DBAccessError $e ) {
678 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
680 if ( !empty( $this->debug ) ) {
681 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
685 return $html;
689 * @return ParserOptions
691 public function getParserOptions() {
692 return $this->parserOptions;
695 public function disableLinkPopups() {
696 $this->parserOptions->setExternalLinkTarget( false );
699 public function restoreLinkPopups() {
700 global $wgExternalLinkTarget;
701 $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
705 * Install step which adds a row to the site_stats table with appropriate
706 * initial values.
708 * @param DatabaseInstaller $installer
710 * @return Status
712 public function populateSiteStats( DatabaseInstaller $installer ) {
713 $status = $installer->getConnection();
714 if ( !$status->isOK() ) {
715 return $status;
717 $status->value->insert(
718 'site_stats',
720 'ss_row_id' => 1,
721 'ss_total_edits' => 0,
722 'ss_good_articles' => 0,
723 'ss_total_pages' => 0,
724 'ss_users' => 0,
725 'ss_images' => 0
727 __METHOD__, 'IGNORE'
730 return Status::newGood();
734 * Environment check for DB types.
735 * @return bool
737 protected function envCheckDB() {
738 global $wgLang;
740 $allNames = [];
742 // Messages: config-type-mysql, config-type-postgres, config-type-oracle,
743 // config-type-sqlite
744 foreach ( self::getDBTypes() as $name ) {
745 $allNames[] = wfMessage( "config-type-$name" )->text();
748 $databases = $this->getCompiledDBs();
750 $databases = array_flip( $databases );
751 foreach ( array_keys( $databases ) as $db ) {
752 $installer = $this->getDBInstaller( $db );
753 $status = $installer->checkPrerequisites();
754 if ( !$status->isGood() ) {
755 $this->showStatusMessage( $status );
757 if ( !$status->isOK() ) {
758 unset( $databases[$db] );
761 $databases = array_flip( $databases );
762 if ( !$databases ) {
763 $this->showError( 'config-no-db', $wgLang->commaList( $allNames ), count( $allNames ) );
765 // @todo FIXME: This only works for the web installer!
766 return false;
769 return true;
773 * Some versions of libxml+PHP break < and > encoding horribly
774 * @return bool
776 protected function envCheckBrokenXML() {
777 $test = new PhpXmlBugTester();
778 if ( !$test->ok ) {
779 $this->showError( 'config-brokenlibxml' );
781 return false;
784 return true;
788 * Environment check for the PCRE module.
790 * @note If this check were to fail, the parser would
791 * probably throw an exception before the result
792 * of this check is shown to the user.
793 * @return bool
795 protected function envCheckPCRE() {
796 MediaWiki\suppressWarnings();
797 $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
798 // Need to check for \p support too, as PCRE can be compiled
799 // with utf8 support, but not unicode property support.
800 // check that \p{Zs} (space separators) matches
801 // U+3000 (Ideographic space)
802 $regexprop = preg_replace( '/\p{Zs}/u', '', "-\xE3\x80\x80-" );
803 MediaWiki\restoreWarnings();
804 if ( $regexd != '--' || $regexprop != '--' ) {
805 $this->showError( 'config-pcre-no-utf8' );
807 return false;
810 return true;
814 * Environment check for available memory.
815 * @return bool
817 protected function envCheckMemory() {
818 $limit = ini_get( 'memory_limit' );
820 if ( !$limit || $limit == -1 ) {
821 return true;
824 $n = wfShorthandToInteger( $limit );
826 if ( $n < $this->minMemorySize * 1024 * 1024 ) {
827 $newLimit = "{$this->minMemorySize}M";
829 if ( ini_set( "memory_limit", $newLimit ) === false ) {
830 $this->showMessage( 'config-memory-bad', $limit );
831 } else {
832 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
833 $this->setVar( '_RaiseMemory', true );
837 return true;
841 * Environment check for compiled object cache types.
843 protected function envCheckCache() {
844 $caches = [];
845 foreach ( $this->objectCaches as $name => $function ) {
846 if ( function_exists( $function ) ) {
847 if ( $name == 'xcache' && !wfIniGetBool( 'xcache.var_size' ) ) {
848 continue;
850 $caches[$name] = true;
854 if ( !$caches ) {
855 $key = 'config-no-cache-apcu';
856 $this->showMessage( $key );
859 $this->setVar( '_Caches', $caches );
863 * Scare user to death if they have mod_security or mod_security2
864 * @return bool
866 protected function envCheckModSecurity() {
867 if ( self::apacheModulePresent( 'mod_security' )
868 || self::apacheModulePresent( 'mod_security2' ) ) {
869 $this->showMessage( 'config-mod-security' );
872 return true;
876 * Search for GNU diff3.
877 * @return bool
879 protected function envCheckDiff3() {
880 $names = [ "gdiff3", "diff3", "diff3.exe" ];
881 $versionInfo = [ '$1 --version 2>&1', 'GNU diffutils' ];
883 $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
885 if ( $diff3 ) {
886 $this->setVar( 'wgDiff3', $diff3 );
887 } else {
888 $this->setVar( 'wgDiff3', false );
889 $this->showMessage( 'config-diff3-bad' );
892 return true;
896 * Environment check for ImageMagick and GD.
897 * @return bool
899 protected function envCheckGraphics() {
900 $names = [ wfIsWindows() ? 'convert.exe' : 'convert' ];
901 $versionInfo = [ '$1 -version', 'ImageMagick' ];
902 $convert = self::locateExecutableInDefaultPaths( $names, $versionInfo );
904 $this->setVar( 'wgImageMagickConvertCommand', '' );
905 if ( $convert ) {
906 $this->setVar( 'wgImageMagickConvertCommand', $convert );
907 $this->showMessage( 'config-imagemagick', $convert );
909 return true;
910 } elseif ( function_exists( 'imagejpeg' ) ) {
911 $this->showMessage( 'config-gd' );
912 } else {
913 $this->showMessage( 'config-no-scaling' );
916 return true;
920 * Search for git.
922 * @since 1.22
923 * @return bool
925 protected function envCheckGit() {
926 $names = [ wfIsWindows() ? 'git.exe' : 'git' ];
927 $versionInfo = [ '$1 --version', 'git version' ];
929 $git = self::locateExecutableInDefaultPaths( $names, $versionInfo );
931 if ( $git ) {
932 $this->setVar( 'wgGitBin', $git );
933 $this->showMessage( 'config-git', $git );
934 } else {
935 $this->setVar( 'wgGitBin', false );
936 $this->showMessage( 'config-git-bad' );
939 return true;
943 * Environment check to inform user which server we've assumed.
945 * @return bool
947 protected function envCheckServer() {
948 $server = $this->envGetDefaultServer();
949 if ( $server !== null ) {
950 $this->showMessage( 'config-using-server', $server );
952 return true;
956 * Environment check to inform user which paths we've assumed.
958 * @return bool
960 protected function envCheckPath() {
961 $this->showMessage(
962 'config-using-uri',
963 $this->getVar( 'wgServer' ),
964 $this->getVar( 'wgScriptPath' )
966 return true;
970 * Environment check for preferred locale in shell
971 * @return bool
973 protected function envCheckShellLocale() {
974 $os = php_uname( 's' );
975 $supported = [ 'Linux', 'SunOS', 'HP-UX', 'Darwin' ]; # Tested these
977 if ( !in_array( $os, $supported ) ) {
978 return true;
981 # Get a list of available locales.
982 $ret = false;
983 $lines = wfShellExec( '/usr/bin/locale -a', $ret );
985 if ( $ret ) {
986 return true;
989 $lines = array_map( 'trim', explode( "\n", $lines ) );
990 $candidatesByLocale = [];
991 $candidatesByLang = [];
993 foreach ( $lines as $line ) {
994 if ( $line === '' ) {
995 continue;
998 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
999 continue;
1002 list( , $lang, , , ) = $m;
1004 $candidatesByLocale[$m[0]] = $m;
1005 $candidatesByLang[$lang][] = $m;
1008 # Try the current value of LANG.
1009 if ( isset( $candidatesByLocale[getenv( 'LANG' )] ) ) {
1010 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
1012 return true;
1015 # Try the most common ones.
1016 $commonLocales = [ 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' ];
1017 foreach ( $commonLocales as $commonLocale ) {
1018 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
1019 $this->setVar( 'wgShellLocale', $commonLocale );
1021 return true;
1025 # Is there an available locale in the Wiki's language?
1026 $wikiLang = $this->getVar( 'wgLanguageCode' );
1028 if ( isset( $candidatesByLang[$wikiLang] ) ) {
1029 $m = reset( $candidatesByLang[$wikiLang] );
1030 $this->setVar( 'wgShellLocale', $m[0] );
1032 return true;
1035 # Are there any at all?
1036 if ( count( $candidatesByLocale ) ) {
1037 $m = reset( $candidatesByLocale );
1038 $this->setVar( 'wgShellLocale', $m[0] );
1040 return true;
1043 # Give up.
1044 return true;
1048 * Environment check for the permissions of the uploads directory
1049 * @return bool
1051 protected function envCheckUploadsDirectory() {
1052 global $IP;
1054 $dir = $IP . '/images/';
1055 $url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/';
1056 $safe = !$this->dirIsExecutable( $dir, $url );
1058 if ( !$safe ) {
1059 $this->showMessage( 'config-uploads-not-safe', $dir );
1062 return true;
1066 * Checks if suhosin.get.max_value_length is set, and if so generate
1067 * a warning because it decreases ResourceLoader performance.
1068 * @return bool
1070 protected function envCheckSuhosinMaxValueLength() {
1071 $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
1072 if ( $maxValueLength > 0 && $maxValueLength < 1024 ) {
1073 // Only warn if the value is below the sane 1024
1074 $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
1077 return true;
1081 * Convert a hex string representing a Unicode code point to that code point.
1082 * @param string $c
1083 * @return string|false
1085 protected function unicodeChar( $c ) {
1086 $c = hexdec( $c );
1087 if ( $c <= 0x7F ) {
1088 return chr( $c );
1089 } elseif ( $c <= 0x7FF ) {
1090 return chr( 0xC0 | $c >> 6 ) . chr( 0x80 | $c & 0x3F );
1091 } elseif ( $c <= 0xFFFF ) {
1092 return chr( 0xE0 | $c >> 12 ) . chr( 0x80 | $c >> 6 & 0x3F ) .
1093 chr( 0x80 | $c & 0x3F );
1094 } elseif ( $c <= 0x10FFFF ) {
1095 return chr( 0xF0 | $c >> 18 ) . chr( 0x80 | $c >> 12 & 0x3F ) .
1096 chr( 0x80 | $c >> 6 & 0x3F ) .
1097 chr( 0x80 | $c & 0x3F );
1098 } else {
1099 return false;
1104 * Check the libicu version
1106 protected function envCheckLibicu() {
1108 * This needs to be updated something that the latest libicu
1109 * will properly normalize. This normalization was found at
1110 * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
1111 * Note that we use the hex representation to create the code
1112 * points in order to avoid any Unicode-destroying during transit.
1114 $not_normal_c = $this->unicodeChar( "FA6C" );
1115 $normal_c = $this->unicodeChar( "242EE" );
1117 $useNormalizer = 'php';
1118 $needsUpdate = false;
1120 if ( function_exists( 'normalizer_normalize' ) ) {
1121 $useNormalizer = 'intl';
1122 $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
1123 if ( $intl !== $normal_c ) {
1124 $needsUpdate = true;
1128 // Uses messages 'config-unicode-using-php' and 'config-unicode-using-intl'
1129 if ( $useNormalizer === 'php' ) {
1130 $this->showMessage( 'config-unicode-pure-php-warning' );
1131 } else {
1132 $this->showMessage( 'config-unicode-using-' . $useNormalizer );
1133 if ( $needsUpdate ) {
1134 $this->showMessage( 'config-unicode-update-warning' );
1140 * Environment prep for the server hostname.
1142 protected function envPrepServer() {
1143 $server = $this->envGetDefaultServer();
1144 if ( $server !== null ) {
1145 $this->setVar( 'wgServer', $server );
1150 * Helper function to be called from envPrepServer()
1151 * @return string
1153 abstract protected function envGetDefaultServer();
1156 * Environment prep for setting $IP and $wgScriptPath.
1158 protected function envPrepPath() {
1159 global $IP;
1160 $IP = dirname( dirname( __DIR__ ) );
1161 $this->setVar( 'IP', $IP );
1165 * Get an array of likely places we can find executables. Check a bunch
1166 * of known Unix-like defaults, as well as the PATH environment variable
1167 * (which should maybe make it work for Windows?)
1169 * @return array
1171 protected static function getPossibleBinPaths() {
1172 return array_merge(
1173 [ '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
1174 '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ],
1175 explode( PATH_SEPARATOR, getenv( 'PATH' ) )
1180 * Search a path for any of the given executable names. Returns the
1181 * executable name if found. Also checks the version string returned
1182 * by each executable.
1184 * Used only by environment checks.
1186 * @param string $path Path to search
1187 * @param array $names Array of executable names
1188 * @param array|bool $versionInfo False or array with two members:
1189 * 0 => Command to run for version check, with $1 for the full executable name
1190 * 1 => String to compare the output with
1192 * If $versionInfo is not false, only executables with a version
1193 * matching $versionInfo[1] will be returned.
1194 * @return bool|string
1196 public static function locateExecutable( $path, $names, $versionInfo = false ) {
1197 if ( !is_array( $names ) ) {
1198 $names = [ $names ];
1201 foreach ( $names as $name ) {
1202 $command = $path . DIRECTORY_SEPARATOR . $name;
1204 MediaWiki\suppressWarnings();
1205 $file_exists = is_executable( $command );
1206 MediaWiki\restoreWarnings();
1208 if ( $file_exists ) {
1209 if ( !$versionInfo ) {
1210 return $command;
1213 $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
1214 if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
1215 return $command;
1220 return false;
1224 * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
1225 * @see locateExecutable()
1226 * @param array $names Array of possible names.
1227 * @param array|bool $versionInfo Default: false or array with two members:
1228 * 0 => Command to run for version check, with $1 for the full executable name
1229 * 1 => String to compare the output with
1231 * If $versionInfo is not false, only executables with a version
1232 * matching $versionInfo[1] will be returned.
1233 * @return bool|string
1235 public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
1236 foreach ( self::getPossibleBinPaths() as $path ) {
1237 $exe = self::locateExecutable( $path, $names, $versionInfo );
1238 if ( $exe !== false ) {
1239 return $exe;
1243 return false;
1247 * Checks if scripts located in the given directory can be executed via the given URL.
1249 * Used only by environment checks.
1250 * @param string $dir
1251 * @param string $url
1252 * @return bool|int|string
1254 public function dirIsExecutable( $dir, $url ) {
1255 $scriptTypes = [
1256 'php' => [
1257 "<?php echo 'ex' . 'ec';",
1258 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
1262 // it would be good to check other popular languages here, but it'll be slow.
1264 MediaWiki\suppressWarnings();
1266 foreach ( $scriptTypes as $ext => $contents ) {
1267 foreach ( $contents as $source ) {
1268 $file = 'exectest.' . $ext;
1270 if ( !file_put_contents( $dir . $file, $source ) ) {
1271 break;
1274 try {
1275 $text = Http::get( $url . $file, [ 'timeout' => 3 ], __METHOD__ );
1276 } catch ( Exception $e ) {
1277 // Http::get throws with allow_url_fopen = false and no curl extension.
1278 $text = null;
1280 unlink( $dir . $file );
1282 if ( $text == 'exec' ) {
1283 MediaWiki\restoreWarnings();
1285 return $ext;
1290 MediaWiki\restoreWarnings();
1292 return false;
1296 * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too.
1298 * @param string $moduleName Name of module to check.
1299 * @return bool
1301 public static function apacheModulePresent( $moduleName ) {
1302 if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) {
1303 return true;
1305 // try it the hard way
1306 ob_start();
1307 phpinfo( INFO_MODULES );
1308 $info = ob_get_clean();
1310 return strpos( $info, $moduleName ) !== false;
1314 * ParserOptions are constructed before we determined the language, so fix it
1316 * @param Language $lang
1318 public function setParserLanguage( $lang ) {
1319 $this->parserOptions->setTargetLanguage( $lang );
1320 $this->parserOptions->setUserLang( $lang );
1324 * Overridden by WebInstaller to provide lastPage parameters.
1325 * @param string $page
1326 * @return string
1328 protected function getDocUrl( $page ) {
1329 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1333 * Finds extensions that follow the format /$directory/Name/Name.php,
1334 * and returns an array containing the value for 'Name' for each found extension.
1336 * Reasonable values for $directory include 'extensions' (the default) and 'skins'.
1338 * @param string $directory Directory to search in
1339 * @return array
1341 public function findExtensions( $directory = 'extensions' ) {
1342 if ( $this->getVar( 'IP' ) === null ) {
1343 return [];
1346 $extDir = $this->getVar( 'IP' ) . '/' . $directory;
1347 if ( !is_readable( $extDir ) || !is_dir( $extDir ) ) {
1348 return [];
1351 // extensions -> extension.json, skins -> skin.json
1352 $jsonFile = substr( $directory, 0, strlen( $directory ) -1 ) . '.json';
1354 $dh = opendir( $extDir );
1355 $exts = [];
1356 while ( ( $file = readdir( $dh ) ) !== false ) {
1357 if ( !is_dir( "$extDir/$file" ) ) {
1358 continue;
1360 if ( file_exists( "$extDir/$file/$jsonFile" ) || file_exists( "$extDir/$file/$file.php" ) ) {
1361 $exts[] = $file;
1364 closedir( $dh );
1365 natcasesort( $exts );
1367 return $exts;
1371 * Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings,
1372 * but will fall back to another if the default skin is missing and some other one is present
1373 * instead.
1375 * @param string[] $skinNames Names of installed skins.
1376 * @return string
1378 public function getDefaultSkin( array $skinNames ) {
1379 $defaultSkin = $GLOBALS['wgDefaultSkin'];
1380 if ( !$skinNames || in_array( $defaultSkin, $skinNames ) ) {
1381 return $defaultSkin;
1382 } else {
1383 return $skinNames[0];
1388 * Installs the auto-detected extensions.
1390 * @return Status
1392 protected function includeExtensions() {
1393 global $IP;
1394 $exts = $this->getVar( '_Extensions' );
1395 $IP = $this->getVar( 'IP' );
1398 * We need to include DefaultSettings before including extensions to avoid
1399 * warnings about unset variables. However, the only thing we really
1400 * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
1401 * if the extension has hidden hook registration in $wgExtensionFunctions,
1402 * but we're not opening that can of worms
1403 * @see https://phabricator.wikimedia.org/T28857
1405 global $wgAutoloadClasses;
1406 $wgAutoloadClasses = [];
1407 $queue = [];
1409 require "$IP/includes/DefaultSettings.php";
1411 foreach ( $exts as $e ) {
1412 if ( file_exists( "$IP/extensions/$e/extension.json" ) ) {
1413 $queue["$IP/extensions/$e/extension.json"] = 1;
1414 } else {
1415 require_once "$IP/extensions/$e/$e.php";
1419 $registry = new ExtensionRegistry();
1420 $data = $registry->readFromQueue( $queue );
1421 $wgAutoloadClasses += $data['autoload'];
1423 $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
1424 /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */
1425 $wgHooks['LoadExtensionSchemaUpdates'] : [];
1427 if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
1428 $hooksWeWant = array_merge_recursive(
1429 $hooksWeWant,
1430 $data['globals']['wgHooks']['LoadExtensionSchemaUpdates']
1433 // Unset everyone else's hooks. Lord knows what someone might be doing
1434 // in ParserFirstCallInit (see bug 27171)
1435 $GLOBALS['wgHooks'] = [ 'LoadExtensionSchemaUpdates' => $hooksWeWant ];
1437 return Status::newGood();
1441 * Get an array of install steps. Should always be in the format of
1443 * 'name' => 'someuniquename',
1444 * 'callback' => [ $obj, 'method' ],
1446 * There must be a config-install-$name message defined per step, which will
1447 * be shown on install.
1449 * @param DatabaseInstaller $installer DatabaseInstaller so we can make callbacks
1450 * @return array
1452 protected function getInstallSteps( DatabaseInstaller $installer ) {
1453 $coreInstallSteps = [
1454 [ 'name' => 'database', 'callback' => [ $installer, 'setupDatabase' ] ],
1455 [ 'name' => 'tables', 'callback' => [ $installer, 'createTables' ] ],
1456 [ 'name' => 'interwiki', 'callback' => [ $installer, 'populateInterwikiTable' ] ],
1457 [ 'name' => 'stats', 'callback' => [ $this, 'populateSiteStats' ] ],
1458 [ 'name' => 'keys', 'callback' => [ $this, 'generateKeys' ] ],
1459 [ 'name' => 'updates', 'callback' => [ $installer, 'insertUpdateKeys' ] ],
1460 [ 'name' => 'sysop', 'callback' => [ $this, 'createSysop' ] ],
1461 [ 'name' => 'mainpage', 'callback' => [ $this, 'createMainpage' ] ],
1464 // Build the array of install steps starting from the core install list,
1465 // then adding any callbacks that wanted to attach after a given step
1466 foreach ( $coreInstallSteps as $step ) {
1467 $this->installSteps[] = $step;
1468 if ( isset( $this->extraInstallSteps[$step['name']] ) ) {
1469 $this->installSteps = array_merge(
1470 $this->installSteps,
1471 $this->extraInstallSteps[$step['name']]
1476 // Prepend any steps that want to be at the beginning
1477 if ( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
1478 $this->installSteps = array_merge(
1479 $this->extraInstallSteps['BEGINNING'],
1480 $this->installSteps
1484 // Extensions should always go first, chance to tie into hooks and such
1485 if ( count( $this->getVar( '_Extensions' ) ) ) {
1486 array_unshift( $this->installSteps,
1487 [ 'name' => 'extensions', 'callback' => [ $this, 'includeExtensions' ] ]
1489 $this->installSteps[] = [
1490 'name' => 'extension-tables',
1491 'callback' => [ $installer, 'createExtensionTables' ]
1495 return $this->installSteps;
1499 * Actually perform the installation.
1501 * @param callable $startCB A callback array for the beginning of each step
1502 * @param callable $endCB A callback array for the end of each step
1504 * @return array Array of Status objects
1506 public function performInstallation( $startCB, $endCB ) {
1507 $installResults = [];
1508 $installer = $this->getDBInstaller();
1509 $installer->preInstall();
1510 $steps = $this->getInstallSteps( $installer );
1511 foreach ( $steps as $stepObj ) {
1512 $name = $stepObj['name'];
1513 call_user_func_array( $startCB, [ $name ] );
1515 // Perform the callback step
1516 $status = call_user_func( $stepObj['callback'], $installer );
1518 // Output and save the results
1519 call_user_func( $endCB, $name, $status );
1520 $installResults[$name] = $status;
1522 // If we've hit some sort of fatal, we need to bail.
1523 // Callback already had a chance to do output above.
1524 if ( !$status->isOk() ) {
1525 break;
1528 if ( $status->isOk() ) {
1529 $this->setVar( '_InstallDone', true );
1532 return $installResults;
1536 * Generate $wgSecretKey. Will warn if we had to use an insecure random source.
1538 * @return Status
1540 public function generateKeys() {
1541 $keys = [ 'wgSecretKey' => 64 ];
1542 if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
1543 $keys['wgUpgradeKey'] = 16;
1546 return $this->doGenerateKeys( $keys );
1550 * Generate a secret value for variables using our CryptRand generator.
1551 * Produce a warning if the random source was insecure.
1553 * @param array $keys
1554 * @return Status
1556 protected function doGenerateKeys( $keys ) {
1557 $status = Status::newGood();
1559 $strong = true;
1560 foreach ( $keys as $name => $length ) {
1561 $secretKey = MWCryptRand::generateHex( $length, true );
1562 if ( !MWCryptRand::wasStrong() ) {
1563 $strong = false;
1566 $this->setVar( $name, $secretKey );
1569 if ( !$strong ) {
1570 $names = array_keys( $keys );
1571 $names = preg_replace( '/^(.*)$/', '\$$1', $names );
1572 global $wgLang;
1573 $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
1576 return $status;
1580 * Create the first user account, grant it sysop and bureaucrat rights
1582 * @return Status
1584 protected function createSysop() {
1585 $name = $this->getVar( '_AdminName' );
1586 $user = User::newFromName( $name );
1588 if ( !$user ) {
1589 // We should've validated this earlier anyway!
1590 return Status::newFatal( 'config-admin-error-user', $name );
1593 if ( $user->idForName() == 0 ) {
1594 $user->addToDatabase();
1596 try {
1597 $user->setPassword( $this->getVar( '_AdminPassword' ) );
1598 } catch ( PasswordError $pwe ) {
1599 return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
1602 $user->addGroup( 'sysop' );
1603 $user->addGroup( 'bureaucrat' );
1604 if ( $this->getVar( '_AdminEmail' ) ) {
1605 $user->setEmail( $this->getVar( '_AdminEmail' ) );
1607 $user->saveSettings();
1609 // Update user count
1610 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
1611 $ssUpdate->doUpdate();
1613 $status = Status::newGood();
1615 if ( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
1616 $this->subscribeToMediaWikiAnnounce( $status );
1619 return $status;
1623 * @param Status $s
1625 private function subscribeToMediaWikiAnnounce( Status $s ) {
1626 $params = [
1627 'email' => $this->getVar( '_AdminEmail' ),
1628 'language' => 'en',
1629 'digest' => 0
1632 // Mailman doesn't support as many languages as we do, so check to make
1633 // sure their selected language is available
1634 $myLang = $this->getVar( '_UserLang' );
1635 if ( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
1636 $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
1637 $params['language'] = $myLang;
1640 if ( MWHttpRequest::canMakeRequests() ) {
1641 $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
1642 [ 'method' => 'POST', 'postData' => $params ], __METHOD__ )->execute();
1643 if ( !$res->isOK() ) {
1644 $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
1646 } else {
1647 $s->warning( 'config-install-subscribe-notpossible' );
1652 * Insert Main Page with default content.
1654 * @param DatabaseInstaller $installer
1655 * @return Status
1657 protected function createMainpage( DatabaseInstaller $installer ) {
1658 $status = Status::newGood();
1659 try {
1660 $page = WikiPage::factory( Title::newMainPage() );
1661 $content = new WikitextContent(
1662 wfMessage( 'mainpagetext' )->inContentLanguage()->text() . "\n\n" .
1663 wfMessage( 'mainpagedocfooter' )->inContentLanguage()->text()
1666 $status = $page->doEditContent( $content,
1668 EDIT_NEW,
1669 false,
1670 User::newFromName( 'MediaWiki default' )
1672 } catch ( Exception $e ) {
1673 // using raw, because $wgShowExceptionDetails can not be set yet
1674 $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
1677 return $status;
1681 * Override the necessary bits of the config to run an installation.
1683 public static function overrideConfig() {
1684 // Use PHP's built-in session handling, since MediaWiki's
1685 // SessionHandler can't work before we have an object cache set up.
1686 define( 'MW_NO_SESSION_HANDLER', 1 );
1688 // Don't access the database
1689 $GLOBALS['wgUseDatabaseMessages'] = false;
1690 // Don't cache langconv tables
1691 $GLOBALS['wgLanguageConverterCacheType'] = CACHE_NONE;
1692 // Debug-friendly
1693 $GLOBALS['wgShowExceptionDetails'] = true;
1694 // Don't break forms
1695 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1697 // Extended debugging
1698 $GLOBALS['wgShowSQLErrors'] = true;
1699 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1701 // Allow multiple ob_flush() calls
1702 $GLOBALS['wgDisableOutputCompression'] = true;
1704 // Use a sensible cookie prefix (not my_wiki)
1705 $GLOBALS['wgCookiePrefix'] = 'mw_installer';
1707 // Some of the environment checks make shell requests, remove limits
1708 $GLOBALS['wgMaxShellMemory'] = 0;
1710 // Override the default CookieSessionProvider with a dummy
1711 // implementation that won't stomp on PHP's cookies.
1712 $GLOBALS['wgSessionProviders'] = [
1714 'class' => 'InstallerSessionProvider',
1715 'args' => [ [
1716 'priority' => 1,
1721 // Don't try to use any object cache for SessionManager either.
1722 $GLOBALS['wgSessionCacheType'] = CACHE_NONE;
1726 * Add an installation step following the given step.
1728 * @param callable $callback A valid installation callback array, in this form:
1729 * [ 'name' => 'some-unique-name', 'callback' => [ $obj, 'function' ] ];
1730 * @param string $findStep The step to find. Omit to put the step at the beginning
1732 public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
1733 $this->extraInstallSteps[$findStep][] = $callback;
1737 * Disable the time limit for execution.
1738 * Some long-running pages (Install, Upgrade) will want to do this
1740 protected function disableTimeLimit() {
1741 MediaWiki\suppressWarnings();
1742 set_time_limit( 0 );
1743 MediaWiki\restoreWarnings();