Extension:CategoryLink

From MediaWiki.org

Jump to: navigation, search

           

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
CategoryLinks

Release status: stable

Implementation  Tag, Parser function
Description Generates an N-column list of all categories in the wiki.
Author(s)  Kyle van der Meer
Last Version  1.5.0 (2007-11-19)
MediaWiki  1.9.3-1.10.1
License No license specified
Download see below
Example  Yahowto

check usage (experimental)

This extensions adds the ability to create a N-column table of categories to a wiki site and it creates a link to each category. I couldn't find something simple that would do this, so I decided to write one myself. Any improvements to make it more dynamic would be appreciated.

To change how many Columns you want on a page, change the column variable value. Other than that, it is all set to go!

This extension can be called with:

<categorylinks />

[edit] Installation

  1. Copy code below to extensions/CategoryLinks/CategoryLinks.php
  2. Add require_once "$IP/extensions/CategoryLinks/CategoryLinks.php"; to the end of your LocalSettings.php

[edit] Code

<?php
        $wgExtensionFunctions[] = 'registercategorylinks';
        $wgExtensionCredits['parserhook'][] = array(
                'name' => 'Category Links',
                'author' => 'Kyle van der Meer',
                'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryLink',
                'description' => 'Displays a N-column table of categories.',);
 
        function registercategorylinks() {
                global $wgParser;
                $wgParser->setHook('categorylinks', 'printcategorylinks');
        }
 
       function printcategorylinks() {
                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 cl_to FROM '.$wgDBprefix.'categorylinks group by cl_to';
                $result = mysql_query($query) or die('Query failed: ' . mysql_error());
                $num_rows = mysql_num_rows($result);
                while($num_row = mysql_fetch_array($result)) 
                        $data[] = $num_row['cl_to'];             
 
                $columns=3;//change this number to the number of columns you want.
                $width=ceil(100/$columns);
                $args.="<table width=\"95%\" style=\"border-style:outset; border-width:2px; border-color:#006600;\" align=\"center\">\n";
                for($j=0;$j<$num_rows;$j++){
                        if(($j % $columns)==0)
                                $args.="\t<tr>\n";
                        $args.="\t\t<td width=\"$width%\" valign=\"top\"><p><a href=\"../index.php/Category:$data[$j]\">".preg_replace("/_/"," ",$data[$j])."</a></p>\n";
                        if(($j % $columns)==$columns-1)
                                $args.="\t</tr>\n";
                }
                $args.="</table>";
                return (''.$args.'');
        }
?>

[edit] Related Extensions

These can also produce category lists, but with different appearances and more/different options.