* API: added categories property
[mediawiki.git] / install-utils.inc
blob4e1aad27a3155bd2d1abc6dff79106580a6d6297
1 <?php
3 function install_version_checks() {
4         # We dare not turn output buffer _off_ since this will break completely
5         # if PHP is globally configured to run through a gzip filter.
6         @ob_implicit_flush( true );
8         if( !function_exists( 'version_compare' ) ) {
9                 # version_compare was introduced in 4.1.0
10                 echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
11                 die( -1 );
12         }
13         if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
14                 echo "PHP 5.0.0 or higher is required. ABORTING.\n";
15                 die( -1 );
16         }
17         
18         // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
19         // As of 1.8 this breaks lots of common operations instead
20         // of just some rare ones like export.
21         $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
22         if( !isset( $borked[-1] ) ) {
23                 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
24                         "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
25                 die( -1 );
26         }
28         global $wgCommandLineMode;
29         $wgCommandLineMode = true;
30         umask( 000 );
31         @set_time_limit( 0 );
34 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
35         copyfileto( $sdir, $name, $ddir, $name, $perms );
38 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
39         global $wgInstallOwner, $wgInstallGroup;
41         $d = "{$ddir}/{$dname}";
42         if ( copy( "{$sdir}/{$sname}", $d ) ) {
43                 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
44                 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
45                 chmod( $d, $perms );
46                 # print "Copied \"{$sname}\" to \"{$d}\".\n";
47         } else {
48                 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
49                 exit();
50         }
53 function copydirectory( $source, $dest ) {
54         $handle = opendir( $source );
55         while ( false !== ( $f = readdir( $handle ) ) ) {
56                 $fullname = "$source/$f";
57                 if ( $f{0} != '.' && is_file( $fullname ) ) {
58                         copyfile( $source, $f, $dest );
59                 }
60         }
63 function readconsole( $prompt = '' ) {
64         static $isatty = null;
65         if ( is_null( $isatty ) ) {
66                 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
67                         $isatty = true;
68                 } else {
69                         $isatty = false;
70                 }
71         }
73         if ( $isatty && function_exists( 'readline' ) ) {
74                 return readline( $prompt );
75         } else {
76                 if ( $isatty ) {
77                         print $prompt;
78                 }
79                 if ( feof( STDIN ) ) {
80                         return false;
81                 }
82                 $st = fgets(STDIN, 1024);
83                 if ($st === false) return false;
84                 $resp = trim( $st );
85                 return $resp;
86         }
90 # Read and execute SQL commands from a file
92 function dbsource( $fname, $db = false ) {
93         if ( !$db ) {
94                 // Try $wgDatabase, which is used in the install and update scripts
95                 global $wgDatabase;
96                 if ( isset( $wgDatabase ) ) {
97                         $db = $wgDatabase;
98                 } else {
99                         // No? Well, we must be outside of those scripts, so use the standard method
100                         $db = wfGetDB( DB_MASTER );
101                 }
102         }
103         $error = $db->sourceFile( $fname );
104         if ( $error !== true ) {
105                 print $error;
106                 exit(1);
107         }