Ticket #44541: 44541.5.diff
File 44541.5.diff, 14.2 KB (added by , 6 years ago) |
---|
-
src/wp-admin/includes/dashboard.php
diff --git src/wp-admin/includes/dashboard.php src/wp-admin/includes/dashboard.php index 0c5bb5f..e1762f3 100644
function wp_dashboard_recent_drafts( $drafts = false ) { 587 587 } 588 588 echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>"; 589 589 590 /* translators: This sets the text length for the draft. */ 591 $draft_length = intval( _x( '10', 'draft_length' ) ); 592 590 593 $drafts = array_slice( $drafts, 0, 3 ); 591 594 foreach ( $drafts as $draft ) { 592 595 $url = get_edit_post_link( $draft->ID ); … … function wp_dashboard_recent_drafts( $drafts = false ) { 595 598 /* translators: %s: post title */ 596 599 echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>'; 597 600 echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>'; 598 if ( $the_content = wp_trim_words( $draft->post_content, 10) ) {601 if ( $the_content = wp_trim_words( $draft->post_content, $draft_length ) ) { 599 602 echo '<p>' . $the_content . '</p>'; 600 603 } 601 604 echo "</li>\n"; -
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index 649f29a..634cbb5 100644
function comment_date( $d = '', $comment_ID = 0 ) { 593 593 function get_comment_excerpt( $comment_ID = 0 ) { 594 594 $comment = get_comment( $comment_ID ); 595 595 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 596 $words = explode( ' ', $comment_text ); 596 597 /* translators: This sets the text length for the comment excerpt. */ 598 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); 597 599 598 600 /** 599 601 * Filters the amount of words used in the comment excerpt. … … function get_comment_excerpt( $comment_ID = 0 ) { 602 604 * 603 605 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 604 606 */ 605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20);607 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 606 608 607 $use_ellipsis = count( $words ) > $comment_excerpt_length; 608 if ( $use_ellipsis ) { 609 $words = array_slice( $words, 0, $comment_excerpt_length ); 610 } 609 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 611 610 612 $excerpt = trim( join( ' ', $words ) );613 if ( $use_ellipsis ) {614 $excerpt .= '…';615 }616 611 /** 617 612 * Filters the retrieved comment excerpt. 618 613 * -
src/wp-includes/formatting.php
diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php index bf03e78..c351dd3 100644
function wp_trim_excerpt( $text = '' ) { 3636 3636 $text = apply_filters( 'the_content', $text ); 3637 3637 $text = str_replace( ']]>', ']]>', $text ); 3638 3638 3639 /* translators: This sets the text length for the excerpt. */ 3640 $excerpt_length = intval( _x( '55', 'excerpt_length' ) ); 3641 3639 3642 /** 3640 3643 * Filters the number of words in an excerpt. 3641 3644 * … … function wp_trim_excerpt( $text = '' ) { 3643 3646 * 3644 3647 * @param int $number The number of words. Default 55. 3645 3648 */ 3646 $excerpt_length = apply_filters( 'excerpt_length', 55);3649 $excerpt_length = apply_filters( 'excerpt_length', $excerpt_length ); 3647 3650 /** 3648 3651 * Filters the string in the "more" link displayed after a trimmed excerpt. 3649 3652 * -
tests/phpunit/data/languages/ja_JP.po
diff --git tests/phpunit/data/languages/ja_JP.mo tests/phpunit/data/languages/ja_JP.mo index 1399898..da16813 100644 Binary files tests/phpunit/data/languages/ja_JP.mo and tests/phpunit/data/languages/ja_JP.mo differ diff --git tests/phpunit/data/languages/ja_JP.po tests/phpunit/data/languages/ja_JP.po index f71a737..f59ec51 100644
msgstr "number_format_thousands_sep" 40 40 #: wp-includes/script-loader.php:620 41 41 msgid "Update %s now" 42 42 msgstr "今すぐ %s を更新" 43 44 #. translators: If your word count is based on single characters (e.g. East 45 #. Asian characters), enter 'characters_excluding_spaces' or 46 #. 'characters_including_spaces'. Otherwise, enter 'words'. Do not translate 47 #. into your own language. 48 #: wp-includes/formatting.php:3372 wp-includes/script-loader.php:1100 49 msgctxt "Word count type. Do not translate!" 50 msgid "words" 51 msgstr "characters_including_spaces" 52 53 #. translators: This sets the text length for the excerpt. 54 #: wp-includes/formatting.php:3640 55 msgctxt "excerpt_length" 56 msgid "55" 57 msgstr "110" 58 59 #. translators: This sets the text length for the comment excerpt. 60 #: wp-includes/comment-template.ph:599 61 msgctxt "comment_excerpt_length" 62 msgid "20" 63 msgstr "40" 64 65 #. translators: This sets the text length for the comment excerpt. 66 #: wp-admin/includes/dashboard.php:591 67 msgctxt "draft_length" 68 msgid "10" 69 msgstr "40" -
tests/phpunit/tests/formatting/WPTrimWords.php
diff --git tests/phpunit/tests/formatting/WPTrimWords.php tests/phpunit/tests/formatting/WPTrimWords.php index 7f2a27f..6dab8f6 100644
4 4 * @group formatting 5 5 */ 6 6 class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { 7 /** 8 * Long Dummy Text. 9 * 10 * @since 5.0.0 11 * 12 * @var string $long_text 13 */ 7 14 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit mollis viverra. Pellentesque id urna euismod dolor cursus sagittis.'; 8 15 9 16 function test_trims_to_55_by_default() { … … class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { 42 49 $text = 'This is some short text.'; 43 50 $this->assertEquals( $text, wp_trim_words( $text ) ); 44 51 } 52 53 /** 54 * @ticket 44541 55 */ 56 function test_trims_to_20_counted_by_chars() { 57 switch_to_locale( 'ja_JP' ); 58 $expected = substr( $this->long_text, 0, 20 ) . '…'; 59 $actual = wp_trim_words( $this->long_text, 20 ); 60 restore_previous_locale(); 61 $this->assertEquals( $expected, $actual ); 62 } 63 64 /** 65 * @ticket 44541 66 */ 67 function test_trims_to_20_counted_by_chars_with_double_width_chars() { 68 switch_to_locale( 'ja_JP' ); 69 $text = str_repeat( 'あ', 100 ); 70 $expected = str_repeat( 'あ', 19 ) . '…'; 71 $actual = wp_trim_words( $text, 19 ); 72 restore_previous_locale(); 73 $this->assertEquals( $expected, $actual ); 74 } 45 75 } -
tests/phpunit/tests/l10n.php
diff --git tests/phpunit/tests/l10n.php tests/phpunit/tests/l10n.php index 5173621..46dcf32 100644
5 5 * @group i18n 6 6 */ 7 7 class Tests_L10n extends WP_UnitTestCase { 8 /** 9 * Long Dummy Text. 10 * 11 * @since 5.0.0 12 * 13 * @var string $long_text 14 */ 15 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; 8 16 9 17 /** 10 18 * @ticket 35961 … … class Tests_L10n extends WP_UnitTestCase { 242 250 $this->assertNotEmpty( $array['Project-Id-Version'] ); 243 251 $this->assertNotEmpty( $array['X-Generator'] ); 244 252 } 253 254 /** 255 * @ticket 44541 256 */ 257 function test_length_of_excerpt_should_be_counted_by_words() { 258 global $post; 259 260 switch_to_locale( 'en_US' ); 261 262 $args = array( 263 'post_content' => $this->long_text, 264 'post_excerpt' => '', 265 ); 266 267 $post = $this->factory()->post->create_and_get( $args ); 268 setup_postdata( $post ); 269 270 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]</p>\n"; 271 the_excerpt(); 272 273 restore_previous_locale(); 274 275 $this->expectOutputString( $expect ); 276 } 277 278 /** 279 * @ticket 44541 280 */ 281 function test_length_of_excerpt_should_be_counted_by_chars() { 282 global $post; 283 284 switch_to_locale( 'ja_JP' ); 285 286 $args = array( 287 'post_content' => $this->long_text, 288 'post_excerpt' => '', 289 ); 290 291 $post = $this->factory()->post->create_and_get( $args ); 292 setup_postdata( $post ); 293 294 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]</p>\n"; 295 the_excerpt(); 296 297 restore_previous_locale(); 298 299 $this->expectOutputString( $expect ); 300 } 301 302 /** 303 * @ticket 44541 304 */ 305 function test_length_of_excerpt_should_be_counted_by_chars_in_japanese() { 306 global $post; 307 308 switch_to_locale( 'ja_JP' ); 309 310 $args = array( 311 'post_content' => str_repeat( 'あ', 200 ), 312 'post_excerpt' => '', 313 ); 314 315 $post = $this->factory()->post->create_and_get( $args ); 316 setup_postdata( $post ); 317 318 $expect = '<p>' . str_repeat( 'あ', 110 ) . " […]</p>\n"; 319 the_excerpt(); 320 321 restore_previous_locale(); 322 323 $this->expectOutputString( $expect ); 324 } 325 326 /** 327 * @ticket 44541 328 */ 329 function test_length_of_excerpt_rss_should_be_counted_by_words() { 330 global $post; 331 332 switch_to_locale( 'en_US' ); 333 334 $args = array( 335 'post_content' => $this->long_text, 336 'post_excerpt' => '', 337 ); 338 339 $post = $this->factory()->post->create_and_get( $args ); 340 setup_postdata( $post ); 341 342 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]'; 343 the_excerpt_rss(); 344 345 restore_previous_locale(); 346 347 $this->expectOutputString( $expect ); 348 } 349 350 /** 351 * @ticket 44541 352 */ 353 function test_length_of_excerpt_rss_should_be_counted_by_chars() { 354 global $post; 355 356 switch_to_locale( 'ja_JP' ); 357 358 $args = array( 359 'post_content' => $this->long_text, 360 'post_excerpt' => '', 361 ); 362 363 $post = $this->factory()->post->create_and_get( $args ); 364 setup_postdata( $post ); 365 366 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]'; 367 368 the_excerpt_rss(); 369 370 restore_previous_locale(); 371 372 $this->expectOutputString( $expect ); 373 } 374 375 /** 376 * @ticket 44541 377 */ 378 function test_length_of_draft_should_be_counted_by_words() { 379 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 380 381 switch_to_locale( 'en_US' ); 382 383 $args = array( 384 'post_content' => $this->long_text, 385 'post_excerpt' => '', 386 'post_status' => 'draft', 387 ); 388 389 $this->factory()->post->create( $args ); 390 391 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…'; 392 wp_dashboard_recent_drafts(); 393 394 restore_previous_locale(); 395 396 $this->expectOutputRegex( '/' . $expect . '/' ); 397 } 398 399 /** 400 * @ticket 44541 401 */ 402 function test_length_of_draft_should_be_counted_by_chars() { 403 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 404 405 switch_to_locale( 'ja_JP' ); 406 407 $args = array( 408 'post_content' => $this->long_text, 409 'post_excerpt' => '', 410 'post_status' => 'draft', 411 ); 412 413 $post = $this->factory()->post->create( $args ); 414 415 $expect = 'Lorem ipsum dolor sit amet, consectetur …'; 416 wp_dashboard_recent_drafts(); 417 418 restore_previous_locale(); 419 420 $this->expectOutputRegex( '/' . $expect . '/' ); 421 } 422 423 /** 424 * @ticket 44541 425 */ 426 function test_length_of_draft_should_be_counted_by_chars_in_japanese() { 427 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 428 429 switch_to_locale( 'ja_JP' ); 430 431 $args = array( 432 'post_content' => str_repeat( 'あ', 200 ), 433 'post_excerpt' => '', 434 'post_status' => 'draft', 435 ); 436 437 $this->factory()->post->create( $args ); 438 439 $expect = str_repeat( 'あ', 40 ) . '…'; 440 wp_dashboard_recent_drafts(); 441 442 restore_previous_locale(); 443 444 $this->expectOutputRegex( '/' . $expect . '/' ); 445 } 446 447 /** 448 * @ticket 44541 449 */ 450 function test_length_of_comment_excerpt_should_be_counted_by_words() { 451 switch_to_locale( 'en_US' ); 452 453 $args = array( 454 'comment_content' => $this->long_text, 455 ); 456 $comment_id = $this->factory()->comment->create( $args ); 457 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut…'; 458 $comment_excerpt = get_comment_excerpt( $comment_id ); 459 460 restore_previous_locale(); 461 462 $this->assertSame( $expect, $comment_excerpt ); 463 } 464 465 /** 466 * @ticket 44541 467 */ 468 function test_length_of_comment_excerpt_should_be_counted_by_chars() { 469 switch_to_locale( 'ja_JP' ); 470 471 $args = array( 472 'comment_content' => $this->long_text, 473 ); 474 $comment_id = $this->factory()->comment->create( $args ); 475 $expect = 'Lorem ipsum dolor sit amet, consectetur …'; 476 $comment_excerpt = get_comment_excerpt( $comment_id ); 477 478 restore_previous_locale(); 479 480 $this->assertSame( $expect, $comment_excerpt ); 481 } 482 483 /** 484 * @ticket 44541 485 */ 486 function test_length_of_comment_excerpt_should_be_counted_by_chars_in_Japanese() { 487 switch_to_locale( 'ja_JP' ); 488 489 $args = array( 490 'comment_content' => str_repeat( 'あ', 200 ), 491 ); 492 $comment_id = $this->factory()->comment->create( $args ); 493 $expect = str_repeat( 'あ', 40 ) . '…'; 494 $comment_excerpt = get_comment_excerpt( $comment_id ); 495 496 restore_previous_locale(); 497 498 $this->assertSame( $expect, $comment_excerpt ); 499 } 245 500 }