Merge "mediawiki.user: Use then() instead of done()"
[lhc/web/wiklou.git] / includes / media / MediaHandlerFactory.php
index c6b4e8d..82e8d1f 100644 (file)
 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 ) {
-               global $wgMediaHandlers;
-               if ( isset( $wgMediaHandlers[$type] ) ) {
-                       return $wgMediaHandlers[$type];
-               } else {
-                       return false;
-               }
+               return $this->registry[$type] ?? false;
        }
 
        /**