We're having lots of issues with files that used to be defined as audio, image, or video that are now being classified as 'undefined'. This requires integrating modules to both use hook_file_mimetype_mapping_alter() and hook_file_default_types_alter(). Now if we add a new file mimetype in core or things change we have to update the default and people that have altered the description or something else on the file type, no longer get the change.
I think it would be best for usability that the three main media file types use a wildcard selection of audio/*, image/* and video/*. I think this will give us a much better default config that admins don't have to go back and edit every time there is a new mime type.
Comment | File | Size | Author |
---|---|---|---|
#22 | wildcards_1911970_22.patch | 4.94 KB | slashrsm |
#22 | interdiff.txt | 899 bytes | slashrsm |
#20 | interdiff.txt | 3.21 KB | slashrsm |
#20 | wildcards_1911970_20.patch | 4.06 KB | slashrsm |
#17 | wildcards_1911970_17.patch | 3.83 KB | aaron |
Comments
Comment #1
Dave ReidBumping to major. We shouldn't be requiring modules like media_youtube to be updating the file types themselves.
Comment #2
azinck CreditAttribution: azinck commentedRelated: #1920350: Provide a "catch all" default application file type
Comment #3
aaron CreditAttribution: aaron commentedhere is a proof of concept.
Comment #4
slashrsm CreditAttribution: slashrsm commentedLooks good. Attached patch adds submit validation.
Comment #5
bneil CreditAttribution: bneil commentedComment #6
aaron CreditAttribution: aaron commentedThanks so much! This patch improves it by adding some sensible defaults.
Comment #7
slashrsm CreditAttribution: slashrsm commentedLooks good to me. Ready to roll?
Comment #8
Dave ReidI'm a little confused as to the usage of fnmatch, since I've never seen that function before. It appears that according to http://php.net/manual/en/function.fnmatch.php it's not available on Windows PHP until 5.3.0, so let's use preg for regex instead of fnmatch.
Comment #9
ParisLiakos CreditAttribution: ParisLiakos commentedfirst time i saw this function here as well..nice job aaron digging this up:)
Comment #10
Dave ReidAlso if we're going to use a fnmatch() like pattern, then we should support all possible syntaxes that it can use, like
*gr[ae]y!?
I would prefer we use something that checks for the characters
*?[]
in *any* part of the mimetype, and then do the following:And we could add a @todo that this logic could be replaced by fnmatch() in Drupal 8.
Comment #11
slashrsm CreditAttribution: slashrsm commentedI agree that we should support all possible syntaxes, but I am not sure about fnmatch(). Code that uses it looks MUCH simpler and more readable. Drupal 7 recommends PHP 5.3 anyway and most hosting providers are at least offering it nowadays.
Comment #12
ParisLiakos CreditAttribution: ParisLiakos commentedwell, i have seen many hosts with CentOs and php 5.2..but the thing here is that this applies for windows servers...i have no clue what happens there and what version the usually are in
Comment #13
slashrsm CreditAttribution: slashrsm commentedTrue. Windows market share in server environments is very low. Dev envs should be even less problematic when it comes to upgrades.
Comment #14
Dave ReidMy point with the code is #10 is that I love the fnmatch syntax as well, but we cannot rely on it. Which is why I emulated the use of fnmatch using preg_replace, but the actual syntax is the same. We could make a file_entity_fnmatch() wrapper that calls fnmatch directly if it exists, or does the alternative code if necessary.
Comment #15
slashrsm CreditAttribution: slashrsm commentedI may be stupid, but I really don't get why we cannot rely on fnmatch(). Alternative implementation sounds good, though. Maybe something like this (as proposed on php.net):
Comment #16
Dave ReidWe cannot rely on fnmatch because the minimum requirement for Drupal 7 is PHP 5.2, and this function isn't available at all on Windows systems until PHP 5.3.0. We also shouldn't define PHP-namespaced functions like that. If anything we should just use a wrapper named file_entity_fnmatch() that calls fnmatch() if it exists, or does the backup logic. Also note that fnmatch is case sensitive by default, so we cannot use the 'i' modifier in preg_match().
Comment #17
aaron CreditAttribution: aaron commentedThanks for the suggestions, here is a reroll with a wrapper named file_entity_fnmatch().
Comment #18
slashrsm CreditAttribution: slashrsm commentedThanks aaron. I tested some patterns and I found that those do not work properly with fallback code (while they do with fnmatch()):
The following patterns work correctly with both implementations:
Comment #19
Dave ReidI feel like this logic and the one in file_entity_file_type() could use a helper function for 'does this mimetype match an array of possible mimetypes and mimetype wildcards'.
This should also be checking the other characters of
?[]
. Also, the wildcard shouldn't be limited to only the second part of the mimetype. It should likely do a check likestrpbrk($mimetype, '*?[]');
This needs to add support for
'\[' => '[', '\]' => ']'
And it needs to remove the
i
modifier from the regex as fnmatch() is case-sensitive by default.Comment #20
slashrsm CreditAttribution: slashrsm commentedComments from #19 taken into consideration + some whitespace fixes.
Comment #22
slashrsm CreditAttribution: slashrsm commentedLet's see if we fixed those nasty tests....
Comment #23
aaron CreditAttribution: aaron commentedThis looks great to me.
Comment #24
Devin Carlson CreditAttribution: Devin Carlson commentedThe patch in #22 applied with an offset.
Looks good and I tested this in our Windows [read: only] environments with no issues.
Committed to 7.x-2.x. Great work everyone!
Comment #25
Dave ReidFollow-up for Media: Youtube - #1949520: Remove media_youtube_update_7202() and media_youtube_file_default_types_alter()
Comment #26
Dave ReidNotes posted in existing issues:
#1931136: Notify via hook_update_N / document that the file MIME types and displays may need to be rebuilt
#1850924: Create Mime types
Comment #27
Dave ReidFollow-up for Media: Vimeo - #1950188: Remove media_vimeo_update_7200() and media_vimeo_file_default_types_alter()
Comment #31
Devin Carlson CreditAttribution: Devin Carlson commented