From 367846470d3bb658a5156384300ef738aee93e85 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 6 Jun 2004 02:06:46 +0000 Subject: [PATCH] Very simple category locator just like dmoz. It prints under the category something like Music > Jazz > Acid Jazz It needs a lot of improvment though --- includes/Skin.php | 9 +++++++++ includes/Title.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/includes/Skin.php b/includes/Skin.php index 11df111b34..81d1f2c138 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -369,6 +369,15 @@ class Skin { $s = $this->makeKnownLink( "Special:Categories", wfMsg( "categories" ), "article=" . urlencode( $wgTitle->getPrefixedDBkey() ) ) . ": " . $t; + + $s .= "

"; + $catstack = array(); + $wgTitle->getAllParentCategories(&$catstack); + foreach ($catstack as $key => $cat) + { + $s .= $key." > ".$cat."
\n"; + } + return $s; } diff --git a/includes/Title.php b/includes/Title.php index 636dd5c023..48ac5bf0a6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1167,5 +1167,55 @@ class Title { return true; } + # Get categories to wich belong this title and return an array of + # categories names. + function getParentCategories( ) + { + global $wgLang,$wgUser; + + #$titlekey = wfStrencode( $this->getArticleID() ); + $titlekey = $this->getArticleId(); + $cns = Namespace::getCategory(); + $sk =& $wgUser->getSkin(); + $parents = array(); + + # get the parents categories of this title from the database + $sql = "SELECT DISTINCT cl_from,cur_namespace,cur_title,cur_id FROM cur,categorylinks + WHERE cl_from='$titlekey' AND cl_to=cur_title AND cur_namespace='$cns' + ORDER BY cl_sortkey" ; + $res = wfQuery ( $sql, DB_READ ) ; + + if(wfNumRows($res) > 0) { + while ( $x = wfFetchObject ( $res ) ) $data[] = $x ; + wfFreeResult ( $res ) ; + } else { + $data = array(); + } + return $data; + } + + # will get the parents and grand-parents + function getAllParentCategories(&$stack) + { + # getting parents + $parents = $this->getParentCategories( ); + + foreach($parents as $parent) + { + # create a title object for the parent + $tpar = Title::newFromID($parent->cur_id); + + $stack[$tpar->getText()] = $this->getText(); + if(isset($stack[$this->getText()])) + { + $stack[$tpar->getText()] .= " > ".$stack[$this->getText()]; + } + + unset( $stack[$this->getText()] ); + $tpar->getAllParentCategories(&$stack); + } + } + + } ?> -- 2.20.1