r44208 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44207‎ | r44208 | r44209 >
Date:00:47, 4 December 2008
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for new 'input type' feature; removed handling for SMW 0.7
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_Filter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
@@ -12,7 +12,8 @@
1313 var $is_relation;
1414 var $is_boolean;
1515 var $category;
16 - var $time_period = NULL;
 16+ var $time_period = null;
 17+ var $input_type = null;
1718 var $allowed_values;
1819 var $possible_applied_filters = array();
1920
@@ -22,44 +23,31 @@
2324
2425 $f = new SDFilter();
2526 $f->name = $filter_name;
26 - $relations_used = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_COVERS_PROPERTY, true, SMW_NS_RELATION);
27 - $smw_version = SMW_VERSION;
28 - if ($smw_version{0} == '0') {
29 - $attribute_ns = SMW_NS_ATTRIBUTE;
30 - } else {
31 - $attribute_ns = SMW_NS_PROPERTY;
 27+ $properties_used = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY);
 28+ if (count($properties_used) > 0) {
 29+ $f->property = $properties_used[0];
3230 }
33 - $attributes_used = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_COVERS_PROPERTY, true, $attribute_ns);
34 - if (count($relations_used) > 0) {
35 - $f->property = $relations_used[0];
36 - $f->is_relation = true;
37 - } elseif (count($attributes_used) > 0) {
38 - $f->property = $attributes_used[0];
39 - $f->is_relation = false;
40 - }
41 - // handling of SMW 1.0 is somewhat awkward - the above code
42 - // retrieves the property correctly for SMW 1.0, but not the
43 - // "is_relation" value; for that, we need to get this
44 - // "special value" separately
45 - if ($smw_version{0} != '0') {
46 - $f->is_relation = false;
47 - $proptitle = Title::newFromText($f->property, SMW_NS_PROPERTY);
48 - if ($proptitle != NULL) {
49 - $store = smwfGetStore();
 31+ $f->is_relation = false;
 32+ $proptitle = Title::newFromText($f->property, SMW_NS_PROPERTY);
 33+ if ($proptitle != NULL) {
 34+ $store = smwfGetStore();
 35+ if (class_exists('SMWPropertyValue')) {
 36+ $types = $store->getPropertyValues($proptitle, SMWPropertyValue::makeUserProperty('Has type'));
 37+ } else {
5038 $types = $store->getSpecialValues($proptitle, SMW_SP_HAS_TYPE);
51 - global $smwgContLang;
52 - $datatypeLabels = $smwgContLang->getDatatypeLabels();
53 - if (count($types) > 0) {
54 - if ($types[0]->getWikiValue() == $datatypeLabels['_wpg']) {
55 - $f->is_relation = true;
56 - } elseif ($types[0]->getWikiValue() == $datatypeLabels['_boo']) {
57 - $f->is_boolean = true;
58 - }
 39+ }
 40+ global $smwgContLang;
 41+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 42+ if (count($types) > 0) {
 43+ if ($types[0]->getWikiValue() == $datatypeLabels['_wpg']) {
 44+ $f->is_relation = true;
 45+ } elseif ($types[0]->getWikiValue() == $datatypeLabels['_boo']) {
 46+ $f->is_boolean = true;
5947 }
6048 }
6149 }
62 - $categories = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_GETS_VALUES_FROM_CATEGORY, true, NS_CATEGORY);
63 - $time_periods = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_USES_TIME_PERIOD, false, null);
 50+ $categories = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY);
 51+ $time_periods = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_USES_TIME_PERIOD, null);
6452 if (count($categories) > 0) {
6553 $f->category = $categories[0];
6654 $f->allowed_values = sdfGetCategoryChildren($f->category, false, 5);
@@ -69,9 +57,13 @@
7058 } elseif ($f->is_boolean) {
7159 $f->allowed_values = array('0', '1');
7260 } else {
73 - $values = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_HAS_VALUE, false, null);
 61+ $values = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_HAS_VALUE, null);
7462 $f->allowed_values = $values;
7563 }
 64+ $input_types = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, SD_SP_HAS_INPUT_TYPE, null);
 65+ if (count($input_types) > 0) {
 66+ $f->input_type = $input_types[0];
 67+ }
7668 // set list of possible applied filters if allowed values
7769 // array was set
7870 foreach($f->allowed_values as $allowed_value) {

Status & tagging log