예제 #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);
 }
예제 #3
0
 function getImageInfoWidget($title)
 {
     global $wgUser, $wgOut;
     $sk = $wgUser->getSkin();
     $t = Title::newFromText('Image-Templates', NS_CATEGORY);
     if ($t) {
         $cv = new WikihowCategoryViewer($t);
         $cv->clearCategoryState();
         $cv->doQuery();
         $templates = array();
         foreach ($cv->articles as $article) {
             $start = strrpos($article, 'title="Template:');
             if ($start > 0) {
                 $end = strrpos($article, '"', $start + 16 + 1);
                 if ($end > 0) {
                     $templates[] = strtolower(str_replace(' ', '-', substr($article, $start + 16, $end - $start - 16)));
                 }
             }
         }
         $license = '';
         $content = preg_replace_callback('@({{([^}|]+)(\\|[^}]*)?}})@', function ($m) use($templates, &$license) {
             $name = trim(strtolower($m[2]));
             $name = str_replace(' ', '-', $name);
             foreach ($templates as $template) {
                 if ($name == $template) {
                     $license .= $m[0];
                     return '';
                 }
             }
             return $m[1];
         }, $this->getContent());
     }
     $lastUser = $this->current->getUser();
     $userLink = $sk->makeLinkObj(Title::makeTitle(NS_USER, $lastUser), $lastUser);
     $html = "<div id='im-info' style='word-wrap: break-word;'>";
     $html .= $wgOut->parse("=== Licensing / Attribution === \n" . $license) . "<p>" . wfMsg('image_upload', $userLink) . "</p><br />";
     //now remove old licensing header
     $content = str_replace("== Licensing ==", "", $content);
     $content = str_replace("== Summary ==", "=== Summary ===", $content);
     $content = trim($content);
     if (strlen($content) > 0 && substr($content, 0, 1) != "=") {
         $content = "=== Summary === \n" . $content;
     } else {
     }
     $html .= $wgOut->parse($content);
     $html .= "</div>";
     return $html;
 }