http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88196
Revision: 88196
Author: mkroetzsch
Date: 2011-05-15 17:01:06 +0000 (Sun, 15 May 2011)
Log Message:
-----------
restored basic Type:Record functionality for the SQL store
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStubSemanticData.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
Modified:
trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -27,12 +27,13 @@
* Throws SMWDataItemException if problems occur, to get our callers
* used to it.
*
- * @param $typeid id string for the given type
- * @param $dbkeys array of mixed
+ * @param $typeid string id for the given type
+ * @param $dbkeys array of mixed
+ * @param $diProperty mixed SMWDIProperty or null, the property for
which this value is built, currently needed for records
*
* @return SMWDataItem
*/
- static public function dataItemFromDBKeys( $typeid, $dbkeys ) {
+ static public function dataItemFromDBKeys( $typeid, $dbkeys,
$diProperty = null ) {
switch ( SMWDataValueFactory::getDataItemId( $typeid ) ) {
case SMWDataItem::TYPE_ERROR:
break;
@@ -70,9 +71,30 @@
break;
case SMWDataItem::TYPE_GEO:
return new SMWDIGeoCoord( array( 'lat' =>
(float)$dbkeys[0], 'lon' => (float)$dbkeys[1] ), $typeid );
- break;
case SMWDataItem::TYPE_CONTAINER:
- break;
+ $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 );
+ }
+ }
+ }
+ } 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,
$typeid );
case SMWDataItem::TYPE_WIKIPAGE:
if ( $typeid == '__typ' ) { // DBkeys for types
values are special (used to be a SMWSimpleWikiPageValue)
$pagedbkey = str_replace( ' ', '_',
SMWDataValueFactory::findTypeLabel( $dbkeys[0] ) );
@@ -147,11 +169,11 @@
return array( $dataItem->getKey() );
case '_geo':
$coordinateSet = $dataItem->getCoordinateSet();
-
+
return array(
$coordinateSet['lat'],
$coordinateSet['lon']
- );
+ );
break;
default:
$typeid = $dataItem->getTypeId();
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -63,7 +63,7 @@
/**
* The text label of the respective property or false if none given.
- * @var unknown_type
+ * @var SMWDIProperty
*/
protected $m_property = null;
@@ -74,12 +74,6 @@
protected $m_caption;
/**
- * True if a value was set.
- * @var boolean
- */
- private $m_isset;
-
- /**
* The type id for this value object.
* @var string
*/
@@ -256,7 +250,10 @@
if ( $this->mHasServiceLinks ) {
return;
}
- if ( ( $this->m_property === null ) || (
$this->m_property->getWikiPageValue() === null ) ) {
+ if ( $this->m_property !== null ) {
+ $propertyDiWikiPage =
$this->m_property->getDiWikiPage();
+ }
+ if ( ( $this->m_property === null ) || ( $propertyDiWikiPage
=== null ) ) {
return; // no property known
}
@@ -267,11 +264,12 @@
}
array_unshift( $args, '' ); // add a 0 element as placeholder
- $servicelinks = smwfGetStore()->getPropertyValues(
$this->m_property->getWikiPageValue(), new SMWDIProperty( '_SERV' ) );
+ $servicelinks = smwfGetStore()->getPropertyValues(
$propertyDiWikiPage, new SMWDIProperty( '_SERV' ) );
- foreach ( $servicelinks as $dv ) {
+ foreach ( $servicelinks as $dataItem ) {
smwfLoadExtensionMessages( 'SemanticMediaWiki' );
-
+ $dv = SMWDataValueFactory::newDataItemValue( $dataItem
);
+
$args[0] = 'smw_service_' . str_replace( ' ', '_',
$dv->getWikiValue() ); // messages distinguish ' ' from '_'
$text = call_user_func_array( 'wfMsgForContent', $args
);
$links = preg_split( "/[\n][\s]?/u", $text );
@@ -681,10 +679,11 @@
* text, but no more. Result might have no entries but is always an
array.
*/
public function getInfolinks() {
- if ( $this->isValid() && ( $this->m_property !== null ) && (
$this->m_property->getWikiPageValue() !== null ) ) {
+ if ( $this->isValid() && ( $this->m_property !== null ) ) {
if ( !$this->mHasSearchLink ) { // add default search
link
+ $propertyDataValue =
SMWDataValueFactory::newDataItemValue( $this->m_property );
$this->mHasSearchLink = true;
- $this->m_infolinks[] =
SMWInfolink::newPropertySearchLink( '+', $this->m_property->getWikiValue(),
$this->getWikiValue() );
+ $this->m_infolinks[] =
SMWInfolink::newPropertySearchLink( '+', $propertyDataValue->getWikiValue(),
$this->getWikiValue() );
}
if ( !$this->mHasServiceLinks ) { // add further
service links
@@ -795,12 +794,16 @@
* Creates an error if the value is illegal.
*/
protected function checkAllowedValues() {
- if ( ( $this->m_property === null ) || (
$this->m_property->getDiWikiPage() === null ) || ( !isset( $this->m_dataitem )
) ) {
+ if ( $this->m_property !== null ) {
+ $propertyDiWikiPage =
$this->m_property->getDiWikiPage();
+ }
+
+ if ( ( $this->m_property === null ) || ( $propertyDiWikiPage
=== null ) || ( !isset( $this->m_dataitem ) ) ) {
return; // no property known, or no data to check
}
$allowedvalues = smwfGetStore()->getPropertyValues(
- $this->m_property->getDiWikiPage(),
+ $propertyDiWikiPage,
new SMWDIProperty( '_PVAL' )
);
@@ -835,19 +838,5 @@
);
}
}
-
- /**
- * Returns if the data value holds info about a main object (page)
- * or not (property). This allows query printers to distinguise
- * the main object from properties of type page (count does not
- * suffice as the main object can be omitted using mainlabel=-)
- *
- * @since 1.5.6
- *
- * @return boolean
- */
- public function isMainObject() {
- return $this->m_property == null;
- }
}
\ No newline at end of file
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -59,10 +59,10 @@
* given SMWTypesValue object specifies. If no $value is given, an empty
* container is created, the value of which can be set later on.
*
- * @param SMWTypesValue $typevalue Represents the type of the object
- * @param mixed $value user value string, or false if unknown
- * @param mixed $caption user-defined caption or false if none given
- * @param SMWDIProperty $property property object for which this value
was made, or null
+ * @param $typevalue SMWTypesValue Represents the type of the object
+ * @param $value mixed user value string, or false if unknown
+ * @param $caption mixed user-defined caption or false if none given
+ * @param $property SMWDIProperty property object for which this value
was made, or null
*/
static public function newTypeObjectValue( SMWTypesValue $typeValue,
$value = false, $caption = false, $property = null ) {
if ( !$typeValue->isValid() ) { // just return the error, pass
it through
@@ -112,9 +112,9 @@
/**
* Create a value for a data item.
*
- * @param SMWDataItem $typeid id string for the given type
- * @param mixed $caption user-defined caption, or false if none given
- * @param SMWDIProperty $property property object for which this value
is made, or NULL
+ * @param $typeid SMWDataItem id string for the given type
+ * @param $caption mixed user-defined caption, or false if none given
+ * @param $property SMWDIProperty property object for which this value
is made, or NULL
*
* @return SMWDataValue
*/
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php 2011-05-15
16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php 2011-05-15
17:01:06 UTC (rev 88196)
@@ -87,7 +87,7 @@
}
}
$i += 1;
- $dv =
SMWDataValueFactory::newDataItemValue( $di );
+ $dv =
SMWDataValueFactory::newDataItemValue( $di, false, $propertyDi );
$text .= $dv->getLongWikiText( true ) .
$dv->getInfolinkText( SMW_OUTPUT_WIKI );
}
$text .= '</td></tr>';
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -175,14 +175,14 @@
$ctx = hash_init( 'md5' );
if ( $this->mSubject !== null ) { // here and below, use "_#_"
to separate values; really not much care needed here
- hash_update( $ctx, '_#_' .
$this->mSubject->getSerialisation() );
+ hash_update( $ctx, '_#_' .
$this->mSubject->getSerialization() );
}
foreach ( $this->getProperties() as $property ) {
hash_update( $ctx, '_#_' . $property->getKey() . '##' );
foreach ( $this->getPropertyValues( $property ) as $dv
) {
- hash_update( $ctx, '_#_' .
$dv->getSerialisation() );
+ hash_update( $ctx, '_#_' .
$dv->getSerialization() );
}
}
Modified:
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -32,10 +32,17 @@
*/
public function __construct( $noDuplicates = true ) {
$subject = new SMWDIWikiPage( 'SMWInternalObject', NS_SPECIAL,
'' ); // dummy subject
- parent::__construct( $noDuplicates );
+ parent::__construct( $subject, $noDuplicates );
}
/**
+ * Restore complete serialization which is disabled in SMWSemanticData.
+ */
+ public function __sleep() {
+ return array( 'mSubject', 'mProperties', 'mPropVals',
'mHasVisibleProps', 'mHasVisibleSpecs', 'mNoDuplicates' );
+ }
+
+ /**
* Clone handler. Make any clone mutable again.
*/
public function __clone() {
@@ -127,16 +134,30 @@
}
public function getSerialization() {
- return $this->m_string;
+ return serialize( $this->m_semanticData );
}
/**
+ * Get a hash string for this data item.
+ *
+ * @return string
+ */
+ public function getHash() {
+ return $this->m_semanticData->getHash();
+ }
+
+ /**
* Create a data item from the provided serialization string and type
* ID.
* @return SMWDIContainer
*/
public static function doUnserialize( $serialization, $typeid = '_rec'
) {
- return new SMWDIBlob( $serialization, $typeid );
+ /// TODO May issue an E_NOTICE when problems occur; catch this
+ $data = unserialize( $serialization );
+ if ( !( $data instanceof SMWContainerSemanticData ) ) {
+ throw SMWDataItemException( "Could not unserialize
SMWDIContainer from the given string." );
+ }
+ return new SMWDIContainer( $data, $typeid );
}
}
Modified:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -14,23 +14,7 @@
*/
abstract class SMWContainerValue extends SMWDataValue {
- protected $m_data;
-
- public function __construct( $typeid ) {
- parent::__construct( $typeid );
- $this->m_data = new SMWSemanticData( null );
- }
-
/**
- * We use the internal SMWSemanticData object to store some of this
objects
- * data. Clone it to make sure that data can be modified independelty
from
- * the original object's content.
- */
- public function __clone() {
- $this->m_data = clone $this->m_data; // note that this is
always set
- }
-
- /**
* Containers have one DB key, so the value of this function should be
an array with one
* element. This one DB key should consist of an array of arbitrary
length where each
* entry encodes one property-value pair. The pairs are encoded as
arrays of size two
Modified:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -14,65 +14,95 @@
* @author Markus Krötzsch
* @ingroup SMWDataValues
*/
-class SMWRecordValue extends SMWContainerValue {
+class SMWRecordValue extends SMWDataValue {
/// cache for datavalues of types belonging to this object
private $m_typevalues = null;
protected function parseUserValue( $value ) {
- $this->m_data->clear();
$this->parseUserValueOrQuery( $value, false );
}
protected function parseUserValueOrQuery( $value, $querymode ) {
if ( $value == '' ) {
$this->addError( wfMsg( 'smw_novalues' ) );
- return $querymode ? new SMWThingDescription() :
$this->m_data;
+ if ( $querymode ) {
+ return new SMWThingDescription();
+ } else {
+ return;
+ }
}
- $subdescriptions = array(); // only used for query mode
+ 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
$empty = true;
for ( $i = 0; $i < max( 5, count( $types ) ); $i++ ) { //
iterate over slots
- // special handling for supporting query parsing
- if ( $querymode ) {
+
+ if ( $querymode ) { // special handling for supporting
query parsing
$comparator = SMW_CMP_EQ;
SMWDataValue::prepareValue( $values[$vi],
$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
- $dv = SMWDataValueFactory::newTypeObjectValue(
$types[$i], $values[$vi] );
- if ( $dv->isValid() ) { // valid DV: keep
+ $dataValue =
SMWDataValueFactory::newTypeObjectValue( $types[$i], $values[$vi] );
+ if ( $dataValue->isValid() ) { // valid DV: keep
if ( $querymode ) {
- $subdescriptions[] = new
SMWRecordFieldDescription( $i, new SMWValueDescription( $dv, $comparator ) );
+ $subdescriptions[] = new
SMWRecordFieldDescription( $i, new SMWValueDescription(
$dataValue->getDataItem(), $comparator ) );
} else {
$property = new SMWDIProperty(
'_' . ( $i + 1 ) );
-
$this->m_data->addPropertyObjectValue( $property, $dv );
+
$semanticData->addPropertyObjectValue( $property, $dataValue->getDataItem() );
}
$vi++;
$empty = false;
} elseif ( ( count( $values ) - $vi ) == (
count( $types ) - $i ) ) {
// too many errors: keep this one to
have enough slots left
- $this->m_data->addPropertyObjectValue(
new SMWDIProperty( '_' . ( $i + 1 ) ), $dv );
- $this->addError( $dv->getErrors() );
+ if ( !$querymode ) {
+ $property = new SMWDIProperty(
'_' . ( $i + 1 ) );
+
$semanticData->addPropertyObjectValue( $property, $dataValue->getDataItem() );
+ }
+ $this->addError(
$dataValue->getErrors() );
$vi++;
}
}
}
+
if ( $empty ) {
$this->addError( wfMsg( 'smw_novalues' ) );
}
+
if ( $querymode ) {
return $empty ? new SMWThingDescription() : new
SMWRecordDescription( $subdescriptions );
+ } else {
+ $this->m_dataitem = new SMWDIContainer( $semanticData,
$this->m_typeid );
}
}
/**
+ * @see SMWDataValue::setDataItem()
+ * @param $dataitem SMWDataItem
+ * @return boolean
+ */
+ public function setDataItem( SMWDataItem $dataItem ) {
+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER ) {
+ $this->m_dataitem = $dataItem;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* This function resembles SMWContainerValue::parseDBkeys() but it
already unstubs
* the values instead of passing on initialisation strings. This is
required since
* the datatype of each entry is not determined by the property here
(since we are
@@ -176,18 +206,23 @@
////// Additional API for value lists
/**
- * Create a list (array with numeric keys) containing the datavalue
objects
- * that this SMWRecordValue object holds. Values that are not present
are
- * set to null. Note that the first index in the array is 0, not 1.
+ * Create a list (array with numeric keys) containing the datavalue
+ * objects that this SMWRecordValue object holds. Values that are not
+ * present are set to null. Note that the first index in the array is
+ * 0, not 1.
+ *
+ * @todo This method should be renamed to getDataItems().
+ * @return array of SMWDataItem
*/
public function getDVs() {
if ( !$this->isValid() ) return array();
$result = array();
- foreach ( $this->m_data->getProperties() as $prop ) {
+ $semanticData = $this->m_dataitem->getSemanticData();
+ foreach ( $semanticData->getProperties() as $prop ) {
$propname = $prop->getPropertyID();
$propnum = substr( $propname, 1 );
if ( ( $propname != false ) && ( is_numeric( $propnum )
) ) {
- $propertyvalues =
$this->m_data->getPropertyValues( $prop ); // combining this with next line
violates PHP strict standards
+ $propertyvalues =
$semanticData->getPropertyValues( $prop ); // combining this with next line
violates PHP strict standards
$result[( $propnum - 1 )] = reset(
$propertyvalues );
}
}
@@ -195,60 +230,121 @@
}
/**
- * Return the array (list) of datatypes 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).
+ * Return the array (list) of datatypes 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
*/
public function getTypeValues() {
- if ( $this->m_typevalues !== null ) return $this->m_typevalues;
// local cache
- if ( ( $this->m_property === null ) || (
$this->m_property->getWikiPageValue() === null ) ) {
- $this->m_typevalues = array(); // no property known ->
no types
- } else { // query for type values
- $typelist = smwfGetStore()->getPropertyValues(
$this->m_property->getWikiPageValue(), new SMWDIProperty( '_LIST' ) );
- if ( count( $typelist ) == 1 ) {
- $this->m_typevalues = reset( $typelist
)->getTypeValues();
- } else { ///TODO internalionalize
+ 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.' );
- $this->m_typevalues = array();
}
}
+
return $this->m_typevalues;
}
+ /**
+ * Return the array (list) of datatypes that the individual entries of
+ * this datatype consist of.
+ *
+ * @param $diProperty SMWDIProperty object for which to retrieve the
types
+ * @return array of SMWTypesValue
+ */
+ public static function findTypeValues( $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 ) {
+ $typeListValue = new SMWTypeListValue( '__tls'
);
+ $typeListValue->setDataItem( reset( $dataitems
) );
+ return $typeListValue->getTypeValues();
+ } 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
- private function makeOutputText( $type = 0, $linker = null ) {
+ protected function makeOutputText( $type = 0, $linker = null ) {
if ( !$this->isValid() ) {
return ( ( $type == 0 ) || ( $type == 1 ) ) ? '' :
$this->getErrorText();
}
+
$result = '';
for ( $i = 0; $i < count( $this->getTypeValues() ); $i++ ) {
if ( $i == 1 ) {
- $result .= ( $type == 4 ) ? '; ':' (';
+ $result .= ( $type == 4 ) ? '; ' : ' (';
} elseif ( $i > 1 ) {
- $result .= ( $type == 4 ) ? '; ':", ";
+ $result .= ( $type == 4 ) ? '; ' : ', ';
}
$property = new SMWDIProperty( '_' . ( $i + 1 ) );
- $propertyvalues = $this->m_data->getPropertyValues(
$property ); // combining this with next line violates PHP strict standards
- $dv = reset( $propertyvalues );
- $result .= ( $dv !== false ) ?
$this->makeValueOutputText( $type, $dv, $linker ): '?';
+ $propertyvalues =
$this->m_dataitem->getSemanticData()->getPropertyValues( $property ); //
combining this with next line violates PHP strict standards
+ $dataItem = reset( $propertyvalues );
+ if ( $dataItem !== false ) {
+ $dataValue =
SMWDataValueFactory::newDataItemValue( $dataItem );
+ $result .= $this->makeValueOutputText( $type,
$dataValue, $linker );
+ } else {
+ $result .= '?';
+ }
}
if ( ( $i > 1 ) && ( $type != 4 ) ) $result .= ')';
+
return $result;
}
- private function makeValueOutputText( $type, $datavalue, $linker ) {
+ protected function makeValueOutputText( $type, $dataValue, $linker ) {
switch ( $type ) {
- case 0: return $datavalue->getShortWikiText( $linker );
- case 1: return $datavalue->getShortHTMLText( $linker );
- case 2: return $datavalue->getShortWikiText( $linker );
- case 3: return $datavalue->getShortHTMLText( $linker );
- case 4: return $datavalue->getWikiValue();
+ case 0: return $dataValue->getShortWikiText( $linker );
+ case 1: return $dataValue->getShortHTMLText( $linker );
+ case 2: return $dataValue->getShortWikiText( $linker );
+ case 3: return $dataValue->getShortHTMLText( $linker );
+ case 4: return $dataValue->getWikiValue();
}
}
- public function setDataItem( SMWDataItem $dataItem ) {
- // TODO: Make me do something
+ public function getDBkeys() {
+ return array();// no longer used
}
}
Modified:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -16,7 +16,7 @@
/**
* List of type data value objects corresponding to the stored data.
- * @var array
+ * @var array of SMWTypesValue
*/
protected $m_typevalues;
Modified: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -209,9 +209,9 @@
/**
* @see SMWStore::getPropertyValues
*
- * @param SMWDataItem $subject
- * @param SMWDIProperty $property
- * @param SMWRequestOptions $requestoptions
+ * @param $subject mixed SMWDataItem or null
+ * @param $property SMWDIProperty
+ * @param $requestoptions SMWRequestOptions
*
* @return array of SMWDataItem
*/
@@ -515,17 +515,18 @@
if ( $value instanceof SMWDIContainer ) { // recursive handling
of containers
$joinfield = "t$tableindex." . reset( array_keys(
$proptable->objectfields ) ); // this must be a type 'p' object
$proptables = self::getPropertyTables();
+ $semanticData = $value->getSemanticData();
- foreach ( $value->getData()->getProperties() as
$subproperty ) {
+ foreach ( $semanticData->getProperties() as
$subproperty ) {
$tableid = self::findPropertyTableID(
$subproperty );
if ( ( $tableid == '' ) && ( $value !== null )
) { // maybe a type-polymorphic property like _1; use value to find type
- $tableid = self::findTypeTableID(
reset( $value->getData()->getPropertyValues( $subproperty ) )->getTypeID() );
+ $tableid = self::findTypeTableID(
reset( $semanticData->getPropertyValues( $subproperty ) )->getTypeID() );
}
$subproptable = $proptables[$tableid];
- foreach ( $value->getData()->getPropertyValues(
$subproperty ) as $subvalue ) {
+ foreach ( $semanticData->getPropertyValues(
$subproperty ) as $subvalue ) {
$tableindex++;
if ( $subproptable->idsubject ) { //
simply add property table to check values
@@ -838,8 +839,13 @@
* @param $pageid
*/
protected function prepareDBUpdates( &$updates, SMWSemanticData $data,
$pageid ) {
- $subject = $data->getSubject();
- $sid = ( $subject !== null ) ? $pageid:$this->makeSMWBnodeID(
$pageid );
+ if ( $data instanceof SMWContainerSemanticData ) {
+ $sid = $this->makeSMWBnodeID( $pageid );
+ } else {
+ $subject = $data->getSubject();
+ $sid = $pageid;
+ }
+
$proptables = self::getPropertyTables();
foreach ( $data->getProperties() as $property ) {
@@ -874,7 +880,7 @@
}
if ( $di instanceof SMWDIContainer ) { //
process subobjects recursively
- $bnode = $this->prepareDBUpdates(
$updates, $di->getData(), $pageid );
+ $bnode = $this->prepareDBUpdates(
$updates, $di->getSemanticData(), $pageid );
// Note: tables for container objects
MUST have objectfields == array(<somename> => 'p')
reset( $proptable->objectfields );
$uvals[key( $proptable->objectfields )]
= $bnode;
Modified:
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStubSemanticData.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStubSemanticData.php
2011-05-15 16:59:24 UTC (rev 88195)
+++
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStubSemanticData.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -86,7 +86,7 @@
foreach ( $this->mStubPropVals[$property->getKey()] as
$dbkeys ) {
try {
- $di =
SMWCompatibilityHelpers::dataItemFromDBKeys( $property->findPropertyTypeID(),
$dbkeys );
+ $di =
SMWCompatibilityHelpers::dataItemFromDBKeys( $property->findPropertyTypeID(),
$dbkeys, $property );
if ( $this->mNoDuplicates ) {
$this->mPropVals[$property->getKey()][$di->getHash()] = $di;
} else {
Modified: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
2011-05-15 16:59:24 UTC (rev 88195)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -162,6 +162,12 @@
*
* If called with $subject == null, all values for the given property
* are returned.
+ *
+ * @param $subject mixed SMWDataItem or null
+ * @param $property SMWDIProperty
+ * @param $requestoptions SMWRequestOptions
+ *
+ * @return array of SMWDataItem
*/
public abstract function getPropertyValues( $subject, SMWDIProperty
$property, $requestoptions = null );
Modified:
trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
2011-05-15 16:59:24 UTC (rev 88195)
+++
trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
2011-05-15 17:01:06 UTC (rev 88196)
@@ -153,7 +153,7 @@
// if there are more incoming
values than a certain treshold, display a link to the rest instead
$body .= '<a href="' .
$skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode(
$dvProperty->getWikiValue() ) . '&value=' . urlencode(
$this->subject->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) .
"</a>\n";
} else {
- $dv =
SMWDataValueFactory::newDataItemValue( $di );
+ $dv =
SMWDataValueFactory::newDataItemValue( $di, false, $diProperty );
$body .= "<span class=\"smwb-"
. $inv . "value\">" .
$this->displayValue(
$dvProperty, $dv, $incoming ) . "</span>";
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs