From d0c8ba037cf6901d490984106677ec4785c51796 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 9 Oct 2013 09:46:57 -0700 Subject: [PATCH] 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 --- includes/DefaultSettings.php | 7 ---- includes/GlobalFunctions.php | 32 ------------------- includes/MimeMagic.php | 11 +------ includes/db/DatabaseMysql.php | 5 +-- includes/diff/DifferenceEngine.php | 20 ------------ includes/installer/DatabaseInstaller.php | 7 +--- maintenance/backup.inc | 7 ++-- maintenance/sqlite.inc | 5 +-- tests/phpunit/includes/CollationTest.php | 2 +- .../media/BitmapMetadataHandlerTest.php | 6 ++-- .../phpunit/includes/media/ExifBitmapTest.php | 7 ++-- .../includes/media/ExifRotationTest.php | 7 ++-- tests/phpunit/includes/media/ExifTest.php | 7 ++-- .../includes/media/FormatMetadataTest.php | 2 +- tests/phpunit/includes/media/JpegTest.php | 7 ++-- tests/phpunit/includes/media/TiffTest.php | 9 ++---- tests/phpunit/includes/media/XMPTest.php | 2 +- 17 files changed, 31 insertions(+), 112 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 98c583b939..21cd1ff53d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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. diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b11bce9b93..8241d81ae9 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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() diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 44fafcaf15..8220e92fc4 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -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" ); diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index b75d615b10..956bb694e2 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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" ); } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 0c9086bd3e..e436f58d30 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -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 diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index 3739bb5de2..8bb782615d 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -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 ); } /** diff --git a/maintenance/backup.inc b/maintenance/backup.inc index db045cf2d6..3dc94c889b 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -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: diff --git a/maintenance/sqlite.inc b/maintenance/sqlite.inc index 49f4e00f8e..08188cade4 100644 --- a/maintenance/sqlite.inc +++ b/maintenance/sqlite.inc @@ -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' ); } /** diff --git a/tests/phpunit/includes/CollationTest.php b/tests/phpunit/includes/CollationTest.php index ae35fd7a42..f1004fbf66 100644 --- a/tests/phpunit/includes/CollationTest.php +++ b/tests/phpunit/includes/CollationTest.php @@ -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' ); } } diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php index ffa6084939..43792c1da5 100644 --- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php +++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php @@ -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(); diff --git a/tests/phpunit/includes/media/ExifBitmapTest.php b/tests/phpunit/includes/media/ExifBitmapTest.php index 1109c478c2..532182c7f9 100644 --- a/tests/phpunit/includes/media/ExifBitmapTest.php +++ b/tests/phpunit/includes/media/ExifBitmapTest.php @@ -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() { diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php index f02e8b912c..c16de8bf88 100644 --- a/tests/phpunit/includes/media/ExifRotationTest.php +++ b/tests/phpunit/includes/media/ExifRotationTest.php @@ -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, diff --git a/tests/phpunit/includes/media/ExifTest.php b/tests/phpunit/includes/media/ExifTest.php index 6ad28ac514..b84ed56cb8 100644 --- a/tests/phpunit/includes/media/ExifTest.php +++ b/tests/phpunit/includes/media/ExifTest.php @@ -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 ); } diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index f26d27eedf..bee0906f6b 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -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'; diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php index 05d3661efa..7775c41733 100644 --- a/tests/phpunit/includes/media/JpegTest.php +++ b/tests/phpunit/includes/media/JpegTest.php @@ -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 ); } diff --git a/tests/phpunit/includes/media/TiffTest.php b/tests/phpunit/includes/media/TiffTest.php index 91c35c4b91..1ec34d5796 100644 --- a/tests/phpunit/includes/media/TiffTest.php +++ b/tests/phpunit/includes/media/TiffTest.php @@ -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 diff --git a/tests/phpunit/includes/media/XMPTest.php b/tests/phpunit/includes/media/XMPTest.php index 25a43ebc61..aa0cdd2ec8 100644 --- a/tests/phpunit/includes/media/XMPTest.php +++ b/tests/phpunit/includes/media/XMPTest.php @@ -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' ); } } -- 2.20.1