: How to configure MediaWiki to allow uploading text/plain ".conf' files I'm having a heck of a time getting our internal MediaWiki to allow CONF file uploads. A CONF file is just a plain text
I'm having a heck of a time getting our internal MediaWiki to allow CONF file uploads. A CONF file is just a plain text file with a *.conf extension.
In ...LocalSettings.php, I added txt and conf to the array of $wgFileExtensions. The extensions are recognized after an apache restart (see the preferred file types in the image below). $wgCheckFileExtensions is false and $wgStrictFileExtensions is false.
Yet when I try to upload, I get a the following warning:
File extension ".conf" does not match the detected MIME type of the file (text/plain)
Not that this is not an error and the file is not uploaded. (I also have "Ignore warnings" checked). An image of a failed attempt is shown below.
How does one enable and upload a CONF file to MediaWiki?
More posts by @Merenda212
2 Comments
Sorted by latest first Latest Oldest Best
As Stephen Ostermiller says, in this case you want to add "conf" to the line beginning with "text/plain" in:
includes/mime.types
In other cases though it may not be this simple. When you upload a file, mediawiki executes the PHP function
mime_content_type("my_uploaded.wth");
which takes the result and looks it up in includes/mime.types. If you find that php doesn't recognize a file type you want to accept, you can set $wgMimeDetectorCommand in LocalSettings.php to designate a custom command to analyze files for you. Here's an example that uses a magic.mgc file with more file type information than the default:
$wgMimeDetectorCommand = "/usr/bin/file -bi -m /usr/local/share/magic.mgc";
But you could specify a path to any executable and customize to your heart's content. So you could set
$wgMimeDetectorCommand = "/usr/local/sbin/my_custom_mimechecker.py
Which tries the file command above, say, and adds some custom logic. In the end, if the following command is run:
/usr/local/sbin/my_custom_mimechecker.py my_uploaded.wth
and it returns (prints to STDOUT and exits with status 0)
application/heck; charset=binary
and you have a line in mime.types
application/heck wtg wth wti wtj
I.e. the wth extension of the uploaded file matches the output of the $wgMimeDetectorCommand, the upload will be allowed.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.