X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=48ac5bf0a67fe39f3732015f839157482e762e4b;hb=367846470d3bb658a5156384300ef738aee93e85;hp=636dd5c0233bdb7e22058043e8c6dfbefe3ca07b;hpb=7d8f6fe7f7c7d66150d04bff35db9964a87206eb;p=lhc%2Fweb%2Fwiklou.git 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); + } + } + + } ?>