Ticket #44541: 44541.3.patch
File 44541.3.patch, 13.3 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 0c5bb5f5b1..e1762f34be 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 649f29a10b..634cbb54e8 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 bf03e78e1e..c351dd35f1 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 1399898aa7..da1681326c 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 f71a737714..82a6d7e277 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 #: src/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 #: src/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 7f2a27fc05..8a207a6f9c 100644
class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { 42 42 $text = 'This is some short text.'; 43 43 $this->assertEquals( $text, wp_trim_words( $text ) ); 44 44 } 45 46 /** 47 * @ticket 44541 48 */ 49 function test_trims_to_20_counted_by_chars() { 50 switch_to_locale( 'ja_JP' ); 51 $expected = substr( $this->long_text, 0, 20 ) . '…'; 52 $this->assertEquals( $expected, wp_trim_words( $this->long_text, 20 ) ); 53 restore_previous_locale(); 54 } 55 56 /** 57 * @ticket 44541 58 */ 59 function test_trims_to_20_counted_by_chars_with_double_width_chars() { 60 switch_to_locale( 'ja_JP' ); 61 $text = str_repeat( 'あ', 100 ); 62 $expected = str_repeat( 'あ', 19 ) . '…'; 63 $this->assertEquals( $expected, wp_trim_words( $text, 19 ) ); 64 restore_previous_locale(); 65 } 45 66 } -
tests/phpunit/tests/l10n.php
diff --git tests/phpunit/tests/l10n.php tests/phpunit/tests/l10n.php index 5173621d2c..8146c58d3c 100644
6 6 */ 7 7 class Tests_L10n extends WP_UnitTestCase { 8 8 9 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.'; 10 9 11 /** 10 12 * @ticket 35961 11 13 */ … … class Tests_L10n extends WP_UnitTestCase { 242 244 $this->assertNotEmpty( $array['Project-Id-Version'] ); 243 245 $this->assertNotEmpty( $array['X-Generator'] ); 244 246 } 247 248 /** 249 * @ticket 44541 250 */ 251 function test_length_of_excerpt_should_be_counted_by_words() { 252 global $post; 253 254 switch_to_locale( 'en_US' ); 255 256 $args = array( 257 'post_content' => $this->long_text, 258 'post_excerpt' => '', 259 ); 260 261 $post = $this->factory()->post->create_and_get( $args ); 262 setup_postdata( $post ); 263 264 $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"; 265 $this->expectOutputString( $expect ); 266 the_excerpt(); 267 268 restore_previous_locale(); 269 } 270 271 /** 272 * @ticket 44541 273 */ 274 function test_length_of_excerpt_should_be_counted_by_chars() { 275 global $post; 276 277 switch_to_locale( 'ja_JP' ); 278 279 $args = array( 280 'post_content' => $this->long_text, 281 'post_excerpt' => '', 282 ); 283 284 $post = $this->factory()->post->create_and_get( $args ); 285 setup_postdata( $post ); 286 287 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]</p>\n"; 288 $this->expectOutputString( $expect ); 289 the_excerpt(); 290 291 restore_previous_locale(); 292 } 293 294 /** 295 * @ticket 44541 296 */ 297 function test_length_of_excerpt_should_be_counted_by_chars_in_japanese() { 298 global $post; 299 300 switch_to_locale( 'ja_JP' ); 301 302 $args = array( 303 'post_content' => str_repeat( 'あ', 200 ), 304 'post_excerpt' => '', 305 ); 306 307 $post = $this->factory()->post->create_and_get( $args ); 308 setup_postdata( $post ); 309 310 $expect = "<p>" . str_repeat( 'あ', 110 ) . " […]</p>\n"; 311 $this->expectOutputString( $expect ); 312 the_excerpt(); 313 314 restore_previous_locale(); 315 } 316 317 /** 318 * @ticket 44541 319 */ 320 function test_length_of_excerpt_rss_should_be_counted_by_words() { 321 global $post; 322 323 switch_to_locale( 'en_US' ); 324 325 $args = array( 326 'post_content' => $this->long_text, 327 'post_excerpt' => '', 328 ); 329 330 $post = $this->factory()->post->create_and_get( $args ); 331 setup_postdata( $post ); 332 333 $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 […]"; 334 $this->expectOutputString( $expect ); 335 the_excerpt_rss(); 336 337 restore_previous_locale(); 338 } 339 340 /** 341 * @ticket 44541 342 */ 343 function test_length_of_excerpt_rss_should_be_counted_by_chars() { 344 global $post; 345 346 switch_to_locale( 'ja_JP' ); 347 348 $args = array( 349 'post_content' => $this->long_text, 350 'post_excerpt' => '', 351 ); 352 353 $post = $this->factory()->post->create_and_get( $args ); 354 setup_postdata( $post ); 355 356 $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]"; 357 $this->expectOutputString( $expect ); 358 the_excerpt_rss(); 359 360 restore_previous_locale(); 361 } 362 363 /** 364 * @ticket 44541 365 */ 366 function test_length_of_draft_should_be_counted_by_words() { 367 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 368 369 switch_to_locale( 'en_US' ); 370 371 $args = array( 372 'post_content' => $this->long_text, 373 'post_excerpt' => '', 374 'post_status' => 'draft', 375 ); 376 377 $this->factory()->post->create( $args ); 378 379 $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…"; 380 wp_dashboard_recent_drafts(); 381 $this->expectOutputRegex( '/' . $expect . '/' ); 382 383 restore_previous_locale(); 384 } 385 386 /** 387 * @ticket 44541 388 */ 389 function test_length_of_draft_should_be_counted_by_chars() { 390 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 391 392 switch_to_locale( 'ja_JP' ); 393 394 $args = array( 395 'post_content' => $this->long_text, 396 'post_excerpt' => '', 397 'post_status' => 'draft', 398 ); 399 400 $post = $this->factory()->post->create( $args ); 401 402 $expect = "Lorem ipsum dolor sit amet, consectetur …"; 403 wp_dashboard_recent_drafts(); 404 $this->expectOutputRegex( '/' . $expect . '/' ); 405 406 restore_previous_locale(); 407 } 408 409 /** 410 * @ticket 44541 411 */ 412 function test_length_of_draft_should_be_counted_by_chars_in_japanese() { 413 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 414 415 switch_to_locale( 'ja_JP' ); 416 417 $args = array( 418 'post_content' => str_repeat( 'あ', 200 ), 419 'post_excerpt' => '', 420 'post_status' => 'draft', 421 ); 422 423 $this->factory()->post->create( $args ); 424 425 $expect = str_repeat( 'あ', 40 ) . "…"; 426 wp_dashboard_recent_drafts(); 427 $this->expectOutputRegex( '/' . $expect . '/' ); 428 429 restore_previous_locale(); 430 } 431 432 /** 433 * @ticket 44541 434 */ 435 function test_length_of_comment_excerpt_should_be_counted_by_words() { 436 switch_to_locale( 'en_US' ); 437 438 $args = array( 439 'comment_content' => $this->long_text, 440 ); 441 442 $comment_id = $this->factory()->comment->create( $args ); 443 444 $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut…"; 445 446 $comment_excerpt = get_comment_excerpt( $comment_id ); 447 448 $this->assertSame( $expect, $comment_excerpt ); 449 450 restore_previous_locale(); 451 } 452 453 /** 454 * @ticket 44541 455 */ 456 function test_length_of_comment_excerpt_should_be_counted_by_chars() { 457 switch_to_locale( 'ja_JP' ); 458 459 $args = array( 460 'comment_content' => $this->long_text, 461 ); 462 463 $comment_id = $this->factory()->comment->create( $args ); 464 465 $expect = "Lorem ipsum dolor sit amet, consectetur …"; 466 467 $comment_excerpt = get_comment_excerpt( $comment_id ); 468 469 $this->assertSame( $expect, $comment_excerpt ); 470 471 restore_previous_locale(); 472 } 473 474 /** 475 * @ticket 44541 476 */ 477 function test_length_of_comment_excerpt_should_be_counted_by_chars_in_Japanese() { 478 switch_to_locale( 'ja_JP' ); 479 480 $args = array( 481 'comment_content' => str_repeat( 'あ', 200 ), 482 ); 483 484 $comment_id = $this->factory()->comment->create( $args ); 485 486 $expect = str_repeat( 'あ', 40 ) . "…"; 487 488 $comment_excerpt = get_comment_excerpt( $comment_id ); 489 490 $this->assertSame( $expect, $comment_excerpt ); 491 492 restore_previous_locale(); 493 } 245 494 }