Cleanup most of the DIY extension detection/dl() code into nice clean wfDl()
authorChad Horohoe <demon@users.mediawiki.org>
Mon, 14 Jun 2010 18:09:19 +0000 (18:09 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Mon, 14 Jun 2010 18:09:19 +0000 (18:09 +0000)
config/Installer.php
includes/GlobalFunctions.php
includes/MimeMagic.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMysql.php
includes/diff/DifferenceInterface.php
includes/installer/Installer.php
includes/installer/InstallerDBType.php
maintenance/backup.inc

index 191ca85..3b24ef8 100644 (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;
        }
index 67b8212..76d67f9 100644 (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.
index 364c09b..555cc11 100644 (file)
@@ -102,7 +102,7 @@ END_STRING
 global $wgLoadFileinfoExtension;
 
 if ($wgLoadFileinfoExtension) {
-       if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX);
+       wfDl( 'fileinfo' );
 }
 
 /**
index 2319056..824267c 100644 (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";
index a08b694..68a7fee 100644 (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
index 3ec9d40..617f39a 100644 (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' );
                }
index 9e734a7..b923394 100644 (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() {
index 2b03d63..0abb450 100644 (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;
        }
index 73c0ed3..9b2ff89 100644 (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" );