function setCategories() { global $wgUser; $tree = Categoryhelper::getCurrentParentCategoryTree(); if ($tree != null) { foreach ($tree as $key => $path) { $catString = str_replace("Category:", "", $key); self::$mCategories[$catString] = $catString; $subtree = Categoryhelper::flattenCategoryTree($path); for ($i = 0; $i < count($subtree); $i++) { $catString = str_replace("Category:", "", $subtree[$i]); self::$mCategories[$catString] = $catString; } } } }
static function getCategoryOptionsForm($default, $cats = null) { global $wgUser, $wgMaxCategories, $wgRequest; if (!$wgUser->isLoggedIn()) { return ""; } // get the top and bottom categories $valid_cats = array(); if (is_array($cats)) { $valid_cats = array_flip($cats); } if ($wgRequest->getVal('oldid') != null && $default != "") { $fakeparent = array(); $fakeparent[Title::makeTitle(NS_CATEGORY, $default)->getFullText()] = array(); $tree = self::modifiedParentCategoryTree($fakeparent); } else { $tree = Categoryhelper::getCurrentParentCategoryTree(); } if (!$tree) { $tree = array(); } $toplevel = array(); $bottomlevel = array(); if ($wgRequest->getVal('topcategory0', null) != null) { // user has already submitted form, could be a preview, just set it to what they posted for ($i = 0; $i < $wgMaxCategories; $i++) { if ($wgRequest->getVal('topcategory' . $i, null) != null) { $toplevel[] = $wgRequest->getVal('topcategory' . $i); $bottomlevel[] = $wgRequest->getVal('category' . $i); } } } else { // fresh new form from existing article foreach ($tree as $k => $v) { $keys = array_keys($tree); $bottomleveltext = $k; $child = $v; $topleveltext = $k; while (is_array($child) && sizeof($child) > 0) { $keys = array_keys($child); $topleveltext = $keys[0]; $child = $child[$topleveltext]; } $tl_title = Title::newFromText($topleveltext); $bl_title = Title::newFromText($bottomleveltext); if (isset($valid_cats[$bl_title->getText()])) { if ($tl_title != null) { $toplevel[] = $tl_title->getText(); $bottomlevel[] = $bl_title->getText(); } else { $toplevel[] = $bl_title->getText(); } } else { #print_r($tree); #echo "shit! <b>{$bl_title->getText()}</b><br/><br/>"; print_r($bl_title); print_r($valid_cats); } } } $helper = Title::makeTitle(NS_SPECIAL, "Categoryhelper"); $toplevels = self::getTopLevelCategoriesForDropDown(); $options = self::getCategoryDropDownTree(); $html = "<script type='text/javascript' src='/extensions/wikihow/categories.js'></script>"; $html .= '<style type="text/css" media="all">/*<![CDATA[*/ @import "/extensions/wikihow/categories.css"; /*]]>*/</style>'; $html .= " <script type='text/javascript'>\n\t\t\t\t\tvar gCatHelperUrl = \"{$helper->getFullURL()}\";\n\t\t\t\t\tvar gCatHelperSMsg = \"" . wfMessage('selectsubcategory')->text() . "\";\n\t\t\t\t\tvar gMaxCats = {$wgMaxCategories};\n\t\t\t\t\tvar gCatMsg = '" . wfMessage('categoryhelper_summarymsg')->text() . "';\n\t\t\t\t</script>\n\t\t\t\t\t<input type='hidden' name='TopLevelCategoryOk' value='" . (sizeof($toplevel) == sizeof($bottomlevel) ? "false" : "true") . "'/>\n\t\t\t\t<noscript>" . wfMessage('categoryhelper_javascript')->text() . "<br/></noscript>\n\t\t\t\t"; $i = 0; $max = 1; if (sizeof($toplevel) > 0) { $max = sizeof($toplevel); } for ($i = 0; $i < $max || $i < $wgMaxCategories; $i++) { $top = $bot = ''; $style = ' style="display:none;" '; if ($i < sizeof($toplevel) || $i == 0) { $top = $toplevel[$i]; $bot = $bottomlevel[$i]; $style = ''; } if ($i > 0) { $html .= "<br/>"; } $html .= "<SELECT class='topcategory_dropdown' name='topcategory{$i}' id='topcategory{$i}' onchange='updateCategories({$i});' {$style}>\n\t\t\t\t\t<OPTION VALUE=''>" . wfMessage('selectcategory')->text() . "</OPTION>"; foreach ($toplevels as $c) { $c = trim($c); if ($c == "") { continue; } $html .= "<OPTION VALUE=\"{$c}\" " . ($c == $top ? "SELECTED" : "") . " >{$c}</OPTION>\n"; } $html .= "</SELECT> <span id='category_div{$i}'><SELECT onchange='catHelperUpdateSummary();' class='subcategory_dropdown' name='category{$i}' id='category{$i}' {$style}>"; if (is_array($options[$top])) { if ($bot == "") { $html .= "<OPTION VALUE=''>" . wfMessage('selectcategory')->text() . "</OPTION>"; } foreach ($options[$top] as $sub) { $html .= self::getHTMLForCategoryOption($sub, $bot); } } $html .= "</SELECT> </span> "; } if ($i >= sizeof($toplevel)) { $html .= "<a onclick='javascript:showanother();' id='showmorecats'>" . wfMessage('addanothercategory')->text() . "</a>"; } return $html; }
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; }
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; }
function getCategoryLinks() { global $wgOut, $wgTitle, $wgUseCategoryBrowser; global $wgContLang; if (count($wgOut->mCategoryLinks) == 0) { return ''; } # Separator $sep = wfMsgHtml('catseparator'); // 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} {$sep} {$embed}", $wgOut->mCategoryLinks) . $pop; $msg = wfMsgExt('pagecategories', array('parsemag', 'escape'), count($wgOut->mCategoryLinks)); $s = $this->makeLinkObj(Title::newFromText(wfMsgForContent('pagecategorieslink')), $msg) . ': ' . $t; # optional 'dmoz-like' category browser. Will be shown under the list # of categories an article belong to if ($wgUseCategoryBrowser) { $s .= '<br /><hr />'; # get a big array of the parents tree $parenttree = Categoryhelper::getCurrentParentCategoryTree(); # Skin object passed by reference cause it can not be # accessed under the method subfunction drawCategoryBrowser $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this)); # Clean out bogus first entry and sort them unset($tempout[0]); asort($tempout); # Output one per line $s .= implode("<br />\n", $tempout); } return $s; }