Ticket #7151: large-size-images-r8585.patch

File large-size-images-r8585.patch, 10.5 KB (added by tellyworth, 4 years ago)

Refresh patch post 2.6

  • wp-includes/version.php

     
    1515 * 
    1616 * @global int $wp_db_version 
    1717 */ 
    18 $wp_db_version = 8539; 
     18$wp_db_version = 8585; 
    1919 
    2020?> 
  • wp-includes/media.php

     
    44 
    55// scale down the default size of an image so it's a better fit for the editor and theme 
    66function image_constrain_size_for_editor($width, $height, $size = 'medium') { 
     7        global $content_width; 
    78 
    89        if ( is_array($size) ) { 
    910                $max_width = $size[0]; 
     
    2324                $max_height = intval(get_option('medium_size_h')); 
    2425                // if no width is set, default to the theme content width if available 
    2526        } 
    26         else { // $size == 'full' 
    27                 // we're inserting a full size image into the editor.  if it's a really big image we'll scale it down to fit reasonably 
     27        elseif ( $size == 'large' ) { 
     28                // we're inserting a large size image into the editor.  if it's a really big image we'll scale it down to fit reasonably 
    2829                // within the editor itself, and within the theme's content width if it's known.  the user can resize it in the editor 
    2930                // if they wish. 
    30                 if ( !empty($GLOBALS['content_width']) ) { 
    31                         $max_width = $GLOBALS['content_width']; 
    32                 } 
    33                 else 
    34                         $max_width = 500; 
     31                $max_width = intval(get_option('large_size_w')); 
     32                $max_height = intval(get_option('large_size_h')); 
     33                if ( intval($content_width) > 0 ) 
     34                        $max_width = min( intval($content_width), $max_width ); 
    3535        } 
     36        // $size == 'full' has no constraint 
     37        else { 
     38                $max_width = $width; 
     39                $max_height = $height; 
     40        } 
    3641 
    3742        list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); 
    38  
     43         
    3944        return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); 
    4045} 
    4146 
     
    5156 
    5257// Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width. 
    5358// The URL might be the original image, or it might be a resized version.  This function won't create a new resized copy, it will just return an already resized one if it exists. 
    54 // returns an array($url, $width, $height) 
     59// returns an array($url, $width, $height, $is_intermediate) 
     60// $is_intermediate is true if $url is a resized image, false if it is the original 
    5561function image_downsize($id, $size = 'medium') { 
    5662 
    5763        if ( !wp_attachment_is_image($id) ) 
     
    6066        $img_url = wp_get_attachment_url($id); 
    6167        $meta = wp_get_attachment_metadata($id); 
    6268        $width = $height = 0; 
     69        $is_intermediate = false; 
    6370 
    6471        // plugins can use this to provide resize services 
    6572        if ( $out = apply_filters('image_downsize', false, $id, $size) ) 
     
    7077                $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url); 
    7178                $width = $intermediate['width']; 
    7279                $height = $intermediate['height']; 
     80                $is_intermediate = true; 
    7381        } 
    7482        elseif ( $size == 'thumbnail' ) { 
    7583                // fall back to the old thumbnail 
     
    7785                        $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url); 
    7886                        $width = $info[0]; 
    7987                        $height = $info[1]; 
     88                        $is_intermediate = true; 
    8089                } 
    8190        } 
    8291        if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { 
    83                 // any other type: use the real image and constrain it 
    84                 list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); 
     92                // any other type: use the real image 
     93                $width = $meta['width']; 
     94                $height = $meta['height']; 
    8595        } 
     96         
     97        if ( $img_url) { 
     98                // we have the actual image size, but might need to further constrain it if content_width is narrower 
     99                list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size ); 
    86100 
    87         if ( $img_url) 
    88                 return array( $img_url, $width, $height ); 
     101                return array( $img_url, $width, $height, $is_intermediate ); 
     102        } 
    89103        return false; 
    90104 
    91105} 
  • wp-admin/includes/schema.php

     
    258258        add_option('enable_app', 0); 
    259259        add_option('enable_xmlrpc', 0); 
    260260         
     261        // 2.7 
     262+       add_option('large_size_w', 1024); 
     263+       add_option('large_size_h', 1024); 
     264         
    261265        // Delete unused options 
    262266        $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins'); 
    263267        foreach ($unusedoptions as $option) : 
  • wp-admin/includes/media.php

     
    505505        return wp_iframe( 'media_upload_library_form', $errors ); 
    506506} 
    507507 
     508function image_size_input_fields($post, $checked='') { 
     509                 
     510                // get a list of the actual pixel dimensions of each possible intermediate version of this image 
     511                $sizes = array(); 
     512                $size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size'); 
     513                 
     514                foreach ( $size_names as $size => $name) { 
     515                        $downsize = image_downsize($post->ID, $size); 
     516                         
     517                        // is this size selectable? 
     518                        $enabled = ( $downsize[3] || 'full' == $size ); 
     519                        $css_id = "image-size-{$size}-{$post->ID}"; 
     520                        // if $checked was not specified, default to the first available size that's bigger than a thumbnail 
     521                        if ( !$checked && $enabled && 'thumbnail' != $size ) 
     522                                $checked = $size; 
     523                         
     524                        $html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />"; 
     525                         
     526                        $html .= "<label for='{$css_id}'>" . __($name). "</label>"; 
     527                        // only show the dimensions if that choice is available 
     528                        if ( $enabled ) 
     529                                $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2] ). "</label>"; 
     530                                 
     531                        $html .= '</div>'; 
     532                 
     533                        $out[] = $html; 
     534                } 
     535                 
     536                return array( 
     537                        'label' => __('Size'), 
     538                        'input' => 'html', 
     539                        'html'  => join("\n", $out), 
     540                ); 
     541} 
     542 
    508543function image_attachment_fields_to_edit($form_fields, $post) { 
    509544        if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 
    510545                $form_fields['post_title']['required'] = true; 
     
    514549 
    515550                $form_fields['post_content']['label'] = __('Description'); 
    516551 
    517                 $thumb = wp_get_attachment_thumb_url($post->ID); 
    518  
    519552                $form_fields['align'] = array( 
    520553                        'label' => __('Alignment'), 
    521554                        'input' => 'html', 
     
    529562                                <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' /> 
    530563                                <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n", 
    531564                ); 
    532                 $form_fields['image-size'] = array( 
    533                         'label' => __('Size'), 
    534                         'input' => 'html', 
    535                         'html'  => " 
    536                                 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' /> 
    537                                 <label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label> 
    538                                 " : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' /> 
    539                                 <label for='image-size-medium-$post->ID'>" . __('Medium') . "</label> 
    540                                 <input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' /> 
    541                                 <label for='image-size-full-$post->ID'>" . __('Full size') . "</label>", 
    542                 ); 
     565                $form_fields['image-size'] = image_size_input_fields($post); 
    543566        } 
    544567        return $form_fields; 
    545568} 
  • wp-admin/includes/image.php

     
    9696                $metadata['file'] = $file; 
    9797 
    9898                // make thumbnails and other intermediate sizes 
    99                 $sizes = array('thumbnail', 'medium'); 
     99                $sizes = array('thumbnail', 'medium', 'large'); 
    100100                $sizes = apply_filters('intermediate_image_sizes', $sizes); 
    101101                 
    102102                foreach ($sizes as $size) { 
  • wp-admin/options-misc.php

     
    6262<input name="medium_size_h" type="text" id="medium_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" /> 
    6363</fieldset></td> 
    6464</tr> 
     65<tr valign="top"> 
     66<th scope="row"><?php _e('Large size') ?></th> 
     67<td><fieldset><legend class="hidden"><?php _e('Large size') ?></legend> 
     68<label for="large_size_w"><?php _e('Max Width'); ?></label> 
     69<input name="large_size_w" type="text" id="large_size_w" value="<?php form_option('large_size_w'); ?>" size="6" /> 
     70<label for="large_size_h"><?php _e('Max Height'); ?></label> 
     71<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" size="6" /> 
     72</fieldset></td> 
     73</tr> 
    6574</table> 
    6675 
    6776 
  • wp-admin/css/media.css

     
    8383        display: none; 
    8484} 
    8585 
     86tr.image-size td { 
     87        width: 460px; 
     88} 
     89tr.image-size div.image-size-item { 
     90        float: left; 
     91        width: 25%; 
     92        margin: 0; 
     93} 
    8694tr.image-size label { 
    8795        display: inline; 
    88         margin: 0 1em 0 0; 
     96        margin: 0 0 0 1em; 
    8997} 
    9098.pinkynail { 
    9199        max-width: 40px; 
     
    202210        padding: 1em 0; 
    203211} 
    204212 
    205 #media-upload p.help { 
     213#media-upload p.help, #media-upload label.help { 
    206214        font-style: italic; 
    207215        font-weight: normal; 
    208216}