From: Kunal Mehta Date: Tue, 26 Jul 2016 02:56:16 +0000 (-0700) Subject: Move MediaHandler defaults out of global scope X-Git-Tag: 1.31.0-rc.0~6172^2 X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=commitdiff_plain;h=1b1b3cdb5438e4b649e425e0334c3a72bfca0598;p=lhc%2Fweb%2Fwiklou.git Move MediaHandler defaults out of global scope The defaults that were in $wgMediaHandlers are now listed in MediaHandlerFactory. The main advantage of doing this is we get O(1) replacement when extensions set a media handler in their extension.json. Bug: T141305 Change-Id: I05771a673837ab8d6331eedc24eb707be7f3a250 --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1e6030226c..27fdd90fd7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -941,22 +941,11 @@ $wgTrustedMediaFormats = [ /** * Plugins for media file type handling. * Each entry in the array maps a MIME type to a class name + * + * Core media handlers are listed in MediaHandlerFactory, + * and extensions should use extension.json. */ -$wgMediaHandlers = [ - 'image/jpeg' => 'JpegHandler', - 'image/png' => 'PNGHandler', - 'image/gif' => 'GIFHandler', - 'image/tiff' => 'TiffHandler', - 'image/webp' => 'WebPHandler', - 'image/x-ms-bmp' => 'BmpHandler', - 'image/x-bmp' => 'BmpHandler', - 'image/x-xcf' => 'XCFHandler', - 'image/svg+xml' => 'SvgHandler', // official - 'image/svg' => 'SvgHandler', // compat - 'image/vnd.djvu' => 'DjVuHandler', // official - 'image/x.djvu' => 'DjVuHandler', // compat - 'image/x-djvu' => 'DjVuHandler', // compat -]; +$wgMediaHandlers = []; /** * Plugins for page content model handling. diff --git a/includes/media/MediaHandlerFactory.php b/includes/media/MediaHandlerFactory.php index c6b4e8dbdc..1deecd7b09 100644 --- a/includes/media/MediaHandlerFactory.php +++ b/includes/media/MediaHandlerFactory.php @@ -29,14 +29,39 @@ class MediaHandlerFactory { /** + * Default, MediaWiki core media handlers + * + * @var array + */ + private static $coreHandlers = [ + 'image/jpeg' => JpegHandler::class, + 'image/png' => PNGHandler::class, + 'image/gif' => GIFHandler::class, + 'image/tiff' => TiffHandler::class, + 'image/webp' => WebPHandler::class, + 'image/x-ms-bmp' => BmpHandler::class, + 'image/x-bmp' => BmpHandler::class, + 'image/x-xcf' => XCFHandler::class, + 'image/svg+xml' => SvgHandler::class, // official + 'image/svg' => SvgHandler::class, // compat + 'image/vnd.djvu' => DjVuHandler::class, // official + 'image/x.djvu' => DjVuHandler::class, // compat + 'image/x-djvu' => DjVuHandler::class, // compat + ]; + + /** + * Instance cache of MediaHandler objects by mimetype + * * @var MediaHandler[] */ private $handlers; protected function getHandlerClass( $type ) { global $wgMediaHandlers; - if ( isset( $wgMediaHandlers[$type] ) ) { - return $wgMediaHandlers[$type]; + + $registry = $wgMediaHandlers + self::$coreHandlers; + if ( isset( $registry[$type] ) ) { + return $registry[$type]; } else { return false; }