WordPress.org

Make WordPress Core

Changeset 35479


Ignore:
Timestamp:
10/31/2015 08:49:26 PM (4 years ago)
Author:
wonderboymusic
Message:

Media: add a new image size, medium_large. Bumps db version to add new options.

Adds unit tests.

Props DH-Shredder, joemcgill, azaozz.
Fixes #34196.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r35360 r35479  
    507507    'finished_splitting_shared_terms' => 1,
    508508    'site_icon' => 0,
     509
     510    // 4.4.0
     511    'medium_large_size_w' => 768,
     512    'medium_large_size_h' => 0,
    509513    );
    510514
  • trunk/src/wp-admin/options.php

    r35337 r35479  
    8585    'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'timezone_string', 'WPLANG' ),
    8686    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    87     'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
     87    'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'medium_large_size_w', 'medium_large_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
    8888    'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
    8989    'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r35063 r35479  
    213213     *
    214214     * @param array $sizes {
    215      *     An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
     215     *     An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'.
    216216     *
    217217     *     Either a height or width must be provided.
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r35063 r35479  
    271271     *
    272272     * @param array $sizes {
    273      *     An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
     273     *     An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'.
    274274     *
    275275     *     Either a height or width must be provided.
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r35366 r35479  
    514514                'option'        => 'medium_size_h'
    515515            ),
     516            'medium_large_size_w'   => array(
     517                'desc'          => __( 'Medium-Large size image width' ),
     518                'readonly'      => false,
     519                'option'        => 'medium_large_size_w'
     520            ),
     521            'medium_large_size_h'   => array(
     522                'desc'          => __( 'Medium-Large size image height' ),
     523                'readonly'      => false,
     524                'option'        => 'medium_large_size_h'
     525            ),
    516526            'large_size_w'      => array(
    517527                'desc'          => __( 'Large size image width' ),
  • trunk/src/wp-includes/formatting.php

    r35370 r35479  
    36633663        case 'medium_size_w':
    36643664        case 'medium_size_h':
     3665        case 'medium_large_size_w':
     3666        case 'medium_large_size_h':
    36653667        case 'large_size_w':
    36663668        case 'large_size_h':
  • trunk/src/wp-includes/media.php

    r35465 r35479  
    1515 * values are 'thumb' or 'thumbnail' for the given thumbnail size or defaults at
    1616 * 128 width and 96 height in pixels. Also supported for the string value is
    17  * 'medium' and 'full'. The 'full' isn't actually supported, but any value other
     17 * 'medium', 'medium_large' and 'full'. The 'full' isn't actually supported, but any value other
    1818 * than the supported will result in the content_width size or 500 if that is
    1919 * not set.
     
    6161        $max_width = intval(get_option('medium_size_w'));
    6262        $max_height = intval(get_option('medium_size_h'));
    63         // if no width is set, default to the theme content width if available
     63
     64    }
     65    elseif ( $size == 'medium_large' ) {
     66        $max_width = intval( get_option( 'medium_large_size_w' ) );
     67        $max_height = intval( get_option( 'medium_large_size_h' ) );
     68
     69        if ( intval( $content_width ) > 0 ) {
     70            $max_width = min( intval( $content_width ), $max_width );
     71        }
    6472    }
    6573    elseif ( $size == 'large' ) {
     
    7280        $max_width = intval(get_option('large_size_w'));
    7381        $max_height = intval(get_option('large_size_h'));
    74         if ( intval($content_width) > 0 )
     82        if ( intval($content_width) > 0 ) {
    7583            $max_width = min( intval($content_width), $max_width );
     84        }
    7685    } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
    7786        $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
     
    707716function get_intermediate_image_sizes() {
    708717    global $_wp_additional_image_sizes;
    709     $image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
     718    $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes
    710719    if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
    711720        $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
     
    717726     *
    718727     * @param array $image_sizes An array of intermediate image sizes. Defaults
    719      *                           are 'thumbnail', 'medium', 'large'.
     728     *                           are 'thumbnail', 'medium', 'medium_large', 'large'.
    720729     */
    721730    return apply_filters( 'intermediate_image_sizes', $image_sizes );
  • trunk/src/wp-includes/version.php

    r35425 r35479  
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 35329;
     14$wp_db_version = 35465;
    1515
    1616/**
  • trunk/tests/phpunit/tests/media.php

    r35464 r35479  
    725725            case 'medium':
    726726                return array( 300, 225 );
     727            case 'medium_large':
     728                return array( 768, 576 );
    727729            case 'large':
    728730                return array( 1024, 768 );
     
    743745
    744746        $expected = $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
     747                $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ' .
    745748                $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
    746749                $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
    747750
    748751        // Set up test cases for all expected size names and a random one.
    749         $sizes = array( 'medium', 'large', 'full', 'yoav' );
     752        $sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' );
    750753
    751754        foreach ( $sizes as $size ) {
     
    774777
    775778        $expected = $uploads_dir_url . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
     779                $uploads_dir_url . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ' .
    776780                $uploads_dir_url . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
    777781                $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
    778782
    779783        // Set up test cases for all expected size names and a random one.
    780         $sizes = array( 'medium', 'large', 'full', 'yoav' );
     784        $sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' );
    781785
    782786        foreach ( $sizes as $size ) {
     
    807811        $image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] );
    808812        $image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] );
     813        $image_meta['sizes']['medium_large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium_large']['file'] );
    809814        $image_meta['sizes']['large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['large']['file'] );
    810815
     
    857862        $expected = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
    858863            . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ';
     864        $expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
     865            . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ';
    859866        $expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
    860867            . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ';
     
    884891    function test_wp_get_attachment_image_sizes() {
    885892        // Test sizes against the default WP sizes.
    886         $intermediates = array( 'thumbnail', 'medium', 'large' );
     893        $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
    887894        $image_meta = wp_get_attachment_metadata( self::$large_id );
    888895
  • trunk/tests/phpunit/tests/post/attachments.php

    r35309 r35479  
    3636        $this->assertFalse( image_get_intermediate_size($id, 'thumbnail') );
    3737        $this->assertFalse( image_get_intermediate_size($id, 'medium') );
    38 
    39         // medium and full size will both point to the original
     38        $this->assertFalse( image_get_intermediate_size($id, 'medium_large') );
     39
     40        // medium, medium_large, and full size will both point to the original
    4041        $downsize = image_downsize($id, 'medium');
    4142        $this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
     
    4344        $this->assertEquals( 50, $downsize[2] );
    4445
     46        $downsize = image_downsize($id, 'medium_large');
     47        $this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
     48        $this->assertEquals( 50, $downsize[1] );
     49        $this->assertEquals( 50, $downsize[2] );
     50
    4551        $downsize = image_downsize($id, 'full');
    4652        $this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
     
    7379
    7480        $this->assertFalse( image_get_intermediate_size($id, 'medium') );
     81        $this->assertFalse( image_get_intermediate_size($id, 'medium_large') );
    7582
    7683        // the thumb url should point to the thumbnail intermediate
     
    8390        $this->assertEquals( 150, $downsize[2] );
    8491
    85         // medium and full will both point to the original
     92        // medium, medium_large, and full will both point to the original
    8693        $downsize = image_downsize($id, 'medium');
    8794        $this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
     
    8996        $this->assertEquals( 300, $downsize[2] );
    9097
     98        $downsize = image_downsize($id, 'medium_large');
     99        $this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
     100        $this->assertEquals( 400, $downsize[1] );
     101        $this->assertEquals( 300, $downsize[2] );
     102
    91103        $downsize = image_downsize($id, 'full');
    92104        $this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
     
    96108    }
    97109
    98     function test_insert_image_medium() {
     110    function test_insert_image_medium_sizes() {
    99111        if ( !function_exists( 'imagejpeg' ) )
    100112            $this->markTestSkipped( 'jpeg support unavailable' );
     
    102114        update_option('medium_size_w', 400);
    103115        update_option('medium_size_h', 0);
     116
     117        update_option('medium_large_size_w', 600);
     118        update_option('medium_large_size_h', 0);
    104119
    105120        $filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' );
     
    120135        $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
    121136        $this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );
     137
     138        $medium_large = image_get_intermediate_size($id, 'medium_large');
     139        $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     140        $this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );
    122141
    123142        // the thumb url should point to the thumbnail intermediate
     
    135154        $this->assertEquals( 602, $downsize[2] );
    136155
     156        $downsize = image_downsize($id, 'medium_large');
     157        $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename($downsize[0]) );
     158        $this->assertEquals( 600, $downsize[1] );
     159        $this->assertEquals( 904, $downsize[2] );
     160
    137161        $downsize = image_downsize($id, 'full');
    138162        $this->assertEquals( '2007-06-17DSC_4173.jpg', basename($downsize[0]) );
     
    149173        update_option('medium_size_h', 0);
    150174
     175        update_option('medium_large_size_w', 600);
     176        update_option('medium_large_size_h', 0);
     177
    151178        $filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' );
    152179        $contents = file_get_contents($filename);
     
    167194        $this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );
    168195
     196        $medium_large = image_get_intermediate_size($id, 'medium_large');
     197        $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     198        $this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );
     199
    169200        $meta = wp_get_attachment_metadata($id);
    170201        $original = $meta['file'];
     
    176207        $this->assertFalse( is_file($thumb['path']) );
    177208        $this->assertFalse( is_file($medium['path']) );
     209        $this->assertFalse( is_file($medium_large['path']) );
    178210        $this->assertFalse( is_file($original) );
    179211    }
Note: See TracChangeset for help on using the changeset viewer.