The maintenance theme loads the entire file.inc for the simple task of determining the maintenance theme favicon.

Besides complicating #227232: Support PHP stream wrappers, this also causes some code duplication, and uses the inferior file_get_mimetype rather than the built-in and more accurate PHP functionality for determining an image's mimetype.

This patch consolidates the functionality for determining the favicon's mimetype. It also stores the info in an associative array of variable_get('theme_favicon_mimetypes', array()) keyed by the $favicon path, so we are not needlessly reading the info on every page load. This is rebuilt when the theme is rebuilt normally, and the first time the setting is called for a specific favicon file.

The mimetype can now be retrieved by theme_get_setting('favicon_mimetype'), which (re)builds the array when needed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

aaron’s picture

This consolidates the two functions.

Note we're using a private function _theme_get_favicon_mimetype rather than theme_get_favicon_mimetype, both so that it's not confused as a theme('function'), and because we trust $favicon to be a valid path returned from the earlier call to theme_get_setting.

Now to find out why it's failing the tests...

aaron’s picture

Status: Needs work » Needs review
Issue tags: +D7FileAPIWishlist
FileSize
4.95 KB

rerolling the patch:

* fix index errors (which were caused by using isnull rather than !is_set)
* don't add base_path till the end of looking for our favicon in theme_get_setting
* this should fix the tests

Status: Needs review » Needs work

The last submitted patch failed testing.

aaron’s picture

Status: Needs work » Needs review
FileSize
4.92 KB

This just moves the last check for favicon toggles below the logic to make it more clear to future developers.

Status: Needs review » Needs work

The last submitted patch failed testing.

drewish’s picture

subscribing

aaron’s picture

Status: Needs work » Needs review
FileSize
5.43 KB

Because this version uses variable_set, and we don't have the database during installation (or maintenance mode in general), I check for that. I also initialize our array with the default array('misc/favicon.ico' => 'image/x-icon') for performance during maintenance mode.

This version should pass, but drewish points out we may wish to use cache instead, as the cache is a little smarter than variable. The downside to that is that the file mime type info will be parsed every 15 minutes (or whenever the cache is rebuilt), rather than just when the theme is rebuilt.

aaron’s picture

doh! i forgot about CACHE_PERMANENT. good deal; i'll just use that. new patch coming in a few minutes.

aaron’s picture

ok, this one uses cache. should be good to go.

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

So now instead of loading the extension mapping on every page, we add a cache_get() on every page instead. I'm not sure that's too much of an improvement and prefer the variable version in #8 which looks more or less RTBC to me.

Also some more history on this one, doesn't affect the current patch but really, really glad to see this get fixed properly here since we didn't come up with this idea in #473652: file_get_mimetype() unneeded loop. If we get this in, we could possibly revert back to the single file extension mapping array which was replaced in that issue for similar reasons.

aaron’s picture

I prefer #8 too; it was drewish's idea to use caching instead. I'll let him talk up that one. And thanks for the heads up re. #473652: file_get_mimetype() unneeded loop -- I definitely agree with you catch. I think in favor of getting the ball rolling, perhaps that should be another issue; easier for people to digest these things in smaller chunks, it seems :D

Is there a way I can tell the system to go with #8 again? Or do we need to resubmit that patch?

catch’s picture

I think #8 will have to be resubmitted for the test bot to start liking it. And yes we can probably re-open #473652: file_get_mimetype() unneeded loop once this is in (or a new issue to tidy up differently if we don't want to do a straight revert there).

aaron’s picture

Status: Needs work » Needs review
FileSize
5.43 KB

OK, here it is again. This is the same patch from #8.

mfb’s picture

FileSize
3.16 KB

For posterity (and in case any of it is useful) here's the original version of this from #331171: Allow modules to alter the MIME extension mapping rather than setting a huge variable. I appreciate its simplicity. We set a sane default for the favicon_mimetype. And we add a custom favicon_mimetype setting to the settings array (if default icon is not used) when the theme settings form is submitted.

aaron’s picture

Yeah, that looks really clean. Why 'image/vnd.microsoft.icon' rather than 'image/x-icon'?

aaron’s picture

I've racked my brain, and I can't think of any reason why not to use #16. It's far superior to my proposed method, and doesn't require setting $conf for a maintenance mode favicon (which mine would have required).

The only questions I have are re the icon in #17, and whether we'd want to switch it to use the superior getimagesize info as drewish proposes (which would take care of misnamed images), or stick to eating Drupal's dogfood?

mfb’s picture

"image/vnd.microsoft.icon" is the type used in d7 currently, as determined by file_get_mimetype(). It's also officially correct according to http://en.wikipedia.org/wiki/ICO_%28file_format%29

Unfortunately getimagesize() didn't get icon support until PHP 5.3 according to http://www.php.net/function.getimagesize so I don't think it's an option.

BTW, random trivia from wikipedia article, "Windows Vista adds support for natively displaying 256×256 pixel icon images, and supports (but does not require) the compressed PNG format... It is recommended that all 256×256 icons should be stored in the ICO file in PNG format to reduce the overall size of the file." So what we'll commonly see is PNG-encoded icons, with "ico" extension and "image/vnd.microsoft.icon" as the mimetype even if the file is PNG not ICO format. (Firefox and Webkit already supported PNG-encoded icons for a long time).

aaron’s picture

sorry about railroading the last issue; turns out if i'd given your patch a proper review, it could probably have gone in at the same time :P this looks solid to me as well. just needs some changelog info. testing, looks this works fine now, even in maintenance mode.

just needs some changelog magic; attached here.

aaron’s picture

uggh. why did that repeat those lines in changelog? was i saving it incorrectly? (using Kate in kubuntu, if anyone has any pointers).

aaron’s picture

oh, wait, the other point of this issue was to remove file.inc from the maintenance theme, which can also still be done safely now.

rolling a patch that includes that.

drewish’s picture

aaron, the changelog lines are whitespace changes. your editor is removing trailing whitespace. when you generate the patch you can just explicitly name the files to diff if you want to ignore that or use one of the diff options to ignore whitespace.

personally i'd love to avoid using file_get_mimetype() on images because unlike getimagesize() it's it just looks at the extension rather than the contents of the file.

mfb’s picture

Not clear we even need a changelog entry for a new setting that developers shouldn't have to worry about. But if you can clean up the patch... :)

If someone is maintaining a list of things to redo when drupal moves to PHP >= 5.3, using getimagesize() here could go on that list. Meanwhile looking at the file extension isn't that bad, it's what apache is doing anyways :)

Status: Needs review » Needs work

The last submitted patch failed testing.

mfb’s picture

Patch at #16 still applies.

I'm not sure about removing file.inc from the maintenance theme. Seems like this could potentially break calls to file_*() functions during install or update? At least, that is my reading of http://api.drupal.org/api/function/_drupal_maintenance_theme/7

aaron’s picture

Status: Needs work » Needs review
FileSize
3.16 KB

grrr... that would have been bad. i wasn't seeing the forest for the trees.

in any case, the original issue for loading files during installation during the php stream wrapper sprint has long been solved, and is no longer an issue.

can we mark #16 as RTBC then? Here it is again, to make things clear and to give everyone a chance to give a final review.

catch’s picture

All looks good to me, can we maybe add some documentation as to why 'image/vnd.microsoft.icon' is the default?

mfb’s picture

FileSize
3.17 KB

Added comment about image/vnd.microsoft.icon

catch’s picture

Status: Needs review » Reviewed & tested by the community

Can't find any other objections, great patch!

Let's have another look at #473652: file_get_mimetype() unneeded loop once this lands.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

JohnAlbin’s picture

Title: Add favicon mimetype theme setting » regression: Add favicon mimetype theme setting
Category: task » bug
Priority: Critical » Normal
Status: Fixed » Needs work
FileSize
988 bytes

Don't we have a little bit of a regression of #415710: Favicon.ico defaults to 'type="image/x-icon"' here?

If the file has a .ico extension, file_get_mimetype() correctly determines the mime type to be “image/vnd.microsoft.icon”. But if file_get_mimetype() can't determine the mime type and just returns application/octet-stream, we really should be using the generic MIME type for favicons, “image/x-icon”.

This new patch… bah! I just realized its insufficient. Themes can set the default favicon to have whatever file extension they want, .gif, .png, etc. And the code committed for this patch never checks the file extension of the default favicon; it just assumes its .ico. So the mime type will be set incorrectly for those themes using a non-.ico file extension.

JohnAlbin’s picture

Status: Needs work » Needs review

Ok. I'm doing too much at the same time. Namely I'm trying to pack for an international flight. And now I can't even remember/don't have time to check if theme's can set a default favicon that isn't named favicon.ico. :-p

So the patch in #32 needs review.

mfb’s picture

So what makes image/x-icon a good default if it's not even a valid registered MIME type? Is there some spec or browser issue in play here?

JohnAlbin’s picture

Title: regression: Add favicon mimetype theme setting » Add favicon mimetype theme setting
FileSize
953 bytes

Hmm… I stand corrected. The favicon “spec” used image/x-icon not because its the default mime type for an unknown favicon type, but because .ico files specifically didn't have a mime type before 2003. http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)

But actually, that means we shouldn't be doing “Use the default MIME type for favicons if no other was found.” Instead, we really should set the mime type to be "application/octet-stream" if we come across an unknown image type. Right?

New patch just removes the check for "application/octet-stream".

Dries’s picture

Status: Needs review » Fixed

JohnAlbin is correct, and the behavior in the proposed patch is technically correct. Committed to CVS HEAD.

webchick’s picture

Sorry about that! :\

Status: Fixed » Closed (fixed)
Issue tags: -D7FileAPIWishlist

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