/** * OutputPageMakeCategoryLinks hook, override category links */ function efCategoryTreeOutputPageMakeCategoryLinks($out, &$categories, &$links) { global $wgCategoryTreePageCategoryOptions; foreach ($categories as $category => $type) { $links[$type][] = efCategoryTreeParserHook($category, $wgCategoryTreePageCategoryOptions, null, true); } return false; }
public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { // escape if CategoryTree extension isn't included if (!function_exists('efCategoryTreeParserHook')) { return null; } global $sfgTabIndex, $sfgFieldNum, $wgCapitalLinks; $input_id = "input_{$sfgFieldNum}"; // get list delimiter - default is comma if (array_key_exists('delimiter', $other_args)) { $delimiter = $other_args['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($cur_value, $delimiter); if (array_key_exists('top category', $other_args)) { $top_category = $other_args['top category']; } else { // escape - we can't do anything return null; } $hideroot = array_key_exists('hideroot', $other_args); if (array_key_exists('depth', $other_args)) { $depth = $other_args['depth']; } else { $depth = '10'; } if (array_key_exists('height', $other_args)) { $height = $other_args['height']; } else { $height = '100'; } if (array_key_exists('width', $other_args)) { $width = $other_args['width']; } else { $width = '500'; } global $wgCategoryTreeMaxDepth; $wgCategoryTreeMaxDepth = 10; $tree = efCategoryTreeParserHook($top_category, array('mode' => 'categories', 'namespaces' => array(NS_CATEGORY), 'depth' => $depth, 'hideroot' => $hideroot)); // Some string that will hopefully never show up in a category, // template or field name. $dummy_str = 'REPLACE THIS STRING!'; $tree = preg_replace('/(<a class="CategoryTreeLabel.*>)(.*)(<\\/a>)/', '<input id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[' . $dummy_str . ']" value="$2" type="checkbox"> $1$2$3', $tree); // replace values one at a time, by an incrementing index - // inspired by http://bugs.php.net/bug.php?id=11457 $i = 0; while (($a = strpos($tree, $dummy_str)) > 0) { $tree = substr($tree, 0, $a) . $i++ . substr($tree, $a + strlen($dummy_str)); } // set all checkboxes matching $cur_values to checked foreach ($cur_values as $value) { // Capitalize the first letter, if first letters // always get capitalized. if ($wgCapitalLinks) { global $wgContLang; $value = $wgContLang->ucfirst($value); } $tree = str_replace("value=\"{$value}\"", "value=\"{$value}\" checked=\"checked\"", $tree); } // if it's disabled, set all to disabled if ($is_disabled) { $tree = str_replace('type="checkbox"', 'type="checkbox" disabled', $tree); } // Get rid of all the 'no subcategories' messages. $tree = str_replace('<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg('categorytree-no-subcategories') . '</i></div>', '', $tree); $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">' . $tree . '</div>'; $text .= Html::hidden($input_name . '[is_list]', 1); $spanClass = 'checkboxesSpan'; if ($is_mandatory) { $spanClass .= ' mandatoryFieldSpan'; } $text = "\n" . Html::rawElement('span', array('class' => $spanClass), $text) . "\n"; return $text; }
public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { // escape if CategoryTree extension isn't included if (!function_exists('efCategoryTreeParserHook')) { return null; } global $sfgTabIndex; if (array_key_exists('top category', $other_args)) { $top_category = $other_args['top category']; } else { // escape - we can't do anything return null; } $hideroot = array_key_exists('hideroot', $other_args); if (array_key_exists('depth', $other_args)) { $depth = $other_args['depth']; } else { $depth = '10'; } if (array_key_exists('height', $other_args)) { $height = $other_args['height']; } else { $height = '100'; } if (array_key_exists('width', $other_args)) { $width = $other_args['width']; } else { $width = '500'; } $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">'; // Start with an initial "None" value, unless this is a // mandatory field and there's a current value in place // (either through a default value or because we're editing // an existing page) if (!$is_mandatory || $cur_value === '') { $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""'; if (!$cur_value) { $text .= ' checked="checked"'; } $disabled_text = $is_disabled ? 'disabled' : ''; $text .= " {$disabled_text}/> <em>" . wfMessage('sf_formedit_none')->escaped() . "</em>\n"; } global $wgCategoryTreeMaxDepth; $wgCategoryTreeMaxDepth = 10; $tree = efCategoryTreeParserHook($top_category, array('mode' => 'categories', 'namespaces' => array(NS_CATEGORY), 'depth' => $depth, 'hideroot' => $hideroot)); // Capitalize the first letter, if first letters always get // capitalized. global $wgCapitalLinks; if ($wgCapitalLinks) { global $wgContLang; $cur_value = $wgContLang->ucfirst($cur_value); } $tree = preg_replace('/(<a class="CategoryTreeLabel.*>)(.*)(<\\/a>)/', '<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="$2" type="radio"> $1$2$3', $tree); $tree = str_replace("value=\"{$cur_value}\"", "value=\"{$cur_value}\" checked=\"checked\"", $tree); // if it's disabled, set all to disabled if ($is_disabled) { $tree = str_replace('type="radio"', 'type="radio" disabled', $tree); } // Get rid of all the 'no subcategories' messages. $tree = str_replace('<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMessage('categorytree-no-subcategories')->escaped() . '</i></div>', '', $tree); $text .= $tree . '</div>'; $spanClass = 'radioButtonSpan'; if ($is_mandatory) { $spanClass .= ' mandatoryFieldSpan'; } $text = Html::rawElement('span', array('class' => $spanClass), $text); return $text; }
/** * Entry point for the {{#categorytree}} tag parser function. * This is a wrapper around efCategoryTreeParserHook */ function efCategoryTreeParserFunction(&$parser) { $params = func_get_args(); array_shift($params); //first is &$parser, strip it //first user-supplied parameter must be category name if (!$params) { return ''; } //no category specified, return nothing $cat = array_shift($params); //build associative arguments from flat parameter list $argv = array(); foreach ($params as $p) { if (preg_match('/^\\s*(\\S.*?)\\s*=\\s*(.*?)\\s*$/', $p, $m)) { $k = $m[1]; $v = $m[2]; } else { $k = trim($p); $v = true; } $argv[$k] = $v; } //now handle just like a <categorytree> tag $html = efCategoryTreeParserHook($cat, $argv, $parser); return array($html, 'isHTML' => true); }
/** * OutputPageMakeCategoryLinks hook, override category links */ function efCategoryTreeOutputPageMakeCategoryLinks(&$out, &$categories, &$links) { global $wgContLang, $wgCategoryTreePageCategoryOptions; $ct = new CategoryTree($wgCategoryTreePageCategoryOptions); foreach ($categories as $category => $type) { $links[$type][] = efCategoryTreeParserHook($category, $wgCategoryTreePageCategoryOptions, NULL, true); } return false; }