X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FMediaHandlerFactory.php;h=543dc80dfd7ef529e6dae2576a41442666593cfc;hb=69240c4b143ef9e01a7f3479349c56e568504ba3;hp=7e412428234a26ee31db0d39b261cc604c5e24d4;hpb=b4596edd0096746735214a00578e24f389060ae6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/MediaHandlerFactory.php b/includes/media/MediaHandlerFactory.php index 7e41242823..543dc80dfd 100644 --- a/includes/media/MediaHandlerFactory.php +++ b/includes/media/MediaHandlerFactory.php @@ -29,30 +29,73 @@ 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 + ]; + + /** + * @var array + */ + private $registry; + + /** + * Instance cache of MediaHandler objects by mimetype + * * @var MediaHandler[] */ private $handlers; + public function __construct( array $registry ) { + $this->registry = $registry + self::$coreHandlers; + } + + protected function getHandlerClass( $type ) { + if ( isset( $this->registry[$type] ) ) { + return $this->registry[$type]; + } else { + return false; + } + } + /** * @param string $type mimetype * @return bool|MediaHandler */ public function getHandler( $type ) { - global $wgMediaHandlers; - if ( !isset( $wgMediaHandlers[$type] ) ) { - wfDebug( __METHOD__ . ": no handler found for $type.\n" ); - - return false; + if ( isset( $this->handlers[$type] ) ) { + return $this->handlers[$type]; } - $class = $wgMediaHandlers[$type]; - if ( !isset( $this->handlers[$class] ) ) { - $this->handlers[$class] = new $class; - if ( !$this->handlers[$class]->isEnabled() ) { + + $class = $this->getHandlerClass( $type ); + if ( $class !== false ) { + /** @var MediaHandler $handler */ + $handler = new $class; + if ( !$handler->isEnabled() ) { wfDebug( __METHOD__ . ": $class is not enabled\n" ); - $this->handlers[$class] = false; + $handler = false; } + } else { + wfDebug( __METHOD__ . ": no handler found for $type.\n" ); + $handler = false; } - return $this->handlers[$class]; + $this->handlers[$type] = $handler; + return $handler; } }