/** * Main execution function * @param $par Parameters passed to the page */ function execute($par) { global $wgRequest, $wgOut, $wgMakeBotPrivileged, $wgUser; $this->setHeaders(); if ($par) { $this->target = $par; } else { $this->target = $wgRequest->getVal('target', wfMsg('rootcategory')); } $this->target = trim($this->target); #HACK for undefined root category if ($this->target == '<rootcategory>' || $this->target == '<rootcategory>') { $this->target = NULL; } $this->mode = $wgRequest->getVal('mode', CT_MODE_CATEGORIES); if ($this->mode == 'all') { $this->mode = CT_MODE_ALL; } else { if ($this->mode == 'pages') { $this->mode = CT_MODE_PAGES; } else { if ($this->mode == 'categories') { $this->mode = CT_MODE_CATEGORIES; } } } $this->mode = (int) $this->mode; $wgOut->addWikiText(wfMsgNoTrans('categorytree-header')); $wgOut->addHtml($this->makeInputForm()); if ($this->target !== '' && $this->target !== NULL) { CategoryTree::setHeaders($wgOut); $title = CategoryTree::makeTitle($this->target); if ($title && $title->getArticleID()) { $html = ''; $html .= wfOpenElement('div', array('class' => 'CategoryTreeParents')); $html .= wfElement('span', array('class' => 'CategoryTreeParents'), wfMsg('categorytree-parents')) . ': '; $ct = new CategoryTree(); $parents = $ct->renderParents($title, $this->mode); if ($parents == '') { $html .= wfMsg('categorytree-nothing-found'); } else { $html .= $parents; } $html .= wfCloseElement('div'); $html .= wfOpenElement('div', array('class' => 'CategoryTreeResult')); $html .= $ct->renderNode($title, $this->mode, true, false); $html .= wfCloseElement('div'); $wgOut->addHtml($html); } else { $wgOut->addHtml(wfOpenElement('div', array('class' => 'CategoryTreeNotice'))); $wgOut->addWikiText(wfMsg('categorytree-not-found', $this->target)); $wgOut->addHtml(wfCloseElement('div')); } } }
/** * Main execution function * @param $par array Parameters passed to the page */ function execute($par) { global $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders; $this->setHeaders(); $request = $this->getRequest(); if ($par) { $this->target = $par; } else { $this->target = $request->getVal('target', wfMessage('rootcategory')->text()); } $this->target = trim($this->target); # HACK for undefined root category if ($this->target == '<rootcategory>' || $this->target == '<rootcategory>') { $this->target = null; } $options = array(); # grab all known options from the request. Normalization is done by the CategoryTree class foreach ($wgCategoryTreeDefaultOptions as $option => $default) { if (isset($wgCategoryTreeSpecialPageOptions[$option])) { $default = $wgCategoryTreeSpecialPageOptions[$option]; } $options[$option] = $request->getVal($option, $default); } $this->tree = new CategoryTree($options); $output = $this->getOutput(); $output->addWikiMsg('categorytree-header'); $this->executeInputForm(); if ($this->target !== '' && $this->target !== null) { if (!$wgCategoryTreeForceHeaders) { CategoryTree::setHeaders($output); } $title = CategoryTree::makeTitle($this->target); if ($title && $title->getArticleID()) { $output->addHTML(Xml::openElement('div', array('class' => 'CategoryTreeParents'))); $output->addHTML(wfMessage('categorytree-parents')->parse()); $output->addHTML(wfMessage('colon-separator')->escaped()); $parents = $this->tree->renderParents($title); if ($parents == '') { $output->addHTML(wfMessage('categorytree-no-parent-categories')->parse()); } else { $output->addHTML($parents); } $output->addHTML(Xml::closeElement('div')); $output->addHTML(Xml::openElement('div', array('class' => 'CategoryTreeResult'))); $output->addHTML($this->tree->renderNode($title, 1)); $output->addHTML(Xml::closeElement('div')); } else { $output->addHTML(Xml::openElement('div', array('class' => 'CategoryTreeNotice'))); $output->addHTML(wfMessage('categorytree-not-found', $this->target)->parse()); $output->addHTML(Xml::closeElement('div')); } } }
/** * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to * load CategoryTreeFunctions.php on demand. */ function getTag(&$parser, $category, $mode, $hideroot = false, $style = '', $depth = 1) { global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; static $uniq = 0; $this->mIsAjaxRequest = false; $category = trim($category); if ($category === '') { return false; } if ($wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag) { $parser->disableCache(); } $title = self::makeTitle($category); if ($title === false || $title === NULL) { return false; } $html = ''; $html .= wfOpenElement('div', array('class' => 'CategoryTreeTag', 'style' => $style)); if (!$title->getArticleID()) { $html .= wfOpenElement('span', array('class' => 'CategoryTreeNotice')); $html .= self::msg('not-found', htmlspecialchars($category)); $html .= wfCloseElement('span'); } else { if (!$hideroot) { $html .= CategoryTree::renderNode($title, $mode, $depth > 0, $wgCategoryTreeDynamicTag, $depth - 1); } else { if (!$wgCategoryTreeDynamicTag) { $html .= $this->renderChildren($title, $mode, $depth - 1); } else { //FIXME: depth would need to be propagated here. this would imact the cache key, too $uniq += 1; $load = 'ct-' . $uniq . '-' . mt_rand(1, 100000); $html .= wfOpenElement('script', array('type' => 'text/javascript', 'id' => $load)); $html .= 'categoryTreeLoadChildren("' . Xml::escapeJsString($title->getDBkey()) . '", "' . $mode . '", document.getElementById("' . $load . '").parentNode );'; $html .= wfCloseElement('script'); } } } $html .= wfCloseElement('div'); $html .= "\n\t\t"; return $html; }
function getSubcategorySection() { global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode; if ($wgRequest->getCheck('notree')) { return parent::getSubcategorySection(); } if ($GLOBALS['wgCategoryTreeUnifiedView']) { return parent::getSubcategorySection(); } if (count($this->children) == 0) { return ''; } $r = '<h2>' . wfMsg('subcategories') . "</h2>\n" . wfMsgExt('subcategorycount', array('parse'), count($this->children)); # Use a cookie to save the user's last selection, so that AJAX doesn't # keep coming back to haunt them. # # FIXME: This doesn't work very well with IMS handling in # OutputPage::checkLastModified, because when the cookie changes, the # category pages are not, at present, invalidated. $cookieName = $wgCookiePrefix . 'ShowSubcatAs'; $cookieVal = @$_COOKIE[$cookieName]; $reqShowAs = $wgRequest->getVal('showas'); if ($reqShowAs == 'list') { $showAs = 'list'; } elseif ($reqShowAs == 'tree') { $showAs = 'tree'; } elseif ($cookieVal == 'list' || $cookieVal == 'tree') { $showAs = $cookieVal; } else { $showAs = 'tree'; } if (!is_null($reqShowAs)) { global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgCookieSecure; $exp = time() + $wgCookieExpiration; setcookie($cookieName, $showAs, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure); } if ($showAs == 'tree' && count($this->children) > $this->limit) { # Tree doesn't page properly $showAs = 'list'; $r .= self::msg('too-many-subcats'); } else { $sk = $this->getSkin(); $r .= '<p>' . $this->makeShowAsLink('tree', $showAs) . ' | ' . $this->makeShowAsLink('list', $showAs) . '</p>'; } if ($showAs == 'list') { $r .= $this->formatList($this->children, $this->children_start_char); } else { CategoryTree::setHeaders($wgOut); $ct = new CategoryTree(); foreach ($this->child_titles as $title) { $r .= $ct->renderNode($title, $wgCategoryTreeCategoryPageMode); } } return $r; }
/** * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to * load CategoryTreeFunctions.php on demand. */ function getTag($parser, $category, $hideroot = false, $attr, $depth = 1, $allowMissing = false) { global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; static $uniq = 0; $category = trim($category); if ($category === '') { return false; } if ($parser && $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag) { $parser->disableCache(); } $title = self::makeTitle($category); if ($title === false || $title === NULL) { return false; } if (isset($attr['class'])) { $attr['class'] .= ' CategoryTreeTag'; } else { $attr['class'] = ' CategoryTreeTag'; } $this->init(); $html = ''; $html .= Xml::openElement('div', $attr); if (!$allowMissing && !$title->getArticleID()) { $html .= Xml::openElement('span', array('class' => 'CategoryTreeNotice')); $html .= wfMsgExt('categorytree-not-found', 'parseinline', htmlspecialchars($category)); $html .= Xml::closeElement('span'); } else { if (!$hideroot) { $html .= CategoryTree::renderNode($title, $depth, $wgCategoryTreeDynamicTag); } else { if (!$wgCategoryTreeDynamicTag) { $html .= $this->renderChildren($title, $depth); } else { $uniq += 1; $load = 'ct-' . $uniq . '-' . mt_rand(1, 100000); $html .= Xml::openElement('script', array('type' => 'text/javascript', 'id' => $load)); $html .= 'categoryTreeLoadChildren("' . Xml::escapeJsString($title->getDBkey()) . '", ' . $this->getOptionsAsJsStructure($depth) . ', document.getElementById("' . $load . '").parentNode);'; $html .= Xml::closeElement('script'); } } } $html .= Xml::closeElement('div'); $html .= "\n\t\t"; return $html; }