function columnList Output fix

Jump to: navigation, search
Edited by another user.
Last edit: 17:39, 10 June 2011

FROM: /includes/CategoryPage.php

        /**
         * Format a list of articles chunked by letter in a three-column
         * list, ordered vertically.
         *
         * TODO: Take the headers into account when creating columns, so they're
         * more visually equal.
         *
         * More distant TODO: Scrap this and use CSS columns, whenever IE finally
         * supports those.
         *
         * @param $articles Array
         * @param $articles_start_char Array
         * @return String
         * @private
         */
        function columnList( $articles, $articles_start_char ) {
                $columns = array_combine( $articles, $articles_start_char );
                # Split into three columns
                $columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
 
                $ret = '<table width="100%"><tr valign="top"><td>';
                $prevchar = null;
 
                foreach ( $columns as $column ) {
                        $colContents = array();
 
                        # Kind of like array_flip() here, but we keep duplicates in an
                        # array instead of dropping them.
                        foreach ( $column as $article => $char ) {
                                if ( !isset( $colContents[$char] ) ) {
                                        $colContents[$char] = array();
                                }
                                $colContents[$char][] = $article;
                        }
 
                        $first = true;
                        foreach ( $colContents as $char => $articles ) {
                                $ret .= '<h3>' . htmlspecialchars( $char );
                                if ( $first && $char === $prevchar ) {
                                        # We're continuing a previous chunk at the top of a new
                                        # column, so add " cont." after the letter.
                                        $ret .= ' ' . wfMsgHtml( 'listingcontinuesabbrev' );
                                }
                                $ret .= "</h3>\n";
 
                                $ret .= '<ul><li>';
                                $ret .= implode( "</li>\n<li>", $articles );
                                $ret .= '</li></ul>';
 
                                $first = false;
                                $prevchar = $char;
                        }
 
                        $ret .= "</td>\n<td>";
                }
 
                $ret .= '</td></tr></table>';
                return $ret;
        }

This resulted in an empty cell column on the right...

        /**
         * Format a list of articles chunked by letter in a three-column
         * list, ordered vertically.
         *
         * TODO: Take the headers into account when creating columns, so they're
         * more visually equal.
         *
         * More distant TODO: Scrap this and use CSS columns, whenever IE finally
         * supports those.
         *
         * @param $articles Array
         * @param $articles_start_char Array
         * @return String
         * @private
         */
        function columnList( $articles, $articles_start_char ) {
                $columns = array_combine( $articles, $articles_start_char );
                # Split into three columns
                $columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
 
                $ret = '<table width="100%"><tr valign="top"><td id="column-cat">';
                $prevchar = null;
 
                foreach ( $columns as $column ) {
                        $ret .= "<td id='start-column'>";
                        $colContents = array();
 
                        # Kind of like array_flip() here, but we keep duplicates in an
                        # array instead of dropping them.
                        foreach ( $column as $article => $char ) {
                                if ( !isset( $colContents[$char] ) ) {
                                        $colContents[$char] = array();
                                }
                                $colContents[$char][] = $article;
                        }
 
                        $first = true;
                        foreach ( $colContents as $char => $articles ) {
                                $ret .= '<h3>' . htmlspecialchars( $char );
                                if ( $first && $char === $prevchar ) {
                                        # We're continuing a previous chunk at the top of a new
                                        # column, so add " cont." after the letter.
                                        $ret .= ' ' . wfMsgHtml( 'listingcontinuesabbrev' );
                                }
                                $ret .= "</h3>\n";
 
                                $ret .= '<ul id="cat-art-list"><li>';
                                $ret .= implode( "</li>\n<li>", $articles );
                                $ret .= '</li></ul>';
 
                                $first = false;
                                $prevchar = $char;
                        }
 
                        $ret .= "</td>\n";
                }
 
                $ret .= '</td></tr></table>';
                return $ret;
        }

This worked, and removed the extra cell. Hope I get credit for this little hack… surprised nobody noticed it.

Dsgncr8or17:34, 10 June 2011

This results in invalid HTML. There can't be a <td> in another <td>.

Please file a bug in our BugZilla and attach your proposed fix as a patch.

Krinkle22:59, 10 June 2011
 
Personal tools

Variants
Actions
Navigation
Support
Download
Development
Communication
Toolbox