Difference between revisions of "List-Cat.php"

From Organic Design wiki
(Bug fix - couldn't handle other namespaces)
(inefficient way - should be using more MW functions)
Line 1: Line 1:
 
<?
 
<?
 
# Append article content with a list of article-names from category specified in properties
 
# Append article content with a list of article-names from category specified in properties
 +
global $wgContLang;
 
$db =& wfGetDB( DB_MASTER );
 
$db =& wfGetDB( DB_MASTER );
 
$subdb =& wfGetDB( DB_SLAVE );
 
$subdb =& wfGetDB( DB_SLAVE );
Line 14: Line 15:
 
if ($subrow = mysql_fetch_assoc($subresult)) {
 
if ($subrow = mysql_fetch_assoc($subresult)) {
 
$title = Title::makeTitle( $subrow['cur_namespace'], $subrow['cur_title'] );
 
$title = Title::makeTitle( $subrow['cur_namespace'], $subrow['cur_title'] );
#$title = str_replace('_', ' ', $subrow['cur_title']);
+
$title = str_replace('_', ' ', $subrow['cur_title']);
 +
if ($ns = $wgContLang->getNsText( $ns )) $title = "$ns:$title";
 
$anchor = str_replace('_', ' ', $row['cl_sortkey']);
 
$anchor = str_replace('_', ' ', $row['cl_sortkey']);
 
$anchor = ($title != $anchor) ? "|$anchor" : '';
 
$anchor = ($title != $anchor) ? "|$anchor" : '';

Revision as of 01:59, 27 January 2006

<?

  1. Append article content with a list of article-names from category specified in properties

global $wgContLang; $db =& wfGetDB( DB_MASTER ); $subdb =& wfGetDB( DB_SLAVE ); $cl = $db->tableName('categorylinks'); $cur = $db->tableName('cur'); xwGetProperty($properties, 'list-cat', $cat); $cat = str_replace(' ', '_', $cat); $article = trim($article)."\n"; $result = $db->query("SELECT cl_from,cl_sortkey FROM $cl WHERE cl_to = '$cat' ORDER BY cl_sortkey"); while ($row = mysql_fetch_assoc($result)) { $id = $row['cl_from']; $subresult = $subdb->query("SELECT cur_title,cur_namespace FROM $cur WHERE cur_id=$id"); if ($subrow = mysql_fetch_assoc($subresult)) { $title = Title::makeTitle( $subrow['cur_namespace'], $subrow['cur_title'] ); $title = str_replace('_', ' ', $subrow['cur_title']); if ($ns = $wgContLang->getNsText( $ns )) $title = "$ns:$title"; $anchor = str_replace('_', ' ', $row['cl_sortkey']); $anchor = ($title != $anchor) ? "|$anchor" : ; $article .= "*$title$anchor\n"; } } ?>