Difference between revisions of "List-Cat.php"

From Organic Design wiki
(This was corrupting $title which is passed by ref)
(Yo Milan, try that crazy list-cat shit again...)
Line 6: Line 6:
 
$cl = $db->tableName( 'categorylinks' );
 
$cl = $db->tableName( 'categorylinks' );
 
$cur = $db->tableName( 'cur' );
 
$cur = $db->tableName( 'cur' );
xwGetProperty( $properties, 'list-cat', $cat );
+
xwGetProperty( $properties, 'list-cat', $cats );
$cat = str_replace( ' ', '_', $cat );
+
$cat = str_replace( ' ', '_', $cats );
 
$article = trim( $article )."\n";
 
$article = trim( $article )."\n";
$result = $db->query( "SELECT cl_from,cl_sortkey FROM $cl WHERE cl_to = '$cat' ORDER BY cl_sortkey" );
+
foreach ( split( ',', $cats ) as $cat ) {
while ( $row = mysql_fetch_assoc( $result ) ) {
+
$result = $db->query( "SELECT cl_from,cl_sortkey FROM $cl WHERE cl_to = '$cat' ORDER BY cl_sortkey" );
$id = $row['cl_from'];
+
while ( $row = mysql_fetch_assoc( $result ) ) {
$subresult = $subdb->query( "SELECT cur_title,cur_namespace FROM $cur WHERE cur_id=$id" );
+
$id = $row['cl_from'];
if ( $subrow = mysql_fetch_assoc( $subresult ) ) {
+
$subresult = $subdb->query( "SELECT cur_title,cur_namespace FROM $cur WHERE cur_id=$id" );
$t = str_replace( '_', ' ', $subrow['cur_title'] );
+
if ( $subrow = mysql_fetch_assoc( $subresult ) ) {
if ( $ns = $wgContLang->getNsText( $subrow['cur_namespace'] ) ) $t = "$ns:$t";
+
$t = str_replace( '_', ' ', $subrow['cur_title'] );
$a = str_replace( '_', ' ', $row['cl_sortkey'] );
+
if ( $ns = $wgContLang->getNsText( $subrow['cur_namespace'] ) ) $t = "$ns:$t";
$a = ( $t != $a ) ? "|$a" : '';
+
$a = str_replace( '_', ' ', $row['cl_sortkey'] );
$t = preg_replace( '/^(?=Category:)/', ':', $t );
+
$a = ( $t != $a ) ? "|$a" : '';
$article .= "*[[$t$a]]\n";
+
$t = preg_replace( '/^(?=Category:)/', ':', $t );
 +
$article .= "*[[$t$a]]\n";
 +
}
 
}
 
}
 
}
 
}
 
?>
 
?>

Revision as of 11:51, 6 April 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', $cats ); $cat = str_replace( ' ', '_', $cats ); $article = trim( $article )."\n"; foreach ( split( ',', $cats ) as $cat ) { $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 ) ) { $t = str_replace( '_', ' ', $subrow['cur_title'] ); if ( $ns = $wgContLang->getNsText( $subrow['cur_namespace'] ) ) $t = "$ns:$t"; $a = str_replace( '_', ' ', $row['cl_sortkey'] ); $a = ( $t != $a ) ? "|$a" : ; $t = preg_replace( '/^(?=Category:)/', ':', $t ); $article .= "*$t$a\n"; } } } ?>