[BUGFIX] Support SVG without XML prologue 27/38727/11
authorFrank Nägler <typo3@naegler.net>
Thu, 16 Apr 2015 07:50:21 +0000 (09:50 +0200)
committerFrans Saris <franssaris@gmail.com>
Mon, 20 Apr 2015 17:09:19 +0000 (19:09 +0200)
If a SVG does not contains a XML prologue, TYPO3 indexes this file with
mimetype text/plain, which results in missing width and height in the
database. This patch adds a mapping for known filetypes to support
also files which mimetype can not detected automatically.

Resolves: #66445
Releases: master
Change-Id: I908e2f1bb95f9e59ebf23f79f09645afd6696ecd
Reviewed-on: http://review.typo3.org/38727
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Type/File/FileInfo.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Feature-66445-AddFileExtensionToMimeTypeMapping.rst [new file with mode: 0644]

index b7f7d10..cd803b3 100644 (file)
@@ -29,11 +29,17 @@ class FileInfo extends \SplFileInfo implements TypeInterface {
        public function getMimeType() {
                $mimeType = FALSE;
                if ($this->isFile()) {
-                       if (function_exists('finfo_file')) {
-                               $fileInfo = new \finfo();
-                               $mimeType = $fileInfo->file($this->getPathname(), FILEINFO_MIME_TYPE);
-                       } elseif (function_exists('mime_content_type')) {
-                               $mimeType = mime_content_type($this->getPathname());
+                       $fileExtensionToMimeTypeMapping = $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType'];
+                       $lowercaseFileExtension = strtolower($this->getExtension());
+                       if (!empty($fileExtensionToMimeTypeMapping[$lowercaseFileExtension])) {
+                               $mimeType = $fileExtensionToMimeTypeMapping[$lowercaseFileExtension];
+                       } else {
+                               if (function_exists('finfo_file')) {
+                                       $fileInfo = new \finfo();
+                                       $mimeType = $fileInfo->file($this->getPathname(), FILEINFO_MIME_TYPE);
+                               } elseif (function_exists('mime_content_type')) {
+                                       $mimeType = mime_content_type($this->getPathname());
+                               }
                        }
                }
 
index c3d3b91..37bdc35 100644 (file)
@@ -268,6 +268,14 @@ return array(
                                'category' => \TYPO3\CMS\Core\Resource\Collection\CategoryBasedFileCollection::class,
                        )
                ),
+               'FileInfo' => array(
+                       // Static mapping for file extensions to mime types.
+                       // In special cases the mime type is not detected correctly.
+                       // Use this array only if the automatic detection does not work correct!
+                       'fileExtensionToMimeType' => array(
+                               'svg' => 'image/svg+xml'
+                       )
+               ),
                'isInitialInstallationInProgress' => FALSE,             // Boolean: If TRUE, the installation is 'in progress'. This value is handled within the install tool step installer internally.
                'clearCacheSystem' => FALSE,            // Boolean: If set, the toolbar menu entry for clearing system caches (core cache, class cache, etc.) is visible for admin users.
        ),
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-66445-AddFileExtensionToMimeTypeMapping.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-66445-AddFileExtensionToMimeTypeMapping.rst
new file mode 100644 (file)
index 0000000..e0da06d
--- /dev/null
@@ -0,0 +1,21 @@
+========================================================
+Feature: #66445 - Add file extension to mimeType mapping
+========================================================
+
+Description
+===========
+
+As bugfix for wrong mimeType detection for SVG files without XML prolog we added a new setting to map known file extensions to mimeTypes.
+The new setting is ``$GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType']`` which contains an array:
+
+.. code-block::
+
+       array(
+               'svg' => 'image/svg+xml'
+       )
+
+Impact
+======
+
+The automatic detection for mimeTypes works great, but in some special cases not.
+This new setting should only be used, if the automatic detection fails.