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