From 491c863f3527c33ccb99407cf9f9c53d5d2940f6 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe <*@iseulde.com> Date: Mon, 27 Jul 2015 11:19:26 +0000 Subject: [PATCH] Editor: word count: better names for types. Also fix it in wp_trim_words(). Fixes #30966. Built from https://develop.svn.wordpress.org/trunk@33440 git-svn-id: http://core.svn.wordpress.org/trunk@33407 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/word-count.js | 6 +++--- wp-admin/js/word-count.min.js | 2 +- wp-includes/formatting.php | 14 ++++++++++---- wp-includes/script-loader.php | 6 +++--- wp-includes/version.php | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/wp-admin/js/word-count.js b/wp-admin/js/word-count.js index c8cfb2f52d..c0255fd295 100644 --- a/wp-admin/js/word-count.js +++ b/wp-admin/js/word-count.js @@ -61,8 +61,8 @@ ].join( '' ), 'g' ), astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, wordsRegExp: /\S\s+/g, - charactersRegExp: /\S/g, - allRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g, + characters_excluding_spacesRegExp: /\S/g, + characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g, l10n: window.wordCountL10n || {} }; @@ -71,7 +71,7 @@ type = type || this.settings.l10n.type; - if ( type !== 'characters' && type !== 'all' ) { + if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) { type = 'words'; } diff --git a/wp-admin/js/word-count.min.js b/wp-admin/js/word-count.min.js index 0b16f0d8b7..296ef2578f 100644 --- a/wp-admin/js/word-count.min.js +++ b/wp-admin/js/word-count.min.js @@ -1 +1 @@ -!function(){function a(a){var b,c;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);c=this.settings.l10n.shortcodes,c&&c.length&&(this.settings.shortcodesRegExp=new RegExp("\\[\\/?(?:"+c.join("|")+")[^\\]]*?\\]","g"))}a.prototype.settings={HTMLRegExp:/<\/?[a-z][^>]*?>/gi,HTMLcommentRegExp://g,spaceRegExp:/ | /gi,HTMLEntityRegExp:/&\S+?;/g,connectorRegExp:/--|\u2014/g,removeRegExp:new RegExp(["[","!-@[-`{-~","\x80-\xbf\xd7\xf7","\u2000-\u2bff","\u2e00-\u2e7f","]"].join(""),"g"),astralRegExp:/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,wordsRegExp:/\S\s+/g,charactersRegExp:/\S/g,allRegExp:/[^\f\n\r\t\v\u00AD\u2028\u2029]/g,l10n:window.wordCountL10n||{}},a.prototype.count=function(a,b){var c=0;return b=b||this.settings.l10n.type,"characters"!==b&&"all"!==b&&(b="words"),a&&(a+="\n",a=a.replace(this.settings.HTMLRegExp,"\n"),a=a.replace(this.settings.HTMLcommentRegExp,""),this.settings.shortcodesRegExp&&(a=a.replace(this.settings.shortcodesRegExp,"\n")),a=a.replace(this.settings.spaceRegExp," "),"words"===b?(a=a.replace(this.settings.HTMLEntityRegExp,""),a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")):(a=a.replace(this.settings.HTMLEntityRegExp,"a"),a=a.replace(this.settings.astralRegExp,"a")),a=a.match(this.settings[b+"RegExp"]),a&&(c=a.length)),c},window.wp=window.wp||{},window.wp.utils=window.wp.utils||{},window.wp.utils.WordCounter=a}(); \ No newline at end of file +!function(){function a(a){var b,c;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);c=this.settings.l10n.shortcodes,c&&c.length&&(this.settings.shortcodesRegExp=new RegExp("\\[\\/?(?:"+c.join("|")+")[^\\]]*?\\]","g"))}a.prototype.settings={HTMLRegExp:/<\/?[a-z][^>]*?>/gi,HTMLcommentRegExp://g,spaceRegExp:/ | /gi,HTMLEntityRegExp:/&\S+?;/g,connectorRegExp:/--|\u2014/g,removeRegExp:new RegExp(["[","!-@[-`{-~","\x80-\xbf\xd7\xf7","\u2000-\u2bff","\u2e00-\u2e7f","]"].join(""),"g"),astralRegExp:/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,wordsRegExp:/\S\s+/g,characters_excluding_spacesRegExp:/\S/g,characters_including_spacesRegExp:/[^\f\n\r\t\v\u00AD\u2028\u2029]/g,l10n:window.wordCountL10n||{}},a.prototype.count=function(a,b){var c=0;return b=b||this.settings.l10n.type,"characters_excluding_spaces"!==b&&"characters_including_spaces"!==b&&(b="words"),a&&(a+="\n",a=a.replace(this.settings.HTMLRegExp,"\n"),a=a.replace(this.settings.HTMLcommentRegExp,""),this.settings.shortcodesRegExp&&(a=a.replace(this.settings.shortcodesRegExp,"\n")),a=a.replace(this.settings.spaceRegExp," "),"words"===b?(a=a.replace(this.settings.HTMLEntityRegExp,""),a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")):(a=a.replace(this.settings.HTMLEntityRegExp,"a"),a=a.replace(this.settings.astralRegExp,"a")),a=a.match(this.settings[b+"RegExp"]),a&&(c=a.length)),c},window.wp=window.wp||{},window.wp.utils=window.wp.utils||{},window.wp.utils.WordCounter=a}(); \ No newline at end of file diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index ed28e0ae9b..25fb02d608 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2812,13 +2812,17 @@ function wp_trim_excerpt( $text = '' ) { * @return string Trimmed text. */ function wp_trim_words( $text, $num_words = 55, $more = null ) { - if ( null === $more ) + if ( null === $more ) { $more = __( '…' ); + } + $original_text = $text; $text = wp_strip_all_tags( $text ); - /* translators: If your word count is based on single characters (East Asian characters), - enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ - if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { + + /* translators: If your word count is based on single characters (e.g. East Asian characters), + enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. + Do not translate into your own language. */ + if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); preg_match_all( '/./u', $text, $words_array ); $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); @@ -2827,6 +2831,7 @@ function wp_trim_words( $text, $num_words = 55, $more = null ) { $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); $sep = ' '; } + if ( count( $words_array ) > $num_words ) { array_pop( $words_array ); $text = implode( $sep, $words_array ); @@ -2834,6 +2839,7 @@ function wp_trim_words( $text, $num_words = 55, $more = null ) { } else { $text = implode( $sep, $words_array ); } + /** * Filter the text content after words have been trimmed. * diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 8862b764e6..67a43d7fea 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -401,10 +401,10 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 ); did_action( 'init' ) && $scripts->localize( 'word-count', 'wordCountL10n', array( - /* translators: If your word count is based on single characters (East Asian characters), - enter 'characters', or 'all' to include spaces. Otherwise, enter 'words'. + /* translators: If your word count is based on single characters (e.g. East Asian characters), + enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. Do not translate into your own language. */ - 'type' => _x( 'words', 'word count: words, characters or all?' ), + 'type' => _x( 'words', 'Word count type. Do not translate!' ), 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 0f21eb8036..7fec7243fd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-beta4-33439'; +$wp_version = '4.3-beta4-33440'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.