Merge "installer: Replace bad calls to getText() on DBQueryError exceptions"
[lhc/web/wiklou.git] / includes / media / MediaHandlerFactory.php
index c6b4e8d..543dc80 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];
+               if ( isset( $this->registry[$type] ) ) {
+                       return $this->registry[$type];
                } else {
                        return false;
                }