Extension talk:CategoryLink

From MediaWiki.org
Jump to: navigation, search


[edit] Archive

I archived discussion relating to the older version Kyle van der Meer 16:42, 10 February 2010 (UTC)

[edit] Forked code (refactored, more configurable)

Hi Kyle, thanks for this extension. I needed to fork it for my purposes and thought you and your users might find it usefull. All I did is that I threw out dependecy on external CSS, cleaned the main cycle and added few variables for strings. Use it as you wish. My changed printcategorylinks() function looks like this:

     function printcategorylinks() {
                /* begin config */
                $columns = 3;//change this number to the number of columns you want.
                $html_list_begin = "\n\t\t".'<table class="category_link">';
                $html_list_end = "\n\t\t".'</table>';
                $html_line_begin = "\n\t\t\t".'<tr>';
                $html_line_end = "\n\t\t\t".'</tr>';
                $html_cell_begin = "\n\t\t\t\t".'<td style="vertical-align: top; padding-right: 20px; font-size: 120%;">';
                $html_cell_end = '</td>';
                $html_emptycell_placeholder = "<span class=\"empty\"> </span>";

                /* end config */

                global $wgDBuser,$wgDBpassword, $wgDBname,$wgDBserver,$IP, $wgDBprefix;
                $link = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword)
                        or die('Could not connect: ' . mysql_error());
                mysql_select_db($wgDBname) 
                        or die('Could not select database');
                $query = 'SELECT DISTINCT cl_to FROM '.$wgDBprefix.'categorylinks';
                $result = mysql_query($query) 
                        or die('Query failed: ' . mysql_error());
                $cell_count = 0;
                
                $output = $html_list_begin;
                $output .= $html_line_begin;
                while($row = mysql_fetch_row($result)) {
                        $category_code = $row[0];
                        $category_name = preg_replace("/_/"," ",$row[0]);

                        $output .= $html_cell_begin."\n\t\t\t\t".'<a href="../index.php/Category:'.$category_code.'">'.$category_name."</a>".$html_cell_end;
                        $cell_count++;
                        if($cell_count%$columns==0)
                                $output .= $html_line_end.$html_line_begin;
                }

                for($i=($columns - $cell_count%$columns)%$columns; $i>0; $i--)
                        $output .= $html_cell_begin . $html_emptycell_placeholder . $html_cell_end;

                $output .= $html_line_end;
                $output .= $html_list_end;

                return (''.$output.'');
        }
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox