From: Tim Starling Date: Sat, 20 Nov 2004 03:35:00 +0000 (+0000) Subject: fixed bug 875, circular category references cause timeout or stack overflow X-Git-Tag: 1.5.0alpha1~1304 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=608ea9cafdbaa52803cb965b3482042ca36849f5;p=lhc%2Fweb%2Fwiklou.git fixed bug 875, circular category references cause timeout or stack overflow --- diff --git a/includes/Skin.php b/includes/Skin.php index 406e83cb3c..f3af0d76c7 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -451,7 +451,7 @@ class Skin { $s .= '

'; # get a big array of the parents tree - $parenttree = $wgTitle->getCategorieBrowser(); + $parenttree = $wgTitle->getParentCategoryTree(); # Render the array as a serie of links function walkThrough ($tree) { diff --git a/includes/Title.php b/includes/Title.php index 921ec85240..b23dd4b2e7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1648,11 +1648,10 @@ class Title { $sk =& $wgUser->getSkin(); $parents = array(); $dbr =& wfGetDB( DB_SLAVE ); - $cur = $dbr->tableName( 'cur' ); $categorylinks = $dbr->tableName( 'categorylinks' ); # NEW SQL - $sql = "SELECT * FROM categorylinks" + $sql = "SELECT * FROM $categorylinks" ." WHERE cl_from='$titlekey'" ." AND cl_from <> '0'" ." ORDER BY cl_sortkey"; @@ -1671,18 +1670,24 @@ class Title { } /** - * Go through all parent categories of this Title + * Get a tree of parent categories + * @param array $children an array with the children in the keys, to check for circular refs * @return array * @access public */ - function getCategorieBrowser() { + function getParentCategoryTree( $children = array() ) { $parents = $this->getParentCategories(); if($parents != '') { foreach($parents as $parent => $current) { - $nt = Title::newFromText($parent); - $stack[$parent] = $nt->getCategorieBrowser(); + if ( array_key_exists( $parent, $children ) ) { + # Circular reference + $stack[$parent] = array(); + } else { + $nt = Title::newFromText($parent); + $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) ); + } } return $stack; } else {