properties[] = $property; } } } /** * @since 2.5 * * {@inheritDoc} */ public function getProperties() { return $this->properties; } /** * @since 2.5 * * {@inheritDoc} */ public function getValuesFromString( $value ) { // #664 / T17732 $value = str_replace( "\;", "-3B", $value ); // Bug 21926 / T23926 // Values that use html entities are encoded with a semicolon $value = htmlspecialchars_decode( $value, ENT_QUOTES ); $values = preg_split( '/[\s]*;[\s]*/u', trim( $value ) ); return str_replace( "-3B", ";", $values ); } /** * @see DataValue::getShortWikiText * @since 2.5 * * {@inheritDoc} */ public function getShortWikiText( $linker = null ) { return $this->dataValueServiceFactory->getValueFormatter( $this )->format( DataValueFormatter::WIKI_SHORT, $linker ); } /** * @see DataValue::getShortHTMLText * @since 2.5 * * {@inheritDoc} */ public function getShortHTMLText( $linker = null ) { return $this->dataValueServiceFactory->getValueFormatter( $this )->format( DataValueFormatter::HTML_SHORT, $linker ); } /** * @see DataValue::getLongWikiText * @since 2.5 * * {@inheritDoc} */ public function getLongWikiText( $linker = null ) { return $this->dataValueServiceFactory->getValueFormatter( $this )->format( DataValueFormatter::WIKI_LONG, $linker ); } /** * @see DataValue::getLongHTMLText * @since 2.5 * * {@inheritDoc} */ public function getLongHTMLText( $linker = null ) { return $this->dataValueServiceFactory->getValueFormatter( $this )->format( DataValueFormatter::HTML_LONG, $linker ); } /** * @see DataValue::getWikiValue * @since 2.5 * * {@inheritDoc} */ public function getWikiValue() { return $this->dataValueServiceFactory->getValueFormatter( $this )->format( DataValueFormatter::VALUE ); } /** * @since 2.5 * * {@inheritDoc} */ public function getPropertyDataItems() { if ( $this->properties === null ) { $this->properties = $this->getFieldProperties( $this->getProperty() ); if ( count( $this->properties ) == 0 ) { $this->addErrorMsg( [ 'smw-datavalue-reference-invalid-fields-definition' ], Message::PARSE ); } } return $this->properties; } /** * @since 2.5 * * {@inheritDoc} */ public function getDataItems() { return parent::getDataItems(); } /** * @note called by DataValue::setUserValue * @see DataValue::parseUserValue * * {@inheritDoc} */ protected function parseUserValue( $value ) { if ( $value === '' ) { $this->addErrorMsg( [ 'smw_novalues' ] ); return; } $containerSemanticData = $this->newContainerSemanticData( $value ); $sortKeys = []; $values = $this->getValuesFromString( $value ); $index = 0; // index in value array $propertyIndex = 0; // index in property list $empty = true; foreach ( $this->getPropertyDataItems() as $property ) { if ( !array_key_exists( $index, $values ) || $this->getErrors() !== [] ) { break; // stop if there are no values left } // generating the DVs: if ( ( $values[$index] === '' ) || ( $values[$index] == '?' ) ) { // explicit omission $index++; } else { $dataValue = DataValueFactory::getInstance()->newDataValueByProperty( $property, $values[$index], false, $containerSemanticData->getSubject() ); if ( $dataValue->isValid() ) { // valid DV: keep $dataItem = $dataValue->getDataItem(); $containerSemanticData->addPropertyObjectValue( $property, $dataItem ); // Chronological order determined first if ( $dataItem instanceof DITime ) { array_unshift( $sortKeys, $dataItem->getSortKey() ); } else { $sortKeys[] = $dataItem->getSortKey(); } $index++; $empty = false; } elseif ( $index == 0 || ( count( $values ) - $index ) == ( count( $this->properties ) - $propertyIndex ) ) { $containerSemanticData->addPropertyObjectValue( $property, $dataValue->getDataItem() ); $this->addError( $dataValue->getErrors() ); ++$index; } } ++$propertyIndex; } if ( $empty && $this->getErrors() === [] ) { $this->addErrorMsg( [ 'smw_novalues' ] ); } // Remember the data to extend the sortkey $containerSemanticData->setExtensionData( 'sort.data', implode( ';', $sortKeys ) ); $this->m_dataitem = new DIContainer( $containerSemanticData ); } /** * @see DataValue::loadDataItem */ protected function loadDataItem( DataItem $dataItem ) { if ( $dataItem->getDIType() === DataItem::TYPE_CONTAINER ) { $this->m_dataitem = $dataItem; return true; } elseif ( $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE ) { $semanticData = new ContainerSemanticData( $dataItem ); $semanticData->copyDataFrom( ApplicationFactory::getInstance()->getStore()->getSemanticData( $dataItem ) ); $this->m_dataitem = new DIContainer( $semanticData ); return true; } return false; } private function newContainerSemanticData( $value ) { if ( $this->m_contextPage === null ) { $containerSemanticData = ContainerSemanticData::makeAnonymousContainer(); $containerSemanticData->skipAnonymousCheck(); } else { $subobjectName = '_REF' . md5( $value ); $subject = new DIWikiPage( $this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName ); $containerSemanticData = new ContainerSemanticData( $subject ); } return $containerSemanticData; } }