Index: trunk/phase3/languages/Language.php |
— | — | @@ -2174,7 +2174,7 @@ |
2175 | 2175 | $string = $this->removeBadCharFirst( $string ); |
2176 | 2176 | $string = $ellipsis . $string; |
2177 | 2177 | } |
2178 | | - # Do not truncate if the ellipsis makes the string longer (bug 22181) |
| 2178 | + # Do not truncate if the ellipsis makes the string longer/equal (bug 22181) |
2179 | 2179 | if ( strlen( $string ) < strlen( $stringOriginal ) ) { |
2180 | 2180 | return $string; |
2181 | 2181 | } else { |
— | — | @@ -2248,7 +2248,7 @@ |
2249 | 2249 | } |
2250 | 2250 | $text = MWTidy::tidy( $text ); // fix tags |
2251 | 2251 | $displayLen = 0; // innerHTML legth so far |
2252 | | - $doTruncate = true; // truncated string plus '...' shorter than original? |
| 2252 | + $testingEllipsis = false; // checking if ellipses will make string longer/equal? |
2253 | 2253 | $tagType = 0; // 0-open, 1-close |
2254 | 2254 | $bracketState = 0; // 1-tag start, 2-tag name, 0-neither |
2255 | 2255 | $entityState = 0; // 0-not entity, 1-entity |
— | — | @@ -2301,15 +2301,20 @@ |
2302 | 2302 | } |
2303 | 2303 | } |
2304 | 2304 | } |
2305 | | - if( !$doTruncate ) continue; |
2306 | | - # Truncate if not in the middle of a bracket/entity... |
| 2305 | + # Consider truncation once the display length has reached the maximim. |
| 2306 | + # Double-check that we're not in the middle of a bracket/entity... |
2307 | 2307 | if ( $displayLen >= $length && $bracketState == 0 && $entityState == 0 ) { |
2308 | | - $remaining = substr( $text, $pos + 1 ); // remaining string |
2309 | | - $remaining = StringUtils::delimiterReplace( '<', '>', '', $remaining ); // rm tags |
2310 | | - $remaining = StringUtils::delimiterReplace( '&', ';', '', $remaining ); // rm entities |
2311 | | - $doTruncate = ( strlen($remaining) > strlen($ellipsis) ); |
2312 | | - if ( $doTruncate ) { |
2313 | | - $ret = $this->removeBadCharLast( $ret ) . $ellipsis; |
| 2308 | + if ( !$testingEllipsis ) { |
| 2309 | + $testingEllipsis = true; |
| 2310 | + # Save were we are; we will truncate here unless |
| 2311 | + # the ellipsis actually makes the string longer. |
| 2312 | + $pOpenTags = $openTags; // save state |
| 2313 | + $pRet = $ret; // save state |
| 2314 | + } elseif ( $displayLen > ($length + strlen($ellipsis)) ) { |
| 2315 | + # Ellipsis won't make string longer/equal, the truncation point was OK. |
| 2316 | + $openTags = $pOpenTags; // reload state |
| 2317 | + $ret = $this->removeBadCharLast( $pRet ); // reload state, multi-byte char fix |
| 2318 | + $ret .= $ellipsis; // add ellipsis |
2314 | 2319 | break; |
2315 | 2320 | } |
2316 | 2321 | } |