4

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.

"Upload warning" on the "Upload file" page

How does one enable and upload a CONF file to MediaWiki?

migrated from webapps.stackexchange.com Dec 7 '14 at 10:26

This question came from our site for power users of web applications.

4

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.

1

Here is the MediaWiki documentation for mime type detection. It says that you need to add modify two files:

mime.types

Add conf to the text/plain line

mime.info

Ensure that text/plain is on the line ending in [TEXT]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.