Index: trunk/phase3/languages/Language.php |
— | — | @@ -2365,7 +2365,7 @@ |
2366 | 2366 | * |
2367 | 2367 | * Note: tries to fix broken HTML with MWTidy |
2368 | 2368 | * |
2369 | | - * @param string $text String to truncate |
| 2369 | + * @param string $text HTML string to truncate |
2370 | 2370 | * @param int $length (zero/positive) Maximum length (excluding ellipses) |
2371 | 2371 | * @param string $ellipsis String to append to the truncated text |
2372 | 2372 | * @returns string |
— | — | @@ -2388,7 +2388,7 @@ |
2389 | 2389 | $bracketState = 0; // 1-tag start, 2-tag name, 0-neither |
2390 | 2390 | $entityState = 0; // 0-not entity, 1-entity |
2391 | 2391 | $tag = $ret = ''; |
2392 | | - $openTags = array(); |
| 2392 | + $openTags = array(); // open tag stack |
2393 | 2393 | $textLen = strlen( $text ); |
2394 | 2394 | for ( $pos = 0; $pos < $textLen; ++$pos ) { |
2395 | 2395 | $ch = $text[$pos]; |
— | — | @@ -2457,7 +2457,8 @@ |
2458 | 2458 | if ( $displayLen == 0 ) { |
2459 | 2459 | return ''; // no text shown, nothing to format |
2460 | 2460 | } |
2461 | | - $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); // for bad HTML |
| 2461 | + // Close the last tag if left unclosed by bad HTML |
| 2462 | + $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); |
2462 | 2463 | while ( count( $openTags ) > 0 ) { |
2463 | 2464 | $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags |
2464 | 2465 | } |
— | — | @@ -2475,9 +2476,15 @@ |
2476 | 2477 | return $skipCount; |
2477 | 2478 | } |
2478 | 2479 | |
2479 | | - // truncateHtml() helper function |
2480 | | - // (a) push or pop $tag from $openTags as needed |
2481 | | - // (b) clear $tag value |
| 2480 | + /* |
| 2481 | + * truncateHtml() helper function |
| 2482 | + * (a) push or pop $tag from $openTags as needed |
| 2483 | + * (b) clear $tag value |
| 2484 | + * @param String &$tag Current HTML tag name we are looking at |
| 2485 | + * @param int $tagType (0-open tag, 1-close tag) |
| 2486 | + * @param char $lastCh Character before the '>' that ended this tag |
| 2487 | + * @param array &$openTags Open tag stack (not accounting for $tag) |
| 2488 | + */ |
2482 | 2489 | private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) { |
2483 | 2490 | $tag = ltrim( $tag ); |
2484 | 2491 | if ( $tag != '' ) { |