Cleanup most of the DIY extension detection/dl() code into nice clean wfDl()

This commit is contained in:
Chad Horohoe 2010-06-14 18:09:19 +00:00
parent b921f0cc29
commit 94a69f24fc
9 changed files with 33 additions and 22 deletions

View file

@ -333,7 +333,7 @@ error_reporting( 0 );
$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;
}

View file

@ -2304,6 +2304,30 @@ function wfIniGetBool( $setting ) {
|| 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.

View file

@ -102,7 +102,7 @@ END_STRING
global $wgLoadFileinfoExtension;
if ($wgLoadFileinfoExtension) {
if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX);
wfDl( 'fileinfo' );
}
/**

View file

@ -484,9 +484,8 @@ class DatabaseIbm_db2 extends DatabaseBase {
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";

View file

@ -26,9 +26,7 @@ class DatabaseMysql extends DatabaseBase {
# 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

View file

@ -657,7 +657,7 @@ CONTROL;
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' );
}

View file

@ -38,6 +38,7 @@ abstract class Installer {
'wgLogo',
'wgShellLocale',
'wgSecretKey',
'wgExternalDiffEngine',
);
/**
@ -350,16 +351,6 @@ abstract class Installer {
$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() {

View file

@ -128,8 +128,7 @@ abstract class InstallerDBType {
*/
function checkExtension( $name ) {
wfSuppressWarnings();
$compiled = extension_loaded( $name )
|| ( $this->parent->haveDl() && dl( $name . '.' . PHP_SHLIB_SUFFIX ) );
$compiled = wfDl( $name );
wfRestoreWarnings();
return $compiled;
}

View file

@ -146,7 +146,7 @@ class BackupDumper {
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" );