Ejemplo n.º 1
0
 /**
  * Gets all the display parameters defined for a category
  */
 static function getDisplayParamsForCategory($category)
 {
     $return_display_params = array();
     $title = Title::newFromText($category, NS_CATEGORY);
     $pageID = $title->getArticleID();
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('page_props', array('pp_value'), array('pp_page' => $pageID, 'pp_propname' => 'SDDisplayParams'));
     while ($row = $dbr->fetchRow($res)) {
         // There should only be one row.
         $displayParamsStr = $row['pp_value'];
         $return_display_params[] = explode(';', $displayParamsStr);
     }
     // Get "legacy" parameters defined via special properties.
     $all_display_params = SDUtils::getValuesForProperty(str_replace(' ', '_', $category), NS_CATEGORY, '_SD_DP');
     foreach ($all_display_params as $display_params) {
         $return_display_params[] = explode(';', $display_params);
     }
     return $return_display_params;
 }
Ejemplo n.º 2
0
	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;
	}
Ejemplo n.º 3
0
 function printFilterLabel($filter_name)
 {
     $labels_for_filter = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_L', SD_SP_HAS_LABEL, NS_MAIN);
     if (count($labels_for_filter) > 0) {
         $filter_label = $labels_for_filter[0];
     } else {
         $filter_label = str_replace('_', ' ', $filter_name);
     }
     return $filter_label;
 }
Ejemplo n.º 4
0
 /**
  * @deprecated as of SD 2.0 - will be removed when the "Filter:"
  * namespace goes away.
  */
 static function load($filter_name)
 {
     $f = new SDFilter();
     $f->setName($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->setProperty($properties_used[0]);
         // This may not be necessary, or useful.
         $f->property_type = 'page';
     }
     $proptitle = Title::newFromText($f->property, SMW_NS_PROPERTY);
     if ($proptitle != null) {
         $f->loadPropertyTypeFromProperty();
     }
     $categories = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_VC', SD_SP_GETS_VALUES_FROM_CATEGORY, NS_CATEGORY);
     if (count($categories) > 0) {
         $f->setCategory($categories[0]);
     } elseif ($f->property_type === 'boolean') {
         $f->allowed_values = array('0', '1');
     } else {
         $f->allowed_values = array();
     }
     // 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;
 }
Ejemplo n.º 5
0
	/**
	 * Gets all the display parameters defined for a category
	 */
	static function getDisplayParamsForCategory( $category ) {
		$all_display_params = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_DP' );

		$return_display_params = array();
		foreach ( $all_display_params as $display_params ) {
			$return_display_params[] = explode( ';', $display_params );
		}
		return $return_display_params;
	}