Ejemplo n.º 1
0
 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;
 }