[wp-trac] [WordPress Trac] #15149: image_get_intermediate_size partly ignores 'path' and 'url' fields and has inconsistent return values

WordPress Trac wp-trac at lists.automattic.com
Wed Oct 20 20:22:29 UTC 2010


#15149: image_get_intermediate_size partly ignores 'path' and 'url' fields and has
inconsistent return values
-------------------------+--------------------------------------------------
 Reporter:  whoismanu    |       Owner:                 
     Type:  enhancement  |      Status:  new            
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Media        |     Version:  3.1            
 Severity:  normal       |    Keywords:  has-patch      
-------------------------+--------------------------------------------------

Comment(by whoismanu):

 unless i overlooked something, the patch shouldn't break anything. here is
 my reasoning:

 before the patch, the url is computed in image_downsize() like this:

 {{{
 $img_url = str_replace(basename($img_url), $intermediate['file'],
 $img_url);
 }}}

 where

 {{{
 $img_url = wp_get_attachment_url($id);
 }}}

 and $intermediate[!''file!''] is the file field returned by
 image_get_intermediate_size(). it follows that the result is equivalent to
 dirname($img_url).$intermediate[!''file!''].

 with the patch, the url is calculated inside
 image_get_intermediate_size(). there we have that $file_url is equivalent
 to $img_url above and $data[!''file!''] corresponds to
 $intermediate[!''file!'']. the url is computed as


 {{{
 $data['url'] = path_join( dirname($file_url), $data['file'] );
 }}}

 looking at path_join(), this results in

 a) dirname($file_url).$data[!''file!''] if $data[!''file!''] is not
 absolute, which is thus the same as
 dirname($img_url).$intermediate[!''file!''] without the patch

 b) $data[!''file!''] if $data[!''file!''] is absolute. here the result is
 thus not the same as without the patch. however, without the patch the
 result here must be wrong anyway since it corresponds to a concatenation
 of a path with an absolute path (
 dirname($img_url).$intermediate[!''file!''] and $intermediate[!''file!'']
 here is absolute) which doesn't make sense.

 so up to now the patch returns either exactly the same as what was
 returned before, or it returns something that makes sense where something
 that was obviously wrong was returned before.

 there is one more case, where the patch returns something different from
 what was returned before. this is if the !''path!'' or !''url!'' fields
 are already set in the metadata. with the patch, the url corresponds to
 the one from the metadata. without the patch, the metadata is ignored. so
 the only way backwards compatibility could be broken is if a plugin
 requires that the 'path' and !''url!'' fields in the metadata must be
 ignored. now if this really is the case, then !''path!'' and !''url!''
 should be removed altogether from image_get_intermediate_size() because
 right now they are never used, as i detailed in my initial posting above.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15149#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list