Remove wfDl() and cleanup everything it touched
wfDl() is a wrapper around dl(), which is an evil function and basically only works from the command line of Zend. Luckily no extension has ever used this thing, so let's just remove it outright. For comparison, here's a list of places it does not work: - hhvm - php as apache module - php compiled with zts support - safe_mode - Basically any shared host that cares about security Most callers are using it to check for extension support and are actually failing gracefully when wfDl() returns false. In these places we're just going to use extension_loaded(). While we're at it, clean up some of the test skip logic in the media tests so we can bail as early as possible if we know we can't complete the test. This also immediately removes $wgLoadFileinfoExtension. It's been enabled by default since 5.3 and falls back gracefully when the support isn't available. Change-Id: Ieb430dfc74483731dde51d6e20fa700d641ba1f4
This commit is contained in:
parent
51833b036f
commit
d0c8ba037c
17 changed files with 31 additions and 112 deletions
|
|
@ -1125,13 +1125,6 @@ $wgMimeTypeFile = 'includes/mime.types';
|
|||
*/
|
||||
$wgMimeInfoFile = 'includes/mime.info';
|
||||
|
||||
/**
|
||||
* Switch for loading the FileInfo extension by PECL at runtime.
|
||||
* This should be used only if fileinfo is installed as a shared object
|
||||
* or a dynamic library.
|
||||
*/
|
||||
$wgLoadFileinfoExtension = false;
|
||||
|
||||
/**
|
||||
* Sets an external mime detector program. The command must print only
|
||||
* the mime type to standard output.
|
||||
|
|
|
|||
|
|
@ -2634,38 +2634,6 @@ 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 string $extension A PHP extension. The file suffix (.so or .dll)
|
||||
* should be omitted
|
||||
* @param string $fileName Name of the library, if not $extension.suffix
|
||||
* @return Bool - Whether or not the extension is loaded
|
||||
*/
|
||||
function wfDl( $extension, $fileName = null ) {
|
||||
if ( extension_loaded( $extension ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$canDl = false;
|
||||
if ( PHP_SAPI == 'cli' || PHP_SAPI == 'cgi' || PHP_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( $fileName . '.' . PHP_SHLIB_SUFFIX );
|
||||
wfRestoreWarnings();
|
||||
}
|
||||
return extension_loaded( $extension );
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows-compatible version of escapeshellarg()
|
||||
* Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
|
||||
|
|
|
|||
|
|
@ -169,10 +169,6 @@ class MimeMagic {
|
|||
*/
|
||||
private static $instance;
|
||||
|
||||
/** True if the fileinfo extension has been loaded
|
||||
*/
|
||||
private static $extensionLoaded = false;
|
||||
|
||||
/** Initializes the MimeMagic object. This is called by MimeMagic::singleton().
|
||||
*
|
||||
* This constructor parses the mime.types and mime.info files and build internal mappings.
|
||||
|
|
@ -182,7 +178,7 @@ class MimeMagic {
|
|||
* --- load mime.types ---
|
||||
*/
|
||||
|
||||
global $wgMimeTypeFile, $IP, $wgLoadFileinfoExtension;
|
||||
global $wgMimeTypeFile, $IP;
|
||||
|
||||
$types = MM_WELL_KNOWN_MIME_TYPES;
|
||||
|
||||
|
|
@ -190,11 +186,6 @@ class MimeMagic {
|
|||
$wgMimeTypeFile = "$IP/$wgMimeTypeFile";
|
||||
}
|
||||
|
||||
if ( $wgLoadFileinfoExtension && !self::$extensionLoaded ) {
|
||||
self::$extensionLoaded = true;
|
||||
wfDl( 'fileinfo' );
|
||||
}
|
||||
|
||||
if ( $wgMimeTypeFile ) {
|
||||
if ( is_file( $wgMimeTypeFile ) and is_readable( $wgMimeTypeFile ) ) {
|
||||
wfDebug( __METHOD__ . ": loading mime types from $wgMimeTypeFile\n" );
|
||||
|
|
|
|||
|
|
@ -43,12 +43,9 @@ class DatabaseMysql extends DatabaseMysqlBase {
|
|||
}
|
||||
|
||||
protected function mysqlConnect( $realServer ) {
|
||||
# Load mysql.so if we don't have it
|
||||
wfDl( 'mysql' );
|
||||
|
||||
# Fail now
|
||||
# Otherwise we get a suppressed fatal error, which is very hard to track down
|
||||
if ( !function_exists( 'mysql_connect' ) ) {
|
||||
if ( !extension_loaded( 'mysql' ) ) {
|
||||
throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -695,24 +695,6 @@ class DifferenceEngine extends ContextSource {
|
|||
return $difftext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the proper modules are loaded before we try to
|
||||
* make the diff
|
||||
*/
|
||||
private function initDiffEngines() {
|
||||
global $wgExternalDiffEngine;
|
||||
if ( $wgExternalDiffEngine == 'wikidiff' && !function_exists( 'wikidiff_do_diff' ) ) {
|
||||
wfProfileIn( __METHOD__ . '-php_wikidiff.so' );
|
||||
wfDl( 'php_wikidiff' );
|
||||
wfProfileOut( __METHOD__ . '-php_wikidiff.so' );
|
||||
}
|
||||
elseif ( $wgExternalDiffEngine == 'wikidiff2' && !function_exists( 'wikidiff2_do_diff' ) ) {
|
||||
wfProfileIn( __METHOD__ . '-php_wikidiff2.so' );
|
||||
wfDl( 'wikidiff2' );
|
||||
wfProfileOut( __METHOD__ . '-php_wikidiff2.so' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a diff, no caching.
|
||||
*
|
||||
|
|
@ -779,8 +761,6 @@ class DifferenceEngine extends ContextSource {
|
|||
$otext = str_replace( "\r\n", "\n", $otext );
|
||||
$ntext = str_replace( "\r\n", "\n", $ntext );
|
||||
|
||||
$this->initDiffEngines();
|
||||
|
||||
if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
|
||||
# For historical reasons, external diff engine expects
|
||||
# input text to be HTML-escaped already
|
||||
|
|
|
|||
|
|
@ -321,16 +321,11 @@ abstract class DatabaseInstaller {
|
|||
* Convenience function.
|
||||
* Check if a named extension is present.
|
||||
*
|
||||
* @see wfDl
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
protected static function checkExtension( $name ) {
|
||||
wfSuppressWarnings();
|
||||
$compiled = wfDl( $name );
|
||||
wfRestoreWarnings();
|
||||
|
||||
return $compiled;
|
||||
return extension_loaded( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -170,11 +170,8 @@ class BackupDumper {
|
|||
break;
|
||||
case "force-normal":
|
||||
if ( !function_exists( 'utf8_normalize' ) ) {
|
||||
wfDl( "php_utfnormal.so" );
|
||||
if ( !function_exists( 'utf8_normalize' ) ) {
|
||||
$this->fatalError( "Failed to load UTF-8 normalization extension. " .
|
||||
"Install or remove --force-normal parameter to use slower code." );
|
||||
}
|
||||
$this->fatalError( "UTF-8 normalization extension not loaded. " .
|
||||
"Install or remove --force-normal parameter to use slower code." );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -33,10 +33,7 @@ class Sqlite {
|
|||
* @return bool
|
||||
*/
|
||||
public static function isPresent() {
|
||||
wfSuppressWarnings();
|
||||
$compiled = wfDl( 'pdo_sqlite' );
|
||||
wfRestoreWarnings();
|
||||
return $compiled;
|
||||
return extension_loaded( 'pdo_sqlite' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
class CollationTest extends MediaWikiLangTestCase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !wfDl( 'intl' ) ) {
|
||||
if ( !extension_loaded( 'intl' ) ) {
|
||||
$this->markTestSkipped( 'These tests require intl extension' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
|
|||
* translation (to en) where XMP should win.
|
||||
*/
|
||||
public function testMultilingualCascade() {
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
if ( !wfDl( 'xml' ) ) {
|
||||
if ( !extension_loaded( 'xml' ) ) {
|
||||
$this->markTestSkipped( "This test needs the xml extension." );
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testPNGXMP() {
|
||||
if ( !wfDl( 'xml' ) ) {
|
||||
if ( !extension_loaded( 'xml' ) ) {
|
||||
$this->markTestSkipped( "This test needs the xml extension." );
|
||||
}
|
||||
$handler = new BitmapMetadataHandler();
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ class ExifBitmapTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->setMwGlobals( 'wgShowEXIF', true );
|
||||
|
||||
$this->handler = new ExifBitmapHandler;
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testIsOldBroken() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ class ExifRotationTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->handler = new BitmapHandler();
|
||||
$filePath = __DIR__ . '/../../data/media';
|
||||
|
||||
|
|
@ -22,9 +26,6 @@ class ExifRotationTest extends MediaWikiTestCase {
|
|||
'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
|
||||
) )
|
||||
) );
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->setMwGlobals( array(
|
||||
'wgShowEXIF' => true,
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ class ExifTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->mediaPath = __DIR__ . '/../../data/media/';
|
||||
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
|
||||
$this->setMwGlobals( 'wgShowEXIF', true );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class FormatMetadataTest extends MediaWikiTestCase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
$filePath = __DIR__ . '/../../data/media';
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ class JpegTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->filePath = __DIR__ . '/../../data/media/';
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->filePath = __DIR__ . '/../../data/media/';
|
||||
|
||||
|
||||
$this->setMwGlobals( 'wgShowEXIF', true );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ class TiffTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !extension_loaded( 'exif' ) ) {
|
||||
$this->markTestSkipped( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$this->setMwGlobals( 'wgShowEXIF', true );
|
||||
|
||||
|
|
@ -11,17 +14,11 @@ class TiffTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testInvalidFile() {
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
$this->markTestIncomplete( "This test needs the exif extension." );
|
||||
}
|
||||
$res = $this->handler->getMetadata( null, $this->filePath . 'README' );
|
||||
$this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
|
||||
}
|
||||
|
||||
public function testTiffMetadataExtraction() {
|
||||
if ( !wfDl( 'exif' ) ) {
|
||||
$this->markTestIncomplete( "This test needs the exif extension." );
|
||||
}
|
||||
$res = $this->handler->getMetadata( null, $this->filePath . 'test.tiff' );
|
||||
$expected = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
|
||||
// Re-unserialize in case there are subtle differences between how versions
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class XMPTest extends MediaWikiTestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ( !wfDl( 'xml' ) ) {
|
||||
if ( !extension_loaded( 'xml' ) ) {
|
||||
$this->markTestSkipped( 'Requires libxml to do XMP parsing' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue