From 67cc572a100c0b251ea64ea6483e854258840974 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 7 Jun 2004 07:55:27 +0000 Subject: [PATCH] Major rewrite / bug fixing of the dmoz-like category browser --- includes/Skin.php | 6 +----- includes/Title.php | 53 +++++++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 765c193f46..fa842d116f 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -374,11 +374,7 @@ class Skin { if($wgUseCategoryBrowser) { $s .= "

"; $catstack = array(); - $wgTitle->getAllParentCategories(&$catstack); - foreach ($catstack as $key => $cat) - { - $s .= $this->makeLink($wgLang->getNSText( Namespace::getCategory() ).":".$key, $key )." > ".$cat."
\n"; - } + $s.= $wgTitle->getAllParentCategories(&$catstack); } return $s; diff --git a/includes/Title.php b/includes/Title.php index cc5be068ef..422392f259 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1189,37 +1189,56 @@ class Title { while ( $x = wfFetchObject ( $res ) ) $data[] = $x ; wfFreeResult ( $res ) ; } else { - $data = array(); + $data = ""; } return $data; } # will get the parents and grand-parents + # TODO : not sure what's happening when a loop happen like: + # Encyclopedia > Astronomy > Encyclopedia function getAllParentCategories(&$stack) { - global $wgUser; - $sk =& $wgUser->getSkin() ; - + global $wgUser,$wgLang; + $result = ""; + # getting parents $parents = $this->getParentCategories( ); - - foreach($parents as $parent) + + if($parents == "") { - # create a title object for the parent - $tpar = Title::newFromID($parent->cur_id); - - if(isset($stack[$this->getText()])) + # The current element has no more parent so we dump the stack + # and make a clean line of categories + $sk =& $wgUser->getSkin() ; + + foreach ( array_reverse($stack) as $child => $parent ) { - $stack[$tpar->getText()] = $sk->makeLink( $this->getPrefixedDBkey(), $this->getText() ); - $stack[$tpar->getText()] .= " > ".$stack[$this->getText()]; - } else { - # don't make a link for current page - $stack[$tpar->getText()] = $this->getText(); + # make a link of that parent + $result .= $sk->makeLink($wgLang->getNSText ( Namespace::getCategory() ).":".$parent,$parent); + $result .= " > "; + $lastchild = $child; } + # append the last child + $result .= "$lastchild
\n"; + + # now we can empty the stack + $stack = array(); - unset( $stack[$this->getText()] ); - $tpar->getAllParentCategories(&$stack); + } else { + # look at parents of current category + foreach($parents as $parent) + { + # create a title object for the parent + $tpar = Title::newFromID($parent->cur_id); + # add it to the stack + $stack[$this->getText()] = $tpar->getText(); + # grab its parents + $result .= $tpar->getAllParentCategories(&$stack); + } } + + if(isset($result)) { return $result; } + else { return ""; }; } -- 2.20.1