r75603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75602‎ | r75603 | r75604 >
Date:02:47, 28 October 2010
Author:aaron
Status:ok
Tags:
Comment:
truncateHtml() comment tweaks
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -2365,7 +2365,7 @@
23662366 *
23672367 * Note: tries to fix broken HTML with MWTidy
23682368 *
2369 - * @param string $text String to truncate
 2369+ * @param string $text HTML string to truncate
23702370 * @param int $length (zero/positive) Maximum length (excluding ellipses)
23712371 * @param string $ellipsis String to append to the truncated text
23722372 * @returns string
@@ -2388,7 +2388,7 @@
23892389 $bracketState = 0; // 1-tag start, 2-tag name, 0-neither
23902390 $entityState = 0; // 0-not entity, 1-entity
23912391 $tag = $ret = '';
2392 - $openTags = array();
 2392+ $openTags = array(); // open tag stack
23932393 $textLen = strlen( $text );
23942394 for ( $pos = 0; $pos < $textLen; ++$pos ) {
23952395 $ch = $text[$pos];
@@ -2457,7 +2457,8 @@
24582458 if ( $displayLen == 0 ) {
24592459 return ''; // no text shown, nothing to format
24602460 }
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 );
24622463 while ( count( $openTags ) > 0 ) {
24632464 $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags
24642465 }
@@ -2475,9 +2476,15 @@
24762477 return $skipCount;
24772478 }
24782479
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+ */
24822489 private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
24832490 $tag = ltrim( $tag );
24842491 if ( $tag != '' ) {

Status & tagging log