From: Antoine Musso Date: Mon, 31 Dec 2018 17:30:00 +0000 (+0100) Subject: Recognizes Open Document Database X-Git-Tag: 1.34.0-rc.0~1119^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=c40d76e23b7a56f816a802750fd7300aebf6a1e8;p=lhc%2Fweb%2Fwiklou.git Recognizes Open Document Database Mediawiki does not recognizes the mime type of an OpenOffice / Libre Office Database Frontend Document and thus uses application/zip. Our MimeAnalyzer::detectZipType() looks at the Zip files to detect known signatures, however it is based on a reference from 2005 which did not have the Database type yet. OASIS Open Document Format v1.2 specify non normative MIME types, the reference supposedly being the ones registered with the IANA, but we have some dispredancy: ODF recommends 'base' while the IANA got 'database' registered: https://www.iana.org/assignments/media-types/ I supposed the format got approved as is, the Database mime type being 'recommended' probably because the IANA registration was pending. Add the 'base' type which is being used by OpenOffice 3.x and later as well as at least Libre Office 5.x. Document my findings in code comments. Add a test. Bug: T35515 Change-Id: If0210a87067358612ecb8b3edd001fb05d01653d --- diff --git a/includes/libs/mime/MimeAnalyzer.php b/includes/libs/mime/MimeAnalyzer.php index f493769968..42146f4f85 100644 --- a/includes/libs/mime/MimeAnalyzer.php +++ b/includes/libs/mime/MimeAnalyzer.php @@ -878,6 +878,14 @@ EOT; $mime = 'application/zip'; $opendocTypes = [ + # In OASIS Open Document Format v1.2, Database front end document + # has a recommended MIME type of: + # application/vnd.oasis.opendocument.base + # Despite the type registered at the IANA being 'database' which is + # supposed to be normative. + # T35515 + 'base', + 'chart-template', 'chart', 'formula-template', @@ -895,7 +903,10 @@ EOT; 'text-web', 'text' ]; - // https://lists.oasis-open.org/archives/office/200505/msg00006.html + // The list of document types is available in OASIS Open Document + // Format version 1.2 under Appendix C. It is not normative though, + // supposedly types registered at the IANA should be. + // http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html $types = '(?:' . implode( '|', $opendocTypes ) . ')'; $opendocRegex = "/^mimetype(application\/vnd\.oasis\.opendocument\.$types)/"; diff --git a/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php b/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php index 194781207e..0f23b8cdc1 100644 --- a/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php +++ b/tests/phpunit/includes/libs/mime/MimeAnalyzerTest.php @@ -137,4 +137,30 @@ class MimeAnalyzerTest extends PHPUnit\Framework\TestCase { $actualType = $this->doGuessMimeType( [ $file, 'doc' ] ); $this->assertEquals( 'application/msword', $actualType ); } + + /** + * @covers MimeAnalyzer::detectZipType + * @dataProvider provideOpendocumentsformatHeaders + */ + function testDetectZipTypeRecognizesOpendocuments( $expected, $header ) { + $this->assertEquals( + $expected, + $this->mimeAnalyzer->detectZipType( $header ) + ); + } + + /** + * An ODF file is a ZIP file of multiple files. The first one being + * 'mimetype' and is not compressed. + */ + function provideOpendocumentsformatHeaders() { + $thirtychars = str_repeat( 0, 30 ); + return [ + 'Database front end document header based on ODF 1.2' => [ + 'application/vnd.oasis.opendocument.base', + $thirtychars . 'mimetypeapplication/vnd.oasis.opendocument.basePK', + ], + ]; + } + }