Manual:MIME type detection/cs

MediaWiki se pokouší detekovat MIME type souborů, které nahráváte, a odmítne soubor, pokud přípona souboru neodpovídá typu MIME ("Soubor je poškozený nebo má nesprávné rozšíření"). Pokud se tato chyba zobrazuje u platných souborů, zkuste použít externí příkaz pro zjištění typu MIME (viz níže).

Pro konfiguraci, které typy souborů bude MediaWiki přijímat pro nahrávání, použijte.



Detekce MIME
Pokud je nainstalována, MediaWiki používá modul FileInfo PHP nebo starší modul MimeMagic. Pokud se vám zobrazuje chyba jako mime_magic nelze inicializovat, magický soubor není dostupný, tento modul není správně nakonfigurován &mdash; informace o tom, jak to opravit, najdete v dokumentaci PHP nebo místo toho použijte příkaz externího detektoru mime (viz níže).

Alternativně lze nakonfigurovat externí příkaz pro detekci typu mime nastavením možnosti. Nejběžnější nastavení je:

To používá nástroj GNU  k určení typu souboru, který by měl v Linuxu okamžitě fungovat. Pamatujte, že utilita  poskytovaná jinými Unixy nemusí podporovat volbu , a proto nebude fungovat. The GNU  utility is also available for Mac OS-X, and for Windows via Cygwin.

If no mime module is installed, and no external mime detector command is configured, MediaWiki relies on PHP's GD module to detect the mime type. Note that this only works for some well known image types (see ), other files will be accepted without any additional checks!

You can also disable the MIME type check completely by setting  &mdash; note however that this is very insecure: arbitrary files can then be uploaded with a "harmless" file extension, but may possibly still get executed/interpreted in a harmful way on the client computer, or the web server. '' Pending: how does this relate to ? ''

MIME type validation
MediaWiki stores its default mime types and media types in MimeMap.php.

To support extra mime types for uploads on your wiki, you can use the hook since MediaWiki 1.24.

Extra types
The MIME type define file extensions that are allowed for a given mime type. To recognise  files as   for Markdown:

Remember to also add the extension to to allow it to be used for new uploads on your wiki.

You can specify multiple file extensions as well, for example the following is what MediaWiki internally would have done for JPEG:

Note that the MIME type of some file formats may be detected too broadly - any XML-based format may show up as text/xml, any ZIP-based format as application/zip. Consequently, the file extensions for such formats must be associated with their broader MIME type, e.g.:

text/xml xml xsl xslt rss rdf application/zip zip jar xpi application/msword doc xls ppt

Extra info
The "mime info" data is used to resolve aliases for MIME types, and to assign a media type to them. It contains one line per mime type; the first item on the line is the canonical MIME type name (which will be used internally), the last item is of the form [XXX] and defines the media type for the mime type.

To assign  under the "OFFICE" media type:

Some examples:

image/png image/x-png	[BITMAP] image/svg image/svg+xml application/svg+xml application/svg	[DRAWING] audio/mp3 audio/mpeg3 audio/mpeg	[AUDIO]

Note that for OGG files, the media type is determined programmatically: AUDIO for vorbis, VIDEO for theora, MULTIMEDIA otherwise.

The media type is specific to MediaWiki, and determines what kind of media is contained in the file, as opposed to what format the file is in. This information is stored in the table, along with the mime type. It is currently not used for much, but could be used in the future to determine how to present a file to the user. The following types are defined:

Forbidden files
In addition to the  option, the following settings may cause files to be rejected (even if   is set):


 * - a list of file extensions.
 * - a list of forbidden MIME types.

In addition, MediaWiki rejects all files that look like scripts that could be accidentally executed on either the web server or the user's browser. Notably, anything that looks like one of the following formats will be rejected, regardless of detected mime type or file extension: HTML, JavaScript, PHP, shell scripts. Note that the detection of HTML and JavaScript is rather broad, and may report false positives &mdash; this is so because the Microsoft Internet Explorer is known to interpret files that look like HTML, regardless of file extension or MIME type reported by the web server, which would lead to the site being vulnerable to cross-site scripting attacks. If you really want to allow even such dangerous files, you can hack the  function in the UploadBase.php file to always return false.

Virus scans
'' Pending. For now, see and  ''

MIME types when downloading
Note that the MIME type used when the actual file is served to the user's browser is not determined by MediaWiki's MIME-detection: files are not served through MediaWiki, but directly by the web server. Thus, the web server must be configured to use the correct MIME type for each file extension - for example, if you are having trouble viewing SVG files in your browser, make sure the server is configured to deliver them as. (For Apache, read about mod_mime.)