Пример #1
0
 function view()
 {
     global $wgOut, $wgRequest, $wgUser, $wgTitle, $wgHooks;
     if (!$wgTitle->exists()) {
         parent::view();
         return;
     }
     if (count($wgRequest->getVal('diff')) > 0) {
         return Article::view();
     }
     $restAction = $wgRequest->getVal('restaction');
     if ($restAction == 'pull-chunk') {
         $wgOut->setArticleBodyOnly(true);
         $start = $wgRequest->getInt('start');
         if (!$start) {
             return;
         }
         $categoryViewer = new WikihowCategoryViewer($wgTitle);
         $this->catStream = new WikihowArticleStream($categoryViewer, $start);
         $html = $this->catStream->getChunks(4, WikihowCategoryPage::SINGLE_WIDTH, WikihowCategoryPage::SINGLE_SPACING, WikihowCategoryPage::SINGLE_HEIGHT);
         $ret = json_encode(array('html' => $html));
         $wgOut->addHTML($ret);
     } else {
         $wgOut->setRobotPolicy('index,follow', 'Category Page');
         $wgOut->setPageTitle($wgTitle->getText());
         $from = $wgRequest->getVal('from');
         $until = $wgRequest->getVal('until');
         $viewer = new WikihowCategoryViewer($this->mTitle, $from, $until);
         $viewer->clearState();
         $viewer->doQuery();
         $viewer->finaliseCategoryState();
         if ($wgRequest->getVal('viewMode', 0)) {
             $wgOut->addHtml('<div class="section minor_section">');
             $wgOut->addHtml('<ul><li>');
             $wgOut->addHtml(implode("</li>\n<li>", $viewer->articles));
             $wgOut->addHtml('</li></ul>');
             $wgOut->addHtml('</div>');
         } else {
             $wgHooks['BeforePageDisplay'][] = array('WikihowCategoryPage::addCSSAndJs');
             $categoryViewer = new WikihowCategoryViewer($wgTitle);
             $this->catStream = new WikihowArticleStream($categoryViewer, 0);
             $html = $this->catStream->getChunks(self::STARTING_CHUNKS, WikihowCategoryPage::SINGLE_WIDTH, WikihowCategoryPage::SINGLE_SPACING, WikihowCategoryPage::SINGLE_HEIGHT);
             $wgOut->addHTML($html);
         }
         $sk = $wgUser->getSkin();
         $subCats = $viewer->shortListRD($viewer->children, $viewer->children_start_char);
         if ($subCats != "") {
             $subCats = "<h3>{$this->mTitle->getText()}</h3>{$subCats}";
             $sk->addWidget($subCats);
         }
         $furtherEditing = $viewer->getArticlesFurtherEditing($viewer->articles, $viewer->article_info);
         if ($furtherEditing != "") {
         }
         $sk->addWidget($furtherEditing);
     }
 }
Пример #2
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);
 }