Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 static function listCategories($includeDatesAndFullURLs)
 {
     $epoch = wfTimestamp(TS_MW, strtotime('January 1, 2010'));
     $ch = new Categoryhelper();
     $tree = $ch->getCategoryTreeArray();
     unset($tree['WikiHow']);
     $list = array();
     self::categoryTreeToList($tree, $list);
     foreach ($list as $cat) {
         $title = Title::makeTitle(NS_CATEGORY, $cat);
         if (!$title || $title->getArticleID() <= 0) {
             continue;
         }
         if ($includeDatesAndFullURLs) {
             $line = $title->getFullUrl() . ' lastmod=' . self::iso8601_date($epoch);
         } else {
             $line = $title->getArticleID() . ' ' . $title->getPrefixedDBkey();
         }
         print "{$line}\n";
     }
 }
 public static function getCategoryTreeArray()
 {
     $ch = new Categoryhelper();
     return $ch->getCategoryTreeArray();
 }