Index: trunk/phase3/includes/Title.php |
— | — | @@ -1252,82 +1252,54 @@ |
1253 | 1253 | |
1254 | 1254 | # Get categories to wich belong this title and return an array of |
1255 | 1255 | # categories names. |
1256 | | - function getParentCategories( ) { |
| 1256 | + # Return an array of parents in the form: |
| 1257 | + # $parent => $currentarticle |
| 1258 | + function getParentCategories() { |
1257 | 1259 | global $wgLang,$wgUser; |
1258 | 1260 | |
1259 | 1261 | $titlekey = $this->getArticleId(); |
1260 | | - $cns = Namespace::getCategory(); |
1261 | 1262 | $sk =& $wgUser->getSkin(); |
1262 | 1263 | $parents = array(); |
1263 | 1264 | $dbr =& wfGetDB( DB_SLAVE ); |
1264 | 1265 | $cur = $dbr->tableName( 'cur' ); |
1265 | 1266 | $categorylinks = $dbr->tableName( 'categorylinks' ); |
1266 | 1267 | |
1267 | | - # get the parents categories of this title from the database |
1268 | | - $sql = "SELECT DISTINCT cur_id FROM $cur,$categorylinks |
1269 | | - WHERE cl_from='$titlekey' AND cl_to=cur_title AND cur_namespace='$cns' |
1270 | | - ORDER BY cl_sortkey" ; |
| 1268 | + # NEW SQL |
| 1269 | + $sql = "SELECT * FROM categorylinks" |
| 1270 | + ." WHERE cl_from='$titlekey'" |
| 1271 | + ." AND cl_from <> '0'" |
| 1272 | + ." ORDER BY cl_sortkey"; |
| 1273 | + |
1271 | 1274 | $res = $dbr->query ( $sql ) ; |
1272 | 1275 | |
1273 | 1276 | if($dbr->numRows($res) > 0) { |
1274 | | - while ( $x = $dbr->fetchObject ( $res ) ) $data[] = $x ; |
| 1277 | + while ( $x = $dbr->fetchObject ( $res ) ) |
| 1278 | + //$data[] = Title::newFromText($wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to); |
| 1279 | + $data[$wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText(); |
1275 | 1280 | $dbr->freeResult ( $res ) ; |
1276 | 1281 | } else { |
1277 | 1282 | $data = ''; |
1278 | 1283 | } |
1279 | 1284 | return $data; |
1280 | 1285 | } |
1281 | | - |
1282 | | - # will get the parents and grand-parents |
1283 | | - # TODO : not sure what's happening when a loop happen like: |
1284 | | - # Encyclopedia > Astronomy > Encyclopedia |
1285 | | - function getAllParentCategories(&$stack) { |
1286 | | - global $wgUser,$wgLang; |
1287 | | - $result = ''; |
1288 | | - |
1289 | | - # getting parents |
1290 | | - $parents = $this->getParentCategories( ); |
1291 | 1286 | |
1292 | | - if($parents == '') |
1293 | | - { |
1294 | | - # The current element has no more parent so we dump the stack |
1295 | | - # and make a clean line of categories |
1296 | | - $sk =& $wgUser->getSkin() ; |
1297 | | - |
1298 | | - foreach ( array_reverse($stack) as $child => $parent ) |
| 1287 | + # Go through all parents |
| 1288 | + function getCategorieBrowser() { |
| 1289 | + $parents = $this->getParentCategories(); |
| 1290 | + |
| 1291 | + if($parents != '') { |
| 1292 | + foreach($parents as $parent => $current) |
1299 | 1293 | { |
1300 | | - # make a link of that parent |
1301 | | - $result .= $sk->makeLink($wgLang->getNSText ( Namespace::getCategory() ).':'.$parent,$parent); |
1302 | | - $result .= ' > '; |
1303 | | - $lastchild = $child; |
| 1294 | + $nt = Title::newFromText($parent); |
| 1295 | + $stack[$parent] = $nt->getCategorieBrowser(); |
1304 | 1296 | } |
1305 | | - # append the last child. |
1306 | | - # TODO : We should have a last child unless there is an error in the |
1307 | | - # "categorylinks" table. |
1308 | | - if(isset($lastchild)) { $result .= $lastchild; } |
1309 | | - |
1310 | | - $result .= "<br/>\n"; |
1311 | | - |
1312 | | - # now we can empty the stack |
1313 | | - $stack = array(); |
1314 | | - |
| 1297 | + return $stack; |
1315 | 1298 | } else { |
1316 | | - # look at parents of current category |
1317 | | - foreach($parents as $parent) |
1318 | | - { |
1319 | | - # create a title object for the parent |
1320 | | - $tpar = Title::newFromID($parent->cur_id); |
1321 | | - # add it to the stack |
1322 | | - $stack[$this->getText()] = $tpar->getText(); |
1323 | | - # grab its parents |
1324 | | - $result .= $tpar->getAllParentCategories($stack); |
1325 | | - } |
| 1299 | + return array(); |
1326 | 1300 | } |
1327 | | - |
1328 | | - if(isset($result)) { return $result; } |
1329 | | - else { return ''; }; |
1330 | 1301 | } |
1331 | 1302 | |
| 1303 | + |
1332 | 1304 | # Returns an associative array for selecting this title from cur |
1333 | 1305 | function curCond() { |
1334 | 1306 | return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform ); |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -413,10 +413,36 @@ |
414 | 414 | wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) ) |
415 | 415 | . ': ' . $t; |
416 | 416 | |
| 417 | + # optional 'dmoz-like' category browser. Will be shown under the list |
| 418 | + # of categories an article belong to |
417 | 419 | if($wgUseCategoryBrowser) { |
418 | 420 | $s .= '<br/><hr/>'; |
419 | | - $catstack = array(); |
420 | | - $s.= $wgTitle->getAllParentCategories($catstack); |
| 421 | + |
| 422 | + # get a big array of the parents tree |
| 423 | + $parenttree = $wgTitle->getCategorieBrowser(); |
| 424 | + |
| 425 | + # Render the array as a serie of links |
| 426 | + function walkThrough ($tree) { |
| 427 | + global $wgUser; |
| 428 | + $sk = $wgUser->getSkin(); |
| 429 | + $return = ''; |
| 430 | + foreach($tree as $element => $parent) { |
| 431 | + if(empty($parent)) { |
| 432 | + # element start a new list |
| 433 | + $return .= '<br />'; |
| 434 | + } else { |
| 435 | + # grab the others elements |
| 436 | + $return .= walkThrough($parent); |
| 437 | + } |
| 438 | + # add our current element to the list |
| 439 | + $eltitle = Title::NewFromText($element); |
| 440 | + # FIXME : should be makeLink() [AV] |
| 441 | + $return .= $sk->makeKnownLink($element, $eltitle->getText()).' > '; |
| 442 | + } |
| 443 | + return $return; |
| 444 | + } |
| 445 | + |
| 446 | + $s .= walkThrough($parenttree); |
421 | 447 | } |
422 | 448 | |
423 | 449 | return $s; |