Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / Installer.php
blobc29b462b7458624d7708254ee0a8a7ac6657d8b6
1 <?php
2 /**
3 * Base code for MediaWiki installer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Deployment
24 /**
25 * This documentation group collects source code files with deployment functionality.
27 * @defgroup Deployment Deployment
30 /**
31 * Base installer class.
33 * This class provides the base for installation and update functionality
34 * for both MediaWiki core and extensions.
36 * @ingroup Deployment
37 * @since 1.17
39 abstract class Installer {
41 /**
42 * The oldest version of PCRE we can support.
44 * Defining this is necessary because PHP may be linked with a system version
45 * of PCRE, which may be older than that bundled with the minimum PHP version.
47 const MINIMUM_PCRE_VERSION = '7.2';
49 /**
50 * @var array
52 protected $settings;
54 /**
55 * List of detected DBs, access using getCompiledDBs().
57 * @var array
59 protected $compiledDBs;
61 /**
62 * Cached DB installer instances, access using getDBInstaller().
64 * @var array
66 protected $dbInstallers = array();
68 /**
69 * Minimum memory size in MB.
71 * @var int
73 protected $minMemorySize = 50;
75 /**
76 * Cached Title, used by parse().
78 * @var Title
80 protected $parserTitle;
82 /**
83 * Cached ParserOptions, used by parse().
85 * @var ParserOptions
87 protected $parserOptions;
89 /**
90 * Known database types. These correspond to the class names <type>Installer,
91 * and are also MediaWiki database types valid for $wgDBtype.
93 * To add a new type, create a <type>Installer class and a Database<type>
94 * class, and add a config-type-<type> message to MessagesEn.php.
96 * @var array
98 protected static $dbTypes = array(
99 'mysql',
100 'postgres',
101 'oracle',
102 'mssql',
103 'sqlite',
107 * A list of environment check methods called by doEnvironmentChecks().
108 * These may output warnings using showMessage(), and/or abort the
109 * installation process by returning false.
111 * For the WebInstaller these are only called on the Welcome page,
112 * if these methods have side-effects that should affect later page loads
113 * (as well as the generated stylesheet), use envPreps instead.
115 * @var array
117 protected $envChecks = array(
118 'envCheckDB',
119 'envCheckRegisterGlobals',
120 'envCheckBrokenXML',
121 'envCheckMagicQuotes',
122 'envCheckMbstring',
123 'envCheckSafeMode',
124 'envCheckXML',
125 'envCheckPCRE',
126 'envCheckMemory',
127 'envCheckCache',
128 'envCheckModSecurity',
129 'envCheckDiff3',
130 'envCheckGraphics',
131 'envCheckGit',
132 'envCheckServer',
133 'envCheckPath',
134 'envCheckShellLocale',
135 'envCheckUploadsDirectory',
136 'envCheckLibicu',
137 'envCheckSuhosinMaxValueLength',
138 'envCheckCtype',
139 'envCheckIconv',
140 'envCheckJSON',
144 * A list of environment preparation methods called by doEnvironmentPreps().
146 * @var array
148 protected $envPreps = array(
149 'envPrepExtension',
150 'envPrepServer',
151 'envPrepPath',
155 * MediaWiki configuration globals that will eventually be passed through
156 * to LocalSettings.php. The names only are given here, the defaults
157 * typically come from DefaultSettings.php.
159 * @var array
161 protected $defaultVarNames = array(
162 'wgSitename',
163 'wgPasswordSender',
164 'wgLanguageCode',
165 'wgRightsIcon',
166 'wgRightsText',
167 'wgRightsUrl',
168 'wgMainCacheType',
169 'wgEnableEmail',
170 'wgEnableUserEmail',
171 'wgEnotifUserTalk',
172 'wgEnotifWatchlist',
173 'wgEmailAuthentication',
174 'wgDBtype',
175 'wgDiff3',
176 'wgImageMagickConvertCommand',
177 'wgGitBin',
178 'IP',
179 'wgScriptPath',
180 'wgScriptExtension',
181 'wgMetaNamespace',
182 'wgDeletedDirectory',
183 'wgEnableUploads',
184 'wgShellLocale',
185 'wgSecretKey',
186 'wgUseInstantCommons',
187 'wgUpgradeKey',
188 'wgDefaultSkin',
192 * Variables that are stored alongside globals, and are used for any
193 * configuration of the installation process aside from the MediaWiki
194 * configuration. Map of names to defaults.
196 * @var array
198 protected $internalDefaults = array(
199 '_UserLang' => 'en',
200 '_Environment' => false,
201 '_SafeMode' => false,
202 '_RaiseMemory' => false,
203 '_UpgradeDone' => false,
204 '_InstallDone' => false,
205 '_Caches' => array(),
206 '_InstallPassword' => '',
207 '_SameAccount' => true,
208 '_CreateDBAccount' => false,
209 '_NamespaceType' => 'site-name',
210 '_AdminName' => '', // will be set later, when the user selects language
211 '_AdminPassword' => '',
212 '_AdminPasswordConfirm' => '',
213 '_AdminEmail' => '',
214 '_Subscribe' => false,
215 '_SkipOptional' => 'continue',
216 '_RightsProfile' => 'wiki',
217 '_LicenseCode' => 'none',
218 '_CCDone' => false,
219 '_Extensions' => array(),
220 '_Skins' => array(),
221 '_MemCachedServers' => '',
222 '_UpgradeKeySupplied' => false,
223 '_ExistingDBSettings' => false,
225 // $wgLogo is probably wrong (bug 48084); set something that will work.
226 // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped.
227 'wgLogo' => '$wgScriptPath/resources/assets/wiki.png',
231 * The actual list of installation steps. This will be initialized by getInstallSteps()
233 * @var array
235 private $installSteps = array();
238 * Extra steps for installation, for things like DatabaseInstallers to modify
240 * @var array
242 protected $extraInstallSteps = array();
245 * Known object cache types and the functions used to test for their existence.
247 * @var array
249 protected $objectCaches = array(
250 'xcache' => 'xcache_get',
251 'apc' => 'apc_fetch',
252 'wincache' => 'wincache_ucache_get'
256 * User rights profiles.
258 * @var array
260 public $rightsProfiles = array(
261 'wiki' => array(),
262 'no-anon' => array(
263 '*' => array( 'edit' => false )
265 'fishbowl' => array(
266 '*' => array(
267 'createaccount' => false,
268 'edit' => false,
271 'private' => array(
272 '*' => array(
273 'createaccount' => false,
274 'edit' => false,
275 'read' => false,
281 * License types.
283 * @var array
285 public $licenses = array(
286 'cc-by' => array(
287 'url' => 'https://creativecommons.org/licenses/by/3.0/',
288 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by.png',
290 'cc-by-sa' => array(
291 'url' => 'https://creativecommons.org/licenses/by-sa/3.0/',
292 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by-sa.png',
294 'cc-by-nc-sa' => array(
295 'url' => 'https://creativecommons.org/licenses/by-nc-sa/3.0/',
296 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by-nc-sa.png',
298 'cc-0' => array(
299 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
300 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-0.png',
302 'pd' => array(
303 'url' => '',
304 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/public-domain.png',
306 'gfdl' => array(
307 'url' => 'https://www.gnu.org/copyleft/fdl.html',
308 'icon' => '{$wgResourceBasePath}/resources/assets/licenses/gnu-fdl.png',
310 'none' => array(
311 'url' => '',
312 'icon' => '',
313 'text' => ''
315 'cc-choose' => array(
316 // Details will be filled in by the selector.
317 'url' => '',
318 'icon' => '',
319 'text' => '',
324 * URL to mediawiki-announce subscription
326 protected $mediaWikiAnnounceUrl =
327 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
330 * Supported language codes for Mailman
332 protected $mediaWikiAnnounceLanguages = array(
333 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
334 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
335 'sl', 'sr', 'sv', 'tr', 'uk'
339 * UI interface for displaying a short message
340 * The parameters are like parameters to wfMessage().
341 * The messages will be in wikitext format, which will be converted to an
342 * output format such as HTML or text before being sent to the user.
343 * @param string $msg
345 abstract public function showMessage( $msg /*, ... */ );
348 * Same as showMessage(), but for displaying errors
349 * @param string $msg
351 abstract public function showError( $msg /*, ... */ );
354 * Show a message to the installing user by using a Status object
355 * @param Status $status
357 abstract public function showStatusMessage( Status $status );
360 * Constructor, always call this from child classes.
362 public function __construct() {
363 global $wgMessagesDirs, $wgUser;
365 // Disable the i18n cache
366 Language::getLocalisationCache()->disableBackend();
367 // Disable LoadBalancer and wfGetDB etc.
368 LBFactory::disableBackend();
370 // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
371 // SqlBagOStuff will then throw since we just disabled wfGetDB)
372 $GLOBALS['wgMemc'] = new EmptyBagOStuff;
373 ObjectCache::clear();
374 $emptyCache = array( 'class' => 'EmptyBagOStuff' );
375 $GLOBALS['wgObjectCaches'] = array(
376 CACHE_NONE => $emptyCache,
377 CACHE_DB => $emptyCache,
378 CACHE_ANYTHING => $emptyCache,
379 CACHE_MEMCACHED => $emptyCache,
382 // Load the installer's i18n.
383 $wgMessagesDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
385 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
386 $wgUser = User::newFromId( 0 );
388 $this->settings = $this->internalDefaults;
390 foreach ( $this->defaultVarNames as $var ) {
391 $this->settings[$var] = $GLOBALS[$var];
394 $this->doEnvironmentPreps();
396 $this->compiledDBs = array();
397 foreach ( self::getDBTypes() as $type ) {
398 $installer = $this->getDBInstaller( $type );
400 if ( !$installer->isCompiled() ) {
401 continue;
403 $this->compiledDBs[] = $type;
406 $this->parserTitle = Title::newFromText( 'Installer' );
407 $this->parserOptions = new ParserOptions; // language will be wrong :(
408 $this->parserOptions->setEditSection( false );
412 * Get a list of known DB types.
414 * @return array
416 public static function getDBTypes() {
417 return self::$dbTypes;
421 * Do initial checks of the PHP environment. Set variables according to
422 * the observed environment.
424 * It's possible that this may be called under the CLI SAPI, not the SAPI
425 * that the wiki will primarily run under. In that case, the subclass should
426 * initialise variables such as wgScriptPath, before calling this function.
428 * Under the web subclass, it can already be assumed that PHP 5+ is in use
429 * and that sessions are working.
431 * @return Status
433 public function doEnvironmentChecks() {
434 // Php version has already been checked by entry scripts
435 // Show message here for information purposes
436 if ( wfIsHHVM() ) {
437 $this->showMessage( 'config-env-hhvm', HHVM_VERSION );
438 } else {
439 $this->showMessage( 'config-env-php', PHP_VERSION );
442 $good = true;
443 // Must go here because an old version of PCRE can prevent other checks from completing
444 list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
445 if ( version_compare( $pcreVersion, self::MINIMUM_PCRE_VERSION, '<' ) ) {
446 $this->showError( 'config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion );
447 $good = false;
448 } else {
449 foreach ( $this->envChecks as $check ) {
450 $status = $this->$check();
451 if ( $status === false ) {
452 $good = false;
457 $this->setVar( '_Environment', $good );
459 return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
462 public function doEnvironmentPreps() {
463 foreach ( $this->envPreps as $prep ) {
464 $this->$prep();
469 * Set a MW configuration variable, or internal installer configuration variable.
471 * @param string $name
472 * @param mixed $value
474 public function setVar( $name, $value ) {
475 $this->settings[$name] = $value;
479 * Get an MW configuration variable, or internal installer configuration variable.
480 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
481 * Installer variables are typically prefixed by an underscore.
483 * @param string $name
484 * @param mixed $default
486 * @return mixed
488 public function getVar( $name, $default = null ) {
489 if ( !isset( $this->settings[$name] ) ) {
490 return $default;
491 } else {
492 return $this->settings[$name];
497 * Get a list of DBs supported by current PHP setup
499 * @return array
501 public function getCompiledDBs() {
502 return $this->compiledDBs;
506 * Get an instance of DatabaseInstaller for the specified DB type.
508 * @param mixed $type DB installer for which is needed, false to use default.
510 * @return DatabaseInstaller
512 public function getDBInstaller( $type = false ) {
513 if ( !$type ) {
514 $type = $this->getVar( 'wgDBtype' );
517 $type = strtolower( $type );
519 if ( !isset( $this->dbInstallers[$type] ) ) {
520 $class = ucfirst( $type ) . 'Installer';
521 $this->dbInstallers[$type] = new $class( $this );
524 return $this->dbInstallers[$type];
528 * Determine if LocalSettings.php exists. If it does, return its variables.
530 * @return array
532 public static function getExistingLocalSettings() {
533 global $IP;
535 // You might be wondering why this is here. Well if you don't do this
536 // then some poorly-formed extensions try to call their own classes
537 // after immediately registering them. We really need to get extension
538 // registration out of the global scope and into a real format.
539 // @see https://bugzilla.wikimedia.org/67440
540 global $wgAutoloadClasses;
541 $wgAutoloadClasses = array();
543 wfSuppressWarnings();
544 $_lsExists = file_exists( "$IP/LocalSettings.php" );
545 wfRestoreWarnings();
547 if ( !$_lsExists ) {
548 return false;
550 unset( $_lsExists );
552 require "$IP/includes/DefaultSettings.php";
553 require "$IP/LocalSettings.php";
555 return get_defined_vars();
559 * Get a fake password for sending back to the user in HTML.
560 * This is a security mechanism to avoid compromise of the password in the
561 * event of session ID compromise.
563 * @param string $realPassword
565 * @return string
567 public function getFakePassword( $realPassword ) {
568 return str_repeat( '*', strlen( $realPassword ) );
572 * Set a variable which stores a password, except if the new value is a
573 * fake password in which case leave it as it is.
575 * @param string $name
576 * @param mixed $value
578 public function setPassword( $name, $value ) {
579 if ( !preg_match( '/^\*+$/', $value ) ) {
580 $this->setVar( $name, $value );
585 * On POSIX systems return the primary group of the webserver we're running under.
586 * On other systems just returns null.
588 * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
589 * webserver user before he can install.
591 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
593 * @return mixed
595 public static function maybeGetWebserverPrimaryGroup() {
596 if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
597 # I don't know this, this isn't UNIX.
598 return null;
601 # posix_getegid() *not* getmygid() because we want the group of the webserver,
602 # not whoever owns the current script.
603 $gid = posix_getegid();
604 $getpwuid = posix_getpwuid( $gid );
605 $group = $getpwuid['name'];
607 return $group;
611 * Convert wikitext $text to HTML.
613 * This is potentially error prone since many parser features require a complete
614 * installed MW database. The solution is to just not use those features when you
615 * write your messages. This appears to work well enough. Basic formatting and
616 * external links work just fine.
618 * But in case a translator decides to throw in a "#ifexist" or internal link or
619 * whatever, this function is guarded to catch the attempted DB access and to present
620 * some fallback text.
622 * @param string $text
623 * @param bool $lineStart
624 * @return string
626 public function parse( $text, $lineStart = false ) {
627 global $wgParser;
629 try {
630 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
631 $html = $out->getText();
632 } catch ( DBAccessError $e ) {
633 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
635 if ( !empty( $this->debug ) ) {
636 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
640 return $html;
644 * @return ParserOptions
646 public function getParserOptions() {
647 return $this->parserOptions;
650 public function disableLinkPopups() {
651 $this->parserOptions->setExternalLinkTarget( false );
654 public function restoreLinkPopups() {
655 global $wgExternalLinkTarget;
656 $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
660 * Install step which adds a row to the site_stats table with appropriate
661 * initial values.
663 * @param DatabaseInstaller $installer
665 * @return Status
667 public function populateSiteStats( DatabaseInstaller $installer ) {
668 $status = $installer->getConnection();
669 if ( !$status->isOK() ) {
670 return $status;
672 $status->value->insert(
673 'site_stats',
674 array(
675 'ss_row_id' => 1,
676 'ss_total_edits' => 0,
677 'ss_good_articles' => 0,
678 'ss_total_pages' => 0,
679 'ss_users' => 0,
680 'ss_images' => 0
682 __METHOD__, 'IGNORE'
685 return Status::newGood();
689 * Exports all wg* variables stored by the installer into global scope.
691 public function exportVars() {
692 foreach ( $this->settings as $name => $value ) {
693 if ( substr( $name, 0, 2 ) == 'wg' ) {
694 $GLOBALS[$name] = $value;
700 * Environment check for DB types.
701 * @return bool
703 protected function envCheckDB() {
704 global $wgLang;
706 $allNames = array();
708 // Messages: config-type-mysql, config-type-postgres, config-type-oracle,
709 // config-type-sqlite
710 foreach ( self::getDBTypes() as $name ) {
711 $allNames[] = wfMessage( "config-type-$name" )->text();
714 $databases = $this->getCompiledDBs();
716 $databases = array_flip( $databases );
717 foreach ( array_keys( $databases ) as $db ) {
718 $installer = $this->getDBInstaller( $db );
719 $status = $installer->checkPrerequisites();
720 if ( !$status->isGood() ) {
721 $this->showStatusMessage( $status );
723 if ( !$status->isOK() ) {
724 unset( $databases[$db] );
727 $databases = array_flip( $databases );
728 if ( !$databases ) {
729 $this->showError( 'config-no-db', $wgLang->commaList( $allNames ), count( $allNames ) );
731 // @todo FIXME: This only works for the web installer!
732 return false;
735 return true;
739 * Environment check for register_globals.
740 * Prevent installation if enabled
741 * @return bool
743 protected function envCheckRegisterGlobals() {
744 if ( wfIniGetBool( 'register_globals' ) ) {
745 $this->showMessage( 'config-register-globals-error' );
746 return false;
749 return true;
753 * Some versions of libxml+PHP break < and > encoding horribly
754 * @return bool
756 protected function envCheckBrokenXML() {
757 $test = new PhpXmlBugTester();
758 if ( !$test->ok ) {
759 $this->showError( 'config-brokenlibxml' );
761 return false;
764 return true;
768 * Environment check for magic_quotes_(gpc|runtime|sybase).
769 * @return bool
771 protected function envCheckMagicQuotes() {
772 $status = true;
773 foreach ( array( 'gpc', 'runtime', 'sybase' ) as $magicJunk ) {
774 if ( wfIniGetBool( "magic_quotes_$magicJunk" ) ) {
775 $this->showError( "config-magic-quotes-$magicJunk" );
776 $status = false;
780 return $status;
784 * Environment check for mbstring.func_overload.
785 * @return bool
787 protected function envCheckMbstring() {
788 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
789 $this->showError( 'config-mbstring' );
791 return false;
794 return true;
798 * Environment check for safe_mode.
799 * @return bool
801 protected function envCheckSafeMode() {
802 if ( wfIniGetBool( 'safe_mode' ) ) {
803 $this->setVar( '_SafeMode', true );
804 $this->showMessage( 'config-safe-mode' );
807 return true;
811 * Environment check for the XML module.
812 * @return bool
814 protected function envCheckXML() {
815 if ( !function_exists( "utf8_encode" ) ) {
816 $this->showError( 'config-xml-bad' );
818 return false;
821 return true;
825 * Environment check for the PCRE module.
827 * @note If this check were to fail, the parser would
828 * probably throw an exception before the result
829 * of this check is shown to the user.
830 * @return bool
832 protected function envCheckPCRE() {
833 wfSuppressWarnings();
834 $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
835 // Need to check for \p support too, as PCRE can be compiled
836 // with utf8 support, but not unicode property support.
837 // check that \p{Zs} (space separators) matches
838 // U+3000 (Ideographic space)
839 $regexprop = preg_replace( '/\p{Zs}/u', '', "-\xE3\x80\x80-" );
840 wfRestoreWarnings();
841 if ( $regexd != '--' || $regexprop != '--' ) {
842 $this->showError( 'config-pcre-no-utf8' );
844 return false;
847 return true;
851 * Environment check for available memory.
852 * @return bool
854 protected function envCheckMemory() {
855 $limit = ini_get( 'memory_limit' );
857 if ( !$limit || $limit == -1 ) {
858 return true;
861 $n = wfShorthandToInteger( $limit );
863 if ( $n < $this->minMemorySize * 1024 * 1024 ) {
864 $newLimit = "{$this->minMemorySize}M";
866 if ( ini_set( "memory_limit", $newLimit ) === false ) {
867 $this->showMessage( 'config-memory-bad', $limit );
868 } else {
869 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
870 $this->setVar( '_RaiseMemory', true );
874 return true;
878 * Environment check for compiled object cache types.
880 protected function envCheckCache() {
881 $caches = array();
882 foreach ( $this->objectCaches as $name => $function ) {
883 if ( function_exists( $function ) ) {
884 if ( $name == 'xcache' && !wfIniGetBool( 'xcache.var_size' ) ) {
885 continue;
887 $caches[$name] = true;
891 if ( !$caches ) {
892 $this->showMessage( 'config-no-cache' );
895 $this->setVar( '_Caches', $caches );
899 * Scare user to death if they have mod_security or mod_security2
900 * @return bool
902 protected function envCheckModSecurity() {
903 if ( self::apacheModulePresent( 'mod_security' )
904 || self::apacheModulePresent( 'mod_security2' ) ) {
905 $this->showMessage( 'config-mod-security' );
908 return true;
912 * Search for GNU diff3.
913 * @return bool
915 protected function envCheckDiff3() {
916 $names = array( "gdiff3", "diff3", "diff3.exe" );
917 $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
919 $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
921 if ( $diff3 ) {
922 $this->setVar( 'wgDiff3', $diff3 );
923 } else {
924 $this->setVar( 'wgDiff3', false );
925 $this->showMessage( 'config-diff3-bad' );
928 return true;
932 * Environment check for ImageMagick and GD.
933 * @return bool
935 protected function envCheckGraphics() {
936 $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
937 $versionInfo = array( '$1 -version', 'ImageMagick' );
938 $convert = self::locateExecutableInDefaultPaths( $names, $versionInfo );
940 $this->setVar( 'wgImageMagickConvertCommand', '' );
941 if ( $convert ) {
942 $this->setVar( 'wgImageMagickConvertCommand', $convert );
943 $this->showMessage( 'config-imagemagick', $convert );
945 return true;
946 } elseif ( function_exists( 'imagejpeg' ) ) {
947 $this->showMessage( 'config-gd' );
948 } else {
949 $this->showMessage( 'config-no-scaling' );
952 return true;
956 * Search for git.
958 * @since 1.22
959 * @return bool
961 protected function envCheckGit() {
962 $names = array( wfIsWindows() ? 'git.exe' : 'git' );
963 $versionInfo = array( '$1 --version', 'git version' );
965 $git = self::locateExecutableInDefaultPaths( $names, $versionInfo );
967 if ( $git ) {
968 $this->setVar( 'wgGitBin', $git );
969 $this->showMessage( 'config-git', $git );
970 } else {
971 $this->setVar( 'wgGitBin', false );
972 $this->showMessage( 'config-git-bad' );
975 return true;
979 * Environment check to inform user which server we've assumed.
981 * @return bool
983 protected function envCheckServer() {
984 $server = $this->envGetDefaultServer();
985 if ( $server !== null ) {
986 $this->showMessage( 'config-using-server', $server );
988 return true;
992 * Environment check to inform user which paths we've assumed.
994 * @return bool
996 protected function envCheckPath() {
997 $this->showMessage(
998 'config-using-uri',
999 $this->getVar( 'wgServer' ),
1000 $this->getVar( 'wgScriptPath' )
1002 return true;
1006 * Environment check for preferred locale in shell
1007 * @return bool
1009 protected function envCheckShellLocale() {
1010 $os = php_uname( 's' );
1011 $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
1013 if ( !in_array( $os, $supported ) ) {
1014 return true;
1017 # Get a list of available locales.
1018 $ret = false;
1019 $lines = wfShellExec( '/usr/bin/locale -a', $ret );
1021 if ( $ret ) {
1022 return true;
1025 $lines = array_map( 'trim', explode( "\n", $lines ) );
1026 $candidatesByLocale = array();
1027 $candidatesByLang = array();
1029 foreach ( $lines as $line ) {
1030 if ( $line === '' ) {
1031 continue;
1034 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
1035 continue;
1038 list( , $lang, , , ) = $m;
1040 $candidatesByLocale[$m[0]] = $m;
1041 $candidatesByLang[$lang][] = $m;
1044 # Try the current value of LANG.
1045 if ( isset( $candidatesByLocale[getenv( 'LANG' )] ) ) {
1046 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
1048 return true;
1051 # Try the most common ones.
1052 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
1053 foreach ( $commonLocales as $commonLocale ) {
1054 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
1055 $this->setVar( 'wgShellLocale', $commonLocale );
1057 return true;
1061 # Is there an available locale in the Wiki's language?
1062 $wikiLang = $this->getVar( 'wgLanguageCode' );
1064 if ( isset( $candidatesByLang[$wikiLang] ) ) {
1065 $m = reset( $candidatesByLang[$wikiLang] );
1066 $this->setVar( 'wgShellLocale', $m[0] );
1068 return true;
1071 # Are there any at all?
1072 if ( count( $candidatesByLocale ) ) {
1073 $m = reset( $candidatesByLocale );
1074 $this->setVar( 'wgShellLocale', $m[0] );
1076 return true;
1079 # Give up.
1080 return true;
1084 * Environment check for the permissions of the uploads directory
1085 * @return bool
1087 protected function envCheckUploadsDirectory() {
1088 global $IP;
1090 $dir = $IP . '/images/';
1091 $url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/';
1092 $safe = !$this->dirIsExecutable( $dir, $url );
1094 if ( !$safe ) {
1095 $this->showMessage( 'config-uploads-not-safe', $dir );
1098 return true;
1102 * Checks if suhosin.get.max_value_length is set, and if so generate
1103 * a warning because it decreases ResourceLoader performance.
1104 * @return bool
1106 protected function envCheckSuhosinMaxValueLength() {
1107 $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
1108 if ( $maxValueLength > 0 && $maxValueLength < 1024 ) {
1109 // Only warn if the value is below the sane 1024
1110 $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
1113 return true;
1117 * Convert a hex string representing a Unicode code point to that code point.
1118 * @param string $c
1119 * @return string
1121 protected function unicodeChar( $c ) {
1122 $c = hexdec( $c );
1123 if ( $c <= 0x7F ) {
1124 return chr( $c );
1125 } elseif ( $c <= 0x7FF ) {
1126 return chr( 0xC0 | $c >> 6 ) . chr( 0x80 | $c & 0x3F );
1127 } elseif ( $c <= 0xFFFF ) {
1128 return chr( 0xE0 | $c >> 12 ) . chr( 0x80 | $c >> 6 & 0x3F )
1129 . chr( 0x80 | $c & 0x3F );
1130 } elseif ( $c <= 0x10FFFF ) {
1131 return chr( 0xF0 | $c >> 18 ) . chr( 0x80 | $c >> 12 & 0x3F )
1132 . chr( 0x80 | $c >> 6 & 0x3F )
1133 . chr( 0x80 | $c & 0x3F );
1134 } else {
1135 return false;
1140 * Check the libicu version
1142 protected function envCheckLibicu() {
1143 $utf8 = function_exists( 'utf8_normalize' );
1144 $intl = function_exists( 'normalizer_normalize' );
1147 * This needs to be updated something that the latest libicu
1148 * will properly normalize. This normalization was found at
1149 * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
1150 * Note that we use the hex representation to create the code
1151 * points in order to avoid any Unicode-destroying during transit.
1153 $not_normal_c = $this->unicodeChar( "FA6C" );
1154 $normal_c = $this->unicodeChar( "242EE" );
1156 $useNormalizer = 'php';
1157 $needsUpdate = false;
1160 * We're going to prefer the pecl extension here unless
1161 * utf8_normalize is more up to date.
1163 if ( $utf8 ) {
1164 $useNormalizer = 'utf8';
1165 $utf8 = utf8_normalize( $not_normal_c, UtfNormal::UNORM_NFC );
1166 if ( $utf8 !== $normal_c ) {
1167 $needsUpdate = true;
1170 if ( $intl ) {
1171 $useNormalizer = 'intl';
1172 $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
1173 if ( $intl !== $normal_c ) {
1174 $needsUpdate = true;
1178 // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8',
1179 // 'config-unicode-using-intl'
1180 if ( $useNormalizer === 'php' ) {
1181 $this->showMessage( 'config-unicode-pure-php-warning' );
1182 } else {
1183 $this->showMessage( 'config-unicode-using-' . $useNormalizer );
1184 if ( $needsUpdate ) {
1185 $this->showMessage( 'config-unicode-update-warning' );
1191 * @return bool
1193 protected function envCheckCtype() {
1194 if ( !function_exists( 'ctype_digit' ) ) {
1195 $this->showError( 'config-ctype' );
1197 return false;
1200 return true;
1204 * @return bool
1206 protected function envCheckIconv() {
1207 if ( !function_exists( 'iconv' ) ) {
1208 $this->showError( 'config-iconv' );
1210 return false;
1213 return true;
1217 * @return bool
1219 protected function envCheckJSON() {
1220 if ( !function_exists( 'json_decode' ) ) {
1221 $this->showError( 'config-json' );
1223 return false;
1226 return true;
1230 * Environment prep for the server hostname.
1232 protected function envPrepServer() {
1233 $server = $this->envGetDefaultServer();
1234 if ( $server !== null ) {
1235 $this->setVar( 'wgServer', $server );
1240 * Helper function to be called from envPrepServer()
1241 * @return string
1243 abstract protected function envGetDefaultServer();
1246 * Environment prep for setting the preferred PHP file extension.
1248 protected function envPrepExtension() {
1249 // @todo FIXME: Detect this properly
1250 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
1251 $ext = '.php5';
1252 } else {
1253 $ext = '.php';
1255 $this->setVar( 'wgScriptExtension', $ext );
1259 * Environment prep for setting $IP and $wgScriptPath.
1261 protected function envPrepPath() {
1262 global $IP;
1263 $IP = dirname( dirname( __DIR__ ) );
1264 $this->setVar( 'IP', $IP );
1268 * Get an array of likely places we can find executables. Check a bunch
1269 * of known Unix-like defaults, as well as the PATH environment variable
1270 * (which should maybe make it work for Windows?)
1272 * @return array
1274 protected static function getPossibleBinPaths() {
1275 return array_merge(
1276 array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
1277 '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
1278 explode( PATH_SEPARATOR, getenv( 'PATH' ) )
1283 * Search a path for any of the given executable names. Returns the
1284 * executable name if found. Also checks the version string returned
1285 * by each executable.
1287 * Used only by environment checks.
1289 * @param string $path Path to search
1290 * @param array $names Array of executable names
1291 * @param array|bool $versionInfo False or array with two members:
1292 * 0 => Command to run for version check, with $1 for the full executable name
1293 * 1 => String to compare the output with
1295 * If $versionInfo is not false, only executables with a version
1296 * matching $versionInfo[1] will be returned.
1297 * @return bool|string
1299 public static function locateExecutable( $path, $names, $versionInfo = false ) {
1300 if ( !is_array( $names ) ) {
1301 $names = array( $names );
1304 foreach ( $names as $name ) {
1305 $command = $path . DIRECTORY_SEPARATOR . $name;
1307 wfSuppressWarnings();
1308 $file_exists = file_exists( $command );
1309 wfRestoreWarnings();
1311 if ( $file_exists ) {
1312 if ( !$versionInfo ) {
1313 return $command;
1316 $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
1317 if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
1318 return $command;
1323 return false;
1327 * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
1328 * @see locateExecutable()
1329 * @param array $names Array of possible names.
1330 * @param array|bool $versionInfo Default: false or array with two members:
1331 * 0 => Command to run for version check, with $1 for the full executable name
1332 * 1 => String to compare the output with
1334 * If $versionInfo is not false, only executables with a version
1335 * matching $versionInfo[1] will be returned.
1336 * @return bool|string
1338 public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
1339 foreach ( self::getPossibleBinPaths() as $path ) {
1340 $exe = self::locateExecutable( $path, $names, $versionInfo );
1341 if ( $exe !== false ) {
1342 return $exe;
1346 return false;
1350 * Checks if scripts located in the given directory can be executed via the given URL.
1352 * Used only by environment checks.
1353 * @param string $dir
1354 * @param string $url
1355 * @return bool|int|string
1357 public function dirIsExecutable( $dir, $url ) {
1358 $scriptTypes = array(
1359 'php' => array(
1360 "<?php echo 'ex' . 'ec';",
1361 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
1365 // it would be good to check other popular languages here, but it'll be slow.
1367 wfSuppressWarnings();
1369 foreach ( $scriptTypes as $ext => $contents ) {
1370 foreach ( $contents as $source ) {
1371 $file = 'exectest.' . $ext;
1373 if ( !file_put_contents( $dir . $file, $source ) ) {
1374 break;
1377 try {
1378 $text = Http::get( $url . $file, array( 'timeout' => 3 ), __METHOD__ );
1379 } catch ( Exception $e ) {
1380 // Http::get throws with allow_url_fopen = false and no curl extension.
1381 $text = null;
1383 unlink( $dir . $file );
1385 if ( $text == 'exec' ) {
1386 wfRestoreWarnings();
1388 return $ext;
1393 wfRestoreWarnings();
1395 return false;
1399 * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too.
1401 * @param string $moduleName Name of module to check.
1402 * @return bool
1404 public static function apacheModulePresent( $moduleName ) {
1405 if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) {
1406 return true;
1408 // try it the hard way
1409 ob_start();
1410 phpinfo( INFO_MODULES );
1411 $info = ob_get_clean();
1413 return strpos( $info, $moduleName ) !== false;
1417 * ParserOptions are constructed before we determined the language, so fix it
1419 * @param Language $lang
1421 public function setParserLanguage( $lang ) {
1422 $this->parserOptions->setTargetLanguage( $lang );
1423 $this->parserOptions->setUserLang( $lang );
1427 * Overridden by WebInstaller to provide lastPage parameters.
1428 * @param string $page
1429 * @return string
1431 protected function getDocUrl( $page ) {
1432 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1436 * Finds extensions that follow the format /$directory/Name/Name.php,
1437 * and returns an array containing the value for 'Name' for each found extension.
1439 * Reasonable values for $directory include 'extensions' (the default) and 'skins'.
1441 * @param string $directory Directory to search in
1442 * @return array
1444 public function findExtensions( $directory = 'extensions' ) {
1445 if ( $this->getVar( 'IP' ) === null ) {
1446 return array();
1449 $extDir = $this->getVar( 'IP' ) . '/' . $directory;
1450 if ( !is_readable( $extDir ) || !is_dir( $extDir ) ) {
1451 return array();
1454 $dh = opendir( $extDir );
1455 $exts = array();
1456 while ( ( $file = readdir( $dh ) ) !== false ) {
1457 if ( !is_dir( "$extDir/$file" ) ) {
1458 continue;
1460 if ( file_exists( "$extDir/$file/$file.php" ) ) {
1461 $exts[] = $file;
1464 closedir( $dh );
1465 natcasesort( $exts );
1467 return $exts;
1471 * Returns a default value to be used for $wgDefaultSkin: normally the one set in DefaultSettings,
1472 * but will fall back to another if the default skin is missing and some other one is present
1473 * instead.
1475 * @param string[] $skinNames Names of installed skins.
1476 * @return string
1478 public function getDefaultSkin( array $skinNames ) {
1479 $defaultSkin = $GLOBALS['wgDefaultSkin'];
1480 if ( !$skinNames || in_array( $defaultSkin, $skinNames ) ) {
1481 return $defaultSkin;
1482 } else {
1483 return $skinNames[0];
1488 * Installs the auto-detected extensions.
1490 * @return Status
1492 protected function includeExtensions() {
1493 global $IP;
1494 $exts = $this->getVar( '_Extensions' );
1495 $IP = $this->getVar( 'IP' );
1498 * We need to include DefaultSettings before including extensions to avoid
1499 * warnings about unset variables. However, the only thing we really
1500 * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
1501 * if the extension has hidden hook registration in $wgExtensionFunctions,
1502 * but we're not opening that can of worms
1503 * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
1505 global $wgAutoloadClasses;
1506 $wgAutoloadClasses = array();
1508 require "$IP/includes/DefaultSettings.php";
1510 foreach ( $exts as $e ) {
1511 require_once "$IP/extensions/$e/$e.php";
1514 $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
1515 $wgHooks['LoadExtensionSchemaUpdates'] : array();
1517 // Unset everyone else's hooks. Lord knows what someone might be doing
1518 // in ParserFirstCallInit (see bug 27171)
1519 $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
1521 return Status::newGood();
1525 * Get an array of install steps. Should always be in the format of
1526 * array(
1527 * 'name' => 'someuniquename',
1528 * 'callback' => array( $obj, 'method' ),
1530 * There must be a config-install-$name message defined per step, which will
1531 * be shown on install.
1533 * @param DatabaseInstaller $installer DatabaseInstaller so we can make callbacks
1534 * @return array
1536 protected function getInstallSteps( DatabaseInstaller $installer ) {
1537 $coreInstallSteps = array(
1538 array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
1539 array( 'name' => 'tables', 'callback' => array( $installer, 'createTables' ) ),
1540 array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
1541 array( 'name' => 'stats', 'callback' => array( $this, 'populateSiteStats' ) ),
1542 array( 'name' => 'keys', 'callback' => array( $this, 'generateKeys' ) ),
1543 array( 'name' => 'updates', 'callback' => array( $installer, 'insertUpdateKeys' ) ),
1544 array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
1545 array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
1548 // Build the array of install steps starting from the core install list,
1549 // then adding any callbacks that wanted to attach after a given step
1550 foreach ( $coreInstallSteps as $step ) {
1551 $this->installSteps[] = $step;
1552 if ( isset( $this->extraInstallSteps[$step['name']] ) ) {
1553 $this->installSteps = array_merge(
1554 $this->installSteps,
1555 $this->extraInstallSteps[$step['name']]
1560 // Prepend any steps that want to be at the beginning
1561 if ( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
1562 $this->installSteps = array_merge(
1563 $this->extraInstallSteps['BEGINNING'],
1564 $this->installSteps
1568 // Extensions should always go first, chance to tie into hooks and such
1569 if ( count( $this->getVar( '_Extensions' ) ) ) {
1570 array_unshift( $this->installSteps,
1571 array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
1573 $this->installSteps[] = array(
1574 'name' => 'extension-tables',
1575 'callback' => array( $installer, 'createExtensionTables' )
1579 return $this->installSteps;
1583 * Actually perform the installation.
1585 * @param callable $startCB A callback array for the beginning of each step
1586 * @param callable $endCB A callback array for the end of each step
1588 * @return array Array of Status objects
1590 public function performInstallation( $startCB, $endCB ) {
1591 $installResults = array();
1592 $installer = $this->getDBInstaller();
1593 $installer->preInstall();
1594 $steps = $this->getInstallSteps( $installer );
1595 foreach ( $steps as $stepObj ) {
1596 $name = $stepObj['name'];
1597 call_user_func_array( $startCB, array( $name ) );
1599 // Perform the callback step
1600 $status = call_user_func( $stepObj['callback'], $installer );
1602 // Output and save the results
1603 call_user_func( $endCB, $name, $status );
1604 $installResults[$name] = $status;
1606 // If we've hit some sort of fatal, we need to bail.
1607 // Callback already had a chance to do output above.
1608 if ( !$status->isOk() ) {
1609 break;
1612 if ( $status->isOk() ) {
1613 $this->setVar( '_InstallDone', true );
1616 return $installResults;
1620 * Generate $wgSecretKey. Will warn if we had to use an insecure random source.
1622 * @return Status
1624 public function generateKeys() {
1625 $keys = array( 'wgSecretKey' => 64 );
1626 if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
1627 $keys['wgUpgradeKey'] = 16;
1630 return $this->doGenerateKeys( $keys );
1634 * Generate a secret value for variables using our CryptRand generator.
1635 * Produce a warning if the random source was insecure.
1637 * @param array $keys
1638 * @return Status
1640 protected function doGenerateKeys( $keys ) {
1641 $status = Status::newGood();
1643 $strong = true;
1644 foreach ( $keys as $name => $length ) {
1645 $secretKey = MWCryptRand::generateHex( $length, true );
1646 if ( !MWCryptRand::wasStrong() ) {
1647 $strong = false;
1650 $this->setVar( $name, $secretKey );
1653 if ( !$strong ) {
1654 $names = array_keys( $keys );
1655 $names = preg_replace( '/^(.*)$/', '\$$1', $names );
1656 global $wgLang;
1657 $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
1660 return $status;
1664 * Create the first user account, grant it sysop and bureaucrat rights
1666 * @return Status
1668 protected function createSysop() {
1669 $name = $this->getVar( '_AdminName' );
1670 $user = User::newFromName( $name );
1672 if ( !$user ) {
1673 // We should've validated this earlier anyway!
1674 return Status::newFatal( 'config-admin-error-user', $name );
1677 if ( $user->idForName() == 0 ) {
1678 $user->addToDatabase();
1680 try {
1681 $user->setPassword( $this->getVar( '_AdminPassword' ) );
1682 } catch ( PasswordError $pwe ) {
1683 return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
1686 $user->addGroup( 'sysop' );
1687 $user->addGroup( 'bureaucrat' );
1688 if ( $this->getVar( '_AdminEmail' ) ) {
1689 $user->setEmail( $this->getVar( '_AdminEmail' ) );
1691 $user->saveSettings();
1693 // Update user count
1694 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
1695 $ssUpdate->doUpdate();
1697 $status = Status::newGood();
1699 if ( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
1700 $this->subscribeToMediaWikiAnnounce( $status );
1703 return $status;
1707 * @param Status $s
1709 private function subscribeToMediaWikiAnnounce( Status $s ) {
1710 $params = array(
1711 'email' => $this->getVar( '_AdminEmail' ),
1712 'language' => 'en',
1713 'digest' => 0
1716 // Mailman doesn't support as many languages as we do, so check to make
1717 // sure their selected language is available
1718 $myLang = $this->getVar( '_UserLang' );
1719 if ( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
1720 $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
1721 $params['language'] = $myLang;
1724 if ( MWHttpRequest::canMakeRequests() ) {
1725 $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
1726 array( 'method' => 'POST', 'postData' => $params ), __METHOD__ )->execute();
1727 if ( !$res->isOK() ) {
1728 $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
1730 } else {
1731 $s->warning( 'config-install-subscribe-notpossible' );
1736 * Insert Main Page with default content.
1738 * @param DatabaseInstaller $installer
1739 * @return Status
1741 protected function createMainpage( DatabaseInstaller $installer ) {
1742 $status = Status::newGood();
1743 try {
1744 $page = WikiPage::factory( Title::newMainPage() );
1745 $content = new WikitextContent(
1746 wfMessage( 'mainpagetext' )->inContentLanguage()->text() . "\n\n" .
1747 wfMessage( 'mainpagedocfooter' )->inContentLanguage()->text()
1750 $page->doEditContent( $content,
1752 EDIT_NEW,
1753 false,
1754 User::newFromName( 'MediaWiki default' )
1756 } catch ( Exception $e ) {
1757 //using raw, because $wgShowExceptionDetails can not be set yet
1758 $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
1761 return $status;
1765 * Override the necessary bits of the config to run an installation.
1767 public static function overrideConfig() {
1768 define( 'MW_NO_SESSION', 1 );
1770 // Don't access the database
1771 $GLOBALS['wgUseDatabaseMessages'] = false;
1772 // Don't cache langconv tables
1773 $GLOBALS['wgLanguageConverterCacheType'] = CACHE_NONE;
1774 // Debug-friendly
1775 $GLOBALS['wgShowExceptionDetails'] = true;
1776 // Don't break forms
1777 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1779 // Extended debugging
1780 $GLOBALS['wgShowSQLErrors'] = true;
1781 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1783 // Allow multiple ob_flush() calls
1784 $GLOBALS['wgDisableOutputCompression'] = true;
1786 // Use a sensible cookie prefix (not my_wiki)
1787 $GLOBALS['wgCookiePrefix'] = 'mw_installer';
1789 // Some of the environment checks make shell requests, remove limits
1790 $GLOBALS['wgMaxShellMemory'] = 0;
1794 * Add an installation step following the given step.
1796 * @param callable $callback A valid installation callback array, in this form:
1797 * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
1798 * @param string $findStep The step to find. Omit to put the step at the beginning
1800 public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
1801 $this->extraInstallSteps[$findStep][] = $callback;
1805 * Disable the time limit for execution.
1806 * Some long-running pages (Install, Upgrade) will want to do this
1808 protected function disableTimeLimit() {
1809 wfSuppressWarnings();
1810 set_time_limit( 0 );
1811 wfRestoreWarnings();