Manual:Adding support for new filetypes
Adding support for new file types to MediaWiki can be quite a daunting task. These are some of the steps you might have to take.
What do I need to do ?Edit
- Check if no one has beat you to it. It might be that there is already an extension that handles uploads and thumbnailing for your file type. See Media handling extensions
- If already supported, make sure the file type is one of the filetypes allowed for uploading See Configuring file uploads.
- Do you only require support for uploading, or do you require support for embedding and thumbnailing ?
- Do you need the file format to be supported on Wikimedia websites ? This introduces additional requirements, with regard to performance, security and support of it's communities
Support for uploadsEdit
- Add support for the mime type to MediaWiki:
includes/libs/mime/mime.info(mime to type matching)
includes/libs/mime/mime.types(mime to file extension matching)
includes/libs/mime/MimeAnalyzer.php(magic number detection if possible)
- Add the file type to $wgFileExtensions to allow the upload on your server.
Note that MediaWiki has default checks for zip file formats, blocks java code and things that might be interpreted as HTML files. If your file format falls into this category, you either need to disable some of those protections (which is not advisable for publicly hosted servers) or implement additional logic.
Support thumbnailing and embeddingEdit
- Determine if you need support in MediaWiki core. Usually exotic formats, formats with lots of dependencies or with special functionality will go in dedicated extensions. Examples of such extensions are: 3D, PagedTiffHandler and more.
- Create a MediaHandler subclass for your filetype. For common cases like images, you can often extend from the subclass BitmapHandler instead. Here you can implement:
- Reading the metadata of the file
- Define what the behaviour should be (thumbnailing, embedding/render, paging etc).
- Implement if the code to do some of that behaviour, like thumbnailing and metadata reading.
- Note that the file format of your thumbnail is allowed to be different from your original file format.
- See other image handlers in:
includes/mediasubdirectory of MediaWiki
- Register your MediaHandler in
includes/media/MediaHandlerFactory.phpfor core handlers, or in your extension.json if you have created an extension.
Support on Wikimedia websitesEdit
- The format should be free from patents (Free and open).
- The format should not allow execution of code when downloaded and executed on the computer of clients, like for instance macros or an embedded scripting language (if it does you will need to scan/sanitize the uploads from within MediaWiki)
- If you are adding a new extension, an external library or console tool, then these will require a security review.
- Your thumbnail format should be a commonly supported format for all browsers.
- Your thumbnail (esp when interactive) should be usable when printing and for screenreader users
- Interactive content should not reflow the page
- Interactive content should perform (JS needs to be added only to the pages that require it etc).
- Anything over $wgMaxImageArea in size requires special support, due to memory limitations. See also VipsScaler.
- You need a thumbor engine to support making thumbnails of your images. All Wikimedia requests use a thumbor engine to do the actual thumbnail generation, instead of the thumbnail support inside the MediaHandler.
- Check if the Wikimedia communities support adding this file format (Hold an RFC)