Difference between revisions of "Categories.php"
From Organic Design wiki
m |
(Cat bug fix confirmed :-)) |
||
Line 35: | Line 35: | ||
$ns = $nt->getNamespace(); | $ns = $nt->getNamespace(); | ||
$pt = $title; | $pt = $title; | ||
− | |||
# Extract category information from article's content and properties | # Extract category information from article's content and properties | ||
Line 65: | Line 64: | ||
# Only do the rest if this is the top level article | # Only do the rest if this is the top level article | ||
# - the embeds still had to have their cat-links removed | # - the embeds still had to have their cat-links removed | ||
− | if ($pt == $GLOBALS['xwArticleTitle']) { | + | if ( $pt == $GLOBALS['xwArticleTitle'] ) { |
# Title used in db-tables | # Title used in db-tables | ||
− | $t = addslashes($nt->getDBkey()); | + | $t = addslashes( $nt->getDBkey() ); |
# Auto-Category: Language | # Auto-Category: Language | ||
Line 76: | Line 75: | ||
if ($update) { | if ($update) { | ||
$result = $db->query("SELECT cur_id FROM $cur WHERE cur_title='$t' AND cur_namespace='$ns' LIMIT 1"); | $result = $db->query("SELECT cur_id FROM $cur WHERE cur_title='$t' AND cur_namespace='$ns' LIMIT 1"); | ||
− | if ($row = mysql_fetch_assoc($result)) $id = $row['cur_id']; | + | if ( $row = mysql_fetch_assoc($result) ) $id = $row['cur_id']; |
else $id = $update = false; | else $id = $update = false; | ||
} | } | ||
Line 82: | Line 81: | ||
# Delete all current category links from this title | # Delete all current category links from this title | ||
if ($update) { | if ($update) { | ||
− | $db->query("DELETE FROM $cl WHERE cl_from='$id'"); | + | $db->query( "DELETE FROM $cl WHERE cl_from='$id'" ); |
# Stop parser from clearing them again after we repopulate it | # Stop parser from clearing them again after we repopulate it | ||
$GLOBALS['wgUseCategoryMagic'] = false; | $GLOBALS['wgUseCategoryMagic'] = false; | ||
Line 89: | Line 88: | ||
# Remove duplicates and sort categories | # Remove duplicates and sort categories | ||
$tmp = array(); | $tmp = array(); | ||
− | foreach ($categories as $cat) { | + | foreach ( $categories as $cat ) { |
− | list($cat, $sortkey) = explode('|', ucfirst($cat)); | + | list($cat, $sortkey) = explode( '|', ucfirst($cat) ); |
− | 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 | ||
− | foreach ($tmp as $cat => $sortkey) { | + | foreach ( $tmp as $cat => $sortkey ) { |
# Add to wiki-output if not properties | # Add to wiki-output if not properties | ||
$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) ); |
# 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 05:32, 28 February 2006
<?
- XmlWiki Category Extension - 2005-08-25
- This data-transform replaces the current MediaWiki category parsing
- - It allows categories to be included in either the article content or its XML properties
- - Maintains rules-based auto-categorisation
- Only apply this transform for the root article, not embeds
$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 ($event != 'data') $apply = false;
- If a category page, add class attribute to table since the MediaWiki fellas didn't for some reason
if (ereg('^Category:.+$', $title)) { # Add this transform to the view stack to adjust page after it's built if ($event == 'data') xwSetProperty($properties, 'xpath:/properties:view', $tTitle); else { # If already in view event now, add a CSS class to letter-headings
$article = preg_replace("/