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