static function getCategoryChildren($category_name, $get_categories, $levels) { if ($levels == 0) { return array(); } $pages = array(); $subcategories = array(); $dbr = wfGetDB(DB_SLAVE); extract($dbr->tableNames('page', 'categorylinks')); $cat_ns = NS_CATEGORY; $query_category = str_replace(' ', '_', $category_name); $sql = "SELECT p.page_title, p.page_namespace FROM {$categorylinks} cl\n\tJOIN {$page} p on cl.cl_from = p.page_id\n\tWHERE cl.cl_to = {$dbr->addQuotes($query_category)}\n"; if ($get_categories) { $sql .= "AND p.page_namespace = {$cat_ns}\n"; } $sql .= "ORDER BY cl.cl_sortkey"; $res = $dbr->query($sql); while ($row = $dbr->fetchRow($res)) { if ($get_categories) { $subcategories[] = $row[0]; $pages[] = $row[0]; } else { if ($row[1] == $cat_ns) { $subcategories[] = $row[0]; } else { $pages[] = $row[0]; } } } $dbr->freeResult($res); foreach ($subcategories as $subcategory) { $pages = array_merge($pages, SDUtils::getCategoryChildren($subcategory, $get_categories, $levels - 1)); } return $pages; }
public function setCategory($cat) { $this->category = $cat; $this->allowed_values = SDUtils::getCategoryChildren($cat, false, 5); }
static function load( $filter_name ) { $f = new SDFilter(); $f->name = $filter_name; $properties_used = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY ); if ( count( $properties_used ) > 0 ) { $f->property = $properties_used[0]; $f->escaped_property = str_replace( array( ' ', "'" ), array( '_', "\'" ), $f->property ); } $f->is_relation = true; $proptitle = Title::newFromText( $f->property, SMW_NS_PROPERTY ); if ( $proptitle != null ) { $store = smwfGetStore(); if ( class_exists( 'SMWDIProperty' ) ) { // SMW 1.6 $propPage = new SMWDIWikiPage( $f->escaped_property, SMW_NS_PROPERTY, null ); $types = $store->getPropertyValues( $propPage, new SMWDIProperty( '_TYPE' ) ); } elseif ( class_exists( 'SMWPropertyValue' ) ) { $types = $store->getPropertyValues( $proptitle, SMWPropertyValue::makeUserProperty( 'Has type' ) ); } else { $types = $store->getSpecialValues( $proptitle, SMW_SP_HAS_TYPE ); } global $smwgContLang; $datatypeLabels = $smwgContLang->getDatatypeLabels(); if ( count( $types ) > 0 ) { if ( $types[0] instanceof SMWDIWikiPage ) { // SMW 1.6 $typeValue = $types[0]->getDBkey(); } elseif ( $types[0] instanceof SMWDIURI ) { // A bit inefficient, but it's the // simplest approach. $typeID = $types[0]->getFragment(); $typeValue = $datatypeLabels[$typeID]; } else { $typeValue = $types[0]->getWikiValue(); } if ( $typeValue != $datatypeLabels['_wpg'] ) { $f->is_relation = false; } if ( $typeValue == $datatypeLabels['_boo'] ) { $f->is_boolean = true; } if ( $typeValue == $datatypeLabels['_dat'] ) { $f->is_date = true; } } } $categories = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_VC', SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY ); $time_periods = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_TP', SD_SP_USES_TIME_PERIOD, null ); if ( count( $categories ) > 0 ) { $f->category = $categories[0]; $f->allowed_values = SDUtils::getCategoryChildren( $f->category, false, 5 ); } elseif ( count( $time_periods ) > 0 ) { $f->time_period = $time_periods[0]; $f->allowed_values = array(); } elseif ( $f->is_boolean ) { $f->allowed_values = array( '0', '1' ); } else { $values = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_V', SD_SP_HAS_VALUE, null ); $f->allowed_values = $values; } $input_types = SDUtils::getValuesForProperty( $filter_name, SD_NS_FILTER, '_SD_IT', SD_SP_HAS_INPUT_TYPE, null ); if ( count( $input_types ) > 0 ) { $f->input_type = $input_types[0]; } // set list of possible applied filters if allowed values // array was set foreach ( $f->allowed_values as $allowed_value ) { $f->possible_applied_filters[] = SDAppliedFilter::create( $f, $allowed_value ); } return $f; }
function getPageHeader() { global $wgRequest; global $sdgContLang, $sdgScriptPath; global $sdgFiltersSmallestFontSize, $sdgFiltersLargestFontSize; $categories = SDUtils::getCategoriesForBrowsing(); // if there are no categories, escape quickly if (count($categories) == 0) { return ""; } $subcategory_text = wfMsg('sd_browsedata_subcategory'); $header = ""; $this->show_single_cat = $wgRequest->getCheck('_single'); if (!$this->show_single_cat) { $header .= $this->printCategoriesList($categories); } // if there are no subcategories or filters for this // category, escape now that we've (possibly) printed the // categories list if (count($this->next_level_subcategories) == 0 && count($this->applied_filters) == 0 && count($this->remaining_filters) == 0) { return $header; } $header .= ' <div id="drilldown-header">' . "\n"; if (count($this->applied_filters) > 0 || $this->subcategory) { $category_url = $this->makeBrowseURL($this->category); $header .= '<a href="' . $category_url . '" title="' . wfMsg('sd_browsedata_resetfilters') . '">' . str_replace('_', ' ', $this->category) . '</a>'; } else { $header .= str_replace('_', ' ', $this->category); } if ($this->subcategory) { $header .= " > "; $header .= "{$subcategory_text}: "; $subcat_string = str_replace('_', ' ', $this->subcategory); $remove_filter_url = $this->makeBrowseURL($this->category, $this->applied_filters); $header .= "\n" . ' <span class="drilldown-header-value">' . $subcat_string . '</span> <a href="' . $remove_filter_url . '" title="' . wfMsg('sd_browsedata_removesubcategoryfilter') . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a> '; } foreach ($this->applied_filters as $i => $af) { $header .= !$this->subcategory && $i == 0 ? " > " : "\n\t\t\t\t\t<span class=\"drilldown-header-value\">&</span> "; $filter_label = $this->printFilterLabel($af->filter->name); // add an "x" to remove this filter, if it has more // than one value if (count($this->applied_filters[$i]->values) > 1) { $temp_filters_array = $this->applied_filters; array_splice($temp_filters_array, $i, 1); $remove_filter_url = $this->makeBrowseURL($this->category, $temp_filters_array, $this->subcategory); array_splice($temp_filters_array, $i, 0); $header .= $filter_label . ' <a href="' . $remove_filter_url . '" title="' . wfMsg('sd_browsedata_removefilter') . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a> : '; } else { $header .= "{$filter_label}: "; } foreach ($af->values as $j => $fv) { if ($j > 0) { $header .= ' <span class="drilldown-or">' . wfMsg('sd_browsedata_or') . '</span> '; } $filter_text = $this->printFilterValue($af->filter, $fv->text); $temp_filters_array = $this->applied_filters; $removed_values = array_splice($temp_filters_array[$i]->values, $j, 1); $remove_filter_url = $this->makeBrowseURL($this->category, $temp_filters_array, $this->subcategory); array_splice($temp_filters_array[$i]->values, $j, 0, $removed_values); $header .= "\n\t" . ' <span class="drilldown-header-value">' . $filter_text . '</span> <a href="' . $remove_filter_url . '" title="' . wfMsg('sd_browsedata_removefilter') . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a>'; } if ($af->search_term != null) { $temp_filters_array = $this->applied_filters; $removed_search_term = $temp_filters_array[$i]->search_term; $temp_filters_array[$i]->search_term = null; $remove_filter_url = $this->makeBrowseURL($this->category, $temp_filters_array, $this->subcategory); $temp_filters_array[$i]->search_term = $removed_search_term; $header .= "\n\t" . '<span class="drilldown-header-value">~ \'' . $af->search_term . '\'</span> <a href="' . $remove_filter_url . '" title="' . wfMsg('sd_browsedata_removefilter') . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /> </a>'; } elseif ($af->lower_date != null || $af->upper_date != null) { $header .= "\n\t<span class=\"drilldown-header-value\">" . $af->lower_date_string . " - " . $af->upper_date_string . "</span>"; } } $header .= "</div>\n"; $drilldown_description = wfMsg('sd_browsedata_docu'); $header .= "\t\t\t\t<p>{$drilldown_description}</p>\n"; // display the list of subcategories on one line, and below // it every filter, each on its own line; each line will // contain the possible values, and, in parentheses, the // number of pages that match that value $header .= "\t\t\t\t<div class=\"drilldown-filters\">\n"; $cur_url = $this->makeBrowseURL($this->category, $this->applied_filters, $this->subcategory); $cur_url .= strpos($cur_url, '?') ? '&' : '?'; $this->createTempTable($this->category, $this->subcategory, $this->all_subcategories, $this->applied_filters); $num_printed_values = 0; if (count($this->next_level_subcategories) > 0) { $results_line = ""; // loop through to create an array of subcategory // names and their number of values, then loop through // the array to print them - we loop through twice, // instead of once, to be able to print a tag-cloud // display if necessary $subcat_values = array(); foreach ($this->next_level_subcategories as $i => $subcat) { $further_subcats = SDUtils::getCategoryChildren($subcat, true, 10); $num_results = $this->getNumResults($subcat, $further_subcats); $subcat_values[$subcat] = $num_results; } // get necessary values for creating the tag cloud, // if appropriate if ($sdgFiltersSmallestFontSize > 0 && $sdgFiltersLargestFontSize > 0) { $lowest_num_results = min($subcat_values); $highest_num_results = max($subcat_values); $num_results_midpoint = ($lowest_num_results + $highest_num_results) / 2; $font_size_midpoint = ($sdgFiltersSmallestFontSize + $sdgFiltersLargestFontSize) / 2; $num_results_per_font_pixel = ($highest_num_results + 1 - $lowest_num_results) / ($sdgFiltersLargestFontSize + 1 - $sdgFiltersSmallestFontSize); } foreach ($subcat_values as $subcat => $num_results) { if ($num_results > 0) { if ($num_printed_values++ > 0) { $results_line .= " · "; } $filter_text = str_replace('_', ' ', $subcat) . " ({$num_results})"; $filter_url = $cur_url . '_subcat=' . urlencode($subcat); if ($sdgFiltersSmallestFontSize > 0 && $sdgFiltersLargestFontSize > 0) { $font_size = round($font_size_midpoint + ($num_results - $num_results_midpoint) / $num_results_per_font_pixel); $results_line .= "\n\t\t\t\t\t" . '<a href="' . $filter_url . '" title="' . wfMsg('sd_browsedata_filterbysubcategory') . '" style="font-size: ' . $font_size . 'px">' . $filter_text . '</a>'; } else { $results_line .= "\n\t\t\t\t\t" . '<a href="' . $filter_url . '" title="' . wfMsg('sd_browsedata_filterbysubcategory') . '">' . $filter_text . '</a>'; } } } if ($results_line != "") { $header .= "\t\t\t\t\t<p><strong>{$subcategory_text}:</strong> {$results_line}</p>\n"; } } $filters = SDUtils::loadFiltersForCategory($this->category); foreach ($filters as $f) { foreach ($this->applied_filters as $af) { if ($af->filter->name == $f->name) { $header .= $this->printAppliedFilterLine($af); } } foreach ($this->remaining_filters as $rf) { if ($rf->name == $f->name) { $header .= $this->printUnappliedFilterLine($rf, $cur_url); } } } $header .= "\t\t\t\t</div> <!-- drilldown-filters -->\n"; return $header; }