r55362 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55361‎ | r55362 | r55363 >
Date:23:40, 19 August 2009
Author:brion
Status:ok
Tags:
Comment:
De-clutter base directory; moving install-utils.inc into maintenance.
Modified paths:
  • /trunk/phase3/config/Installer.php (modified) (history)
  • /trunk/phase3/install-utils.inc (deleted) (history)
  • /trunk/phase3/maintenance/commandLine.inc (modified) (history)
  • /trunk/phase3/maintenance/doMaintenance.php (modified) (history)
  • /trunk/phase3/maintenance/install-utils.inc (added) (history)

Diff [purge]

Index: trunk/phase3/install-utils.inc
@@ -1,196 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * This file contains functions used by the install script (config/index.php)
6 - * and maintenance scripts. It is not loaded in normal web requests.
7 - *
8 - * @file
9 - */
10 -
11 -function install_version_checks() {
12 - # We dare not turn output buffer _off_ since this will break completely
13 - # if PHP is globally configured to run through a gzip filter.
14 - @ob_implicit_flush( true );
15 -
16 - if( !function_exists( 'version_compare' ) ) {
17 - # version_compare was introduced in 4.1.0
18 - echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
19 - die( -1 );
20 - }
21 - if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
22 - echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
23 - "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
24 - "to continue installation. ABORTING.\n";
25 - die( -1 );
26 - }
27 -
28 - // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
29 - // As of 1.8 this breaks lots of common operations instead
30 - // of just some rare ones like export.
31 - $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
32 - if( !isset( $borked[-1] ) ) {
33 - echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
34 - "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
35 - die( -1 );
36 - }
37 -
38 - $test = new PhpXmlBugTester();
39 - if( !$test->ok ) {
40 - echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
41 - "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
42 - "Upgrade to PHP 5.2.9 or later and libxml2 2.7.2 or later!\n" .
43 - "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
44 - die( -1 );
45 - }
46 -
47 -
48 - global $wgCommandLineMode;
49 - $wgCommandLineMode = true;
50 - umask( 000 );
51 - @set_time_limit( 0 );
52 -}
53 -
54 -/**
55 - * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
56 - * http://bugs.php.net/bug.php?id=45996
57 - * Known fixed with PHP 5.2.9 + libxml2-2.7.3
58 - */
59 -class PhpXmlBugTester {
60 - private $parsedData = '';
61 - public $ok = false;
62 - public function __construct() {
63 - $charData = '<b>c</b>';
64 - $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
65 -
66 - $parser = xml_parser_create();
67 - xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
68 - $parsedOk = xml_parse($parser, $xml, true);
69 - $this->ok = $parsedOk && ($this->parsedData == $charData);
70 - }
71 - public function chardata($parser, $data) {
72 - $this->parsedData .= $data;
73 - }
74 -}
75 -
76 -function readconsole( $prompt = '' ) {
77 - static $isatty = null;
78 - if ( is_null( $isatty ) ) {
79 - if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
80 - $isatty = true;
81 - } else {
82 - $isatty = false;
83 - }
84 - }
85 -
86 - if ( $isatty && function_exists( 'readline' ) ) {
87 - return readline( $prompt );
88 - } else {
89 - if ( $isatty ) {
90 - $st = readlineEmulation( $prompt );
91 - } else {
92 - if ( feof( STDIN ) ) {
93 - $st = false;
94 - } else {
95 - $st = fgets(STDIN, 1024);
96 - }
97 - }
98 - if ($st === false) return false;
99 - $resp = trim( $st );
100 - return $resp;
101 - }
102 -}
103 -
104 -function findExecutable( $name ) {
105 - $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
106 - foreach( $paths as $path ) {
107 - $full = $path . DIRECTORY_SEPARATOR . $name;
108 - if( file_exists( $full ) ) {
109 - if( wfIsWindows() || is_executable( $full ) ) {
110 - return $full;
111 - }
112 - }
113 - }
114 - return false;
115 -}
116 -
117 -function readlineEmulation( $prompt ) {
118 - $bash = "bash";
119 - if( !wfIsWindows() && findExecutable( $bash ) ) {
120 - $retval = false;
121 - $encPrompt = wfEscapeShellArg( $prompt );
122 - $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
123 - $encCommand = wfEscapeShellArg( $command );
124 - $line = wfShellExec( "$bash -c $encCommand", $retval );
125 -
126 - if( $retval == 0 ) {
127 - return $line;
128 - } elseif( $retval == 127 ) {
129 - // Couldn't execute bash even though we thought we saw it.
130 - // Shell probably spit out an error message, sorry :(
131 - // Fall through to fgets()...
132 - } else {
133 - // EOF/ctrl+D
134 - return false;
135 - }
136 - }
137 -
138 - // Fallback... we'll have no editing controls, EWWW
139 - if ( feof( STDIN ) ) {
140 - return false;
141 - }
142 - print $prompt;
143 - return fgets(STDIN, 1024);
144 -}
145 -
146 -
147 -#
148 -# Read and execute SQL commands from a file
149 -#
150 -function dbsource( $fname, $db = false ) {
151 - wfDeprecated( __METHOD__ );
152 - if ( !$db ) {
153 - // Try $wgDatabase, which is used in the install and update scripts
154 - global $wgDatabase;
155 - if ( isset( $wgDatabase ) ) {
156 - $db = $wgDatabase;
157 - } else {
158 - // No? Well, we must be outside of those scripts, so use the standard method
159 - $db = wfGetDB( DB_MASTER );
160 - }
161 - }
162 - $error = $db->sourceFile( $fname );
163 - if ( $error !== true ) {
164 - print $error;
165 - exit(1);
166 - }
167 -}
168 -
169 -/**
170 - * Get the value of session.save_path
171 - *
172 - * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
173 - * this might have some additional preceding parts which need to be
174 - * ditched
175 - *
176 - * @return string
177 - */
178 -function mw_get_session_save_path() {
179 - $path = ini_get( 'session.save_path' );
180 - $path = substr( $path, strrpos( $path, ';' ) );
181 - return $path;
182 -}
183 -
184 -/**
185 - * Is dl() available to us?
186 - *
187 - * According to http://www.php.net/manual/en/function.dl.php, dl()
188 - * is *not* available when `enable_dl` is off, or under `safe_mode`
189 - *
190 - * @return bool
191 - */
192 -function mw_have_dl() {
193 - return function_exists( 'dl' )
194 - && is_callable( 'dl' )
195 - && wfIniGetBool( 'enable_dl' )
196 - && !wfIniGetBool( 'safe_mode' );
197 -}
\ No newline at end of file
Index: trunk/phase3/maintenance/doMaintenance.php
@@ -75,7 +75,7 @@
7676 $maintenance->finalSetup();
7777 // Some last includes
7878 require_once( "$IP/includes/Setup.php" );
79 -require_once( "$IP/install-utils.inc" );
 79+require_once( "$IP/maintenance/install-utils.inc" );
8080
8181 // Much much faster startup than creating a title object
8282 $wgTitle = null;
Index: trunk/phase3/maintenance/commandLine.inc
@@ -257,7 +257,7 @@
258258 $wgShowSQLErrors = true;
259259
260260 require_once( "$IP/includes/Setup.php" );
261 -require_once( "$IP/install-utils.inc" );
 261+require_once( "$IP/maintenance/install-utils.inc" );
262262 $wgTitle = null; # Much much faster startup than creating a title object
263263 @set_time_limit(0);
264264
Index: trunk/phase3/maintenance/install-utils.inc
@@ -0,0 +1,196 @@
 2+<?php
 3+
 4+/**
 5+ * This file contains functions used by the install script (config/index.php)
 6+ * and maintenance scripts. It is not loaded in normal web requests.
 7+ *
 8+ * @file
 9+ */
 10+
 11+function install_version_checks() {
 12+ # We dare not turn output buffer _off_ since this will break completely
 13+ # if PHP is globally configured to run through a gzip filter.
 14+ @ob_implicit_flush( true );
 15+
 16+ if( !function_exists( 'version_compare' ) ) {
 17+ # version_compare was introduced in 4.1.0
 18+ echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
 19+ die( -1 );
 20+ }
 21+ if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
 22+ echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
 23+ "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
 24+ "to continue installation. ABORTING.\n";
 25+ die( -1 );
 26+ }
 27+
 28+ // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
 29+ // As of 1.8 this breaks lots of common operations instead
 30+ // of just some rare ones like export.
 31+ $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
 32+ if( !isset( $borked[-1] ) ) {
 33+ echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
 34+ "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
 35+ die( -1 );
 36+ }
 37+
 38+ $test = new PhpXmlBugTester();
 39+ if( !$test->ok ) {
 40+ echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
 41+ "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
 42+ "Upgrade to PHP 5.2.9 or later and libxml2 2.7.2 or later!\n" .
 43+ "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
 44+ die( -1 );
 45+ }
 46+
 47+
 48+ global $wgCommandLineMode;
 49+ $wgCommandLineMode = true;
 50+ umask( 000 );
 51+ @set_time_limit( 0 );
 52+}
 53+
 54+/**
 55+ * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
 56+ * http://bugs.php.net/bug.php?id=45996
 57+ * Known fixed with PHP 5.2.9 + libxml2-2.7.3
 58+ */
 59+class PhpXmlBugTester {
 60+ private $parsedData = '';
 61+ public $ok = false;
 62+ public function __construct() {
 63+ $charData = '<b>c</b>';
 64+ $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
 65+
 66+ $parser = xml_parser_create();
 67+ xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
 68+ $parsedOk = xml_parse($parser, $xml, true);
 69+ $this->ok = $parsedOk && ($this->parsedData == $charData);
 70+ }
 71+ public function chardata($parser, $data) {
 72+ $this->parsedData .= $data;
 73+ }
 74+}
 75+
 76+function readconsole( $prompt = '' ) {
 77+ static $isatty = null;
 78+ if ( is_null( $isatty ) ) {
 79+ if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
 80+ $isatty = true;
 81+ } else {
 82+ $isatty = false;
 83+ }
 84+ }
 85+
 86+ if ( $isatty && function_exists( 'readline' ) ) {
 87+ return readline( $prompt );
 88+ } else {
 89+ if ( $isatty ) {
 90+ $st = readlineEmulation( $prompt );
 91+ } else {
 92+ if ( feof( STDIN ) ) {
 93+ $st = false;
 94+ } else {
 95+ $st = fgets(STDIN, 1024);
 96+ }
 97+ }
 98+ if ($st === false) return false;
 99+ $resp = trim( $st );
 100+ return $resp;
 101+ }
 102+}
 103+
 104+function findExecutable( $name ) {
 105+ $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
 106+ foreach( $paths as $path ) {
 107+ $full = $path . DIRECTORY_SEPARATOR . $name;
 108+ if( file_exists( $full ) ) {
 109+ if( wfIsWindows() || is_executable( $full ) ) {
 110+ return $full;
 111+ }
 112+ }
 113+ }
 114+ return false;
 115+}
 116+
 117+function readlineEmulation( $prompt ) {
 118+ $bash = "bash";
 119+ if( !wfIsWindows() && findExecutable( $bash ) ) {
 120+ $retval = false;
 121+ $encPrompt = wfEscapeShellArg( $prompt );
 122+ $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
 123+ $encCommand = wfEscapeShellArg( $command );
 124+ $line = wfShellExec( "$bash -c $encCommand", $retval );
 125+
 126+ if( $retval == 0 ) {
 127+ return $line;
 128+ } elseif( $retval == 127 ) {
 129+ // Couldn't execute bash even though we thought we saw it.
 130+ // Shell probably spit out an error message, sorry :(
 131+ // Fall through to fgets()...
 132+ } else {
 133+ // EOF/ctrl+D
 134+ return false;
 135+ }
 136+ }
 137+
 138+ // Fallback... we'll have no editing controls, EWWW
 139+ if ( feof( STDIN ) ) {
 140+ return false;
 141+ }
 142+ print $prompt;
 143+ return fgets(STDIN, 1024);
 144+}
 145+
 146+
 147+#
 148+# Read and execute SQL commands from a file
 149+#
 150+function dbsource( $fname, $db = false ) {
 151+ wfDeprecated( __METHOD__ );
 152+ if ( !$db ) {
 153+ // Try $wgDatabase, which is used in the install and update scripts
 154+ global $wgDatabase;
 155+ if ( isset( $wgDatabase ) ) {
 156+ $db = $wgDatabase;
 157+ } else {
 158+ // No? Well, we must be outside of those scripts, so use the standard method
 159+ $db = wfGetDB( DB_MASTER );
 160+ }
 161+ }
 162+ $error = $db->sourceFile( $fname );
 163+ if ( $error !== true ) {
 164+ print $error;
 165+ exit(1);
 166+ }
 167+}
 168+
 169+/**
 170+ * Get the value of session.save_path
 171+ *
 172+ * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
 173+ * this might have some additional preceding parts which need to be
 174+ * ditched
 175+ *
 176+ * @return string
 177+ */
 178+function mw_get_session_save_path() {
 179+ $path = ini_get( 'session.save_path' );
 180+ $path = substr( $path, strrpos( $path, ';' ) );
 181+ return $path;
 182+}
 183+
 184+/**
 185+ * Is dl() available to us?
 186+ *
 187+ * According to http://www.php.net/manual/en/function.dl.php, dl()
 188+ * is *not* available when `enable_dl` is off, or under `safe_mode`
 189+ *
 190+ * @return bool
 191+ */
 192+function mw_have_dl() {
 193+ return function_exists( 'dl' )
 194+ && is_callable( 'dl' )
 195+ && wfIniGetBool( 'enable_dl' )
 196+ && !wfIniGetBool( 'safe_mode' );
 197+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/install-utils.inc
___________________________________________________________________
Added: svn:eol-style
1198 + native
Added: svn:keywords
2199 + Author Date Id Revision
Index: trunk/phase3/config/Installer.php
@@ -32,7 +32,7 @@
3333
3434 // Run version checks before including other files
3535 // so people don't see a scary parse error.
36 -require_once( "$IP/install-utils.inc" );
 36+require_once( "$IP/maintenance/install-utils.inc" );
3737 install_version_checks();
3838
3939 require_once( "$IP/includes/Defines.php" );
@@ -250,7 +250,6 @@
251251 }
252252
253253
254 -require_once( "$IP/install-utils.inc" );
255254 require_once( "$IP/maintenance/updaters.inc" );
256255
257256 class ConfigData {

Status & tagging log