From 8947566ec11bc268692f29590d96407bb682617a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 28 Oct 2010 02:47:48 +0000 Subject: [PATCH] truncateHtml() comment tweaks --- languages/Language.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index 904d956144..965be76639 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2365,7 +2365,7 @@ class Language { * * Note: tries to fix broken HTML with MWTidy * - * @param string $text String to truncate + * @param string $text HTML string to truncate * @param int $length (zero/positive) Maximum length (excluding ellipses) * @param string $ellipsis String to append to the truncated text * @returns string @@ -2388,7 +2388,7 @@ class Language { $bracketState = 0; // 1-tag start, 2-tag name, 0-neither $entityState = 0; // 0-not entity, 1-entity $tag = $ret = ''; - $openTags = array(); + $openTags = array(); // open tag stack $textLen = strlen( $text ); for ( $pos = 0; $pos < $textLen; ++$pos ) { $ch = $text[$pos]; @@ -2457,7 +2457,8 @@ class Language { if ( $displayLen == 0 ) { return ''; // no text shown, nothing to format } - $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); // for bad HTML + // Close the last tag if left unclosed by bad HTML + $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); while ( count( $openTags ) > 0 ) { $ret .= ''; // close open tags } @@ -2475,9 +2476,15 @@ class Language { return $skipCount; } - // truncateHtml() helper function - // (a) push or pop $tag from $openTags as needed - // (b) clear $tag value + /* + * truncateHtml() helper function + * (a) push or pop $tag from $openTags as needed + * (b) clear $tag value + * @param String &$tag Current HTML tag name we are looking at + * @param int $tagType (0-open tag, 1-close tag) + * @param char $lastCh Character before the '>' that ended this tag + * @param array &$openTags Open tag stack (not accounting for $tag) + */ private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) { $tag = ltrim( $tag ); if ( $tag != '' ) { -- 2.20.1