Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php |
— | — | @@ -380,253 +380,6 @@ |
381 | 381 | return $row[0]; |
382 | 382 | } |
383 | 383 | |
384 | | - /** |
385 | | - * Gets an array of the possible time period values (e.g., years, |
386 | | - * years and months) for a given date filter, and, for each one, |
387 | | - * the number of pages that match that time period. |
388 | | - */ |
389 | | - function getTimePeriodValues($date_filter) { |
390 | | - global $smwgDefaultStore; |
391 | | - |
392 | | - $possible_dates = array(); |
393 | | - $property_value = str_replace(' ', '_', $date_filter->property); |
394 | | - $dbr = wfGetDB( DB_SLAVE ); |
395 | | - if ($date_filter->time_period == wfMsg('sd_filter_month')) { |
396 | | - $fields = "YEAR(value_xsd), MONTH(value_xsd)"; |
397 | | - } else { |
398 | | - $fields = "YEAR(value_xsd)"; |
399 | | - } |
400 | | - if ($smwgDefaultStore == 'SMWSQLStore2') { |
401 | | - $smw_attributes = $dbr->tableName( 'smw_atts2' ); |
402 | | - $smw_ids = $dbr->tableName( 'smw_ids' ); |
403 | | - $sql =<<<END |
404 | | - SELECT $fields, count(*) |
405 | | - FROM semantic_drilldown_values sdv |
406 | | - JOIN $smw_attributes a ON sdv.id = a.s_id |
407 | | - JOIN $smw_ids p_ids ON a.p_id = p_ids.smw_id |
408 | | - WHERE p_ids.smw_title = '$property_value' |
409 | | - GROUP BY $fields |
410 | | - ORDER BY $fields |
411 | | - |
412 | | -END; |
413 | | - } else { |
414 | | - $smw_attributes = $dbr->tableName( 'smw_attributes' ); |
415 | | - $sql =<<<END |
416 | | - SELECT $fields, count(*) |
417 | | - FROM semantic_drilldown_values sdv |
418 | | - JOIN $smw_attributes a ON sdv.id = a.subject_id |
419 | | - WHERE a.attribute_title = '$property_value' |
420 | | - GROUP BY $fields |
421 | | - ORDER BY $fields |
422 | | - |
423 | | -END; |
424 | | - } |
425 | | - $res = $dbr->query($sql); |
426 | | - while ($row = $dbr->fetchRow($res)) { |
427 | | - if ($date_filter->time_period == wfMsg('sd_filter_month')) { |
428 | | - global $sdgMonthValues; |
429 | | - $date_string = sdfMonthToString($row[1]) . " " . $row[0]; |
430 | | - $possible_dates[$date_string] = $row[2]; |
431 | | - } else { |
432 | | - $date_string = $row[0]; |
433 | | - $possible_dates[$date_string] = $row[1]; |
434 | | - } |
435 | | - } |
436 | | - $dbr->freeResult($res); |
437 | | - return $possible_dates; |
438 | | - } |
439 | | - |
440 | | - /** |
441 | | - * Gets an array of all values that the property belonging to the |
442 | | - * passed-in filter has, and, for each one, the number of pages |
443 | | - * that match that value. |
444 | | - */ |
445 | | - function getAllValues($filter) { |
446 | | - global $smwgDefaultStore; |
447 | | - if ($smwgDefaultStore == 'SMWSQLStore2') { |
448 | | - return $this->getAllValues_2($filter); |
449 | | - } else { |
450 | | - return $this->getAllValues_orig($filter); |
451 | | - } |
452 | | - } |
453 | | - |
454 | | - function getAllValues_orig($filter) { |
455 | | - $possible_values = array(); |
456 | | - $property_value = str_replace(' ', '_', $filter->property); |
457 | | - $dbr = wfGetDB( DB_SLAVE ); |
458 | | - if ($filter->is_relation) { |
459 | | - $property_table_name = $dbr->tableName('smw_relations'); |
460 | | - $property_table_nickname = "r"; |
461 | | - $property_field = 'relation_title'; |
462 | | - $value_field = 'object_title'; |
463 | | - } else { |
464 | | - $property_table_name = $dbr->tableName('smw_attributes'); |
465 | | - $property_table_nickname = "a"; |
466 | | - $property_field = 'attribute_title'; |
467 | | - $value_field = 'value_xsd'; |
468 | | - } |
469 | | - $sql = "SELECT $value_field, count(*) |
470 | | - FROM semantic_drilldown_values sdv |
471 | | - JOIN $property_table_name $property_table_nickname |
472 | | - ON sdv.id = $property_table_nickname.subject_id |
473 | | - WHERE $property_table_nickname.$property_field = '$property_value' |
474 | | - AND $value_field != '' |
475 | | - GROUP BY $value_field |
476 | | - ORDER BY $value_field"; |
477 | | - $res = $dbr->query($sql); |
478 | | - while ($row = $dbr->fetchRow($res)) { |
479 | | - $value_string = str_replace('_', ' ', $row[0]); |
480 | | - $possible_values[$value_string] = $row[1]; |
481 | | - } |
482 | | - $dbr->freeResult($res); |
483 | | - return $possible_values; |
484 | | - } |
485 | | - |
486 | | - function getAllValues_2($filter) { |
487 | | - $possible_values = array(); |
488 | | - $property_value = str_replace(' ', '_', $filter->property); |
489 | | - $dbr = wfGetDB( DB_SLAVE ); |
490 | | - if ($filter->is_relation) { |
491 | | - $property_table_name = $dbr->tableName('smw_rels2'); |
492 | | - $property_table_nickname = "r"; |
493 | | - $value_field = 'o_ids.smw_title'; |
494 | | - } else { |
495 | | - $property_table_name = $dbr->tableName('smw_atts2'); |
496 | | - $property_table_nickname = "a"; |
497 | | - $value_field = 'value_xsd'; |
498 | | - } |
499 | | - $smw_ids = $dbr->tableName( 'smw_ids' ); |
500 | | - $prop_ns = SMW_NS_PROPERTY; |
501 | | - $sql =<<<END |
502 | | - SELECT $value_field, count(*) |
503 | | - FROM semantic_drilldown_values sdv |
504 | | - JOIN $property_table_name $property_table_nickname ON sdv.id = $property_table_nickname.s_id |
505 | | - |
506 | | -END; |
507 | | - if ($filter->is_relation) { |
508 | | - $sql .= " JOIN $smw_ids o_ids ON r.o_id = o_ids.smw_id"; |
509 | | - } |
510 | | - $sql .=<<<END |
511 | | - JOIN $smw_ids p_ids ON $property_table_nickname.p_id = p_ids.smw_id |
512 | | - WHERE p_ids.smw_title = '$property_value' |
513 | | - AND p_ids.smw_namespace = $prop_ns |
514 | | - AND $value_field != '' |
515 | | - GROUP BY $value_field |
516 | | - ORDER BY $value_field |
517 | | - |
518 | | -END; |
519 | | - $res = $dbr->query($sql); |
520 | | - while ($row = $dbr->fetchRow($res)) { |
521 | | - $value_string = str_replace('_', ' ', $row[0]); |
522 | | - $possible_values[$value_string] = $row[1]; |
523 | | - } |
524 | | - $dbr->freeResult($res); |
525 | | - return $possible_values; |
526 | | - } |
527 | | - |
528 | | - /** |
529 | | - * Gets an array of all values that the property belonging to the |
530 | | - * passed-in filter has, for pages in the current category. |
531 | | - */ |
532 | | - function getAllOrValues($applied_filter) { |
533 | | - global $smwgDefaultStore; |
534 | | - if ($smwgDefaultStore == 'SMWSQLStore2') { |
535 | | - return $this->getAllOrValues_2($applied_filter); |
536 | | - } else { |
537 | | - return $this->getAllOrValues_orig($applied_filter); |
538 | | - } |
539 | | - } |
540 | | - |
541 | | - function getAllOrValues_orig($applied_filter) { |
542 | | - $possible_values = array(); |
543 | | - $property_value = str_replace(' ', '_', $applied_filter->filter->property); |
544 | | - $dbr = wfGetDB( DB_SLAVE ); |
545 | | - if ($applied_filter->filter->is_relation) { |
546 | | - $property_table_name = $dbr->tableName('smw_relations'); |
547 | | - $property_table_nickname = "r"; |
548 | | - $property_field = 'relation_title'; |
549 | | - $value_field = 'object_title'; |
550 | | - } else { |
551 | | - $property_table_name = $dbr->tableName('smw_attributes'); |
552 | | - $property_table_nickname = "a"; |
553 | | - $property_field = 'attribute_title'; |
554 | | - $value_field = 'value_xsd'; |
555 | | - } |
556 | | - if ($applied_filter->filter->time_period != NULL) { |
557 | | - if ($applied_filter->filter->time_period == wfMsg('sd_filter_month')) { |
558 | | - $value_field = "YEAR(value_xsd), MONTH(value_xsd)"; |
559 | | - } else { |
560 | | - $value_field = "YEAR(value_xsd)"; |
561 | | - } |
562 | | - } |
563 | | - $categorylinks = $dbr->tableName( 'categorylinks' ); |
564 | | - $sql = "SELECT $value_field |
565 | | - FROM $property_table_name $property_table_nickname |
566 | | - JOIN $categorylinks c |
567 | | - ON $property_table_nickname.subject_id = c.cl_from |
568 | | - WHERE $property_table_nickname.$property_field = '$property_value' |
569 | | - AND c.cl_to = '{$this->category}' |
570 | | - GROUP BY $value_field |
571 | | - ORDER BY $value_field"; |
572 | | - $res = $dbr->query($sql); |
573 | | - while ($row = $dbr->fetchRow($res)) { |
574 | | - if ($applied_filter->filter->time_period == wfMsg('sd_filter_month')) |
575 | | - $value_string = sdfMonthToString($row[1]) . " " . $row[0]; |
576 | | - else |
577 | | - // why is trim() necessary here??? |
578 | | - $value_string = str_replace('_', ' ', trim($row[0])); |
579 | | - $possible_values[] = $value_string; |
580 | | - } |
581 | | - $dbr->freeResult($res); |
582 | | - return $possible_values; |
583 | | - } |
584 | | - |
585 | | - function getAllOrValues_2($applied_filter) { |
586 | | - $possible_values = array(); |
587 | | - $property_value = str_replace(' ', '_', $applied_filter->filter->property); |
588 | | - $dbr = wfGetDB( DB_SLAVE ); |
589 | | - if ($applied_filter->filter->is_relation) { |
590 | | - $property_table_name = $dbr->tableName('smw_rels2'); |
591 | | - $property_table_nickname = "r"; |
592 | | - $value_field = 'r.o_id'; |
593 | | - } else { |
594 | | - $property_table_name = $dbr->tableName('smw_atts2'); |
595 | | - $property_table_nickname = "a"; |
596 | | - $value_field = 'value_xsd'; |
597 | | - } |
598 | | - if ($applied_filter->filter->time_period != NULL) { |
599 | | - if ($applied_filter->filter->time_period == wfMsg('sd_filter_month')) { |
600 | | - $value_field = "YEAR(value_xsd), MONTH(value_xsd)"; |
601 | | - } else { |
602 | | - $value_field = "YEAR(value_xsd)"; |
603 | | - } |
604 | | - } |
605 | | - $smw_insts = $dbr->tableName( 'smw_inst2' ); |
606 | | - $smw_ids = $dbr->tableName( 'smw_ids' ); |
607 | | - $cat_ns = NS_CATEGORY; |
608 | | - $sql = "SELECT $value_field |
609 | | - FROM $property_table_name $property_table_nickname |
610 | | - JOIN $smw_ids p_ids ON $property_table_nickname.p_id = p_ids.smw_id |
611 | | - JOIN $smw_insts insts ON $property_table_nickname.s_id = insts.s_id |
612 | | - JOIN $smw_ids cat_ids ON insts.o_id = cat_ids.smw_id |
613 | | - WHERE p_ids.smw_title = '$property_value' |
614 | | - AND cat_ids.smw_namespace = $cat_ns |
615 | | - AND cat_ids.smw_title = '{$this->category}' |
616 | | - GROUP BY $value_field |
617 | | - ORDER BY $value_field"; |
618 | | - $res = $dbr->query($sql); |
619 | | - while ($row = $dbr->fetchRow($res)) { |
620 | | - if ($applied_filter->filter->time_period == wfMsg('sd_filter_month')) |
621 | | - $value_string = sdfMonthToString($row[1]) . " " . $row[0]; |
622 | | - else |
623 | | - // why is trim() necessary here??? |
624 | | - $value_string = str_replace('_', ' ', trim($row[0])); |
625 | | - $possible_values[] = $value_string; |
626 | | - } |
627 | | - $dbr->freeResult($res); |
628 | | - return $possible_values; |
629 | | - } |
630 | | - |
631 | 384 | function getName() { |
632 | 385 | return "BrowseData"; |
633 | 386 | } |
— | — | @@ -691,7 +444,7 @@ |
692 | 445 | if ($af->filter->allowed_values != null) |
693 | 446 | $or_values = $af->filter->allowed_values; |
694 | 447 | else |
695 | | - $or_values = $this->getAllOrValues($af); |
| 448 | + $or_values = $af->getAllOrValues($this->category); |
696 | 449 | if ($af->search_term != null) { |
697 | 450 | // HACK - printFreeTextInput() needs values as the |
698 | 451 | // *keys* of the array |
— | — | @@ -923,11 +676,7 @@ |
924 | 677 | $f->createTempTable(); |
925 | 678 | $found_results_for_filter = false; |
926 | 679 | if (count($f->allowed_values) == 0) { |
927 | | - if ($f->time_period != NULL) { |
928 | | - $filter_values = $this->getTimePeriodValues($f); |
929 | | - } else { |
930 | | - $filter_values = $this->getAllValues($f); |
931 | | - } |
| 680 | + $filter_values = $f->getAllValues(); |
932 | 681 | if (count($filter_values) > 0) |
933 | 682 | $found_results_for_filter = true; |
934 | 683 | } else { |
— | — | @@ -1015,7 +764,6 @@ |
1016 | 765 | if (count($categories) == 0) { |
1017 | 766 | return ""; |
1018 | 767 | } |
1019 | | - $sd_props = $sdgContLang->getSpecialPropertiesArray(); |
1020 | 768 | $subcategory_text = wfMsg('sd_browsedata_subcategory'); |
1021 | 769 | |
1022 | 770 | $header = ""; |
— | — | @@ -1261,8 +1009,6 @@ |
1262 | 1010 | |
1263 | 1011 | function doSpecialBrowseData($query) { |
1264 | 1012 | global $wgRequest, $wgOut, $sdgScriptPath, $sdgContLang, $sdgNumResultsPerPage; |
1265 | | - $sd_props = $sdgContLang->getSpecialPropertiesArray(); |
1266 | | - |
1267 | 1013 | $mainCssDir = $sdgScriptPath . '/skins/'; |
1268 | 1014 | $wgOut->addLink( array( |
1269 | 1015 | 'rel' => 'stylesheet', |