$phpdatabases = array();
foreach (array_keys($ourdb) as $db) {
$compname = $ourdb[$db]['compile'];
- if( extension_loaded( $compname ) || ( mw_have_dl() && dl( "{$compname}." . PHP_SHLIB_SUFFIX ) ) ) {
+ if( wfDl( $compname ) ) {
array_push($phpdatabases, $db);
$ourdb[$db]['havedriver'] = 1;
}
|| preg_match( "/^\s*[+-]?0*[1-9]/", $val ); // approx C atoi() function
}
+/**
+ * Wrapper function for PHP's dl(). This doesn't work in most situations from
+ * PHP 5.3 onward, and is usually disabled in shared environments anyway.
+ *
+ * @param $extension String A PHP extension. The file suffix (.so or .dll)
+ * should be omitted
+ * @return Bool - Whether or not the extension is loaded
+ */
+function wfDl( $extension ) {
+ if( extension_loaded( $extension ) ) {
+ return true;
+ }
+
+ $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
+ && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) );
+
+ if( $canDl ) {
+ wfSuppressWarnings();
+ dl( $extension . '.' . PHP_SHLIB_SUFFIX );
+ wfRestoreWarnings();
+ }
+ return extension_loaded( $extension );
+}
+
/**
* Execute a shell command, with time and memory limits mirrored from the PHP
* configuration if supported.
global $wgLoadFileinfoExtension;
if ($wgLoadFileinfoExtension) {
- if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX);
+ wfDl( 'fileinfo' );
}
/**
wfProfileIn( __METHOD__ );
// Load IBM DB2 driver if missing
- if (!@extension_loaded('ibm_db2')) {
- @dl('ibm_db2.so');
- }
+ wfDl( 'ibm_db2' );
+
// Test for IBM DB2 support, to avoid suppressed fatal error
if ( !function_exists( 'db2_connect' ) ) {
$error = "DB2 functions missing, have you enabled the ibm_db2 extension for PHP?\n";
# Test for missing mysql.so
# First try to load it
- if (!@extension_loaded('mysql')) {
- @dl('mysql.so');
- }
+ wfDl( 'mysql' );
# Fail now
# Otherwise we get a suppressed fatal error, which is very hard to track down
else if ( $wgExternalDiffEngine == 'wikidiff2' && !function_exists( 'wikidiff2_do_diff' ) ) {
wfProfileIn( __METHOD__ . '-php_wikidiff2.so' );
wfSuppressWarnings();
- dl( 'php_wikidiff2.so' );
+ wfDl( 'wikidiff2' );
wfRestoreWarnings();
wfProfileOut( __METHOD__ . '-php_wikidiff2.so' );
}
'wgLogo',
'wgShellLocale',
'wgSecretKey',
+ 'wgExternalDiffEngine',
);
/**
$this->setVar( $name, $value );
}
}
-
- /**
- * Returns true if dl() can be used
- */
- function haveDl() {
- return function_exists( 'dl' )
- && is_callable( 'dl' )
- && wfIniGetBool( 'enable_dl' )
- && !wfIniGetBool( 'safe_mode' );
- }
/** Check if we're installing the latest version */
function envLatestVersion() {
*/
function checkExtension( $name ) {
wfSuppressWarnings();
- $compiled = extension_loaded( $name )
- || ( $this->parent->haveDl() && dl( $name . '.' . PHP_SHLIB_SUFFIX ) );
+ $compiled = wfDl( $name );
wfRestoreWarnings();
return $compiled;
}
break;
case "force-normal":
if ( !function_exists( 'utf8_normalize' ) ) {
- dl( "php_utfnormal.so" );
+ wfDl( "php_utfnormal.so" );
if ( !function_exists( 'utf8_normalize' ) ) {
wfDie( "Failed to load UTF-8 normalization extension. " .
"Install or remove --force-normal parameter to use slower code.\n" );