Difference between revisions of "Categories.php"
From Organic Design wiki
(Add document.css to transform exceptions) |
(Attempt adding property inheritence from cats...) |
||
Line 1: | Line 1: | ||
<? | <? | ||
− | # XmlWiki Category Extension - 2005-08-25 | + | # XmlWiki Category Extension - 2005-08-25 - see discussion page |
− | |||
− | |||
− | |||
global $xwIsProperties; | global $xwIsProperties; | ||
$update = $GLOBALS['xwSave']; | $update = $GLOBALS['xwSave']; | ||
Line 13: | Line 10: | ||
# If a category page, add class attribute to table since the MediaWiki fellas didn't for some reason | # If a category page, add class attribute to table since the MediaWiki fellas didn't for some reason | ||
if ( ereg( '^Category:.+$', $title ) ) { | if ( ereg( '^Category:.+$', $title ) ) { | ||
− | # | + | # If event is view, adjust rendered output, else add this to view event |
− | if ( $event == ' | + | if ( $event == 'view' ) { |
− | + | # Add CSS class to headings (see, not just me who hardwires styles!) | |
+ | $article = preg_replace( '/<h3>([A-Z]( cont\\.)?<\\/h3>)/i', '<h3 class="category-heading">$1', $article ); | ||
+ | } | ||
+ | else xwSetProperty( $properties, 'xpath:/properties:view', $tTitle ); | ||
$apply = false; # Just let wiki-parser handle category-links for category pages | $apply = false; # Just let wiki-parser handle category-links for category pages | ||
} | } | ||
Line 22: | Line 22: | ||
# Begin extracting category-link info - first get stuff we'll be needing | # Begin extracting category-link info - first get stuff we'll be needing | ||
− | + | $db =& wfGetDB( DB_SLAVE ); | |
− | $db =& wfGetDB(DB_SLAVE); | + | $cur = $db->tableName( 'cur' ); |
− | $cur = $db->tableName('cur'); | + | $cl = $db->tableName( 'categorylinks' ); |
− | $cl = $db->tableName('categorylinks'); | ||
$category_match = "\\[{2}\\s*category\\s*:\\s*(.+?)\\s*]]\\n?"; | $category_match = "\\[{2}\\s*category\\s*:\\s*(.+?)\\s*]]\\n?"; | ||
$pt = $title; | $pt = $title; | ||
Line 37: | Line 36: | ||
if ( !$language ) $language = xwArticleType( $title, $content ); | if ( !$language ) $language = xwArticleType( $title, $content ); | ||
} | } | ||
− | elseif ( eregi('^sys:(.+)$', $title, $match) ) { | + | elseif ( eregi( '^sys:(.+)$', $title, $match ) ) { |
$title = $match[1]; | $title = $match[1]; | ||
$ns = NS_USER; | $ns = NS_USER; | ||
Line 43: | Line 42: | ||
preg_match_all( "/$category_match/i", $content, $match ); | preg_match_all( "/$category_match/i", $content, $match ); | ||
$categories = $match[1]; | $categories = $match[1]; | ||
− | foreach ( xwGetListByTagname($article, 'groups') as $group ) | + | # Groups auto-categorisation |
− | + | foreach ( xwGetListByTagname( $article, 'groups' ) as $group ) | |
− | + | $categories[] = "Group:$group"; | |
$language = ''; | $language = ''; | ||
} | } | ||
Line 86: | Line 85: | ||
# Get the db-key of this article | # Get the db-key of this article | ||
if ( $update ) { | if ( $update ) { | ||
− | $ | + | $id = Title::makeTitle( $ns, $t ); |
− | + | $id = $update = $id->getArticleID(); | |
− | |||
} | } | ||
Line 104: | Line 102: | ||
if ( !$tmp[$cat] = $sortkey ) $tmp[$cat] = $t; | if ( !$tmp[$cat] = $sortkey ) $tmp[$cat] = $t; | ||
} | } | ||
− | ksort($tmp); | + | ksort( $tmp ); |
# Loop through categories and process each | # Loop through categories and process each | ||
+ | $sk =& $GLOBALS['wgParser']->mOptions->getSkin(); | ||
foreach ( $tmp as $cat => $sortkey ) { | foreach ( $tmp as $cat => $sortkey ) { | ||
− | # Add to wiki-output | + | |
+ | # Add to wiki-output | ||
$nt = Title::makeTitle( NS_CATEGORY, $cat ); | $nt = Title::makeTitle( NS_CATEGORY, $cat ); | ||
$GLOBALS[wgParser]->mOutput->addCategoryLink( $sk->makeLinkObj($nt, $cat) ); | $GLOBALS[wgParser]->mOutput->addCategoryLink( $sk->makeLinkObj($nt, $cat) ); | ||
+ | # Inherit properties from this cat if it has any | ||
+ | xwMerge( $properties, xwArticleProperties( "Category:$cat" ) ); | ||
+ | |||
# Update db if saving and db-key known | # Update db if saving and db-key known | ||
− | $cat = addslashes( str_replace(' ', '_', $cat) ); | + | $cat = addslashes( str_replace( ' ', '_', $cat ) ); |
− | if ($update) $db->query( "INSERT INTO $cl (cl_from,cl_to,cl_sortkey) VALUES('$id','$cat','$sortkey')" ); | + | if ( $update ) $db->query( "INSERT INTO $cl (cl_from,cl_to,cl_sortkey) VALUES('$id','$cat','$sortkey')" ); |
+ | |||
} | } | ||
} | } | ||
} | } | ||
+ | |||
?> | ?> |
Revision as of 06:34, 13 March 2006
<?
- XmlWiki Category Extension - 2005-08-25 - see discussion page
global $xwIsProperties; $update = $GLOBALS['xwSave']; $apply = true;
- Don't apply if page is a category, or if action isn't view or submit
if ( ($action != 'view') && ($action != ) && !$update ) $apply = false;
- If a category page, add class attribute to table since the MediaWiki fellas didn't for some reason
if ( ereg( '^Category:.+$', $title ) ) { # If event is view, adjust rendered output, else add this to view event if ( $event == 'view' ) { # Add CSS class to headings (see, not just me who hardwires styles!)
$article = preg_replace( '/