Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 4 years ago

#38195 closed enhancement (fixed)

Adding more mime_types filter to Media Library

Reported by: zodiac1978's profile zodiac1978 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch has-screenshots has-dev-note
Focuses: Cc:

Description

In https://github.com/WordPress/WordPress/blob/e0a0be9579bf00c673f6fa9c68e87d4546271b37/wp-includes/post.php#L2191-L2206 WordPress is defining some default mime_types for filtering purpose in the media library.

At the moment this is everything starting with image, audio and video.

But there are more mime_types possible:
https://codex.wordpress.org/Function_Reference/get_allowed_mime_types#Default_allowed_mime_types

What about adding these mime_types in the way shown in #30788 ?

I suggest the following groups:

Documents:
-----------
application/pdf
application/rtf
application/msword
application/onenote
application/wordperfect
application/vnd (should handle MS, LO/OOo and iWorks)
text/plain
text/csv
text/calendar
text/tab-separated-values
text/richtext
Web-Documents
--------------
text/css
text/html
application/javascript
application/x-shockwave-flash
application/java
Archives:
---------
application/x-tar
application/zip
application/x-gzip
application/rar
application/x-7z-compressed
Misc:
------
application/x-msdownload (exe)

I'm just concerned about a possible performance problem.
See: #31071

Attachments (6)

38195.diff (4.5 KB) - added by zodiac1978 7 years ago.
Proof of concept
new-UI.png (79.4 KB) - added by zodiac1978 7 years ago.
The new dropdown would look like this
38195.2.diff (5.2 KB) - added by swissspidy 6 years ago.
38195.3.diff (2.2 KB) - added by SergeyBiryukov 5 years ago.
38195.4.diff (2.8 KB) - added by SergeyBiryukov 5 years ago.
38195.4.png (7.4 KB) - added by SergeyBiryukov 5 years ago.

Download all attachments as: .zip

Change History (31)

#1 follow-up: @lukecavanagh
7 years ago

@zodiac1978

Maybe to Documents:

Also add
application/epub+zip
application/x-mobipocket-ebook

#2 in reply to: ↑ 1 @zodiac1978
7 years ago

Replying to lukecavanagh:

Maybe to Documents:

Also add
application/epub+zip
application/x-mobipocket-ebook

This has to be added to the allowed mime types in wp_get_mime_types:
https://core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/functions.php#L2336

I am talking about the filter dropdown in /wp-admin/upload.php.

@zodiac1978
7 years ago

Proof of concept

@zodiac1978
7 years ago

The new dropdown would look like this

#4 @zodiac1978
7 years ago

  • Keywords has-patch dev-feedback has-screenshots added

I think there is better way to achieve the same result. Maybe as an array and with implode? And some filters would be great to add more mime-types to the specific groups. But for now this is an proof of concept, how it can look if we want to implement this.

Powered by #WCMIL Contributor Day :)

Last edited 7 years ago by zodiac1978 (previous) (diff)

#5 @swissspidy
7 years ago

  • Milestone changed from Awaiting Review to Future Release

#6 @zodiac1978
6 years ago

@swissspidy Any chance to get more feedback on this topic than "Future Release"? ;)
A "Wontfix" is totally okay, just want to know if this is something worth considering ...

@swissspidy
6 years ago

#7 @swissspidy
6 years ago

I just refreshed the patch in 38195.2.diff.

I like this enhancement, but it's probably best to bring this up in the weekly media chat in #core-media on Thursday to get a second opinion.

This ticket was mentioned in Slack in #core-media by mike. View the logs.


6 years ago

#9 follow-up: @karmatosed
6 years ago

  • Keywords ui-feedback added

I think right now I'd vote without thought to having 'Documents' added. I am less keen on all the other options, that's not saying some aren't really useful, I just would like to also work out the UI as we add more and more. Documents could be added now and that design problem doesn't need working out.

I would note that some terms used we totally should look at if we do add, for example terms like 'web documents' and 'interactives' could do with investigating if the right ones.

This brings up a design issue though as said, that many items in a drop down causes people to just skip over, not find what they are looking for. We should consider iterating the interface, over adding more than one extra here.

#10 in reply to: ↑ 9 @zodiac1978
5 years ago

Replying to karmatosed:

This brings up a design issue though as said, that many items in a drop down causes people to just skip over, not find what they are looking for.

It is worth mentioning that these new entries just show up if you upload files with these mime types.

I am happily discuss better wordings, but at the moment these are the only suggestions, why not starting with it? Or if you or someone else have specific problems with some of them, please write about it and suggest better ones. I was just trying to find words to describe groups of mime types because of the mentioned UI issue. I don't want to flood this drop down with too many new entries.

#11 @zodiac1978
5 years ago

I'm a little bit disappointed about the lack of specific feedback. Like I already mentioned these entries would just show up if there are files with these mime types uploaded.

I have tried to categorize all mime types for which uploading is allowed. Maybe it would have been better to wait for the discussion about these categories. Or I should have made a suggestion about just the useful categories, but I thought I should solve the bigger picture. Maybe I was wrong.

In the description of the ticket I made a first suggestion about this grouping.

These are the allowed mime types:
https://github.com/WordPress/WordPress/blob/master/wp-includes/functions.php#L2710-L2810

Images, Audio and Video is the status quo of the grouping:
https://github.com/WordPress/WordPress/blob/71cf332e6569f0ac2f263ce9b2168644942f5534/wp-includes/post.php#L2626-L2641

I am not sure if the categories used in the wp_get_mime_types inline docs are a good idea:
Image formats, Video formats, Text formats, Audio formats, Misc application formats, MS Office formats, OpenOffice formats, WordPerfect formats, iWork formats

Maybe the groups used in the wp_get_ext_types are better:
https://github.com/WordPress/WordPress/blob/master/wp-includes/functions.php#L2837-L2845

These would be:
image, audio, video, document, spreadsheet, interactive, text, archive, code

The first three are already used. We could add Documents. This seems to be widely accepted in the Slack. More questions / notices from Slack:

Interesting idea from @mikeschroder :

I think more around making it easy to sort by them in the media modal

Sorting would be great too. My use case is: I have uploaded a PDF and want to find it. I could search for ".pdf", but maybe using the dropdown is faster and more easy.

Issue mentioned from @karmatosed :

To me that list will only continue to grow.

I don't think, because this would handle all allowed mime types and if more mime types are added they could be added to one of the existing groups (like the the ebook mime types mentioned above) which could be added to Documents.

And another question from @karmatosed :

Do we know any examples that have solved this?

Yes, there are some plugins:

The most notable ones are these I think:
https://wordpress.org/plugins/media-library-assistant/ (adds Text and Applications which seems to be quite confusing)
and
https://wordpress.org/plugins/enhanced-media-library/ (adds Documents and PDFs)

Most of the other plugins are just adding specific mime types and are not setting these groups.

Like https://wordpress.org/plugins/mime-types-plus/ - but this is using the same grouping as wp_get_ext_types on their settings screen.

Some plugins are adding specific new groups for their use case (like Favicon Images, PDFs, Avatar Images, CSV for products, XML, GPX data, etc.)

All plugins using the filter can be found here:
https://wpdirectory.net/search/01D6AMX61FZ37RF534Z7BVS0B0

This search is even more helpful to get faster access to the added groups:
https://wpdirectory.net/search/01D6AQMY05PKKSFJP6HCW22127

Most plugins are adding PDFs. Or newly added extensions, but I found some plugins which have added more groups, like this ticket is suggesting.

https://wordpress.org/plugins/media-filter/
https://wordpress.org/plugins/wp-media-manager-lite/
https://wordpress.org/plugins/wp-admin-ui/
https://wordpress.org/plugins/media-library-shortcode/

All of theme using some variation sets of Archives/ZIPs/RARs/TARs, Documents/Docs, Office, OpenOffice, Excel, PDFs, etc. - But I think we should use generic naming and not something app/company specific, like MS Office or OpenOffice.

An one more issue from @karmatosed :

web-document to me just feels weird wording too.

This was my first suggestion. This could be "Text" or "Code" (belongs to the actual mime type). But I'm fine with adding just one or some few of them. For my use case Documents would be totally sufficient. Archives could be helpful too. I haven't uploaded any HTML or CSS file to media ... And Text, Spreadsheets and Interactives could be added to Documents too. Then we would have:
Images, Audio, Video, Documents, Archives

And one last from @karmatosed :

I’ll add my voice to ticket as I feel just get documents in then iterate is a win.

Maybe this is a language problem (I'm not a native English speaker), but I doesn't felt encouraged to to do so after the last comment. Re-thinking the UI looked like something which has to be done before this ticket can go further, so I stopped working it. But there was no discussion about re-thinking the UI ...

But maybe this research helps us to move further now. Any feedback is much appreciated.

#12 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to assigned

#13 follow-up: @SergeyBiryukov
5 years ago

  • Keywords commit added; dev-feedback removed
  • Milestone changed from Future Release to 5.3

I like the idea of extending the MIME types filter in Media Library! I don't like duplicating MIME types and maintaining them in several places though. I think we could reuse the existing wp_get_ext_types() and wp_get_mime_types() functions for this. The former supplies a list of extensions per group (document, spreadsheet, etc.), and the latter returns the list of supported MIME types.

It seems like there's a consensus to add the "Documents" group, let's do that as a first step and then evaluate if any other groups are needed. See 38195.3.diff.

Replying to zodiac1978:

It is worth mentioning that these new entries just show up if you upload files with these mime types.

FWIW, I could not reproduce this part. In my testing, the Documents group shows up even if there are no documents uploaded yet. I also haven't found any code for displaying the list items conditionally based on previously uploaded files. Still, I think it should be fine to proceed with 38195.3.diff.

#14 in reply to: ↑ 13 @SergeyBiryukov
5 years ago

Replying to SergeyBiryukov:

It is worth mentioning that these new entries just show up if you upload files with these mime types.

FWIW, I could not reproduce this part. In my testing, the Documents group shows up even if there are no documents uploaded yet.

Nevermind, looks like it's an issue with the Grid mode, see #43658.

#15 follow-up: @zodiac1978
5 years ago

This looks great! Thanks @SergeyBiryukov !

This would not include the spreadsheets at the moment, correct?

It seems like there's a consensus to add the "Documents" group, let's do that as a first step and then evaluate if any other groups are needed.

Yes, I thinks this is good idea. My only suggestion for another group would be Archives and maybe Spreadsheets (if not put to into Documents). Maybe as a next step.

This ticket was mentioned in Slack in #design by boemedia. View the logs.


5 years ago

#17 @mukesh27
5 years ago

  • Keywords needs-screenshots added; has-screenshots removed

Feedback from the design team: If you need design feedback then please share the latest screenshot so we can check it

#18 in reply to: ↑ 15 @SergeyBiryukov
5 years ago

  • Keywords has-screenshots added; needs-screenshots removed

Replying to zodiac1978:

Yes, I thinks this is good idea. My only suggestion for another group would be Archives and maybe Spreadsheets (if not put to into Documents). Maybe as a next step.

Thanks for the feedback! 38195.4.diff adds Documents, Spreadsheets, and Archives groups, and also makes the code easier to add other groups in the future. It should be as easy as adding a new array entry to $post_mime_types, where the key is a group as returned by wp_get_ext_types(), and the value is an array of labels.

For reference, the only non-supported groups for now would be interactive, text, code.

Replying to mukesh27:

Feedback from the design team: If you need design feedback then please share the latest screenshot so we can check it

Thanks! There are no UI changes per se, the only thing the patch does is add a few more types to filter media files by: Documents, Spreadsheets, Archives. As noted in comment:10, these new entries only show up if you have any files of those types already uploaded, and should not show up otherwise (once #43658 is fixed for the Grid View).

See 38195.4.png, which displays a Documents entry, because I have one PDF file in Media Library.

Last edited 5 years ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in Slack in #design by karmatosed. View the logs.


5 years ago

#20 @kjellr
5 years ago

  • Keywords ui-feedback removed

Thanks! There are no UI changes per se, the only thing the patch does is add a few more types to filter media files by: Documents, Spreadsheets, Archives. As noted in comment:10, these new entries only show up if you have any files of those types already uploaded, and should not show up otherwise (once #43658 is fixed for the Grid View).

Sounds good. Thanks @SergeyBiryukov! I'll remove the ui-feedback label for now then.

#21 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 45651:

Media: Add "Documents", "Spreadsheets", and "Archives" groups to file type filter in Media Library.

Props zodiac1978, swissspidy, karmatosed, SergeyBiryukov.
Fixes #38195.

#22 @SergeyBiryukov
5 years ago

In 45652:

Coding Standards: Fix WPCS issues in [45651].

See #38195.

This ticket was mentioned in Slack in #core-media by zodiac1978. View the logs.


4 years ago

#24 @desrosj
4 years ago

  • Keywords needs-dev-note added; commit removed

Would be nice to call this out in the Miscellaneous Developer Focused Changes dev note.

#25 @desrosj
4 years ago

  • Keywords has-dev-note added; needs-dev-note removed

Mentioned in the Miscellaneous Developer Focused Changes dev note for 5.3: https://make.wordpress.org/core/2019/10/15/miscellaneous-developer-focused-changes-in-5-3/

Note: See TracTickets for help on using tickets.