From: Antoine Musso Date: Mon, 23 Aug 2004 00:49:02 +0000 (+0000) Subject: rewrite of the dmoz-like category browser. Known bugs: makeKnownLink instead of makeL... X-Git-Tag: 1.5.0alpha1~2245 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=c4b66bb7585a7a5149909f056fd8d2a76c596730;p=lhc%2Fweb%2Fwiklou.git rewrite of the dmoz-like category browser. Known bugs: makeKnownLink instead of makeLink,
is put at beginning instead of the end --- diff --git a/includes/Skin.php b/includes/Skin.php index 1ee25243fd..95fcc4fe1a 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -413,10 +413,36 @@ class Skin { wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) ) . ': ' . $t; + # optional 'dmoz-like' category browser. Will be shown under the list + # of categories an article belong to if($wgUseCategoryBrowser) { $s .= '

'; - $catstack = array(); - $s.= $wgTitle->getAllParentCategories($catstack); + + # get a big array of the parents tree + $parenttree = $wgTitle->getCategorieBrowser(); + + # Render the array as a serie of links + function walkThrough ($tree) { + global $wgUser; + $sk = $wgUser->getSkin(); + $return = ''; + foreach($tree as $element => $parent) { + if(empty($parent)) { + # element start a new list + $return .= '
'; + } else { + # grab the others elements + $return .= walkThrough($parent); + } + # add our current element to the list + $eltitle = Title::NewFromText($element); + # FIXME : should be makeLink() [AV] + $return .= $sk->makeKnownLink($element, $eltitle->getText()).' > '; + } + return $return; + } + + $s .= walkThrough($parenttree); } return $s; diff --git a/includes/Title.php b/includes/Title.php index f08d91e669..8e06b752ea 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1252,82 +1252,54 @@ class Title { # Get categories to wich belong this title and return an array of # categories names. - function getParentCategories( ) { + # Return an array of parents in the form: + # $parent => $currentarticle + function getParentCategories() { global $wgLang,$wgUser; $titlekey = $this->getArticleId(); - $cns = Namespace::getCategory(); $sk =& $wgUser->getSkin(); $parents = array(); $dbr =& wfGetDB( DB_SLAVE ); $cur = $dbr->tableName( 'cur' ); $categorylinks = $dbr->tableName( 'categorylinks' ); - # get the parents categories of this title from the database - $sql = "SELECT DISTINCT cur_id FROM $cur,$categorylinks - WHERE cl_from='$titlekey' AND cl_to=cur_title AND cur_namespace='$cns' - ORDER BY cl_sortkey" ; + # NEW SQL + $sql = "SELECT * FROM categorylinks" + ." WHERE cl_from='$titlekey'" + ." AND cl_from <> '0'" + ." ORDER BY cl_sortkey"; + $res = $dbr->query ( $sql ) ; if($dbr->numRows($res) > 0) { - while ( $x = $dbr->fetchObject ( $res ) ) $data[] = $x ; + while ( $x = $dbr->fetchObject ( $res ) ) + //$data[] = Title::newFromText($wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to); + $data[$wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText(); $dbr->freeResult ( $res ) ; } else { $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,$wgLang; - $result = ''; - - # getting parents - $parents = $this->getParentCategories( ); - - if($parents == '') - { - # 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 ) + # Go through all parents + function getCategorieBrowser() { + $parents = $this->getParentCategories(); + + if($parents != '') { + foreach($parents as $parent => $current) { - # make a link of that parent - $result .= $sk->makeLink($wgLang->getNSText ( Namespace::getCategory() ).':'.$parent,$parent); - $result .= ' > '; - $lastchild = $child; + $nt = Title::newFromText($parent); + $stack[$parent] = $nt->getCategorieBrowser(); } - # append the last child. - # TODO : We should have a last child unless there is an error in the - # "categorylinks" table. - if(isset($lastchild)) { $result .= $lastchild; } - - $result .= "
\n"; - - # now we can empty the stack - $stack = array(); - + return $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); - } + return array(); } - - if(isset($result)) { return $result; } - else { return ''; }; } + # Returns an associative array for selecting this title from cur function curCond() { return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform );