function displayCategoryTable()
 {
     global $wgOut;
     $catmap = Categoryhelper::getIconMap();
     ksort($catmap);
     $queryString = WikihowCategoryViewer::getViewModeParam();
     if (!empty($queryString)) {
         $queryString = "?" . $queryString;
     }
     $wgOut->addHTML("<div class='section_text'>");
     foreach ($catmap as $cat => $image) {
         $title = Title::newFromText($image);
         if ($title) {
             $file = wfFindFile($title, false);
             $sourceWidth = $file->getWidth();
             $sourceHeight = $file->getHeight();
             $heightPreference = false;
             if (self::CAT_HEIGHT > self::CAT_WIDTH && $sourceWidth > $sourceHeight) {
                 //desired image is portrait
                 $heightPreference = true;
             }
             $thumb = $file->getThumbnail(self::CAT_WIDTH, self::CAT_HEIGHT, true, true, $heightPreference);
             $category = urldecode(str_replace("-", " ", $cat));
             $catTitle = Title::newFromText("Category:" . $category);
             if ($catTitle) {
                 $wgOut->addHTML("<div class='thumbnail'><a href='{$catTitle->getLocalUrl()}{$queryString}'><img src='" . wfGetPad($thumb->getUrl()) . "' /><div class='text'><p><span>{$category}</span></p></div></a></div>");
             }
         }
     }
     $wgOut->addHTML("<div class='clearall'></div>");
     $wgOut->addHTML("</div><!-- end section_text -->");
 }
 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);
     }
 }
 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);
 }
Exemple #4
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;
 }
 function getCategoryLinks($usebrowser)
 {
     global $wgOut, $wgContLang;
     if (!$usebrowser && empty($wgOut->mCategoryLinks["normal"])) {
         return '';
     }
     // Use Unicode bidi embedding override characters,
     // to make sure links don't smash each other up in ugly ways.
     $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
     $embed = "<span dir='{$dir}'>";
     $pop = '</span>';
     if (empty($wgOut->mCategoryLinks["normal"])) {
         $t = $embed . "" . $pop;
     } else {
         $t = $embed . implode("{$pop} | {$embed}", $wgOut->mCategoryLinks["normal"]) . $pop;
     }
     if (!$usebrowser) {
         return $t;
     }
     $mainPageObj = Title::newMainPage();
     $sk = $this->getSkin();
     $sep = self::BREADCRUMB_SEPARATOR;
     $viewMode = WikihowCategoryViewer::getViewModeArray($this->getContext());
     $categories = Linker::link(Title::newFromText('Special:Categorylisting'), wfMessage('categories')->text(), array(), $viewMode);
     $s = "<li class='home'>" . Linker::link($mainPageObj, wfMessage('home')->text()) . "</li> <li>{$sep} {$categories}</li>";
     # optional 'dmoz-like' category browser. Will be shown under the list
     # of categories an article belong to
     if ($usebrowser) {
         $s .= ' ';
         # get a big array of the parents tree
         $parenttree = Categoryhelper::getCurrentParentCategoryTree();
         if (is_array($parenttree)) {
             $parenttree = array_reverse($parenttree);
         } else {
             return $s;
         }
         # Skin object passed by reference cause it can not be
         # accessed under the method subfunction drawCategoryBrowser
         $tempout = explode("\n", $this->drawCategoryBrowser($parenttree, $this));
         $newarray = array();
         foreach ($tempout as $t) {
             if (trim($t) != "") {
                 $newarray[] = $t;
             }
         }
         $tempout = $newarray;
         asort($tempout);
         $olds = $s;
         if ($tempout) {
             $s .= $tempout[0];
         }
         // this usually works
         if (strpos($s, "/Category:WikiHow") !== false || strpos($s, "/Category:Featured") !== false || strpos($s, "/Category:Nomination") !== false) {
             for ($i = 1; $i <= sizeof($tempout); $i++) {
                 // Reuben: changed to add this isset($tempout[$i]) stuff so that
                 // functionality remains identical but without variable not defined
                 // notice, even though I don't understand the functionality
                 if (strpos(@$tempout[$i], "/Category:WikiHow") === false && strpos(@$tempout[$i], "/Category:Featured") == false && strpos(@$tempout[$i], "/Category:Nomination") == false) {
                     $s = $olds;
                     $s .= isset($tempout[$i]) ? $tempout[$i] : '';
                     break;
                 }
             }
         }
     }
     return $s;
 }
Exemple #6
0
 function getCategoryLinks($usebrowser)
 {
     global $wgOut, $wgUser, $wgContLang;
     if (!$usebrowser && count($wgOut->mCategoryLinks) == 0) {
         return '';
     }
     // Use Unicode bidi embedding override characters,
     // to make sure links don't smash each other up in ugly ways.
     $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
     $embed = "<span dir='{$dir}'>";
     $pop = '</span>';
     $t = $embed . implode("{$pop} | {$embed}", $wgOut->mCategoryLinks) . $pop;
     if (!$usebrowser) {
         return $t;
     }
     $mainPageObj = Title::newMainPage();
     $sk = $wgUser->getSkin();
     $sep = self::BREADCRUMB_SEPARATOR;
     $queryString = WikihowCategoryViewer::getViewModeParam();
     $categories = $sk->makeLinkObj(Title::newFromText('Special:Categorylisting'), wfMsg('categories'), $queryString);
     $s = "<li class='home'>" . $sk->makeLinkObj($mainPageObj, wfMsg('home')) . "</li> <li>{$sep} {$categories}</li>";
     # optional 'dmoz-like' category browser. Will be shown under the list
     # of categories an article belong to
     if ($usebrowser) {
         $s .= ' ';
         # get a big array of the parents tree
         $parenttree = Categoryhelper::getCurrentParentCategoryTree();
         if (is_array($parenttree)) {
             $parenttree = array_reverse($parenttree);
         } else {
             return $s;
         }
         # Skin object passed by reference cause it can not be
         # accessed under the method subfunction drawCategoryBrowser
         $tempout = explode("\n", $this->drawCategoryBrowser($parenttree, $this));
         $newarray = array();
         foreach ($tempout as $t) {
             if (trim($t) != "") {
                 $newarray[] = $t;
             }
         }
         $tempout = $newarray;
         asort($tempout);
         $olds = $s;
         $s .= $tempout[0];
         // this usually works
         if (strpos($s, "/Category:WikiHow") !== false || strpos($s, "/Category:Featured") !== false || strpos($s, "/Category:Nomination") !== false) {
             for ($i = 1; $i <= sizeof($tempout); $i++) {
                 if (strpos($tempout[$i], "/Category:WikiHow") === false && strpos($tempout[$i], "/Category:Featured") == false && strpos($tempout[$i], "/Category:Nomination") == false) {
                     $s = $olds;
                     $s .= $tempout[$i];
                     break;
                 }
             }
         }
     }
     return $s;
 }