Major rewrite / bug fixing of the dmoz-like category browser
authorAntoine Musso <hashar@users.mediawiki.org>
Mon, 7 Jun 2004 07:55:27 +0000 (07:55 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Mon, 7 Jun 2004 07:55:27 +0000 (07:55 +0000)
includes/Skin.php
includes/Title.php

index 765c193..fa842d1 100644 (file)
@@ -374,11 +374,7 @@ class Skin {
                if($wgUseCategoryBrowser) {
                        $s .= "<br/><hr/>";
                        $catstack = array();
-                       $wgTitle->getAllParentCategories(&$catstack);
-                       foreach ($catstack as $key => $cat)
-                       {
-                               $s .= $this->makeLink($wgLang->getNSText( Namespace::getCategory() ).":".$key, $key )." &gt; ".$cat."<br/>\n";
-                       }
+                       $s.= $wgTitle->getAllParentCategories(&$catstack);
                }
                
                return $s;
index cc5be06..422392f 100644 (file)
@@ -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()] .= " &gt; ".$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 .= " &gt; ";
+                               $lastchild = $child;
                        }
+                       # append the last child
+                       $result .= "$lastchild<br/>\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 ""; };
        }