Difference between revisions of "List-Cat.php"

From Organic Design wiki
(can't use dash in element names in php5)
m
Line 11: Line 11:
 
$cur = $db->tableName( 'cur' );
 
$cur = $db->tableName( 'cur' );
 
xwGetProperty( $properties, 'listcat', $cats );
 
xwGetProperty( $properties, 'listcat', $cats );
xwMessage("cats:$cats");
 
xwGetProperty( $properties, 'data', $test );
 
xwMessage("test:$test");
 
 
$cats = str_replace( ' ', '_', $cats );
 
$cats = str_replace( ' ', '_', $cats );
 
$article = trim( $article )."\n";
 
$article = trim( $article )."\n";

Revision as of 09:11, 11 March 2007

<?

  1. The List-Cat.php [[transform]] appends the content of the category
  2. specified in the "List-Cat" [[properties]] element to the current
  3. article as a bullet list of links.
  4. See [[List-Cat Example]]

global $wgContLang; $db =& wfGetDB( DB_MASTER ); $subdb =& wfGetDB( DB_SLAVE ); $cl = $db->tableName( 'categorylinks' ); $cur = $db->tableName( 'cur' ); xwGetProperty( $properties, 'listcat', $cats ); $cats = 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"; } } } ?>