public function testCategoryTree() { /* Workaround for eclipse xdebug $path = '/usr/share/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); */ $catTree = new CategoryTreeManip(); $catNames = array("Root"); $catTree->initialiseFromCategoryNames($catNames); $catTree->printTree(); }
/** * Constructs the filter SQL clause for the given collaborative watchlist ids. * It filters entries which are not relevant for the given watchlists. I.e. * entries which don't belong to a category and are not listed explicitly as a * page for one of the given watchlists. * @param $cw_ids Array: A list of collaborative watchlist ids * @param $catNameCol String: The name of the column containing category names * @param $pageIdCol String: The name of the column containing page ids * @return String: An SQL clause usable in the conditions parameter of $db->select() */ function wlGetFilterClauseForCollabWatchlistIds($cw_ids, $catNameCol, $pageIdCol) { global $wgCollabWatchlistRecursiveCatScan; $excludedCatPageIds = array(); $includedCatPageIds = array(); $includedPageIds = array(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('collabwatchlist', 'collabwatchlistcategory', 'page'), array('cat_page_id', 'page_title', 'page_namespace', 'subtract'), $cw_ids != 0 ? array('collabwatchlist.cw_id' => $cw_ids) : array(), __METHOD__, array(), array('collabwatchlistcategory' => array('JOIN', 'collabwatchlist.cw_id = collabwatchlistcategory.cw_id'), 'page' => array('JOIN', 'page.page_id = collabwatchlistcategory.cat_page_id'))); foreach ($res as $row) { if ($row->page_namespace == NS_CATEGORY) { if ($row->subtract) { $excludedCatPageIds[$row->cat_page_id] = $row->page_title; } else { $includedCatPageIds[$row->cat_page_id] = $row->page_title; } } else { $includedPageIds[$row->cat_page_id] = $row->page_title; } } if ($wgCollabWatchlistRecursiveCatScan && $includedCatPageIds) { $catTree = new CategoryTreeManip(); $catTree->setMaxDepth($wgCollabWatchlistRecursiveCatScan); $catTree->initialiseFromCategoryNames(array_values($includedCatPageIds)); $catTree->disableCategoryIds(array_keys($excludedCatPageIds)); $enabledCategoryNames = $catTree->getEnabledCategoryNames(); if (empty($enabledCategoryNames)) { return; } $collabWatchlistClause = '(' . $catNameCol . " IN (" . implode(',', $this->addQuotes($dbr, $enabledCategoryNames)) . ") "; if (!empty($includedPageIds)) { $collabWatchlistClause .= ' OR ' . $pageIdCol . ' IN (' . implode(',', $this->addQuotes($dbr, array_keys($includedPageIds))) . ')'; } $collabWatchlistClause .= ')'; } elseif (!empty($includedPageIds)) { $collabWatchlistClause = $pageIdCol . ' IN (' . implode(',', $this->addQuotes($dbr, array_keys($includedPageIds))) . ')'; } return $collabWatchlistClause; }