Tweak wfDl() so it actually works properly in 5.3.x
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 20 Apr 2011 23:33:28 +0000 (23:33 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 20 Apr 2011 23:33:28 +0000 (23:33 +0000)
Also add $fileName parameter in case the extension doesn't match the filename
Minor tweak for windows, its files begin php_

includes/GlobalFunctions.php

index 8460c8a..e93cc02 100644 (file)
@@ -2282,19 +2282,30 @@ function wfIniGetBool( $setting ) {
  *
  * @param $extension String A PHP extension. The file suffix (.so or .dll)
  *                          should be omitted
+ * @param $fileName String Name of the library, if not $extension.suffix
  * @return Bool - Whether or not the extension is loaded
  */
-function wfDl( $extension ) {
+function wfDl( $extension, $fileName = null ) {
        if( extension_loaded( $extension ) ) {
                return true;
        }
 
-       $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
+       $canDl = false;
+       $sapi = php_sapi_name();
+       if( version_compare( PHP_VERSION, '5.3.0', '<' ) ||
+               $sapi == 'cli' || $sapi == 'cgi' || $sapi == 'embed' )
+       {
+               $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
                && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) );
+       }
 
        if( $canDl ) {
+               $fileName = $fileName ? $fileName : $extension;
+               if( wfIsWindows() ) {
+                       $fileName = 'php_' . $fileName;
+               }
                wfSuppressWarnings();
-               dl( $extension . '.' . PHP_SHLIB_SUFFIX );
+               dl( $fileName . '.' . PHP_SHLIB_SUFFIX );
                wfRestoreWarnings();
        }
        return extension_loaded( $extension );