truncateHtml() comment tweaks
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 28 Oct 2010 02:47:48 +0000 (02:47 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 28 Oct 2010 02:47:48 +0000 (02:47 +0000)
languages/Language.php

index 904d956..965be76 100644 (file)
@@ -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 .= '</' . array_pop( $openTags ) . '>'; // 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 != '' ) {