From 7503af444b9a5b165df48545c1ff6b138cef16f8 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Fri, 13 Feb 2009 19:13:48 +0000 Subject: [PATCH] * Replace hardcoded '...' as indication of a truncation with the 'ellipsis' message Per Brion's suggestion in http://lists.wikimedia.org/pipermail/wikitech-l/2008-December/040796.html --- RELEASE-NOTES | 2 ++ includes/Article.php | 9 +++------ includes/EditPage.php | 2 +- includes/ImageGallery.php | 2 +- includes/SearchEngine.php | 4 ++-- includes/specials/SpecialAllpages.php | 4 ++-- languages/Language.php | 9 +++++++-- maintenance/orphans.php | 4 ++-- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d3ab9e6a1f..154ffb89d0 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -98,6 +98,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN the active users data from site_stats. * (bug 13040) Gender-aware user namespace aliases * Add a tag on redirected page views +* Replace hardcoded '...' as indication of a truncation with the + 'ellipsis' message === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. diff --git a/includes/Article.php b/includes/Article.php index 82e33889c5..71e230aff8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2175,7 +2175,7 @@ class Article { // Calculate the maximum amount of chars to get // Max content length = max comment length - length of the comment (excl. $1) - '...' $maxLength = 255 - (strlen( $reason ) - 2) - 3; - $contents = $wgContLang->truncate( $contents, $maxLength, '...' ); + $contents = $wgContLang->truncate( $contents, $maxLength ); // Remove possible unfinished links $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents ); // Now replace the '$1' placeholder @@ -3482,8 +3482,7 @@ class Article { global $wgContLang; $truncatedtext = $wgContLang->truncate( str_replace("\n", ' ', $newtext), - max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ), - '...' ); + max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ) ); return wfMsgForContent( 'autosumm-new', $truncatedtext ); } @@ -3495,9 +3494,7 @@ class Article { global $wgContLang; $truncatedtext = $wgContLang->truncate( $newtext, - max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ), - '...' - ); + max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ) ); return wfMsgForContent( 'autosumm-replace', $truncatedtext ); } diff --git a/includes/EditPage.php b/includes/EditPage.php index 2b45444865..acb2d7cc26 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -554,7 +554,7 @@ class EditPage { $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' ); $this->mMetaData = rtrim( $request->getText( 'metadata' ) ); # Truncate for whole multibyte characters. +5 bytes for ellipsis - $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); + $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' ); # Remove extra headings from summaries and new sections. $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary); diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index f3f525c11d..8a38bed728 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -289,7 +289,7 @@ class ImageGallery } $textlink = $this->mShowFilename ? - $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "
\n" : + $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "
\n" : '' ; # ATTENTION: The newline after
is needed to accommodate htmltidy which diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index f69ae8389a..cd8f804b3f 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -1165,12 +1165,12 @@ class SearchHighlighter { continue; } --$contextlines; - $pre = $wgContLang->truncate( $m[1], -$contextchars, ' ... ' ); + $pre = $wgContLang->truncate( $m[1], -$contextchars ); if ( count( $m ) < 3 ) { $post = ''; } else { - $post = $wgContLang->truncate( $m[3], $contextchars, ' ... ' ); + $post = $wgContLang->truncate( $m[3], $contextchars ); } $found = $m[2]; diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index c6c1ca3d19..15c559100d 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -237,8 +237,8 @@ class SpecialAllpages extends IncludableSpecialPage { $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) ); $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) ); // Don't let the length runaway - $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength, '...' ); - $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength, '...' ); + $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength ); + $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength ); $queryparams = $namespace ? "namespace=$namespace&" : ''; $special = $this->getTitle(); diff --git a/languages/Language.php b/languages/Language.php index 9828383da7..08767924e0 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2028,7 +2028,12 @@ class Language { * @param $ellipsis String to append to the truncated text * @return string */ - function truncate( $string, $length, $ellipsis = "" ) { + function truncate( $string, $length, $ellipsis = '...' ) { + # Use the localized ellipsis character + if( $ellipsis == '...' ) { + $ellipsis = wfMsgExt( 'ellipsis', array( 'escapenoentities', 'language' => $this ) ); + } + if( $length == 0 ) { return $ellipsis; } @@ -2045,7 +2050,7 @@ class Language { } elseif( $char >= 0x80 && preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' . '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) { - # We chopped in the middle of a character; remove it + # We chopped in the middle of a character; remove it $string = $m[1]; } return $string . $ellipsis; diff --git a/maintenance/orphans.php b/maintenance/orphans.php index 8ecd9b81a2..480b72207f 100644 --- a/maintenance/orphans.php +++ b/maintenance/orphans.php @@ -63,12 +63,12 @@ function checkOrphans( $fix ) { while( $row = $dbw->fetchObject( $result ) ) { $comment = ( $row->rev_comment == '' ) ? '' - : '(' . $wgContLang->truncate( $row->rev_comment, 40, '...' ) . ')'; + : '(' . $wgContLang->truncate( $row->rev_comment, 40 ) . ')'; printf( "%10d %10d %14s %20s %s\n", $row->rev_id, $row->rev_page, $row->rev_timestamp, - $wgContLang->truncate( $row->rev_user_text, 17, '...' ), + $wgContLang->truncate( $row->rev_user_text, 17 ), $comment ); if( $fix ) { $dbw->delete( 'revision', array( 'rev_id' => $row->rev_id ) ); -- 2.20.1