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 ) { if ( isset( $this->handlers[$type] ) ) { return $this->handlers[$type]; } $class = $this->getHandlerClass( $type ); if ( $class !== false ) { /** @var MediaHandler $handler */ $handler = new $class; if ( !$handler->isEnabled() ) { wfDebug( __METHOD__ . ": $class is not enabled\n" ); $handler = false; } } else { wfDebug( __METHOD__ . ": no handler found for $type.\n" ); $handler = false; } $this->handlers[$type] = $handler; return $handler; } }