http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88381
Revision: 88381
Author: mkroetzsch
Date: 2011-05-18 19:12:40 +0000 (Wed, 18 May 2011)
Log Message:
-----------
changed Type:Vector to use a list of properties for declaration, instead of a
list of types
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
Added Paths:
-----------
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_PropertyList.php
Removed Paths:
-------------
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
Modified:
trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
2011-05-18 18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -77,26 +77,12 @@
return new SMWDIGeoCoord( array( 'lat' =>
(float)$dbkeys[0], 'lon' => (float)$dbkeys[1] ) );
case SMWDataItem::TYPE_CONTAINER:
$semanticData = new SMWContainerSemanticData();
- if ( $typeid == '_rec' ) {
- $types = SMWRecordValue::findTypeIds(
$diProperty );
- foreach ( reset( $dbkeys ) as $value ) {
- if ( is_array( $value ) && (
count( $value ) == 2 ) ) {
- $diP = new
SMWDIProperty( reset( $value ), false );
- $pnum = intval( substr(
reset( $value ), 1 ) ); // try to find the number of this property
- if ( array_key_exists(
$pnum - 1, $types ) ) {
- $diV =
self::dataItemFromDBKeys( $types[$pnum - 1], end( $value ) );
-
$semanticData->addPropertyObjectValue( $diP, $diV );
- }
- }
+ foreach ( reset( $dbkeys ) as $value ) {
+ if ( is_array( $value ) && ( count(
$value ) == 2 ) ) {
+ $diP = new SMWDIProperty(
reset( $value ), false );
+ $diV =
self::dataItemFromDBKeys( $diP->findPropertyTypeID(), end( $value ) );
+
$semanticData->addPropertyObjectValue( $diP, $diV );
}
- } else {
- foreach ( reset( $dbkeys ) as $value ) {
- if ( is_array( $value ) && (
count( $value ) == 2 ) ) {
- $diP = new
SMWDIProperty( reset( $value ), false );
- $diV =
self::dataItemFromDBKeys( $diP->findPropertyTypeID(), end( $value ) );
-
$semanticData->addPropertyObjectValue( $diP, $diV );
- }
- }
}
return new SMWDIContainer( $semanticData );
case SMWDataItem::TYPE_WIKIPAGE:
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2011-05-18 18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -227,7 +227,7 @@
'_qty' => 'SMWQuantityValue', // Type for numbers with
units of measurement
// Special types are not avaialble directly for users
(and have no local language name):
'__typ' => 'SMWTypesValue', // Special type page type
- '__tls' => 'SMWTypeListValue', // Special type list for
decalring _rec properties
+ '__pls' => 'SMWPropertyListValue', // Special type list
for decalring _rec properties
'__con' => 'SMWConceptValue', // Special concept page
type
'__sps' => 'SMWStringValue', // Special string type
'__spu' => 'SMWURIValue', // Special uri type
@@ -263,7 +263,7 @@
'_qty' => SMWDataItem::TYPE_NUMBER, // Type for
numbers with units of measurement
// Special types are not avaialble directly for users
(and have no local language name):
'__typ' => SMWDataItem::TYPE_URI, // Special type page
type
- '__tls' => SMWDataItem::TYPE_STRING, // Special type
list for declaring _rec properties
+ '__pls' => SMWDataItem::TYPE_STRING, // Special type
list for decalring _rec properties
'__con' => SMWDataItem::TYPE_CONCEPT, // Special
concept page type
'__sps' => SMWDataItem::TYPE_STRING, // Special string
type
'__spu' => SMWDataItem::TYPE_URI, // Special uri type
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php 2011-05-18
18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php 2011-05-18
19:12:40 UTC (rev 88381)
@@ -164,7 +164,7 @@
$wgAutoloadClasses['SMWPropertyValue'] = $dvDir .
'SMW_DV_Property.php';
$wgAutoloadClasses['SMWURIValue'] = $dvDir .
'SMW_DV_URI.php';
$wgAutoloadClasses['SMWTypesValue'] = $dvDir .
'SMW_DV_Types.php';
- $wgAutoloadClasses['SMWTypeListValue'] = $dvDir .
'SMW_DV_TypeList.php';
+ $wgAutoloadClasses['SMWPropertyListValue'] = $dvDir .
'SMW_DV_PropertyList.php';
$wgAutoloadClasses['SMWNumberValue'] = $dvDir .
'SMW_DV_Number.php';
$wgAutoloadClasses['SMWTemperatureValue'] = $dvDir .
'SMW_DV_Temperature.php';
$wgAutoloadClasses['SMWQuantityValue'] = $dvDir .
'SMW_DV_Quantity.php';
Modified:
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
2011-05-18 18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -330,7 +330,7 @@
'_CONC' => array( '__con', false ), //
associated concept
'_MDAT' => array( '_dat', false ), //
"modification date"
'_ERRP' => array( '_wpp', false ), // "has
improper value for"
- '_LIST' => array( '__tls', true ), // "has
fields"
+ '_LIST' => array( '__pls', true ), // "has
fields"
'_SKEY' => array( '__key', true ), // sort
key of a page
'_SF_DF' => array( '__spf', true ), // Semantic
Form's default form property
'_SF_AF' => array( '__spf', true ), //
Semantic Form's alternate form property
Added:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_PropertyList.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_PropertyList.php
(rev 0)
+++
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_PropertyList.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -0,0 +1,141 @@
+<?php
+/**
+ * @file
+ * @ingroup SMWDataValues
+ */
+
+/**
+ * This datavalue implements special processing suitable for defining the list
+ * of properties that is required for SMWRecordValue objects. The input is a
+ * plain semicolon-separated list of property names, optionally with the
+ * namespace prefix.
+ *
+ * @author Markus Krötzsch
+ * @ingroup SMWDataValues
+ */
+class SMWPropertyListValue extends SMWDataValue {
+
+ /**
+ * List of properte data items that are stored.
+ * @var array of SMWDIProperty
+ */
+ protected $m_diProperties;
+
+ protected function parseUserValue( $value ) {
+ global $wgContLang;
+
+ $this->m_diProperties = array();
+ $stringValue = '';
+ $valueList = preg_split( '/[\s]*;[\s]*/u', trim( $value ) );
+ foreach ( $valueList as $propertyName ) {
+ $propertyNameParts = explode( ':', $propertyName, 2 );
+ if ( count( $propertyNameParts ) > 1 ) {
+ $namespace = smwfNormalTitleText(
$propertyNameParts[0] );
+ $propertyName = $propertyNameParts[1];
+ $propertyNamespace = $wgContLang->getNsText(
SMW_NS_PROPERTY );
+ if ( $namespace != $propertyNamespace ) {
+ smwfLoadExtensionMessages(
'SemanticMediaWiki' );
+ $this->addError( wfMsgForContent(
'smw_wrong_namespace', $propertyNamespace ) );
+ }
+ }
+
+ $propertyName = smwfNormalTitleText( $propertyName );
+
+ try {
+ $diProperty = SMWDIProperty::newFromUserLabel(
$propertyName );
+ } catch ( SMWDataItemException $e ) {
+ $diProperty = new SMWDIProperty( 'Error' );
+ smwfLoadExtensionMessages( 'SemanticMediaWiki'
);
+ $this->addError( wfMsgForContent(
'smw_noproperty', $propertyName ) );
+ }
+
+ $this->m_diProperties[] = $diProperty;
+ $stringValue .= ( $stringValue ? ';' : '' ) .
$diProperty->getKey();
+ }
+
+ try {
+ $this->m_dataitem = new SMWDIString( $stringValue );
+ } catch ( SMWStringLengthException $e ) {
+ $this->m_dataitem = new SMWDIString( 'Error' );
+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
+ $this->addError( wfMsgForContent( 'smw_maxstring',
$stringValue ) );
+ }
+ }
+
+ /**
+ * @see SMWDataValue::loadDataItem()
+ * @param $dataitem SMWDataItem
+ * @return boolean
+ */
+ protected function loadDataItem( SMWDataItem $dataItem ) {
+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
+ $this->m_dataitem = $dataItem;
+ $this->m_diProperties = array();
+ $propertyKeys = explode( ';', $dataItem->getString() );
+ foreach ( $propertyKeys as $propertyKey ) {
+ try {
+ $this->m_diProperties[] = new
SMWDIProperty( $propertyKey );
+ } catch ( SMWDataItemException $e ) {
+ $this->m_diProperties[] = new
SMWDIProperty( 'Error' );
+ smwfLoadExtensionMessages(
'SemanticMediaWiki' );
+ $this->addError( wfMsgForContent(
'smw_parseerror' ) );
+ }
+ }
+ $this->m_caption = false;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function getShortWikiText( $linked = null ) {
+ return ( $this->m_caption !== false ) ? $this->m_caption :
$this->makeOutputText( 2, $linked );
+ }
+
+ public function getShortHTMLText( $linker = null ) {
+ return ( $this->m_caption !== false ) ? $this->m_caption :
$this->makeOutputText( 3, $linker );
+ }
+
+ public function getLongWikiText( $linked = null ) {
+ return $this->makeOutputText( 2, $linked );
+ }
+
+ public function getLongHTMLText( $linker = null ) {
+ return $this->makeOutputText( 3, $linker );
+ }
+
+ public function getWikiValue() {
+ return $this->makeOutputText( 4 );
+ }
+
+ public function getPropertyDataItems() {
+ return $this->m_diProperties;
+ }
+
+////// Internal helper functions
+
+ protected function makeOutputText( $type, $linker = null ) {
+ if ( !$this->isValid() ) {
+ return ( ( $type == 0 ) || ( $type == 1 ) ) ? '' :
$this->getErrorText();
+ }
+ $result = '';
+ $sep = ( $type == 4 ) ? '; ' : ', ';
+ foreach ( $this->m_diProperties as $diProperty ) {
+ if ( $result != '' ) $result .= $sep;
+ $propertyValue = SMWDataValueFactory::newDataItemValue(
$diProperty, null );
+ $result .= $this->makeValueOutputText( $type,
$propertyValue, $linker );
+ }
+ return $result;
+ }
+
+ protected function makeValueOutputText( $type, $propertyValue, $linker
) {
+ switch ( $type ) {
+ case 0: return $propertyValue->getShortWikiText(
$linker );
+ case 1: return $propertyValue->getShortHTMLText(
$linker );
+ case 2: return $propertyValue->getLongWikiText( $linker
);
+ case 3: return $propertyValue->getLongHTMLText( $linker
);
+ case 4: return $propertyValue->getWikiValue();
+ }
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_PropertyList.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
2011-05-18 18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -16,73 +16,78 @@
*/
class SMWRecordValue extends SMWDataValue {
- /// cache for datavalues of types belonging to this object
- private $m_typevalues = null;
+ /// cache for properties for the fields of this data value
+ protected $m_diProperties = null;
protected function parseUserValue( $value ) {
$this->parseUserValueOrQuery( $value, false );
}
- protected function parseUserValueOrQuery( $value, $querymode ) {
+ protected function parseUserValueOrQuery( $value, $queryMode ) {
if ( $value == '' ) {
+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
$this->addError( wfMsg( 'smw_novalues' ) );
- if ( $querymode ) {
+ if ( $queryMode ) {
return new SMWThingDescription();
} else {
return;
}
}
- if ( $querymode ) {
+ if ( $queryMode ) {
$subdescriptions = array();
} else {
$semanticData = new SMWContainerSemanticData();
}
- $types = $this->getTypeValues();
$values = preg_split( '/[\s]*;[\s]*/u', trim( $value ) );
- $vi = 0; // index in value array
+ $valueIndex = 0; // index in value array
+ $propertyIndex = 0; // index in property list
$empty = true;
- for ( $i = 0; $i < max( 5, count( $types ) ); $i++ ) { //
iterate over slots
+ foreach ( $this->getPropertyDataItems() as $diProperty ) {
+ if ( !array_key_exists( $valueIndex, $values ) ) break;
// stop if there are no values left
- if ( $querymode ) { // special handling for supporting
query parsing
+ if ( $queryMode ) { // special handling for supporting
query parsing
$comparator = SMW_CMP_EQ;
- SMWDataValue::prepareValue( $values[$vi],
$comparator );
+ SMWDataValue::prepareValue(
$values[$valueIndex], $comparator );
}
// generating the DVs:
- if ( ( count( $values ) > $vi ) &&
- ( ( $values[$vi] == '' ) || ( $values[$vi] == '?'
) ) ) { // explicit omission
- $vi++;
- } elseif ( array_key_exists( $vi, $values ) &&
array_key_exists( $i, $types ) ) { // some values left, try next slot
- $dataValue =
SMWDataValueFactory::newTypeObjectValue( $types[$i], $values[$vi] );
+ if ( ( $values[$valueIndex] == '' ) || (
$values[$valueIndex] == '?' ) ) { // explicit omission
+ $valueIndex++;
+ } else {
+ $dataValue =
SMWDataValueFactory::newPropertyObjectValue( $diProperty, $values[$valueIndex]
);
if ( $dataValue->isValid() ) { // valid DV: keep
- if ( $querymode ) {
- $subdescriptions[] = new
SMWRecordFieldDescription( $i, new SMWValueDescription(
$dataValue->getDataItem(), $comparator ) );
+ if ( $queryMode ) {
+ $subdescriptions[] = new
SMWSomeProperty( $diProperty, new SMWValueDescription(
$dataValue->getDataItem(), $comparator ) );
} else {
- $property = new SMWDIProperty(
'_' . ( $i + 1 ) );
-
$semanticData->addPropertyObjectValue( $property, $dataValue->getDataItem() );
+
$semanticData->addPropertyObjectValue( $diProperty, $dataValue->getDataItem() );
}
- $vi++;
+ $valueIndex++;
$empty = false;
- } elseif ( ( count( $values ) - $vi ) == (
count( $types ) - $i ) ) {
+ } elseif ( ( count( $values ) - $valueIndex )
== ( count( $this->m_diProperties ) - $propertyIndex ) ) {
// too many errors: keep this one to
have enough slots left
- if ( !$querymode ) {
- $property = new SMWDIProperty(
'_' . ( $i + 1 ) );
-
$semanticData->addPropertyObjectValue( $property, $dataValue->getDataItem() );
+ if ( !$queryMode ) {
+
$semanticData->addPropertyObjectValue( $diProperty, $dataValue->getDataItem() );
}
$this->addError(
$dataValue->getErrors() );
- $vi++;
+ $valueIndex++;
}
}
+ ++$propertyIndex;
}
if ( $empty ) {
+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
$this->addError( wfMsg( 'smw_novalues' ) );
}
- if ( $querymode ) {
- return $empty ? new SMWThingDescription() : new
SMWRecordDescription( $subdescriptions );
+ if ( $queryMode ) {
+ switch ( count( $subdescriptions ) ) {
+ case 0: return new SMWThingDescription();
+ case 1: return reset( $subdescriptions );
+ default: return new SMWConjunction(
$subdescriptions );
+ }
} else {
$this->m_dataitem = new SMWDIContainer( $semanticData,
$this->m_typeid );
}
@@ -146,7 +151,7 @@
*/
public function setProperty( SMWDIProperty $property ) {
parent::setProperty( $property );
- $this->m_typevalues = null;
+ $this->m_diProperties = null;
}
/**
@@ -206,80 +211,50 @@
}
/**
- * Return the array (list) of datatypes that the individual entries of
+ * Return the array (list) of properties that the individual entries of
* this datatype consist of.
*
- * @todo Add some check to account for maximal number of list entries
- * (maybe this should go to a variant of the SMWTypesValue).
* @todo I18N for error message.
- * @return array of SMWTypesValue
+ * @return array of SMWDIProperty
*/
- public function getTypeValues() {
- if ( $this->m_typevalues === null ) {
- $this->m_typevalues = self::findTypeValues(
$this->m_property );
- if ( count( $this->m_typevalues ) == 0 ) { //TODO
internalionalize
- $this->addError( 'List type not properly
specified for this property.' );
+ public function getPropertyDataItems() {
+ if ( $this->m_diProperties === null ) {
+ $this->m_diProperties = self::findPropertyDataItems(
$this->m_property );
+ if ( count( $this->m_diProperties ) == 0 ) { //TODO
internalionalize
+ $this->addError( 'The list of properties to be
used for the data fields has not been specified properly.' );
}
}
- return $this->m_typevalues;
+ return $this->m_diProperties;
}
/**
- * Return the array (list) of datatypes that the individual entries of
+ * Return the array (list) of properties that the individual entries of
* this datatype consist of.
*
- * @param $diProperty SMWDIProperty object for which to retrieve the
types
- * @return array of SMWTypesValue
+ * @param $diProperty mixed null or SMWDIProperty object for which to
retrieve the types
+ * @return array of SMWDIProperty
*/
- public static function findTypeValues( $diProperty ) {
+ public static function findPropertyDataItems( $diProperty ) {
if ( $diProperty !== null ) {
$propertyDiWikiPage = $diProperty->getDiWikiPage();
}
if ( ( $diProperty === null ) || ( $propertyDiWikiPage === null
) ) {
return array(); // no property known -> no types
- } else { // query for type values
+ } else {
$listDiProperty = new SMWDIProperty( '_LIST' );
$dataitems = smwfGetStore()->getPropertyValues(
$propertyDiWikiPage, $listDiProperty );
if ( count( $dataitems ) == 1 ) {
- $typeListValue = new SMWTypeListValue( '__tls'
);
- $typeListValue->setDataItem( reset( $dataitems
) );
- return $typeListValue->getTypeValues();
+ $propertyListValue = new SMWPropertyListValue(
'__pls' );
+ $propertyListValue->setDataItem( reset(
$dataitems ) );
+ return $propertyListValue->isvalid() ?
$propertyListValue->getPropertyDataItems() : array();
} else {
return array();
}
}
}
- /**
- * Return the array (list) of datatype ID that the individual entries
- * of this datatype consist of.
- *
- * @note The architecture of Records and their types is flawed and needs
- * improvement. The below code duplicates internals of SMWTypeListValue,
- * but we do not care about this now.
- * @param $diProperty SMWDIProperty object for which to retrieve the
types
- * @return array of string
- */
- public static function findTypeIds( $diProperty ) {
- if ( $diProperty !== null ) {
- $propertyDiWikiPage = $diProperty->getDiWikiPage();
- }
-
- if ( ( $diProperty === null ) || ( $propertyDiWikiPage === null
) ) {
- return array(); // no property known -> no types
- } else { // query for type values
- $listDiProperty = new SMWDIProperty( '_LIST' );
- $dataitems = smwfGetStore()->getPropertyValues(
$propertyDiWikiPage, $listDiProperty );
- if ( count( $dataitems ) == 1 ) {
- return explode( ';', reset( $dataitems
)->getString() );
- } else {
- return array();
- }
- }
- }
-
////// Internal helper functions
protected function makeOutputText( $type = 0, $linker = null ) {
@@ -288,17 +263,18 @@
}
$result = '';
- for ( $i = 0; $i < count( $this->getTypeValues() ); $i++ ) {
+ $i = 0;
+ foreach ( $this->getPropertyDataItems() as $propertyDataItem ) {
if ( $i == 1 ) {
$result .= ( $type == 4 ) ? '; ' : ' (';
} elseif ( $i > 1 ) {
$result .= ( $type == 4 ) ? '; ' : ', ';
}
- $property = new SMWDIProperty( '_' . ( $i + 1 ) );
- $propertyvalues =
$this->m_dataitem->getSemanticData()->getPropertyValues( $property ); //
combining this with next line violates PHP strict standards
- $dataItem = reset( $propertyvalues );
+ ++$i;
+ $propertyValues =
$this->m_dataitem->getSemanticData()->getPropertyValues( $propertyDataItem );
// combining this with next line violates PHP strict standards
+ $dataItem = reset( $propertyValues );
if ( $dataItem !== false ) {
- $dataValue =
SMWDataValueFactory::newDataItemValue( $dataItem, $property );
+ $dataValue =
SMWDataValueFactory::newDataItemValue( $dataItem, $propertyDataItem );
$result .= $this->makeValueOutputText( $type,
$dataValue, $linker );
} else {
$result .= '?';
Deleted:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
2011-05-18 18:45:39 UTC (rev 88380)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
2011-05-18 19:12:40 UTC (rev 88381)
@@ -1,125 +0,0 @@
-<?php
-/**
- * @file
- * @ingroup SMWDataValues
- */
-
-/**
- * This datavalue implements special processing suitable for defining the list
- * of types that is required for SMWRecordValue objects. The input is a plain
- * semicolon-separated list of type labels.
- *
- * @author Markus Krötzsch
- * @ingroup SMWDataValues
- */
-class SMWTypeListValue extends SMWDataValue {
-
- /**
- * List of type data value objects corresponding to the stored data.
- * @var array of SMWTypesValue
- */
- protected $m_typevalues;
-
- protected function parseUserValue( $value ) {
- $this->m_typevalues = array();
- $types = explode( ';', $value );
- foreach ( $types as $type ) {
- $tval = SMWDataValueFactory::newTypeIDValue( '__typ',
$type );
- $this->m_typevalues[] = $tval;
- }
- $this->setDataItemFromTypeValues();
- }
-
- /**
- * @see SMWDataValue::setDataItem()
- * @param $dataitem SMWDataItem
- * @return boolean
- */
- protected function loadDataItem( SMWDataItem $dataItem ) {
- if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
- $this->m_dataitem = $dataItem;
- $this->m_typevalues = array();
- $ids = explode( ';', $dataItem->getString() );
- foreach ( $ids as $id ) {
- $this->m_typevalues[] =
SMWDataValueFactory::newTypeIDValue( '__typ',
SMWDataValueFactory::findTypeLabel( $id ) );
- }
- $this->m_caption = false;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * The special feature of this implementation of getDBkeys is that it
uses
- * internal type ids to obtain a short internal value for the type. Note
- * that this also given language independence but that this is of little
- * use: if the value is given in another language in the wiki, then
either
- * the value is still understood, or the language-independent database
- * entry is only of temporary use until someone edits the respective
page.
- */
- protected function setDataItemFromTypeValues() {
- $stringvalue = '';
- foreach ( $this->m_typevalues as $tv ) {
- if ( $stringvalue != '' ) $stringvalue .= ';';
- $stringvalue .= $tv->getDBkey();
- }
- try {
- $this->m_dataitem = new SMWDIString( $stringvalue,
$this->m_typeid );
- } catch ( SMWStringLengthException $e ) {
- smwfLoadExtensionMessages( 'SemanticMediaWiki' );
- $this->addError( wfMsgForContent( 'smw_maxstring', '"'
. $stringvalue . '"' ) );
- $this->m_dataitem = new SMWDIString( 'ERROR',
$this->m_typeid );
- }
- }
-
- public function getShortWikiText( $linked = null ) {
- return ( $this->m_caption !== false ) ? $this->m_caption :
$this->makeOutputText( 0, $linked );
- }
-
- public function getShortHTMLText( $linker = null ) {
- return ( $this->m_caption !== false ) ? $this->m_caption :
$this->makeOutputText( 1, $linker );
- }
-
- public function getLongWikiText( $linked = null ) {
- return $this->makeOutputText( 2, $linked );
- }
-
- public function getLongHTMLText( $linker = null ) {
- return $this->makeOutputText( 3, $linker );
- }
-
- public function getWikiValue() {
- return $this->makeOutputText( 4 );
- }
-
- public function getTypeValues() {
- return $this->m_typevalues;
- }
-
-////// Internal helper functions
-
- protected function makeOutputText( $type = 0, $linker = null ) {
- if ( !$this->isValid() ) {
- return ( ( $type == 0 ) || ( $type == 1 ) ) ? '' :
$this->getErrorText();
- }
- $result = '';
- $sep = ( $type == 4 ) ? '; ' : ', ';
- foreach ( $this->m_typevalues as $tv ) {
- if ( $result != '' ) $result .= $sep;
- $result .= $this->makeValueOutputText( $type, $tv,
$linker );
- }
- return $result;
- }
-
- protected function makeValueOutputText( $type, $datavalue, $linker ) {
- switch ( $type ) {
- case 0: return $datavalue->getShortWikiText( $linker );
- case 1: return $datavalue->getShortHTMLText( $linker );
- case 2: return $datavalue->getLongWikiText( $linker );
- case 3: return $datavalue->getLongHTMLText( $linker );
- case 4: return $datavalue->getWikiValue();
- }
- }
-
-}
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs