public static function getCategoryContents($title = null) { $cats = array(); $fArts = array(); $arts = array(); if (!$title) { $cats = wfGetTopLevelCats(); } else { $tree = Categoryhelper::getCategoryTreeArray(); self::getChildNodesFromTreeNode($tree, str_replace('-', ' ', $title->getBaseText()), $cats); } $catResult = array(); foreach ($cats as $cat) { $catTitle = Title::newFromText($cat, NS_CATEGORY); $catResult[$cat] = $catTitle->getFullURL(); } $fArtResult = array(); $artResult = array(); if ($title && $title->exists()) { $viewer = new WikihowCategoryViewer($title); $viewer->clearState(); $viewer->doQuery(); $viewer->finaliseCategoryState(); // Featured articles: if ($viewer->articles_fa) { foreach ($viewer->articles_fa as $fArtHtml) { // Extract article name from HTML $matches = array(); preg_match('/<a ?.*>(.*)<\\/a>/', $fArtHtml, $matches); $fArt = $matches[1]; $fArtTitle = Title::newFromText($fArt, NS_MAIN); if ($fArtTitle && $fArtTitle->exists() && $fArtTitle->getNamespace() === NS_MAIN) { $fArtResult[$fArt] = $fArtTitle->getFullURL(); } } } // General articles: if ($viewer->articles) { foreach ($viewer->articles as $artHtml) { // Extract article name from HTML $matches = array(); preg_match('/<a ?.*>(.*)<\\/a>/', $artHtml, $matches); $art = $matches[1]; $artTitle = Title::newFromText($art, NS_MAIN); if ($artTitle && $artTitle->exists() && $artTitle->getNamespace() === NS_MAIN) { $artResult[$art] = $artTitle->getFullURL(); } } } } return array('subcats' => $catResult, 'f_articles' => $fArtResult, 'articles' => $artResult); }
function wfUpdateTopLevelCatTable($linker) { // LinksUpdate does not do a lazy update, so neither do we! $dbw = wfGetDB(DB_MASTER); $title = $linker->mTitle; $tree = $title->getParentCategoryTree(); $mine = array_unique(wfFlattenTopLevelCats($tree)); $dbw->delete('categorylinkstop', array('cl_from' => $title->getArticleID())); $top = wfGetTopLevelCats(); foreach ($mine as $m) { $y = Title::makeTitle(NS_CATEGORY, str_replace("Category:", "", $m)); if (in_array($y->getText(), $top)) { $dbw->insert('categorylinkstop', array('cl_from' => $title->getArticleID(), 'cl_to' => $y->getDBKey(), 'cl_sortkey' => $title->getText())); } } return true; }