The <link>
for the Favicon defaults to image/x-icon, even when it would make much more sense to use a different MIME type. Here, we simply default to image/x-icon, but provide specific support for image/x-gif and image/x-png if the file looks like one of those (i.e., ends in the appropriate extension).
See also #400042: Favicon.ico defaults to 'type="image/x-icon"', which is an earlier version of this patch for v6.6, and http://en.wikipedia.org/wiki/Favicon , which describes the favicon "standard" (I use the term loosely).
Comment | File | Size | Author |
---|---|---|---|
#37 | 415710-favicon-no-tert_D6.patch | 2.58 KB | Garrett Albright |
#31 | 415710-favicon-no-tert.patch | 2.58 KB | Garrett Albright |
#29 | 415710-favicon-no-tert.patch | 2.58 KB | Garrett Albright |
#27 | 415710-favicon-type.patch | 2.49 KB | Garrett Albright |
#23 | favicon-mime-type-415710-23.patch | 2.73 KB | dixon_ |
Comments
Comment #1
BMDan CreditAttribution: BMDan commentedThe "type" for the Favicon defaults to image/x-icon, even when it would make much more sense to use a different MIME type. Here, we simply default to image/x-icon, but provide specific support for image/gif and image/png if the file looks like one of those (i.e., ends in the appropriate extension).
See also #400042: Favicon.ico defaults to 'type="image/x-icon"', which is an earlier version of this patch for v6.6, and http://en.wikipedia.org/wiki/Favicon , which describes the favicon "standard" (I use the term loosely).
Comment #2
c960657 CreditAttribution: c960657 commentedI suggest that you use file_get_mimetype().
Also, there should be no space following the opening parenthesis in an if statement.
Comment #3
BMDan CreditAttribution: BMDan commentedGood suggestions, c960657. I've rolled them into this new patch, which also implements a "default to image/x-icon" feature for those using strange favicon names.
Comment #5
BMDan CreditAttribution: BMDan commentedtheme.inc went through a bunch of changes in HEAD; this is the same patch, but freshly diff'd with new offsets and context to reflect those changes.
Comment #6
BMDan CreditAttribution: BMDan commentedSlightly-better patch; I'd missed the change to _add from _set.
Comment #8
BMDan CreditAttribution: BMDan commented+1 to Berdir in IRC for pointing out that I was missing the directory name in my patch.
Comment #9
BMDan CreditAttribution: BMDan commentedSwitching state to "needs review".
Comment #11
Dave ReidCoding style issues in the patch.
Comment #12
BMDan CreditAttribution: BMDan commentedThe shinest and latest version of the patch, complete with the latest stylistic changes, and, as a bonus, a heaping helping of awesome. My thanks to Michelle and chx in IRC for their invaluable assistance. The fact that it works is their fault. Needless to say, the remaining bugs are mine.
Comment #14
BMDan CreditAttribution: BMDan commented/me mutters something dark about the auto-tester's mother.
Comment #15
chx CreditAttribution: chx commentedI do not why are you swearing the bot when there was a typo in the patch which it correctly catched. Anyways, now you call
theme_get_setting('favicon')
twice which calls for a variable.Comment #16
BMDan CreditAttribution: BMDan commentedI'm muttering about the auto-tester because it produces ridiculous results. http://testing.drupal.org/pifr/file/1/theme.finaltry.patch should say "parse error" or similar, not "failed to install HEAD" with no additional information. If I get a spare moment, I'll look into how to improve the auto-tester, but that is not a top priority for me right now.
Now, I feel I need to caveat the rest of this comment. I apologize if any of this seems combative, as that's not my intent. I'm trying to dissuade you from what is probably a deeply-held belief, namely that indiscriminately caching functions' return values in the manner you describe improves performance in a significant way while additionally not substantially detracting from legibility, maintainability, or other important code factors. Accordingly, I've been quite verbose in describing why I believe you are wrong on this count, and quite specific on the followup measures I'd like to see you take. You always have the option, however, to do as you please, including to ignore this patch entirely from now on, to delete this issue from the bug system if that is within your powers, to cause frogs to rain from the sky, etc., etc. I'm just providing a framework within which I believe further discussion will be most productive.
So, let me lay it out frankly: your suggestion is ridiculous. This is a singly-"include"d portion of the code, and the call to theme_get_setting is only made twice. http://api.drupal.org/api/function/theme_get_setting already caches the settings, so there are no calls to the DB; only the second half of the function is actually run. "Premature optimization is the root of all evil," etc., etc. It's the job of the compiler/bytecode cache/optimizer/some portion of the hierarchy generally much higher and smarter than us to determine what is static and what is not. See http://www.acm.org/ubiquity/views/v7i24_fallacy.html for more on this; worrying about things like caching the result of this call is micro-optimization; you could just as easily blow up a memory-constrained environment by optimizing this way as you could correct a performance hiccup in a CPU-bound one. In fact, it's easily arguable that you're more likely to cause a performance problem with the creation and subsequent GC of a twice-used variable than a single "wasted" call to what the optimizer can recognize as a static function.
To bring this firmly and thoroughly into the realm of the hyperbolic, imagine that we created a shared-memory architecture where these variables would only need to be loaded once per (server restart||child restart||insert reload trigger here). Now we've gained significant amounts of performance. Of course, what I've described is the static $settings variable in theme_get_setting--the API has already done the heavy lifting for us, in other words! Double caching, then, is clearly not the solution.
Now, as I see it in my admittedly-limited understanding of you, the project, my code, this dispute, and myself, and the universe as a whole (barring Pluto, which as we all know is not a planet) you have one of just a couple good paths ahead open to you:
Comment #17
chx CreditAttribution: chx commentedHuh. It's just simpler to store the call of a function into a variable than call it twice. That's all.
Comment #18
JohnAlbinBased on http://www.iana.org/assignments/media-types/image/, I see that the "ico" extension should be mapped to "vnd.microsoft.icon". New patch fixes that as well.
Also, I agree with chx. So I added a $favicon variable. This saves the overhead of calling a function twice. Creating a variable is not the same as creating a cache.
Lastly, $icontype doesn't follow the standards of our variable naming conventions. We like underscores so that they are more readable for non-native-English speakers.
Comment #19
JohnAlbinWhoops! Forgot about
template_preprocess_maintenance_page()
.Comment #20
dixon_Although I don't like to have the word "microsoft" in the Drupal source code, the patch from #19 applies fine ;)
Everything seems to work as expected. +1 for this.
Comment #21
JohnAlbinYay! Dixon, patch-reviewer extraordinaire!
Comment #22
Dries CreditAttribution: Dries commented- We should escape $favicon_type because it is not guaranteed to be safe.
- Let's rename $favicon_type to $type.
- Let's document why we check for 'application/octet-stream'. I wonder why we decided to return 'application/octet-stream' instead of FALSE.
Comment #23
dixon_Okey, here is a patch I hope lives up to Dries review.
Comment #24
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #26
klonosDoes this apply to D6 as well? I am asking because #643808: favicon MIME is a duplicate then.
Comment #27
Garrett Albright CreditAttribution: Garrett Albright commentedReroll for D6, and changed a bit - did we still want to default to image/x-icon instead of image/vnd.microsoft.icon?
The way D7 does this sort of thing seems to be radically different now.
Comment #28
klonosIt's been more than a year now and I honestly don't understand why such a small fix doesn't get in. I think it's pretty much a no-brainer.
Comment #29
Garrett Albright CreditAttribution: Garrett Albright commentedIn IRC, pwolanin suggested I ditch the tertiary operator, so here's a reroll. I'm also using D6-style string concatenation (at least, I think I am; I despise D6-style string concatenation and have tended to ignore it in the past).
Comment #30
pwolanin CreditAttribution: pwolanin commentedLooks better though using '==' instead of '===' would be more normal code style.
Comment #31
Garrett Albright CreditAttribution: Garrett Albright commentedMeh. I generally prefer using '===' when there's no doubt that the variables will be the same type, but whatev - I need to fix my assignment operators anyway.
Comment #32
pwolanin CreditAttribution: pwolanin commentedCheck the D7 patch. If not matching file extension is found, then use 'image/x-icon'
Comment #33
Garrett Albright CreditAttribution: Garrett Albright commented…But see #18 above - not the patch, but the comment. Also, ignore the D7 patch, as it's been obliterated by other changes since it was committed. And with those other changes, D7 uses "image/vnd.microsoft.icon" for .ico files. Just check out a D7 installation which uses Garland, which uses an .ico file as its favicon. As I stated in #27, I believe that the use of image/x-icon as the default instead of image/vnd.microsoft.icon in earlier D7 patches was actually an error, and that what's reflected in my patch is the intended result.
Comment #34
Garrett Albright CreditAttribution: Garrett Albright commentedChatting further with pwolanin in IRC… We're both wondering why we fall back to "image/vnd.microsoft.icon" if file_get_mimetype() returns "application/octet-stream", even though we may be lying. Is using "application/octet-stream" so bad?
Nonetheless, the patch as it is now will match both D7's behavior and the behavior of previous versions of D6, given a file whose extension is not in file.inc's array. Thus, it's far better than what we have now and shouldn't break things either now or in the future.
Comment #35
pwolanin CreditAttribution: pwolanin commentedright, I'd prefer to just omit:
since in this situation it's an unknown file extension, but as above, this matches the current (incorrect?) D7 behavior.
Comment #37
Garrett Albright CreditAttribution: Garrett Albright commentedThe patch failed testing because the system tried to apply it to D6 core. However, it's still relevant and should be applied. Renaming so testbot doesn't try to test it anymore.
Comment #38
Garrett Albright CreditAttribution: Garrett Albright commentedComment #39
thedavidmeister CreditAttribution: thedavidmeister commentedNot sure why this is "Needs review", there's no green patch in this thread.
Regardless, patch no longer applies:
The patch in #37 has coding standards issues - missing spaces before and after
.
characters in string concatenation.I can confirm the bug still exists in D6, and I can confirm that the patches in #37 and #31 are diverging from the current logic in D7 in a way that seems inappropriate for a backport, for example we don't seem to run the favicon type through
check_plain()
in D7.Since this is a backport of something that has been fixed in D7+, I'm tagging it as such.
The issue summary should also be updated to explain the proposed resolution, as it currently only describes the problem.
#2094585: [policy, no patch] Core review bonus for #2072647: #theme 'maintenance_page' should support render arrays in #content.
Comment #39.0
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #40
xjm