Mimetypes. Mimetypes! MIMETYPES!

Mime types?

This patchset deals with files in a much better, saner way. Wherever possible, it attempts to:

 - Assign a clean file extension (always the same for the same mime type)
 - Assign a clean mime type / content type
 - Use mime types instead of extensions for any checks of any kind

More complexity will be needed if things such as children mime types of plain/text have to be supported.

Tested locally, but with very limited existing data. Please test if it breaks stuff.