r47224 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47223‎ | r47224 | r47225 >
Date:19:13, 13 February 2009
Author:raymond
Status:deferred
Tags:
Comment:
* 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
Modified paths:
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewHistory.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeCommentsListView.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionListView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php (modified) (history)
  • /trunk/extensions/ImageTagging/ImageTagging.php (modified) (history)
  • /trunk/extensions/ImageTagging/ImageTagging_body.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_ImageGallery.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php (modified) (history)
  • /trunk/extensions/ReplaceText/SpecialReplaceText.php (modified) (history)
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Gettext.php (modified) (history)
  • /trunk/extensions/catfeed/catfeed.php (modified) (history)
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/SearchEngine.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllpages.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/maintenance/orphans.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/orphans.php
@@ -63,12 +63,12 @@
6464 while( $row = $dbw->fetchObject( $result ) ) {
6565 $comment = ( $row->rev_comment == '' )
6666 ? ''
67 - : '(' . $wgContLang->truncate( $row->rev_comment, 40, '...' ) . ')';
 67+ : '(' . $wgContLang->truncate( $row->rev_comment, 40 ) . ')';
6868 printf( "%10d %10d %14s %20s %s\n",
6969 $row->rev_id,
7070 $row->rev_page,
7171 $row->rev_timestamp,
72 - $wgContLang->truncate( $row->rev_user_text, 17, '...' ),
 72+ $wgContLang->truncate( $row->rev_user_text, 17 ),
7373 $comment );
7474 if( $fix ) {
7575 $dbw->delete( 'revision', array( 'rev_id' => $row->rev_id ) );
Index: trunk/phase3/includes/Article.php
@@ -2175,7 +2175,7 @@
21762176 // Calculate the maximum amount of chars to get
21772177 // Max content length = max comment length - length of the comment (excl. $1) - '...'
21782178 $maxLength = 255 - (strlen( $reason ) - 2) - 3;
2179 - $contents = $wgContLang->truncate( $contents, $maxLength, '...' );
 2179+ $contents = $wgContLang->truncate( $contents, $maxLength );
21802180 // Remove possible unfinished links
21812181 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
21822182 // Now replace the '$1' placeholder
@@ -3482,8 +3482,7 @@
34833483 global $wgContLang;
34843484 $truncatedtext = $wgContLang->truncate(
34853485 str_replace("\n", ' ', $newtext),
3486 - max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ),
3487 - '...' );
 3486+ max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ) );
34883487 return wfMsgForContent( 'autosumm-new', $truncatedtext );
34893488 }
34903489
@@ -3495,9 +3494,7 @@
34963495 global $wgContLang;
34973496 $truncatedtext = $wgContLang->truncate(
34983497 $newtext,
3499 - max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ),
3500 - '...'
3501 - );
 3498+ max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ) );
35023499 return wfMsgForContent( 'autosumm-replace', $truncatedtext );
35033500 }
35043501
Index: trunk/phase3/includes/SearchEngine.php
@@ -1165,12 +1165,12 @@
11661166 continue;
11671167 }
11681168 --$contextlines;
1169 - $pre = $wgContLang->truncate( $m[1], -$contextchars, ' ... ' );
 1169+ $pre = $wgContLang->truncate( $m[1], -$contextchars );
11701170
11711171 if ( count( $m ) < 3 ) {
11721172 $post = '';
11731173 } else {
1174 - $post = $wgContLang->truncate( $m[3], $contextchars, ' ... ' );
 1174+ $post = $wgContLang->truncate( $m[3], $contextchars );
11751175 }
11761176
11771177 $found = $m[2];
Index: trunk/phase3/includes/EditPage.php
@@ -554,7 +554,7 @@
555555 $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
556556 $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
557557 # Truncate for whole multibyte characters. +5 bytes for ellipsis
558 - $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
 558+ $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
559559
560560 # Remove extra headings from summaries and new sections.
561561 $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
Index: trunk/phase3/includes/specials/SpecialAllpages.php
@@ -237,8 +237,8 @@
238238 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
239239 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
240240 // Don't let the length runaway
241 - $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength, '...' );
242 - $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength, '...' );
 241+ $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength );
 242+ $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength );
243243
244244 $queryparams = $namespace ? "namespace=$namespace&" : '';
245245 $special = $this->getTitle();
Index: trunk/phase3/includes/ImageGallery.php
@@ -289,7 +289,7 @@
290290 }
291291
292292 $textlink = $this->mShowFilename ?
293 - $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
 293+ $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "<br />\n" :
294294 '' ;
295295
296296 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
Index: trunk/phase3/languages/Language.php
@@ -2028,7 +2028,12 @@
20292029 * @param $ellipsis String to append to the truncated text
20302030 * @return string
20312031 */
2032 - function truncate( $string, $length, $ellipsis = "" ) {
 2032+ function truncate( $string, $length, $ellipsis = '...' ) {
 2033+ # Use the localized ellipsis character
 2034+ if( $ellipsis == '...' ) {
 2035+ $ellipsis = wfMsgExt( 'ellipsis', array( 'escapenoentities', 'language' => $this ) );
 2036+ }
 2037+
20332038 if( $length == 0 ) {
20342039 return $ellipsis;
20352040 }
@@ -2045,7 +2050,7 @@
20462051 } elseif( $char >= 0x80 &&
20472052 preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
20482053 '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) {
2049 - # We chopped in the middle of a character; remove it
 2054+ # We chopped in the middle of a character; remove it
20502055 $string = $m[1];
20512056 }
20522057 return $string . $ellipsis;
Index: trunk/phase3/RELEASE-NOTES
@@ -98,6 +98,8 @@
9999 the active users data from site_stats.
100100 * (bug 13040) Gender-aware user namespace aliases
101101 * Add a <link rel="canonical"> tag on redirected page views
 102+* Replace hardcoded '...' as indication of a truncation with the
 103+ 'ellipsis' message
102104
103105 === Bug fixes in 1.15 ===
104106 * (bug 16968) Special:Upload no longer throws useless warnings.
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -141,7 +141,7 @@
142142 $message = trim( $value );
143143 $lines = explode( "\n", $message, 2 );
144144 $first = $lines[0];
145 - $trimmed = $wgLang->truncate( $first, 80, '...' );
 145+ $trimmed = $wgLang->truncate( $first, 80 );
146146 return $this->formatMessage( $trimmed );
147147 }
148148 /*
Index: trunk/extensions/CodeReview/CodeRevisionListView.php
@@ -151,7 +151,7 @@
152152 return intval( $value );
153153 case 'cr_path':
154154 return Xml::element('div', array( 'title' => (string)$value ),
155 - $wgLang->truncate( (string)$value, 30, '...' ) );
 155+ $wgLang->truncate( (string)$value, 30 ) );
156156 }
157157 }
158158
Index: trunk/extensions/CodeReview/CodeCommentsListView.php
@@ -86,7 +86,7 @@
8787 return $this->mView->messageFragment( $value );
8888 case 'cc_text':
8989 # Truncate this, blah blah...
90 - return htmlspecialchars( $wgLang->truncate( $value, 300, '...' ) );
 90+ return htmlspecialchars( $wgLang->truncate( $value, 300 ) );
9191 case 'cc_timestamp':
9292 global $wgLang;
9393 return $wgLang->timeanddate( $value, true );
Index: trunk/extensions/MetavidWiki/includes/MV_ImageGallery.php
@@ -123,7 +123,7 @@
124124 }
125125
126126 $textlink = $this->mShowFilename ?
127 - $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
 127+ $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "<br />\n" :
128128 '' ;
129129 }
130130 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php
@@ -632,12 +632,12 @@
633633 continue;
634634 }
635635 -- $contextlines;
636 - $pre = $wgContLang->truncate( $m[1], - $contextchars, '...' );
 636+ $pre = $wgContLang->truncate( $m[1], - $contextchars );
637637
638638 if ( count( $m ) < 3 ) {
639639 $post = '';
640640 } else {
641 - $post = $wgContLang->truncate( $m[3], $contextchars, '...' );
 641+ $post = $wgContLang->truncate( $m[3], $contextchars );
642642 }
643643
644644 $found = $m[2];
@@ -651,7 +651,7 @@
652652 }
653653 // if we found no matches just return the first line:
654654 if ( $extract == '' )
655 - return ' ' . $wgContLang->truncate( $text, ( $contextchars * 2 ), '...' ) . '';
 655+ return ' ' . $wgContLang->truncate( $text, ( $contextchars * 2 ) ) . '';
656656 // wfProfileOut( "$fname-extract" );
657657 // wfProfileOut( $fname );
658658 // return "<li>{$link} ({$size}){$extract}</li>\n";
Index: trunk/extensions/ImageTagging/ImageTagging_body.php
@@ -211,7 +211,7 @@
212212
213213 $nb = '';
214214 $textlink = $this->mShowFilename ?
215 - $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . "<br />\n" :
 215+ $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "<br />\n" :
216216 '';
217217
218218 $s .= ($i%4==0) ? '<tr>' : '';
Index: trunk/extensions/ImageTagging/ImageTagging.php
@@ -276,12 +276,12 @@
277277 continue;
278278 }
279279 $contextlines--;
280 - $pre = $wgContLang->truncate( $m[1], -$contextchars, '...' );
 280+ $pre = $wgContLang->truncate( $m[1], -$contextchars );
281281
282282 if ( count( $m ) < 3 ) {
283283 $post = '';
284284 } else {
285 - $post = $wgContLang->truncate( $m[3], $contextchars, '...' );
 285+ $post = $wgContLang->truncate( $m[3], $contextchars );
286286 }
287287
288288 $found = $m[2];
Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -428,7 +428,7 @@
429429 $plot->format['rave'] = array( 'style' => 'stroke:green; stroke-width:1;' );
430430 $plot->format['dcount'] = array( 'style' => 'stroke:red; stroke-width:1;' );
431431 #'attributes' => "marker-end='url(#circle)'");
432 - $pageText = $wgContLang->truncate( $this->page->getPrefixedText(), 65, '...' );
 432+ $pageText = $wgContLang->truncate( $this->page->getPrefixedText(), 65 );
433433 $plot->title = wfMsgExt('ratinghistory-graph',array('parsemag','content'),
434434 $totalCount, wfMsgForContent("readerfeedback-$tag"), $pageText );
435435 $plot->styleTitle = 'font-family: sans-serif; font-weight: bold; font-size: 12pt;';
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewHistory.php
@@ -141,10 +141,10 @@
142142 $formatted = implode( ', ', $flags_display );
143143 break;
144144 case 'afh_pattern':
145 - $formatted = htmlspecialchars( $wgLang->truncate( $value, 200, '...' ) );
 145+ $formatted = htmlspecialchars( $wgLang->truncate( $value, 200 ) );
146146 break;
147147 case 'afh_comments':
148 - $formatted = htmlspecialchars( $wgLang->truncate( $value, 200, '...' ) );
 148+ $formatted = htmlspecialchars( $wgLang->truncate( $value, 200 ) );
149149 break;
150150 case 'afh_actions':
151151 $actions = unserialize( $value );
Index: trunk/extensions/Translate/TranslateUtils.php
@@ -192,7 +192,7 @@
193193 $message = $m->translation ? $m->translation : $original;
194194
195195 global $wgLang;
196 - $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30, '…' ) );
 196+ $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) );
197197
198198 if ( 1 || $wgUser->isAllowed( 'translate' ) ) {
199199 $tools['edit'] = $sk->makeKnownLinkObj( $title, $niceTitle, "action=edit&loadgroup=$group" );
@@ -368,7 +368,7 @@
369369 global $wgLegalTitleChars, $wgContLang;
370370 $snippet = preg_replace( "/[^\p{L}]/u", ' ', $text );
371371 $snippet = preg_replace( "/ {2,}/u", ' ', $snippet );
372 - $snippet = $wgContLang->truncate( $snippet, $length );
 372+ $snippet = $wgContLang->truncate( $snippet, $length, '' );
373373 $snippet = str_replace( ' ', '_', trim( $snippet ) );
374374 return $snippet;
375375 }
Index: trunk/extensions/Translate/ffs/Gettext.php
@@ -148,7 +148,7 @@
149149 $snippet = preg_replace( "/[^$wgLegalTitleChars]/", ' ', $snippet );
150150 $snippet = preg_replace( "/[:&%\/_]/", ' ', $snippet );
151151 $snippet = preg_replace( "/ {2,}/", ' ', $snippet );
152 - $snippet = $lang->truncate( $snippet, 30 );
 152+ $snippet = $lang->truncate( $snippet, 30, '' );
153153 $snippet = str_replace( ' ', '_', trim( $snippet ) );
154154 $key = $this->prefix . $hash . '-' . $snippet;
155155 }
Index: trunk/extensions/catfeed/catfeed.php
@@ -144,7 +144,7 @@
145145 $text = preg_replace( array_keys($rules), array_values($rules), $text);
146146
147147 # only return the first few chars for now
148 - $shorttext = $wgContLang->truncate( trim( $text ), 145, '...' );
 148+ $shorttext = $wgContLang->truncate( trim( $text ), 145 );
149149 return htmlspecialchars( $shorttext );
150150 }
151151
Index: trunk/extensions/ReplaceText/SpecialReplaceText.php
@@ -169,9 +169,9 @@
170170 $title = Title::makeTitleSafe($row->namespace, $row->title);
171171 $article_text = $row->text;
172172 $target_pos = strpos($article_text, $target_str);
173 - $context_str = str_replace($angle_brackets, $escaped_angle_brackets, $wgContLang->truncate(substr($article_text, 0, $target_pos), -$contextchars, '...' ));
 173+ $context_str = str_replace($angle_brackets, $escaped_angle_brackets, $wgContLang->truncate(substr($article_text, 0, $target_pos), -$contextchars ) );
174174 $context_str .= "<span class=\"searchmatch\">" . str_replace($angle_brackets, $escaped_angle_brackets, substr($article_text, $target_pos, strlen($target_str))) . "</span>";
175 - $context_str .= str_replace($angle_brackets, $escaped_angle_brackets, $wgContLang->truncate(substr($article_text, $target_pos + strlen($target_str)), $contextchars, '...' ));
 175+ $context_str .= str_replace($angle_brackets, $escaped_angle_brackets, $wgContLang->truncate(substr($article_text, $target_pos + strlen($target_str)), $contextchars ) );
176176 $found_titles[] = array($title, $context_str);
177177 $num_modified_pages++;
178178 }
Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -941,7 +941,7 @@
942942 htmlspecialchars($row->acr_email) . $econf.'</td></tr>';
943943 # Truncate this, blah blah...
944944 $bio = htmlspecialchars($row->acr_bio);
945 - $preview = $wgLang->truncate( $bio, 400 );
 945+ $preview = $wgLang->truncate( $bio, 400, '' );
946946 if( strlen($preview) < strlen($bio) ) {
947947 $preview = substr( $preview, 0, strrpos($preview,' ') );
948948 $preview .= " . . .";

Status & tagging log