From 94a69f24fc058655e3c12bd81e56734fcddf88a5 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Mon, 14 Jun 2010 18:09:19 +0000 Subject: [PATCH] Cleanup most of the DIY extension detection/dl() code into nice clean wfDl() --- config/Installer.php | 2 +- includes/GlobalFunctions.php | 24 ++++++++++++++++++++++++ includes/MimeMagic.php | 2 +- includes/db/DatabaseIbm_db2.php | 5 ++--- includes/db/DatabaseMysql.php | 4 +--- includes/diff/DifferenceInterface.php | 2 +- includes/installer/Installer.php | 11 +---------- includes/installer/InstallerDBType.php | 3 +-- maintenance/backup.inc | 2 +- 9 files changed, 33 insertions(+), 22 deletions(-) diff --git a/config/Installer.php b/config/Installer.php index 191ca852d7..3b24ef812f 100644 --- a/config/Installer.php +++ b/config/Installer.php @@ -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; } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 67b8212a61..76d67f9567 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 364c09b6f7..555cc11b51 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -102,7 +102,7 @@ END_STRING global $wgLoadFileinfoExtension; if ($wgLoadFileinfoExtension) { - if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX); + wfDl( 'fileinfo' ); } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 2319056d19..824267c7ca 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -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"; diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index a08b69448e..68a7fee913 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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 diff --git a/includes/diff/DifferenceInterface.php b/includes/diff/DifferenceInterface.php index 3ec9d40d9d..617f39ac5a 100644 --- a/includes/diff/DifferenceInterface.php +++ b/includes/diff/DifferenceInterface.php @@ -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' ); } diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 9e734a71d5..b92339407d 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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() { diff --git a/includes/installer/InstallerDBType.php b/includes/installer/InstallerDBType.php index 2b03d637dc..0abb4503e7 100644 --- a/includes/installer/InstallerDBType.php +++ b/includes/installer/InstallerDBType.php @@ -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; } diff --git a/maintenance/backup.inc b/maintenance/backup.inc index 73c0ed3e87..9b2ff89295 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -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" ); -- 2.20.1