Difference between revisions of "List-Cat.php"
(let's do some cat-listing on OD :-)) |
({{legacy}}) |
||
(28 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <? | + | {{legacy}} |
− | # | + | <php><? |
− | $db =& wfGetDB(DB_SLAVE); | + | # The List-Cat.php [[[[transform]]]] appends the content of the category |
− | $cl = $db->tableName('categorylinks'); | + | # specified in the "List-Cat" [[[[properties]]]] element to the current |
− | xwGetProperty($properties, 'list-cat', $cat) | + | # article as a bullet list of links. |
− | $result = $db->query("SELECT cl_sortkey FROM $cl WHERE cl_to = '$cat'"); | + | # See [[[[List-Cat Example]]]] |
− | + | # | |
− | + | global $wgContLang; | |
− | while ($row = mysql_fetch_assoc($result)) $ | + | $db =& wfGetDB( DB_MASTER ); |
− | $ | + | $subdb =& wfGetDB( DB_SLAVE ); |
− | + | $cl = $db->tableName( 'categorylinks' ); | |
− | + | $cur = $db->tableName( 'cur' ); | |
− | + | xwGetProperty( $properties, 'list-cat', $cats ); | |
+ | $cats = str_replace( ' ', '_', $cats ); | ||
+ | xwMessage("cats:$cats"); | ||
+ | xwGetProperty( $properties, 'category', $data ); | ||
+ | xwMessage("data:$data"); | ||
+ | $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"; | ||
+ | } | ||
+ | } | ||
} | } | ||
− | + | ?></php> | |
− |
Latest revision as of 03:21, 28 May 2007
<php><?
- The List-Cat.php [[transform]] appends the content of the category
- specified in the "List-Cat" [[properties]] element to the current
- article as a bullet list of links.
- See [[List-Cat Example]]
global $wgContLang; $db =& wfGetDB( DB_MASTER ); $subdb =& wfGetDB( DB_SLAVE ); $cl = $db->tableName( 'categorylinks' ); $cur = $db->tableName( 'cur' ); xwGetProperty( $properties, 'list-cat', $cats ); $cats = str_replace( ' ', '_', $cats ); xwMessage("cats:$cats"); xwGetProperty( $properties, 'category', $data ); xwMessage("data:$data"); $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"; } } } ?></php>