Modified the environment check of the core installer to check the current MediaWiki...
[lhc/web/wiklou.git] / includes / installer / Installer.php
1 <?php
2
3 /**
4 * This documentation group collects source code files with deployment functionality.
5 *
6 * @defgroup Deployment Deployment
7 */
8
9 /**
10 * Base installer class.
11 *
12 * This class provides the base for installation and update functionality
13 * for both MediaWiki core and extensions.
14 *
15 * @ingroup Deployment
16 * @since 1.17
17 */
18 abstract class Installer {
19
20 /**
21 * TODO: make protected?
22 *
23 * @var array
24 */
25 public $settings;
26
27 /**
28 * Cached DB installer instances, access using getDBInstaller().
29 *
30 * @var array
31 */
32 protected $dbInstallers = array();
33
34 /**
35 * Minimum memory size in MB.
36 *
37 * @var integer
38 */
39 protected $minMemorySize = 50;
40
41 /**
42 * Cached Title, used by parse().
43 *
44 * @var Title
45 */
46 protected $parserTitle;
47
48 /**
49 * Cached ParserOptions, used by parse().
50 *
51 * @var ParserOptions
52 */
53 protected $parserOptions;
54
55 /**
56 * Known database types. These correspond to the class names <type>Installer,
57 * and are also MediaWiki database types valid for $wgDBtype.
58 *
59 * To add a new type, create a <type>Installer class and a Database<type>
60 * class, and add a config-type-<type> message to MessagesEn.php.
61 *
62 * @var array
63 */
64 protected $dbTypes = array(
65 'mysql',
66 'postgres',
67 'sqlite',
68 'oracle'
69 );
70
71 /**
72 * A list of environment check methods called by doEnvironmentChecks().
73 * These may output warnings using showMessage(), and/or abort the
74 * installation process by returning false.
75 *
76 * @var array
77 */
78 protected $envChecks = array(
79 'envLatestVersion',
80 'envCheckDB',
81 'envCheckRegisterGlobals',
82 'envCheckMagicQuotes',
83 'envCheckMagicSybase',
84 'envCheckMbstring',
85 'envCheckZE1',
86 'envCheckSafeMode',
87 'envCheckXML',
88 'envCheckPCRE',
89 'envCheckMemory',
90 'envCheckCache',
91 'envCheckDiff3',
92 'envCheckGraphics',
93 'envCheckPath',
94 'envCheckWriteableDir',
95 'envCheckExtension',
96 'envCheckShellLocale',
97 'envCheckUploadsDirectory',
98 'envCheckLibicu'
99 );
100
101 /**
102 * UI interface for displaying a short message
103 * The parameters are like parameters to wfMsg().
104 * The messages will be in wikitext format, which will be converted to an
105 * output format such as HTML or text before being sent to the user.
106 */
107 public abstract function showMessage( $msg /*, ... */ );
108
109 /**
110 * Constructor, always call this from child classes.
111 */
112 public function __construct() {
113 // Disable the i18n cache and LoadBalancer
114 Language::getLocalisationCache()->disableBackend();
115 LBFactory::disableBackend();
116 }
117
118 /**
119 * Get a list of known DB types.
120 */
121 public function getDBTypes() {
122 return $this->dbTypes;
123 }
124
125 /**
126 * Do initial checks of the PHP environment. Set variables according to
127 * the observed environment.
128 *
129 * It's possible that this may be called under the CLI SAPI, not the SAPI
130 * that the wiki will primarily run under. In that case, the subclass should
131 * initialise variables such as wgScriptPath, before calling this function.
132 *
133 * Under the web subclass, it can already be assumed that PHP 5+ is in use
134 * and that sessions are working.
135 *
136 * @return boolean
137 */
138 public function doEnvironmentChecks() {
139 $this->showMessage( 'config-env-php', phpversion() );
140
141 $good = true;
142
143 foreach ( $this->envChecks as $check ) {
144 $status = $this->$check();
145 if ( $status === false ) {
146 $good = false;
147 }
148 }
149
150 $this->setVar( '_Environment', $good );
151
152 if ( $good ) {
153 $this->showMessage( 'config-env-good' );
154 } else {
155 $this->showMessage( 'config-env-bad' );
156 }
157
158 return $good;
159 }
160
161 /**
162 * Set a MW configuration variable, or internal installer configuration variable.
163 *
164 * @param $name String
165 * @param $value Mixed
166 */
167 public function setVar( $name, $value ) {
168 $this->settings[$name] = $value;
169 }
170
171 /**
172 * Get an MW configuration variable, or internal installer configuration variable.
173 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
174 * Installer variables are typically prefixed by an underscore.
175 *
176 * @param $name String
177 * @param $default Mixed
178 *
179 * @return mixed
180 */
181 public function getVar( $name, $default = null ) {
182 if ( !isset( $this->settings[$name] ) ) {
183 return $default;
184 } else {
185 return $this->settings[$name];
186 }
187 }
188
189 /**
190 * Get an instance of DatabaseInstaller for the specified DB type.
191 *
192 * @param $type Mixed: DB installer for which is needed, false to use default.
193 *
194 * @return DatabaseInstaller
195 */
196 public function getDBInstaller( $type = false ) {
197 if ( !$type ) {
198 $type = $this->getVar( 'wgDBtype' );
199 }
200
201 $type = strtolower( $type );
202
203 if ( !isset( $this->dbInstallers[$type] ) ) {
204 $class = ucfirst( $type ). 'Installer';
205 $this->dbInstallers[$type] = new $class( $this );
206 }
207
208 return $this->dbInstallers[$type];
209 }
210
211 /**
212 * Determine if LocalSettings exists. If it does, return an appropriate
213 * status for whether we should can upgrade or not.
214 *
215 * @return Status
216 */
217 public function getLocalSettingsStatus() {
218 global $IP;
219
220 $status = Status::newGood();
221
222 wfSuppressWarnings();
223 $ls = file_exists( "$IP/LocalSettings.php" );
224 wfRestoreWarnings();
225
226 if( $ls ) {
227 if( $this->getDBInstaller()->needsUpgrade() ) {
228 $status->warning( 'config-localsettings-upgrade' );
229 }
230 else {
231 $status->fatal( 'config-localsettings-noupgrade' );
232 }
233 }
234
235 return $status;
236 }
237
238 /**
239 * Get a fake password for sending back to the user in HTML.
240 * This is a security mechanism to avoid compromise of the password in the
241 * event of session ID compromise.
242 *
243 * @param $realPassword String
244 *
245 * @return string
246 */
247 public function getFakePassword( $realPassword ) {
248 return str_repeat( '*', strlen( $realPassword ) );
249 }
250
251 /**
252 * Set a variable which stores a password, except if the new value is a
253 * fake password in which case leave it as it is.
254 *
255 * @param $name String
256 * @param $value Mixed
257 */
258 public function setPassword( $name, $value ) {
259 if ( !preg_match( '/^\*+$/', $value ) ) {
260 $this->setVar( $name, $value );
261 }
262 }
263
264 /**
265 * On POSIX systems return the primary group of the webserver we're running under.
266 * On other systems just returns null.
267 *
268 * This is used to advice the user that he should chgrp his config/data/images directory as the
269 * webserver user before he can install.
270 *
271 * Public because SqliteInstaller needs it, and doesn't subclass Installer.
272 *
273 * @return mixed
274 */
275 public static function maybeGetWebserverPrimaryGroup() {
276 if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
277 # I don't know this, this isn't UNIX.
278 return null;
279 }
280
281 # posix_getegid() *not* getmygid() because we want the group of the webserver,
282 # not whoever owns the current script.
283 $gid = posix_getegid();
284 $getpwuid = posix_getpwuid( $gid );
285 $group = $getpwuid['name'];
286
287 return $group;
288 }
289
290 /**
291 * Convert wikitext $text to HTML.
292 *
293 * This is potentially error prone since many parser features require a complete
294 * installed MW database. The solution is to just not use those features when you
295 * write your messages. This appears to work well enough. Basic formatting and
296 * external links work just fine.
297 *
298 * But in case a translator decides to throw in a #ifexist or internal link or
299 * whatever, this function is guarded to catch attempted DB access and to present
300 * some fallback text.
301 *
302 * @param $text String
303 * @param $lineStart Boolean
304 * @return String
305 */
306 public function parse( $text, $lineStart = false ) {
307 global $wgParser;
308
309 try {
310 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
311 $html = $out->getText();
312 } catch ( DBAccessError $e ) {
313 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
314
315 if ( !empty( $this->debug ) ) {
316 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
317 }
318 }
319
320 return $html;
321 }
322
323 /**
324 * TODO: document
325 *
326 * @param DatabaseInstaller $installer
327 *
328 * @return Status
329 */
330 public function installDatabase( DatabaseInstaller &$installer ) {
331 if( !$installer ) {
332 $type = $this->getVar( 'wgDBtype' );
333 $status = Status::newFatal( "config-no-db", $type );
334 } else {
335 $status = $installer->setupDatabase();
336 }
337
338 return $status;
339 }
340
341 /**
342 * TODO: document
343 *
344 * @param DatabaseInstaller $installer
345 *
346 * @return Status
347 */
348 public function installTables( DatabaseInstaller &$installer ) {
349 $status = $installer->createTables();
350
351 if( $status->isOK() ) {
352 LBFactory::enableBackend();
353 }
354
355 return $status;
356 }
357
358 /**
359 * TODO: document
360 *
361 * @param DatabaseInstaller $installer
362 *
363 * @return Status
364 */
365 public function installInterwiki( DatabaseInstaller &$installer ) {
366 return $installer->populateInterwikiTable();
367 }
368
369 /**
370 * Exports all wg* variables stored by the installer into global scope.
371 */
372 public function exportVars() {
373 foreach ( $this->settings as $name => $value ) {
374 if ( substr( $name, 0, 2 ) == 'wg' ) {
375 $GLOBALS[$name] = $value;
376 }
377 }
378 }
379
380 /**
381 * Check if we're installing the latest version.
382 */
383 public function envLatestVersion() {
384 global $wgVersion;
385
386 $repository = wfGetRepository();
387 $currentVersion = $repository->getLatestCoreVersion();
388
389 /*
390 if( !$latestInfo ) {
391 $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
392 return;
393 }
394 */
395
396 $this->setVar( '_ExternalHTTP', true );
397
398 if ( $currentVersion === false ) {
399 # For when the request is successful but there's e.g. some silly man in
400 # the middle firewall blocking us, e.g. one of those annoying airport ones
401 $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
402 return;
403 }
404
405 if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
406 $this->showMessage( 'config-env-latest-old' );
407 $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
408 } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
409 $this->showMessage( 'config-env-latest-new' );
410 }
411
412 $this->showMessage( 'config-env-latest-ok' );
413 }
414
415 /**
416 * Environment check for DB types.
417 */
418 public function envCheckDB() {
419 global $wgLang;
420
421 $compiledDBs = array();
422 $goodNames = array();
423 $allNames = array();
424
425 foreach ( $this->dbTypes as $name ) {
426 $db = $this->getDBInstaller( $name );
427 $readableName = wfMsg( 'config-type-' . $name );
428
429 if ( $db->isCompiled() ) {
430 $compiledDBs[] = $name;
431 $goodNames[] = $readableName;
432 }
433
434 $allNames[] = $readableName;
435 }
436
437 $this->setVar( '_CompiledDBs', $compiledDBs );
438
439 if ( !$compiledDBs ) {
440 $this->showMessage( 'config-no-db' );
441 $this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
442 return false;
443 }
444
445 $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
446 }
447
448 /**
449 * Environment check for register_globals.
450 */
451 public function envCheckRegisterGlobals() {
452 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
453 $this->showMessage( 'config-register-globals' );
454 }
455 }
456
457 /**
458 * Environment check for magic_quotes_runtime.
459 */
460 public function envCheckMagicQuotes() {
461 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
462 $this->showMessage( 'config-magic-quotes-runtime' );
463 return false;
464 }
465 }
466
467 /**
468 * Environment check for magic_quotes_sybase.
469 */
470 public function envCheckMagicSybase() {
471 if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
472 $this->showMessage( 'config-magic-quotes-sybase' );
473 return false;
474 }
475 }
476
477 /**
478 * Environment check for mbstring.func_overload.
479 */
480 public function envCheckMbstring() {
481 if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
482 $this->showMessage( 'config-mbstring' );
483 return false;
484 }
485 }
486
487 /**
488 * Environment check for zend.ze1_compatibility_mode.
489 */
490 public function envCheckZE1() {
491 if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
492 $this->showMessage( 'config-ze1' );
493 return false;
494 }
495 }
496
497 /**
498 * Environment check for safe_mode.
499 */
500 public function envCheckSafeMode() {
501 if ( wfIniGetBool( 'safe_mode' ) ) {
502 $this->setVar( '_SafeMode', true );
503 $this->showMessage( 'config-safe-mode' );
504 }
505 }
506
507 /**
508 * Environment check for the XML module.
509 */
510 public function envCheckXML() {
511 if ( !function_exists( "utf8_encode" ) ) {
512 $this->showMessage( 'config-xml-bad' );
513 return false;
514 }
515 $this->showMessage( 'config-xml-good' );
516 }
517
518 /**
519 * Environment check for the PCRE module.
520 */
521 public function envCheckPCRE() {
522 if ( !function_exists( 'preg_match' ) ) {
523 $this->showMessage( 'config-pcre' );
524 return false;
525 }
526 }
527
528 /**
529 * Environment check for available memory.
530 */
531 public function envCheckMemory() {
532 $limit = ini_get( 'memory_limit' );
533
534 if ( !$limit || $limit == -1 ) {
535 $this->showMessage( 'config-memory-none' );
536 return true;
537 }
538
539 $n = intval( $limit );
540
541 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
542 $n = intval( $m[1] * ( 1024 * 1024 ) );
543 }
544
545 if( $n < $this->minMemorySize * 1024 * 1024 ) {
546 $newLimit = "{$this->minMemorySize}M";
547
548 if( ini_set( "memory_limit", $newLimit ) === false ) {
549 $this->showMessage( 'config-memory-bad', $limit );
550 } else {
551 $this->showMessage( 'config-memory-raised', $limit, $newLimit );
552 $this->setVar( '_RaiseMemory', true );
553 }
554 } else {
555 $this->showMessage( 'config-memory-ok', $limit );
556 }
557 }
558
559 /**
560 * Environment check for compiled object cache types.
561 */
562 public function envCheckCache() {
563 $caches = array();
564
565 foreach ( $this->objectCaches as $name => $function ) {
566 if ( function_exists( $function ) ) {
567 $caches[$name] = true;
568 $this->showMessage( 'config-' . $name );
569 }
570 }
571
572 if ( !$caches ) {
573 $this->showMessage( 'config-no-cache' );
574 }
575
576 $this->setVar( '_Caches', $caches );
577 }
578
579 /**
580 * Search for GNU diff3.
581 */
582 public function envCheckDiff3() {
583 $paths = array_merge(
584 array(
585 "/usr/bin",
586 "/usr/local/bin",
587 "/opt/csw/bin",
588 "/usr/gnu/bin",
589 "/usr/sfw/bin"
590 ),
591 explode( PATH_SEPARATOR, getenv( "PATH" ) )
592 );
593
594 $names = array( "gdiff3", "diff3", "diff3.exe" );
595 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
596
597 $haveDiff3 = false;
598
599 foreach ( $paths as $path ) {
600 $exe = $this->locateExecutable( $path, $names, $versionInfo );
601
602 if ($exe !== false) {
603 $this->setVar( 'wgDiff3', $exe );
604 $haveDiff3 = true;
605 break;
606 }
607 }
608
609 if ( $haveDiff3 ) {
610 $this->showMessage( 'config-diff3-good', $exe );
611 } else {
612 $this->setVar( 'wgDiff3', false );
613 $this->showMessage( 'config-diff3-bad' );
614 }
615 }
616
617 /**
618 * Environment check for ImageMagick and GD.
619 */
620 public function envCheckGraphics() {
621 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
622
623 foreach( $imcheck as $dir ) {
624 $im = "$dir/convert";
625
626 wfSuppressWarnings();
627 $file_exists = file_exists( $im );
628 wfRestoreWarnings();
629
630 if( $file_exists ) {
631 $this->showMessage( 'config-imagemagick', $im );
632 $this->setVar( 'wgImageMagickConvertCommand', $im );
633 return true;
634 }
635 }
636
637 if ( function_exists( 'imagejpeg' ) ) {
638 $this->showMessage( 'config-gd' );
639 return true;
640 }
641
642 $this->showMessage( 'no-scaling' );
643 }
644
645 /**
646 * Environment check for setting $IP and $wgScriptPath.
647 */
648 public function envCheckPath() {
649 global $IP;
650 $IP = dirname( dirname( dirname( __FILE__ ) ) );
651
652 $this->setVar( 'IP', $IP );
653 $this->showMessage( 'config-dir', $IP );
654
655 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
656 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
657 // to get the path to the current script... hopefully it's reliable. SIGH
658 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
659 $path = $_SERVER['PHP_SELF'];
660 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
661 $path = $_SERVER['SCRIPT_NAME'];
662 } elseif ( $this->getVar( 'wgScriptPath' ) ) {
663 // Some kind soul has set it for us already (e.g. debconf)
664 return true;
665 } else {
666 $this->showMessage( 'config-no-uri' );
667 return false;
668 }
669
670 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
671 $this->setVar( 'wgScriptPath', $uri );
672 $this->showMessage( 'config-uri', $uri );
673 }
674
675 /**
676 * Environment check for writable config/ directory.
677 */
678 public function envCheckWriteableDir() {
679 $ipDir = $this->getVar( 'IP' );
680 $configDir = $ipDir . '/config';
681
682 if( !is_writeable( $configDir ) ) {
683 $webserverGroup = self::maybeGetWebserverPrimaryGroup();
684
685 if ( $webserverGroup !== null ) {
686 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
687 } else {
688 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
689 }
690
691 return false;
692 }
693 }
694
695 /**
696 * Environment check for setting the preferred PHP file extension.
697 */
698 public function envCheckExtension() {
699 // FIXME: detect this properly
700 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
701 $ext = 'php5';
702 } else {
703 $ext = 'php';
704 }
705
706 $this->setVar( 'wgScriptExtension', ".$ext" );
707 $this->showMessage( 'config-file-extension', $ext );
708 }
709
710 /**
711 * TODO: document
712 */
713 public function envCheckShellLocale() {
714 # Give up now if we're in safe mode or open_basedir.
715 # It's theoretically possible but tricky to work with.
716 if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) || !function_exists( 'exec' ) ) {
717 return true;
718 }
719
720 $os = php_uname( 's' );
721 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
722
723 if ( !in_array( $os, $supported ) ) {
724 return true;
725 }
726
727 # Get a list of available locales.
728 $lines = $ret = false;
729 exec( '/usr/bin/locale -a', $lines, $ret );
730
731 if ( $ret ) {
732 return true;
733 }
734
735 $lines = wfArrayMap( 'trim', $lines );
736 $candidatesByLocale = array();
737 $candidatesByLang = array();
738
739 foreach ( $lines as $line ) {
740 if ( $line === '' ) {
741 continue;
742 }
743
744 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
745 continue;
746 }
747
748 list( $all, $lang, $territory, $charset, $modifier ) = $m;
749
750 $candidatesByLocale[$m[0]] = $m;
751 $candidatesByLang[$lang][] = $m;
752 }
753
754 # Try the current value of LANG.
755 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
756 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
757 $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
758 return true;
759 }
760
761 # Try the most common ones.
762 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
763 foreach ( $commonLocales as $commonLocale ) {
764 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
765 $this->setVar( 'wgShellLocale', $commonLocale );
766 $this->showMessage( 'config-shell-locale', $commonLocale );
767 return true;
768 }
769 }
770
771 # Is there an available locale in the Wiki's language?
772 $wikiLang = $this->getVar( 'wgLanguageCode' );
773
774 if ( isset( $candidatesByLang[$wikiLang] ) ) {
775 $m = reset( $candidatesByLang[$wikiLang] );
776 $this->setVar( 'wgShellLocale', $m[0] );
777 $this->showMessage( 'config-shell-locale', $m[0] );
778 return true;
779 }
780
781 # Are there any at all?
782 if ( count( $candidatesByLocale ) ) {
783 $m = reset( $candidatesByLocale );
784 $this->setVar( 'wgShellLocale', $m[0] );
785 $this->showMessage( 'config-shell-locale', $m[0] );
786 return true;
787 }
788
789 # Give up.
790 return true;
791 }
792
793 /**
794 * TODO: document
795 */
796 public function envCheckUploadsDirectory() {
797 global $IP, $wgServer;
798
799 $dir = $IP . '/images/';
800 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
801 $safe = !$this->dirIsExecutable( $dir, $url );
802
803 if ( $safe ) {
804 $this->showMessage( 'config-uploads-safe' );
805 } else {
806 $this->showMessage( 'config-uploads-not-safe', $dir );
807 }
808 }
809
810 /**
811 * Convert a hex string representing a Unicode code point to that code point.
812 * @param string $c
813 * @return string
814 */
815 protected function unicodeChar( $c ) {
816 $c = hexdec($c);
817 if ($c <= 0x7F) {
818 return chr($c);
819 } else if ($c <= 0x7FF) {
820 return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
821 } else if ($c <= 0xFFFF) {
822 return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
823 . chr(0x80 | $c & 0x3F);
824 } else if ($c <= 0x10FFFF) {
825 return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
826 . chr(0x80 | $c >> 6 & 0x3F)
827 . chr(0x80 | $c & 0x3F);
828 } else {
829 return false;
830 }
831 }
832
833
834 /**
835 * Check the libicu version
836 */
837 public function envCheckLibicu() {
838 $utf8 = function_exists( 'utf8_normalize' );
839 $intl = function_exists( 'normalizer_normalize' );
840
841 /**
842 * This needs to be updated something that the latest libicu
843 * will properly normalize. This normalization was found at
844 * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
845 * Note that we use the hex representation to create the code
846 * points in order to avoid any Unicode-destroying during transit.
847 */
848 $not_normal_c = $this->unicodeChar("FA6C");
849 $normal_c = $this->unicodeChar("242EE");
850
851 $useNormalizer = 'php';
852 $needsUpdate = false;
853
854 /**
855 * We're going to prefer the pecl extension here unless
856 * utf8_normalize is more up to date.
857 */
858 if( $utf8 ) {
859 $useNormalizer = 'utf8';
860 $utf8 = utf8_normalize( $not_normal_c, UNORM_NFC );
861 if ( $utf8 !== $normal_c ) $needsUpdate = true;
862 }
863 if( $intl ) {
864 $useNormalizer = 'intl';
865 $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
866 if ( $intl !== $normal_c ) $needsUpdate = true;
867 }
868
869 // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
870 $this->showMessage( 'config-unicode-using-' . $useNormalizer );
871 if( $useNormalizer === 'php' ) {
872 $this->showMessage( 'config-unicode-pure-php-warning' );
873 } elseif( $needsUpdate ) {
874 $this->showMessage( 'config-unicode-update-warning' );
875 }
876 }
877
878
879 /**
880 * Search a path for any of the given executable names. Returns the
881 * executable name if found. Also checks the version string returned
882 * by each executable.
883 *
884 * Used only by environment checks.
885 *
886 * @param $path String: path to search
887 * @param $names Array of executable names
888 * @param $versionInfo Boolean false or array with two members:
889 * 0 => Command to run for version check, with $1 for the path
890 * 1 => String to compare the output with
891 *
892 * If $versionInfo is not false, only executables with a version
893 * matching $versionInfo[1] will be returned.
894 */
895 protected function locateExecutable( $path, $names, $versionInfo = false ) {
896 if ( !is_array( $names ) ) {
897 $names = array( $names );
898 }
899
900 foreach ( $names as $name ) {
901 $command = "$path/$name";
902
903 wfSuppressWarnings();
904 $file_exists = file_exists( $command );
905 wfRestoreWarnings();
906
907 if ( $file_exists ) {
908 if ( !$versionInfo ) {
909 return $command;
910 }
911
912 $file = str_replace( '$1', $command, $versionInfo[0] );
913
914 # Should maybe be wfShellExec( $file), but runs into a ulimit, see
915 # http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
916 if ( strstr( `$file`, $versionInfo[1]) !== false ) {
917 return $command;
918 }
919 }
920 }
921
922 return false;
923 }
924
925 /**
926 * Checks if scripts located in the given directory can be executed via the given URL.
927 *
928 * Used only by environment checks.
929 */
930 public function dirIsExecutable( $dir, $url ) {
931 $scriptTypes = array(
932 'php' => array(
933 "<?php echo 'ex' . 'ec';",
934 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
935 ),
936 );
937
938 // it would be good to check other popular languages here, but it'll be slow.
939
940 wfSuppressWarnings();
941
942 foreach ( $scriptTypes as $ext => $contents ) {
943 foreach ( $contents as $source ) {
944 $file = 'exectest.' . $ext;
945
946 if ( !file_put_contents( $dir . $file, $source ) ) {
947 break;
948 }
949
950 $text = Http::get( $url . $file );
951 unlink( $dir . $file );
952
953 if ( $text == 'exec' ) {
954 wfRestoreWarnings();
955 return $ext;
956 }
957 }
958 }
959
960 wfRestoreWarnings();
961
962 return false;
963 }
964
965 }