Few bits of documentation
[lhc/web/wiklou.git] / includes / installer / Installer.php
1 <?php
2 /**
3 * Base code for MediaWiki installer.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * This documentation group collects source code files with deployment functionality.
11 *
12 * @defgroup Deployment Deployment
13 */
14
15 /**
16 * Base installer class.
17 *
18 * This class provides the base for installation and update functionality
19 * for both MediaWiki core and extensions.
20 *
21 * @ingroup Deployment
22 * @since 1.17
23 */
24 abstract class Installer {
25
26 // This is the absolute minimum PHP version we can support
27 const MINIMUM_PHP_VERSION = '5.2.3';
28
29 /**
30 * @var array
31 */
32 protected $settings;
33
34 /**
35 * Cached DB installer instances, access using getDBInstaller().
36 *
37 * @var array
38 */
39 protected $dbInstallers = array();
40
41 /**
42 * Minimum memory size in MB.
43 *
44 * @var integer
45 */
46 protected $minMemorySize = 50;
47
48 /**
49 * Cached Title, used by parse().
50 *
51 * @var Title
52 */
53 protected $parserTitle;
54
55 /**
56 * Cached ParserOptions, used by parse().
57 *
58 * @var ParserOptions
59 */
60 protected $parserOptions;
61
62 /**
63 * Known database types. These correspond to the class names <type>Installer,
64 * and are also MediaWiki database types valid for $wgDBtype.
65 *
66 * To add a new type, create a <type>Installer class and a Database<type>
67 * class, and add a config-type-<type> message to MessagesEn.php.
68 *
69 * @var array
70 */
71 protected static $dbTypes = array(
72 'mysql',
73 'postgres',
74 'oracle',
75 'sqlite',
76 'ibm_db2',
77 );
78
79 /**
80 * A list of environment check methods called by doEnvironmentChecks().
81 * These may output warnings using showMessage(), and/or abort the
82 * installation process by returning false.
83 *
84 * @var array
85 */
86 protected $envChecks = array(
87 'envCheckDB',
88 'envCheckRegisterGlobals',
89 'envCheckBrokenXML',
90 'envCheckPHP531',
91 'envCheckMagicQuotes',
92 'envCheckMagicSybase',
93 'envCheckMbstring',
94 'envCheckZE1',
95 'envCheckSafeMode',
96 'envCheckXML',
97 'envCheckPCRE',
98 'envCheckMemory',
99 'envCheckCache',
100 'envCheckModSecurity',
101 'envCheckDiff3',
102 'envCheckGraphics',
103 'envCheckServer',
104 'envCheckPath',
105 'envCheckExtension',
106 'envCheckShellLocale',
107 'envCheckUploadsDirectory',
108 'envCheckLibicu',
109 'envCheckSuhosinMaxValueLength',
110 );
111
112 /**
113 * MediaWiki configuration globals that will eventually be passed through
114 * to LocalSettings.php. The names only are given here, the defaults
115 * typically come from DefaultSettings.php.
116 *
117 * @var array
118 */
119 protected $defaultVarNames = array(
120 'wgSitename',
121 'wgPasswordSender',
122 'wgLanguageCode',
123 'wgRightsIcon',
124 'wgRightsText',
125 'wgRightsUrl',
126 'wgMainCacheType',
127 'wgEnableEmail',
128 'wgEnableUserEmail',
129 'wgEnotifUserTalk',
130 'wgEnotifWatchlist',
131 'wgEmailAuthentication',
132 'wgDBtype',
133 'wgDiff3',
134 'wgImageMagickConvertCommand',
135 'IP',
136 'wgServer',
137 'wgScriptPath',
138 'wgScriptExtension',
139 'wgMetaNamespace',
140 'wgDeletedDirectory',
141 'wgEnableUploads',
142 'wgLogo',
143 'wgShellLocale',
144 'wgSecretKey',
145 'wgUseInstantCommons',
146 'wgUpgradeKey',
147 'wgDefaultSkin',
148 'wgResourceLoaderMaxQueryLength',
149 );
150
151 /**
152 * Variables that are stored alongside globals, and are used for any
153 * configuration of the installation process aside from the MediaWiki
154 * configuration. Map of names to defaults.
155 *
156 * @var array
157 */
158 protected $internalDefaults = array(
159 '_UserLang' => 'en',
160 '_Environment' => false,
161 '_CompiledDBs' => array(),
162 '_SafeMode' => false,
163 '_RaiseMemory' => false,
164 '_UpgradeDone' => false,
165 '_InstallDone' => false,
166 '_Caches' => array(),
167 '_InstallPassword' => '',
168 '_SameAccount' => true,
169 '_CreateDBAccount' => false,
170 '_NamespaceType' => 'site-name',
171 '_AdminName' => '', // will be set later, when the user selects language
172 '_AdminPassword' => '',
173 '_AdminPassword2' => '',
174 '_AdminEmail' => '',
175 '_Subscribe' => false,
176 '_SkipOptional' => 'continue',
177 '_RightsProfile' => 'wiki',
178 '_LicenseCode' => 'none',
179 '_CCDone' => false,
180 '_Extensions' => array(),
181 '_MemCachedServers' => '',
182 '_UpgradeKeySupplied' => false,
183 '_ExistingDBSettings' => false,
184 );
185
186 /**
187 * The actual list of installation steps. This will be initialized by getInstallSteps()
188 *
189 * @var array
190 */
191 private $installSteps = array();
192
193 /**
194 * Extra steps for installation, for things like DatabaseInstallers to modify
195 *
196 * @var array
197 */
198 protected $extraInstallSteps = array();
199
200 /**
201 * Known object cache types and the functions used to test for their existence.
202 *
203 * @var array
204 */
205 protected $objectCaches = array(
206 'xcache' => 'xcache_get',
207 'apc' => 'apc_fetch',
208 'eaccel' => 'eaccelerator_get',
209 'wincache' => 'wincache_ucache_get'
210 );
211
212 /**
213 * User rights profiles.
214 *
215 * @var array
216 */
217 public $rightsProfiles = array(
218 'wiki' => array(),
219 'no-anon' => array(
220 '*' => array( 'edit' => false )
221 ),
222 'fishbowl' => array(
223 '*' => array(
224 'createaccount' => false,
225 'edit' => false,
226 ),
227 ),
228 'private' => array(
229 '*' => array(
230 'createaccount' => false,
231 'edit' => false,
232 'read' => false,
233 ),
234 ),
235 );
236
237 /**
238 * License types.
239 *
240 * @var array
241 */
242 public $licenses = array(
243 'cc-by' => array(
244 'url' => 'http://creativecommons.org/licenses/by/3.0/',
245 'icon' => '{$wgStylePath}/common/images/cc-by.png',
246 ),
247 'cc-by-sa' => array(
248 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
249 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
250 ),
251 'cc-by-nc-sa' => array(
252 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
253 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
254 ),
255 'cc-0' => array(
256 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
257 'icon' => '{$wgStylePath}/common/images/cc-0.png',
258 ),
259 'pd' => array(
260 'url' => '',
261 'icon' => '{$wgStylePath}/common/images/public-domain.png',
262 ),
263 'gfdl' => array(
264 'url' => 'http://www.gnu.org/copyleft/fdl.html',
265 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
266 ),
267 'none' => array(
268 'url' => '',
269 'icon' => '',
270 'text' => ''
271 ),
272 'cc-choose' => array(
273 // Details will be filled in by the selector.
274 'url' => '',
275 'icon' => '',
276 'text' => '',
277 ),
278 );
279
280 /**
281 * URL to mediawiki-announce subscription
282 */
283 protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
284
285 /**
286 * Supported language codes for Mailman
287 */
288 protected $mediaWikiAnnounceLanguages = array(
289 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
290 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
291 'sl', 'sr', 'sv', 'tr', 'uk'
292 );
293
294 /**
295 * UI interface for displaying a short message
296 * The parameters are like parameters to wfMsg().
297 * The messages will be in wikitext format, which will be converted to an
298 * output format such as HTML or text before being sent to the user.
299 * @param $msg
300 */
301 public abstract function showMessage( $msg /*, ... */ );
302
303 /**
304 * Same as showMessage(), but for displaying errors
305 * @param $msg
306 */
307 public abstract function showError( $msg /*, ... */ );
308
309 /**
310 * Show a message to the installing user by using a Status object
311 * @param $status Status
312 */
313 public abstract function showStatusMessage( Status $status );
314
315 /**
316 * Constructor, always call this from child classes.
317 */
318 public function __construct() {
319 global $wgExtensionMessagesFiles, $wgUser;
320
321 // Disable the i18n cache and LoadBalancer
322 Language::getLocalisationCache()->disableBackend();
323 LBFactory::disableBackend();
324
325 // Load the installer's i18n file.
326 $wgExtensionMessagesFiles['MediawikiInstaller'] =
327 dirname( __FILE__ ) . '/Installer.i18n.php';
328
329 // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
330 $wgUser = User::newFromId( 0 );
331
332 $this->settings = $this->internalDefaults;
333
334 foreach ( $this->defaultVarNames as $var ) {
335 $this->settings[$var] = $GLOBALS[$var];
336 }
337
338 $compiledDBs = array();
339 foreach ( self::getDBTypes() as $type ) {
340 $installer = $this->getDBInstaller( $type );
341
342 if ( !$installer->isCompiled() ) {
343 continue;
344 }
345 $compiledDBs[] = $type;
346
347 $defaults = $installer->getGlobalDefaults();
348
349 foreach ( $installer->getGlobalNames() as $var ) {
350 if ( isset( $defaults[$var] ) ) {
351 $this->settings[$var] = $defaults[$var];
352 } else {
353 $this->settings[$var] = $GLOBALS[$var];
354 }
355 }
356 }
357 $this->setVar( '_CompiledDBs', $compiledDBs );
358
359 $this->parserTitle = Title::newFromText( 'Installer' );
360 $this->parserOptions = new ParserOptions; // language will be wrong :(
361 $this->parserOptions->setEditSection( false );
362 }
363
364 /**
365 * Get a list of known DB types.
366 *
367 * @return array
368 */
369 public static function getDBTypes() {
370 return self::$dbTypes;
371 }
372
373 /**
374 * Do initial checks of the PHP environment. Set variables according to
375 * the observed environment.
376 *
377 * It's possible that this may be called under the CLI SAPI, not the SAPI
378 * that the wiki will primarily run under. In that case, the subclass should
379 * initialise variables such as wgScriptPath, before calling this function.
380 *
381 * Under the web subclass, it can already be assumed that PHP 5+ is in use
382 * and that sessions are working.
383 *
384 * @return Status
385 */
386 public function doEnvironmentChecks() {
387 $phpVersion = phpversion();
388 if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
389 $this->showMessage( 'config-env-php', $phpVersion );
390 $good = true;
391 } else {
392 $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
393 $good = false;
394 }
395
396 if( $good ) {
397 foreach ( $this->envChecks as $check ) {
398 $status = $this->$check();
399 if ( $status === false ) {
400 $good = false;
401 }
402 }
403 }
404
405 $this->setVar( '_Environment', $good );
406
407 return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
408 }
409
410 /**
411 * Set a MW configuration variable, or internal installer configuration variable.
412 *
413 * @param $name String
414 * @param $value Mixed
415 */
416 public function setVar( $name, $value ) {
417 $this->settings[$name] = $value;
418 }
419
420 /**
421 * Get an MW configuration variable, or internal installer configuration variable.
422 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
423 * Installer variables are typically prefixed by an underscore.
424 *
425 * @param $name String
426 * @param $default Mixed
427 *
428 * @return mixed
429 */
430 public function getVar( $name, $default = null ) {
431 if ( !isset( $this->settings[$name] ) ) {
432 return $default;
433 } else {
434 return $this->settings[$name];
435 }
436 }
437
438 /**
439 * Get an instance of DatabaseInstaller for the specified DB type.
440 *
441 * @param $type Mixed: DB installer for which is needed, false to use default.
442 *
443 * @return DatabaseInstaller
444 */
445 public function getDBInstaller( $type = false ) {
446 if ( !$type ) {
447 $type = $this->getVar( 'wgDBtype' );
448 }
449
450 $type = strtolower( $type );
451
452 if ( !isset( $this->dbInstallers[$type] ) ) {
453 $class = ucfirst( $type ). 'Installer';
454 $this->dbInstallers[$type] = new $class( $this );
455 }
456
457 return $this->dbInstallers[$type];
458 }
459
460 /**
461 * Determine if LocalSettings.php exists. If it does, return its variables,
462 * merged with those from AdminSettings.php, as an array.
463 *
464 * @return Array
465 */
466 public static function getExistingLocalSettings() {
467 global $IP;
468
469 wfSuppressWarnings();
470 $_lsExists = file_exists( "$IP/LocalSettings.php" );
471 wfRestoreWarnings();
472
473 if( !$_lsExists ) {
474 return false;
475 }
476 unset($_lsExists);
477
478 require( "$IP/includes/DefaultSettings.php" );
479 require( "$IP/LocalSettings.php" );
480 if ( file_exists( "$IP/AdminSettings.php" ) ) {
481 require( "$IP/AdminSettings.php" );
482 }
483 return get_defined_vars();
484 }
485
486 /**
487 * Get a fake password for sending back to the user in HTML.
488 * This is a security mechanism to avoid compromise of the password in the
489 * event of session ID compromise.
490 *
491 * @param $realPassword String
492 *
493 * @return string
494 */
495 public function getFakePassword( $realPassword ) {
496 return str_repeat( '*', strlen( $realPassword ) );
497 }
498
499 /**
500 * Set a variable which stores a password, except if the new value is a
501 * fake password in which case leave it as it is.
502 *
503 * @param $name String
504 * @param $value Mixed
505 */
506 public function setPassword( $name, $value ) {
507 if ( !preg_match( '/^\*+$/', $value ) ) {
508 $this->setVar( $name, $value );
509 }
510 }
511
512 /**
513 * On POSIX systems return the primary group of the webserver we're running under.
514 * On other systems just returns null.
515 *
516 * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
517 * webserver user before he can install.
518 *
519 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
520 *
521 * @return mixed
522 */
523 public static function maybeGetWebserverPrimaryGroup() {
524 if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
525 # I don't know this, this isn't UNIX.
526 return null;
527 }
528
529 # posix_getegid() *not* getmygid() because we want the group of the webserver,
530 # not whoever owns the current script.
531 $gid = posix_getegid();
532 $getpwuid = posix_getpwuid( $gid );
533 $group = $getpwuid['name'];
534
535 return $group;
536 }
537
538 /**
539 * Convert wikitext $text to HTML.
540 *
541 * This is potentially error prone since many parser features require a complete
542 * installed MW database. The solution is to just not use those features when you
543 * write your messages. This appears to work well enough. Basic formatting and
544 * external links work just fine.
545 *
546 * But in case a translator decides to throw in a #ifexist or internal link or
547 * whatever, this function is guarded to catch the attempted DB access and to present
548 * some fallback text.
549 *
550 * @param $text String
551 * @param $lineStart Boolean
552 * @return String
553 */
554 public function parse( $text, $lineStart = false ) {
555 global $wgParser;
556
557 try {
558 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
559 $html = $out->getText();
560 } catch ( DBAccessError $e ) {
561 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
562
563 if ( !empty( $this->debug ) ) {
564 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
565 }
566 }
567
568 return $html;
569 }
570
571 /**
572 * @return ParserOptions
573 */
574 public function getParserOptions() {
575 return $this->parserOptions;
576 }
577
578 public function disableLinkPopups() {
579 $this->parserOptions->setExternalLinkTarget( false );
580 }
581
582 public function restoreLinkPopups() {
583 global $wgExternalLinkTarget;
584 $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
585 }
586
587 /**
588 * Install step which adds a row to the site_stats table with appropriate
589 * initial values.
590 *
591 * @param $installer DatabaseInstaller
592 *
593 * @return Status
594 */
595 public function populateSiteStats( DatabaseInstaller $installer ) {
596 $status = $installer->getConnection();
597 if ( !$status->isOK() ) {
598 return $status;
599 }
600 $status->value->insert( 'site_stats', array(
601 'ss_row_id' => 1,
602 'ss_total_views' => 0,
603 'ss_total_edits' => 0,
604 'ss_good_articles' => 0,
605 'ss_total_pages' => 0,
606 'ss_users' => 0,
607 'ss_admins' => 0,
608 'ss_images' => 0 ),
609 __METHOD__, 'IGNORE' );
610 return Status::newGood();
611 }
612
613 /**
614 * Exports all wg* variables stored by the installer into global scope.
615 */
616 public function exportVars() {
617 foreach ( $this->settings as $name => $value ) {
618 if ( substr( $name, 0, 2 ) == 'wg' ) {
619 $GLOBALS[$name] = $value;
620 }
621 }
622 }
623
624 /**
625 * Environment check for DB types.
626 * @return bool
627 */
628 protected function envCheckDB() {
629 global $wgLang;
630
631 $allNames = array();
632
633 foreach ( self::getDBTypes() as $name ) {
634 $allNames[] = wfMsg( "config-type-$name" );
635 }
636
637 if ( !$this->getVar( '_CompiledDBs' ) ) {
638 $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
639 // @todo FIXME: This only works for the web installer!
640 return false;
641 }
642
643 // Check for FTS3 full-text search module
644 $sqlite = $this->getDBInstaller( 'sqlite' );
645 if ( $sqlite->isCompiled() ) {
646 if( DatabaseSqlite::getFulltextSearchModule() != 'FTS3' ) {
647 $this->showMessage( 'config-no-fts3' );
648 }
649 }
650 }
651
652 /**
653 * Environment check for register_globals.
654 */
655 protected function envCheckRegisterGlobals() {
656 if( wfIniGetBool( 'register_globals' ) ) {
657 $this->showMessage( 'config-register-globals' );
658 }
659 }
660
661 /**
662 * Some versions of libxml+PHP break < and > encoding horribly
663 */
664 protected function envCheckBrokenXML() {
665 $test = new PhpXmlBugTester();
666 if ( !$test->ok ) {
667 $this->showError( 'config-brokenlibxml' );
668 return false;
669 }
670 }
671
672 /**
673 * Test PHP (probably 5.3.1, but it could regress again) to make sure that
674 * reference parameters to __call() are not converted to null
675 */
676 protected function envCheckPHP531() {
677 $test = new PhpRefCallBugTester;
678 $test->execute();
679 if ( !$test->ok ) {
680 $this->showError( 'config-using531', phpversion() );
681 return false;
682 }
683 }
684
685 /**
686 * Environment check for magic_quotes_runtime.
687 */
688 protected function envCheckMagicQuotes() {
689 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
690 $this->showError( 'config-magic-quotes-runtime' );
691 return false;
692 }
693 }
694
695 /**
696 * Environment check for magic_quotes_sybase.
697 */
698 protected function envCheckMagicSybase() {
699 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
700 $this->showError( 'config-magic-quotes-sybase' );
701 return false;
702 }
703 }
704
705 /**
706 * Environment check for mbstring.func_overload.
707 */
708 protected function envCheckMbstring() {
709 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
710 $this->showError( 'config-mbstring' );
711 return false;
712 }
713 }
714
715 /**
716 * Environment check for zend.ze1_compatibility_mode.
717 */
718 protected function envCheckZE1() {
719 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
720 $this->showError( 'config-ze1' );
721 return false;
722 }
723 }
724
725 /**
726 * Environment check for safe_mode.
727 */
728 protected function envCheckSafeMode() {
729 if ( wfIniGetBool( 'safe_mode' ) ) {
730 $this->setVar( '_SafeMode', true );
731 $this->showMessage( 'config-safe-mode' );
732 }
733 }
734
735 /**
736 * Environment check for the XML module.
737 */
738 protected function envCheckXML() {
739 if ( !function_exists( "utf8_encode" ) ) {
740 $this->showError( 'config-xml-bad' );
741 return false;
742 }
743 }
744
745 /**
746 * Environment check for the PCRE module.
747 */
748 protected function envCheckPCRE() {
749 if ( !function_exists( 'preg_match' ) ) {
750 $this->showError( 'config-pcre' );
751 return false;
752 }
753 wfSuppressWarnings();
754 $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
755 wfRestoreWarnings();
756 if ( $regexd != '--' ) {
757 $this->showError( 'config-pcre-no-utf8' );
758 return false;
759 }
760 }
761
762 /**
763 * Environment check for available memory.
764 */
765 protected function envCheckMemory() {
766 $limit = ini_get( 'memory_limit' );
767
768 if ( !$limit || $limit == -1 ) {
769 return true;
770 }
771
772 $n = wfShorthandToInteger( $limit );
773
774 if( $n < $this->minMemorySize * 1024 * 1024 ) {
775 $newLimit = "{$this->minMemorySize}M";
776
777 if( ini_set( "memory_limit", $newLimit ) === false ) {
778 $this->showMessage( 'config-memory-bad', $limit );
779 } else {
780 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
781 $this->setVar( '_RaiseMemory', true );
782 }
783 } else {
784 return true;
785 }
786 }
787
788 /**
789 * Environment check for compiled object cache types.
790 */
791 protected function envCheckCache() {
792 $caches = array();
793 foreach ( $this->objectCaches as $name => $function ) {
794 if ( function_exists( $function ) ) {
795 if ( $name == 'xcache' && !wfIniGetBool( 'xcache.var_size' ) ) {
796 continue;
797 }
798 $caches[$name] = true;
799 }
800 }
801
802 if ( !$caches ) {
803 $this->showMessage( 'config-no-cache' );
804 }
805
806 $this->setVar( '_Caches', $caches );
807 }
808
809 /**
810 * Scare user to death if they have mod_security
811 */
812 protected function envCheckModSecurity() {
813 if ( self::apacheModulePresent( 'mod_security' ) ) {
814 $this->showMessage( 'config-mod-security' );
815 }
816 }
817
818 /**
819 * Search for GNU diff3.
820 */
821 protected function envCheckDiff3() {
822 $names = array( "gdiff3", "diff3", "diff3.exe" );
823 $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
824
825 $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
826
827 if ( $diff3 ) {
828 $this->setVar( 'wgDiff3', $diff3 );
829 } else {
830 $this->setVar( 'wgDiff3', false );
831 $this->showMessage( 'config-diff3-bad' );
832 }
833 }
834
835 /**
836 * Environment check for ImageMagick and GD.
837 */
838 protected function envCheckGraphics() {
839 $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
840 $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
841
842 $this->setVar( 'wgImageMagickConvertCommand', '' );
843 if ( $convert ) {
844 $this->setVar( 'wgImageMagickConvertCommand', $convert );
845 $this->showMessage( 'config-imagemagick', $convert );
846 return true;
847 } elseif ( function_exists( 'imagejpeg' ) ) {
848 $this->showMessage( 'config-gd' );
849 return true;
850 } else {
851 $this->showMessage( 'config-no-scaling' );
852 }
853 }
854
855 /**
856 * Environment check for the server hostname.
857 */
858 protected function envCheckServer() {
859 if ( $this->getVar( 'wgServer' ) ) {
860 // wgServer was pre-defined, perhaps by the cli installer
861 $server = $this->getVar( 'wgServer' );
862 } else {
863 $server = WebRequest::detectServer();
864 }
865 $this->showMessage( 'config-using-server', $server );
866 $this->setVar( 'wgServer', $server );
867 }
868
869 /**
870 * Environment check for setting $IP and $wgScriptPath.
871 * @return bool
872 */
873 protected function envCheckPath() {
874 global $IP;
875 $IP = dirname( dirname( dirname( __FILE__ ) ) );
876 $this->setVar( 'IP', $IP );
877
878 $this->showMessage( 'config-using-uri', $this->getVar( 'wgServer' ), $this->getVar( 'wgScriptPath' ) );
879 return true;
880 }
881
882 /**
883 * Environment check for setting the preferred PHP file extension.
884 */
885 protected function envCheckExtension() {
886 // @todo FIXME: Detect this properly
887 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
888 $ext = 'php5';
889 } else {
890 $ext = 'php';
891 }
892 $this->setVar( 'wgScriptExtension', ".$ext" );
893 }
894
895 /**
896 * TODO: document
897 * @return bool
898 */
899 protected function envCheckShellLocale() {
900 $os = php_uname( 's' );
901 $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
902
903 if ( !in_array( $os, $supported ) ) {
904 return true;
905 }
906
907 # Get a list of available locales.
908 $ret = false;
909 $lines = wfShellExec( '/usr/bin/locale -a', $ret );
910
911 if ( $ret ) {
912 return true;
913 }
914
915 $lines = wfArrayMap( 'trim', explode( "\n", $lines ) );
916 $candidatesByLocale = array();
917 $candidatesByLang = array();
918
919 foreach ( $lines as $line ) {
920 if ( $line === '' ) {
921 continue;
922 }
923
924 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
925 continue;
926 }
927
928 list( $all, $lang, $territory, $charset, $modifier ) = $m;
929
930 $candidatesByLocale[$m[0]] = $m;
931 $candidatesByLang[$lang][] = $m;
932 }
933
934 # Try the current value of LANG.
935 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
936 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
937 return true;
938 }
939
940 # Try the most common ones.
941 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
942 foreach ( $commonLocales as $commonLocale ) {
943 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
944 $this->setVar( 'wgShellLocale', $commonLocale );
945 return true;
946 }
947 }
948
949 # Is there an available locale in the Wiki's language?
950 $wikiLang = $this->getVar( 'wgLanguageCode' );
951
952 if ( isset( $candidatesByLang[$wikiLang] ) ) {
953 $m = reset( $candidatesByLang[$wikiLang] );
954 $this->setVar( 'wgShellLocale', $m[0] );
955 return true;
956 }
957
958 # Are there any at all?
959 if ( count( $candidatesByLocale ) ) {
960 $m = reset( $candidatesByLocale );
961 $this->setVar( 'wgShellLocale', $m[0] );
962 return true;
963 }
964
965 # Give up.
966 return true;
967 }
968
969 /**
970 * TODO: document
971 */
972 protected function envCheckUploadsDirectory() {
973 global $IP;
974
975 $dir = $IP . '/images/';
976 $url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/';
977 $safe = !$this->dirIsExecutable( $dir, $url );
978
979 if ( $safe ) {
980 return true;
981 } else {
982 $this->showMessage( 'config-uploads-not-safe', $dir );
983 }
984 }
985
986 /**
987 * Checks if suhosin.get.max_value_length is set, and if so, sets
988 * $wgResourceLoaderMaxQueryLength to that value in the generated
989 * LocalSettings file
990 */
991 protected function envCheckSuhosinMaxValueLength() {
992 $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
993 if ( $maxValueLength > 0 ) {
994 if( $maxValueLength < 1024 ) {
995 # Only warn if the value is below the sane 1024
996 $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
997 }
998 } else {
999 $maxValueLength = -1;
1000 }
1001 $this->setVar( 'wgResourceLoaderMaxQueryLength', $maxValueLength );
1002 }
1003
1004 /**
1005 * Convert a hex string representing a Unicode code point to that code point.
1006 * @param $c String
1007 * @return string
1008 */
1009 protected function unicodeChar( $c ) {
1010 $c = hexdec($c);
1011 if ($c <= 0x7F) {
1012 return chr($c);
1013 } elseif ($c <= 0x7FF) {
1014 return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
1015 } elseif ($c <= 0xFFFF) {
1016 return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
1017 . chr(0x80 | $c & 0x3F);
1018 } elseif ($c <= 0x10FFFF) {
1019 return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
1020 . chr(0x80 | $c >> 6 & 0x3F)
1021 . chr(0x80 | $c & 0x3F);
1022 } else {
1023 return false;
1024 }
1025 }
1026
1027
1028 /**
1029 * Check the libicu version
1030 */
1031 protected function envCheckLibicu() {
1032 $utf8 = function_exists( 'utf8_normalize' );
1033 $intl = function_exists( 'normalizer_normalize' );
1034
1035 /**
1036 * This needs to be updated something that the latest libicu
1037 * will properly normalize. This normalization was found at
1038 * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
1039 * Note that we use the hex representation to create the code
1040 * points in order to avoid any Unicode-destroying during transit.
1041 */
1042 $not_normal_c = $this->unicodeChar("FA6C");
1043 $normal_c = $this->unicodeChar("242EE");
1044
1045 $useNormalizer = 'php';
1046 $needsUpdate = false;
1047
1048 /**
1049 * We're going to prefer the pecl extension here unless
1050 * utf8_normalize is more up to date.
1051 */
1052 if( $utf8 ) {
1053 $useNormalizer = 'utf8';
1054 $utf8 = utf8_normalize( $not_normal_c, UtfNormal::UNORM_NFC );
1055 if ( $utf8 !== $normal_c ) $needsUpdate = true;
1056 }
1057 if( $intl ) {
1058 $useNormalizer = 'intl';
1059 $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
1060 if ( $intl !== $normal_c ) $needsUpdate = true;
1061 }
1062
1063 // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
1064 if( $useNormalizer === 'php' ) {
1065 $this->showMessage( 'config-unicode-pure-php-warning' );
1066 } else {
1067 $this->showMessage( 'config-unicode-using-' . $useNormalizer );
1068 if( $needsUpdate ) {
1069 $this->showMessage( 'config-unicode-update-warning' );
1070 }
1071 }
1072 }
1073
1074 /**
1075 * Get an array of likely places we can find executables. Check a bunch
1076 * of known Unix-like defaults, as well as the PATH environment variable
1077 * (which should maybe make it work for Windows?)
1078 *
1079 * @return Array
1080 */
1081 protected static function getPossibleBinPaths() {
1082 return array_merge(
1083 array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
1084 '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
1085 explode( PATH_SEPARATOR, getenv( 'PATH' ) )
1086 );
1087 }
1088
1089 /**
1090 * Search a path for any of the given executable names. Returns the
1091 * executable name if found. Also checks the version string returned
1092 * by each executable.
1093 *
1094 * Used only by environment checks.
1095 *
1096 * @param $path String: path to search
1097 * @param $names Array of executable names
1098 * @param $versionInfo Boolean false or array with two members:
1099 * 0 => Command to run for version check, with $1 for the full executable name
1100 * 1 => String to compare the output with
1101 *
1102 * If $versionInfo is not false, only executables with a version
1103 * matching $versionInfo[1] will be returned.
1104 */
1105 public static function locateExecutable( $path, $names, $versionInfo = false ) {
1106 if ( !is_array( $names ) ) {
1107 $names = array( $names );
1108 }
1109
1110 foreach ( $names as $name ) {
1111 $command = $path . DIRECTORY_SEPARATOR . $name;
1112
1113 wfSuppressWarnings();
1114 $file_exists = file_exists( $command );
1115 wfRestoreWarnings();
1116
1117 if ( $file_exists ) {
1118 if ( !$versionInfo ) {
1119 return $command;
1120 }
1121
1122 $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
1123 if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
1124 return $command;
1125 }
1126 }
1127 }
1128 return false;
1129 }
1130
1131 /**
1132 * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
1133 * @see locateExecutable()
1134 * @param $names
1135 * @param $versionInfo bool
1136 * @return bool|string
1137 */
1138 public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
1139 foreach( self::getPossibleBinPaths() as $path ) {
1140 $exe = self::locateExecutable( $path, $names, $versionInfo );
1141 if( $exe !== false ) {
1142 return $exe;
1143 }
1144 }
1145 return false;
1146 }
1147
1148 /**
1149 * Checks if scripts located in the given directory can be executed via the given URL.
1150 *
1151 * Used only by environment checks.
1152 */
1153 public function dirIsExecutable( $dir, $url ) {
1154 $scriptTypes = array(
1155 'php' => array(
1156 "<?php echo 'ex' . 'ec';",
1157 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
1158 ),
1159 );
1160
1161 // it would be good to check other popular languages here, but it'll be slow.
1162
1163 wfSuppressWarnings();
1164
1165 foreach ( $scriptTypes as $ext => $contents ) {
1166 foreach ( $contents as $source ) {
1167 $file = 'exectest.' . $ext;
1168
1169 if ( !file_put_contents( $dir . $file, $source ) ) {
1170 break;
1171 }
1172
1173 try {
1174 $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
1175 }
1176 catch( MWException $e ) {
1177 // Http::get throws with allow_url_fopen = false and no curl extension.
1178 $text = null;
1179 }
1180 unlink( $dir . $file );
1181
1182 if ( $text == 'exec' ) {
1183 wfRestoreWarnings();
1184 return $ext;
1185 }
1186 }
1187 }
1188
1189 wfRestoreWarnings();
1190
1191 return false;
1192 }
1193
1194 /**
1195 * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too.
1196 *
1197 * @param $moduleName String: Name of module to check.
1198 * @return bool
1199 */
1200 public static function apacheModulePresent( $moduleName ) {
1201 if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) {
1202 return true;
1203 }
1204 // try it the hard way
1205 ob_start();
1206 phpinfo( INFO_MODULES );
1207 $info = ob_get_clean();
1208 return strpos( $info, $moduleName ) !== false;
1209 }
1210
1211 /**
1212 * ParserOptions are constructed before we determined the language, so fix it
1213 *
1214 * @param $lang Language
1215 */
1216 public function setParserLanguage( $lang ) {
1217 $this->parserOptions->setTargetLanguage( $lang );
1218 $this->parserOptions->setUserLang( $lang );
1219 }
1220
1221 /**
1222 * Overridden by WebInstaller to provide lastPage parameters.
1223 * @param $page stirng
1224 * @return string
1225 */
1226 protected function getDocUrl( $page ) {
1227 return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1228 }
1229
1230 /**
1231 * Finds extensions that follow the format /extensions/Name/Name.php,
1232 * and returns an array containing the value for 'Name' for each found extension.
1233 *
1234 * @return array
1235 */
1236 public function findExtensions() {
1237 if( $this->getVar( 'IP' ) === null ) {
1238 return false;
1239 }
1240
1241 $exts = array();
1242 $extDir = $this->getVar( 'IP' ) . '/extensions';
1243 $dh = opendir( $extDir );
1244
1245 while ( ( $file = readdir( $dh ) ) !== false ) {
1246 if( !is_dir( "$extDir/$file" ) ) {
1247 continue;
1248 }
1249 if( file_exists( "$extDir/$file/$file.php" ) ) {
1250 $exts[] = $file;
1251 }
1252 }
1253
1254 return $exts;
1255 }
1256
1257 /**
1258 * Installs the auto-detected extensions.
1259 *
1260 * @return Status
1261 */
1262 protected function includeExtensions() {
1263 global $IP;
1264 $exts = $this->getVar( '_Extensions' );
1265 $IP = $this->getVar( 'IP' );
1266
1267 /**
1268 * We need to include DefaultSettings before including extensions to avoid
1269 * warnings about unset variables. However, the only thing we really
1270 * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
1271 * if the extension has hidden hook registration in $wgExtensionFunctions,
1272 * but we're not opening that can of worms
1273 * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
1274 */
1275 global $wgAutoloadClasses;
1276 $wgAutoloadClasses = array();
1277
1278 require( "$IP/includes/DefaultSettings.php" );
1279
1280 foreach( $exts as $e ) {
1281 require_once( "$IP/extensions/$e/$e.php" );
1282 }
1283
1284 $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
1285 $wgHooks['LoadExtensionSchemaUpdates'] : array();
1286
1287 // Unset everyone else's hooks. Lord knows what someone might be doing
1288 // in ParserFirstCallInit (see bug 27171)
1289 $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
1290
1291 return Status::newGood();
1292 }
1293
1294 /**
1295 * Get an array of install steps. Should always be in the format of
1296 * array(
1297 * 'name' => 'someuniquename',
1298 * 'callback' => array( $obj, 'method' ),
1299 * )
1300 * There must be a config-install-$name message defined per step, which will
1301 * be shown on install.
1302 *
1303 * @param $installer DatabaseInstaller so we can make callbacks
1304 * @return array
1305 */
1306 protected function getInstallSteps( DatabaseInstaller $installer ) {
1307 $coreInstallSteps = array(
1308 array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
1309 array( 'name' => 'tables', 'callback' => array( $installer, 'createTables' ) ),
1310 array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
1311 array( 'name' => 'stats', 'callback' => array( $this, 'populateSiteStats' ) ),
1312 array( 'name' => 'keys', 'callback' => array( $this, 'generateKeys' ) ),
1313 array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
1314 array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
1315 );
1316
1317 // Build the array of install steps starting from the core install list,
1318 // then adding any callbacks that wanted to attach after a given step
1319 foreach( $coreInstallSteps as $step ) {
1320 $this->installSteps[] = $step;
1321 if( isset( $this->extraInstallSteps[ $step['name'] ] ) ) {
1322 $this->installSteps = array_merge(
1323 $this->installSteps,
1324 $this->extraInstallSteps[ $step['name'] ]
1325 );
1326 }
1327 }
1328
1329 // Prepend any steps that want to be at the beginning
1330 if( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
1331 $this->installSteps = array_merge(
1332 $this->extraInstallSteps['BEGINNING'],
1333 $this->installSteps
1334 );
1335 }
1336
1337 // Extensions should always go first, chance to tie into hooks and such
1338 if( count( $this->getVar( '_Extensions' ) ) ) {
1339 array_unshift( $this->installSteps,
1340 array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
1341 );
1342 $this->installSteps[] = array(
1343 'name' => 'extension-tables',
1344 'callback' => array( $installer, 'createExtensionTables' )
1345 );
1346 }
1347 return $this->installSteps;
1348 }
1349
1350 /**
1351 * Actually perform the installation.
1352 *
1353 * @param $startCB Array A callback array for the beginning of each step
1354 * @param $endCB Array A callback array for the end of each step
1355 *
1356 * @return Array of Status objects
1357 */
1358 public function performInstallation( $startCB, $endCB ) {
1359 $installResults = array();
1360 $installer = $this->getDBInstaller();
1361 $installer->preInstall();
1362 $steps = $this->getInstallSteps( $installer );
1363 foreach( $steps as $stepObj ) {
1364 $name = $stepObj['name'];
1365 call_user_func_array( $startCB, array( $name ) );
1366
1367 // Perform the callback step
1368 $status = call_user_func( $stepObj['callback'], $installer );
1369
1370 // Output and save the results
1371 call_user_func( $endCB, $name, $status );
1372 $installResults[$name] = $status;
1373
1374 // If we've hit some sort of fatal, we need to bail.
1375 // Callback already had a chance to do output above.
1376 if( !$status->isOk() ) {
1377 break;
1378 }
1379 }
1380 if( $status->isOk() ) {
1381 $this->setVar( '_InstallDone', true );
1382 }
1383 return $installResults;
1384 }
1385
1386 /**
1387 * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
1388 * /dev/urandom
1389 *
1390 * @return Status
1391 */
1392 public function generateKeys() {
1393 $keys = array( 'wgSecretKey' => 64 );
1394 if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
1395 $keys['wgUpgradeKey'] = 16;
1396 }
1397 return $this->doGenerateKeys( $keys );
1398 }
1399
1400 /**
1401 * Generate a secret value for variables using either
1402 * /dev/urandom or mt_rand(). Produce a warning in the later case.
1403 *
1404 * @param $keys Array
1405 * @return Status
1406 */
1407 protected function doGenerateKeys( $keys ) {
1408 $status = Status::newGood();
1409
1410 wfSuppressWarnings();
1411 $file = fopen( "/dev/urandom", "r" );
1412 wfRestoreWarnings();
1413
1414 foreach ( $keys as $name => $length ) {
1415 if ( $file ) {
1416 $secretKey = bin2hex( fread( $file, $length / 2 ) );
1417 } else {
1418 $secretKey = '';
1419
1420 for ( $i = 0; $i < $length / 8; $i++ ) {
1421 $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
1422 }
1423 }
1424
1425 $this->setVar( $name, $secretKey );
1426 }
1427
1428 if ( $file ) {
1429 fclose( $file );
1430 } else {
1431 $names = array_keys ( $keys );
1432 $names = preg_replace( '/^(.*)$/', '\$$1', $names );
1433 global $wgLang;
1434 $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
1435 }
1436
1437 return $status;
1438 }
1439
1440 /**
1441 * Create the first user account, grant it sysop and bureaucrat rights
1442 *
1443 * @return Status
1444 */
1445 protected function createSysop() {
1446 $name = $this->getVar( '_AdminName' );
1447 $user = User::newFromName( $name );
1448
1449 if ( !$user ) {
1450 // We should've validated this earlier anyway!
1451 return Status::newFatal( 'config-admin-error-user', $name );
1452 }
1453
1454 if ( $user->idForName() == 0 ) {
1455 $user->addToDatabase();
1456
1457 try {
1458 $user->setPassword( $this->getVar( '_AdminPassword' ) );
1459 } catch( PasswordError $pwe ) {
1460 return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
1461 }
1462
1463 $user->addGroup( 'sysop' );
1464 $user->addGroup( 'bureaucrat' );
1465 if( $this->getVar( '_AdminEmail' ) ) {
1466 $user->setEmail( $this->getVar( '_AdminEmail' ) );
1467 }
1468 $user->saveSettings();
1469
1470 // Update user count
1471 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
1472 $ssUpdate->doUpdate();
1473 }
1474 $status = Status::newGood();
1475
1476 if( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
1477 $this->subscribeToMediaWikiAnnounce( $status );
1478 }
1479
1480 return $status;
1481 }
1482
1483 /**
1484 * @param $s Status
1485 */
1486 private function subscribeToMediaWikiAnnounce( Status $s ) {
1487 $params = array(
1488 'email' => $this->getVar( '_AdminEmail' ),
1489 'language' => 'en',
1490 'digest' => 0
1491 );
1492
1493 // Mailman doesn't support as many languages as we do, so check to make
1494 // sure their selected language is available
1495 $myLang = $this->getVar( '_UserLang' );
1496 if( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
1497 $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
1498 $params['language'] = $myLang;
1499 }
1500
1501 if( MWHttpRequest::canMakeRequests() ) {
1502 $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
1503 array( 'method' => 'POST', 'postData' => $params ) )->execute();
1504 if( !$res->isOK() ) {
1505 $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
1506 }
1507 } else {
1508 $s->warning( 'config-install-subscribe-notpossible' );
1509 }
1510 }
1511
1512 /**
1513 * Insert Main Page with default content.
1514 *
1515 * @param $installer DatabaseInstaller
1516 * @return Status
1517 */
1518 protected function createMainpage( DatabaseInstaller $installer ) {
1519 $status = Status::newGood();
1520 try {
1521 $article = new Article( Title::newMainPage() );
1522 $article->doEdit( wfMsgForContent( 'mainpagetext' ) . "\n\n" .
1523 wfMsgForContent( 'mainpagedocfooter' ),
1524 '',
1525 EDIT_NEW,
1526 false,
1527 User::newFromName( 'MediaWiki default' ) );
1528 } catch (MWException $e) {
1529 //using raw, because $wgShowExceptionDetails can not be set yet
1530 $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
1531 }
1532
1533 return $status;
1534 }
1535
1536 /**
1537 * Override the necessary bits of the config to run an installation.
1538 */
1539 public static function overrideConfig() {
1540 define( 'MW_NO_SESSION', 1 );
1541
1542 // Don't access the database
1543 $GLOBALS['wgUseDatabaseMessages'] = false;
1544 // Debug-friendly
1545 $GLOBALS['wgShowExceptionDetails'] = true;
1546 // Don't break forms
1547 $GLOBALS['wgExternalLinkTarget'] = '_blank';
1548
1549 // Extended debugging
1550 $GLOBALS['wgShowSQLErrors'] = true;
1551 $GLOBALS['wgShowDBErrorBacktrace'] = true;
1552
1553 // Allow multiple ob_flush() calls
1554 $GLOBALS['wgDisableOutputCompression'] = true;
1555
1556 // Use a sensible cookie prefix (not my_wiki)
1557 $GLOBALS['wgCookiePrefix'] = 'mw_installer';
1558
1559 // Some of the environment checks make shell requests, remove limits
1560 $GLOBALS['wgMaxShellMemory'] = 0;
1561 }
1562
1563 /**
1564 * Add an installation step following the given step.
1565 *
1566 * @param $callback Array A valid installation callback array, in this form:
1567 * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
1568 * @param $findStep String the step to find. Omit to put the step at the beginning
1569 */
1570 public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
1571 $this->extraInstallSteps[$findStep][] = $callback;
1572 }
1573
1574 /**
1575 * Disable the time limit for execution.
1576 * Some long-running pages (Install, Upgrade) will want to do this
1577 */
1578 protected function disableTimeLimit() {
1579 wfSuppressWarnings();
1580 set_time_limit( 0 );
1581 wfRestoreWarnings();
1582 }
1583 }