Problem/Motivation

The template_preprocess_file_link() should not add various metadata attributes. It currently adds the mime type and file size into the type parameter.

The code where this is added links to the following page: http://microformats.org/wiki/file-format-examples

This format is given as an example of how this type of data has been added in other places, but is not proposed as a microformat.

Further the HTML spec formally specifies the type parameter to the a element, and says that it can only contain the mime type of the file.

Proposed resolution

Therefore we should either remove the type parameter all together, or continue to add it, but only include the mime type.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SchnWalter created an issue. See original summary.

SchnWalter’s picture

SchnWalter’s picture

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Kristen Pol’s picture

Version: 8.9.x-dev » 9.1.x-dev
Issue tags: +Bug Smash Initiative

Patch applies cleanly to 9.1.x.

Kristen Pol’s picture

Issue tags: +Needs manual testing

Thanks for the issue and patch.

1) Code changes are straightforward.

2) Marking for manual testing.

3) Kicking of tests for 9.1.x.

tanubansal’s picture

Need a patch for 9.1

Kristen Pol’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
nitesh624’s picture

I'm working on it, will update in few hours.

nitesh624’s picture

Assigned: Unassigned » nitesh624
Status: Needs work » Needs review
FileSize
642 bytes
1.23 KB

Rerolled the patch

nitesh624’s picture

Assigned: nitesh624 » Unassigned

Tested manually in my system, seems to be working file.

Kristen Pol’s picture

Issue tags: -Needs reroll

For historical context, this is from git blame:

ac30bf8a82a modules/file/file.module      (Dries Buytaert      2009-08-29 12:52:32 +0000 1458)   // http://microformats.org/wiki/file-format-examples
0413834556f core/modules/file/file.module (Nathaniel Catchpole 2014-11-10 14:30:41 +0000 1459)   $options['attributes']['type'] = $mime_type . '; length=' . $file->getSize();

so the comment is from 2009 and the code was last updated in 2014 trivially as so:

+  $mime_type = $file->getMimeType();
   // Set options as per anchor format described at
   // http://microformats.org/wiki/file-format-examples
-  $options['attributes']['type'] = $file->getMimeType() . '; length=' . $file->getSize();
+  $options['attributes']['type'] = $mime_type . '; length=' . $file->getSize();
Kristen Pol’s picture

I'm trying to understand why this should be removed. The issue summary doesn't explain why, just that it should be removed.

Kristen Pol’s picture

I have tested with and without the patch and it works as expected. I'm just unclear why it should be removed. I see it defined here as well: https://www.w3.org/TR/html4/struct/links.html#adef-type-A and https://www.w3.org/TR/2011/WD-html5-author-20110809/the-link-element.htm....

jungle’s picture

type
Hints at the linked URL’s format with a MIME type. No built-in functionality.

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

A MIME type (now properly called "media type", but also sometimes "content type") is a string sent along with a file indicating the type of the file (describing the content format, for example, a sound file might be labeled audio/ogg, or an image file image/png).

See https://developer.mozilla.org/en-US/docs/Glossary/MIME_type

Per the docs for the a tag, I think <a href="URL" type="text/plain">A file</a> is good. But <a href="URL" type="text/plain; length:1024">A file</a> with length appended is not good. 1) length is not a part of type obviously, and 2) maybe it's not good for security leaking the file size? -- one can see the url, but no access to the file.

So to me, this issue could be removing the length metadata from the type. Removing the whole type attribute does not make sense to me.

ultrabob’s picture

To clarify a bit. The problematic output is not the microformat. It is, I believe, an alternate solution highlighted in the page linked in the git blame. In any case, I agree that adding file details into the type field is not likely to be expected by anyone, and agree that it should not be added by default. As @jungle mentions, there is nothing wrong with including the type parameter with a mimetype.

Looking at the w3c HTML 5 working draft for web authors (https://www.w3.org/TR/2011/WD-html5-author-20110809/links.html#hyperlink) I find the following text:

The type attribute, if present, gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type.

So clearly the file size and other info doesn't belong there.

I guess the main question left about this issue is whether the type should be inserted there or not.

ultrabob’s picture

Personally I think if we have the mimetype there already we may as well use it. I'll upload a tiny change to the patch to reenable the mimetype shortly.

Kristen Pol’s picture

Right. Well if we have two patches, one that removes all from above and a new one that just removes the length then the core maintainers could choose which patch to use. Thanks to you both for the input.

ultrabob’s picture

FileSize
690 bytes
501 bytes

Adding the mime-type back in without the file size.

ultrabob’s picture

Sorry, I got my comment number wrong, but exactly as #20 mentions. We now have the choice of two approaches.

Kristen Pol’s picture

Thanks for the patch. Marking RTBC since:

1) Code looks fine.

2) Tests pass.

3) Works as expected. See screenshot.

4) Maintainers can choose between patch in #12 that removes the type completely or #21 which only removes the length data.

Kristen Pol’s picture

Status: Needs review » Reviewed & tested by the community

Whoops.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2991219-20-D_9_1_x.patch, failed testing. View results

jungle’s picture

Status: Needs work » Reviewed & tested by the community

A known random fail. Re-queued.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs issue summary update

Can we get an issue summary update detailing why we are doing this? It's not clear to me from reading the comments.

The microformats wiki still has examples that reference file size

Kristen Pol’s picture

I'm not sure but, if I'm understanding this correctly, then only Firefox has built-in support and some other browsers support it with an extension:

http://microformats.org/wiki/browsers

ultrabob’s picture

Unless I’m completely misunderstanding the page at http://microformats.org/wiki/file-format-examples, this is not even a micro format as proposed by micro formats.org. That is either how it has been observed having been done or one of the existing suggestions for how it could be done. The example of this format is in the other attempts to solve the problem section, not any kind of micro format definition.

In short, I don’t think this format is even a defined micro format, and I’m not sure why it ever got added. Type is an officially defined HTML parameter for a tags. The definition says that if it is there, it should contain the mime type. There seems to be no wiggle from for a file micro format to be defined using that parameter.

ultrabob’s picture

As a spot check, I did a quick browse through
the php-mf2 Codebase including the list of mf1 formats it parses, and could find no evidence that it would pick up and parse the type parameter as a micro format at all.

Kristen Pol’s picture

@ultrabob Thanks for the info. Would you update the issue summary with the justification for switching this? Sounds like you have a good handle on it. :)

ultrabob’s picture

Issue summary: View changes
ultrabob’s picture

jungle’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks @ultrabob, applying the IS template and setting back to RTBC.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

As we're removing something here, I think we need to communicate this via a change record.

Tagging as such.

partyka’s picture

Kristen Pol’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Thanks for the change record.

1) Note that the change record is for just removing the size and not removing the type.

2) Assuming that's ok, I'm not sure if change records ever include quotes in them but I'll leave that. I did add an example.

Back to RTBC.

partyka’s picture

@Kirsten Pol -- I only added it as a quote because I thought it summed up the justification perfectly, and didn't want to take credit for that wording :-)

Kristen Pol’s picture

Agreed, great quote :) just don't know if it's customary or not in change records.

larowlan’s picture

Crediting @jungle for taking part in the discussion and @partyka for the change notice.

  • larowlan committed d7d9ebd on 9.1.x
    Issue #2991219 by SchnWalter, ultrabob, nitesh624, Kristen Pol, jungle,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed d7d9ebd and pushed to 9.1.x. Thanks!

Amended and published the change record.

Because there is a slight chance of disruption here (someone may be depending on this feature, as odd as it is), not going to put this forward for backport. In addition, its only a minor bug, so there's not huge demand for it to be backported.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.