Page MenuHomePhabricator

Special:Upload refuses to upload epub file even when "Ignore any warnings" is checked
Open, Needs TriagePublic

Description

I cannot upload ".epub" files on a wiki that's configured to permit them. To reproduce:

Tell LocalSettings.php to permit uploads of zip and epub files:

$wgFileExtensions[] = 'epub';
$wgFileExtensions[] = 'zip';

Then visit Special:Upload, make sure the checkbox Ignore any warnings is CHECKED, and attempt to upload an epub file.

The file does not upload, and I get the warning: File extension ".epub" does not match the detected MIME type of the file (application/zip). This is unexpected behavior because the file types are permitted for upload and the "ignore warnings" checkbox is checked.

Version info:

  • MediaWiki 1.34.1
  • PHP 7.2.24-0ubuntu0.18.04.4 (apache2handler)
  • MySQL 5.7.30-0ubuntu0.18.04.1
  • ICU 60.2

Event Timeline

https://www.mediawiki.org/wiki/Manual:$wgFileExtensions is an array. Overwriting the first values of the array (epub) with something else (zip) will not make the first array definition work.

@Aklapper: I am pretty sure your response is incorrect. This syntax appends the given value to the array:

$wgFileExtensions[] = 'epub';

It does not overwrite the first element. Overwriting an element would look like this:

$wgFileExtensions[0] = 'epub';

The bug still stands, I think?

@maiden_taiwan:

Try:

// Add several file types to the default array

$wgFileExtensions = array_merge(

$wgFileExtensions, [
    'pdf', 'ppt', 'jp2', 'doc', 'docx', 'xls', 'xlsx'
]

);

https://www.mediawiki.org/wiki/Manual:$wgFileExtensions is an array. Overwriting the first values of the array (epub) with something else (zip) will not make the first array definition work.

The second value does not overwrite the first. The array contains both file types now.

The file does not upload, and I get the warning: File extension ".epub" does not match the detected MIME type of the file (application/zip). This is unexpected behavior because the file types are permitted for upload and the "ignore warnings" checkbox is checked.

Not all warnings can be ignored, and the error does not mean the file type is not permitted. You've already allowed it through the above array.

The error message looks pretty self explanatory. The file fails MIME type verification. You should consider setting $wgVerifyMimeType to false. If you're OK with bypassing the verification. Otherwise you should upload epub with valid MIME type of application/epub+zip

Sorry, and thanks for correcting me!

@Ammarpad - Thank you for the suggestion about the MIME type. I don't know much about epub files, but when I unzip my file, I see:

M Filemode      Length  Date         Time      File
- ----------  --------  -----------  --------  --------------------------------------------------------
  -rw-rw-rw-        20   6-Apr-2020  23:23:52  mimetype
  -rw-rw-rw-       350   6-Apr-2020  23:23:56  OEBPS/CoverImage.xhtml
  -rw-rw-rw-     20418   6-Apr-2020  23:23:56  OEBPS/toc.ncx
  -rw-rw-rw-       266   6-Apr-2020  23:23:56  META-INF/container.xml
  ...

When I open the "mimetype" file, it says:

application/epub+zip

Do you know why MediaWiki still identifies the MIME type as application/zip? Is this a problem with MediaWiki or with the file?

I've placed a copy of the file at https://blazemonger.com/dissertation-dominic-stone.epub in case it will help.

Based on my reading, it looks like the mimetype file should be all that's needed.

FYI, I also just added application/epub+zip to /etc/mime.types (on my Ubuntu 18.04 system)

application/epub+zip              epub

and ran sudo update-mime-database /usr/share/mime (and restarted apache just in case).

This did not fix the problem.

I also verified the mimetype:

$ mimetype *epub
dissertation-dominic-stone.epub: application/epub+zip

FYI, I also just added application/epub+zip to /etc/mime.types (on my Ubuntu 18.04 system)

application/epub+zip              epub

and ran sudo update-mime-database /usr/share/mime (and restarted apache just in case).

This did not fix the problem.

Set the above file path as the value of $wgMimeTypeFile.

Thank you for the suggestion, @Ammarpad. I added this line to LocalSettings.php:

$wgMimeTypeFile = '/etc/mime.types';

but unfortunately, this did not change the behavior..