Content added Content deleted
imported>mutante mNo edit summary |
imported>mutante mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
An extension to display the "Top Categories" automatically ,ordered by number of pages in them. |
|||
#REDIRECT [[Top Categories]] |
|||
=== example === |
|||
<nowiki><topcat>10</topcat></nowiki> |
|||
=== result === |
|||
<topcat>10</topcat> |
|||
=== extension source === |
|||
<pre> |
|||
<?php |
|||
# Top Categories Mediawiki extension |
|||
# display a list of the biggest categories on the wiki |
|||
# and the number of pages in them |
|||
# <topcat>23</topcat> |
|||
# where "23" would be the number of results to display |
|||
# by mutante 23.10.2005 |
|||
$wgExtensionFunctions[] = "wfTopCatExtension"; |
|||
function wfTopCatExtension() { |
|||
global $wgParser; |
|||
$wgParser->setHook( "topcat", "renderTopCat" ); |
|||
} |
|||
function renderTopCat( $input ) { |
|||
$input = mysql_escape_string($input); |
|||
# check if input is integer else set to 5 |
|||
if (is_int($input)){ |
|||
$limit = $input; |
|||
} else { |
|||
$limit = 5; |
|||
} |
|||
$hd = mysql_connect("localhost", "wikiuser", "password") or die ("Unable to connect"); |
|||
mysql_select_db ("wikidb", $hd) or die ("Unable to select database"); |
|||
$res= mysql_query("SELECT cl_to , COUNT(*) AS total FROM categorylinks GROUP BY cl_to ORDER BY total DESC LIMIT $input", $hd) or die ("Unable to run query"); |
|||
$output="<table border=\"1\"><tr><th colspan=\"2\" align=\"center\">Top $input Categories</th></tr><tr><th align=\"left\">category</th><th align=\"right\"># of pages</th></tr>"; |
|||
while ($row = mysql_fetch_assoc($res)) |
|||
{ |
|||
$category = $row["cl_to"]; |
|||
$pages = $row["total"]; |
|||
$output.="<tr><td align=\"right\"><a href=\"http://s23.org/wiki/Category:$category\">$category</a></td><td align=\"right\">$pages</td></tr>"; |
|||
} |
|||
$output.="</table>"; |
|||
return $output; |
|||
} |
|||
</pre> |
|||
also see: [[MediawikiExtensions/Top Pages]] |
|||
[[Category:Wiki]] |
|||
[[Category:PHP]] |
|||
[[Category:Mediawiki Extensions]] |
|||
[[Category:Mediawiki]] |
Latest revision as of 20:43, 18 January 2006
An extension to display the "Top Categories" automatically ,ordered by number of pages in them.
example[edit]
<topcat>10</topcat>
result[edit]
<topcat>10</topcat>
extension source[edit]
<?php # Top Categories Mediawiki extension # display a list of the biggest categories on the wiki # and the number of pages in them # <topcat>23</topcat> # where "23" would be the number of results to display # by mutante 23.10.2005 $wgExtensionFunctions[] = "wfTopCatExtension"; function wfTopCatExtension() { global $wgParser; $wgParser->setHook( "topcat", "renderTopCat" ); } function renderTopCat( $input ) { $input = mysql_escape_string($input); # check if input is integer else set to 5 if (is_int($input)){ $limit = $input; } else { $limit = 5; } $hd = mysql_connect("localhost", "wikiuser", "password") or die ("Unable to connect"); mysql_select_db ("wikidb", $hd) or die ("Unable to select database"); $res= mysql_query("SELECT cl_to , COUNT(*) AS total FROM categorylinks GROUP BY cl_to ORDER BY total DESC LIMIT $input", $hd) or die ("Unable to run query"); $output="<table border=\"1\"><tr><th colspan=\"2\" align=\"center\">Top $input Categories</th></tr><tr><th align=\"left\">category</th><th align=\"right\"># of pages</th></tr>"; while ($row = mysql_fetch_assoc($res)) { $category = $row["cl_to"]; $pages = $row["total"]; $output.="<tr><td align=\"right\"><a href=\"http://s23.org/wiki/Category:$category\">$category</a></td><td align=\"right\">$pages</td></tr>"; } $output.="</table>"; return $output; }
also see: MediawikiExtensions/Top Pages