From 8e708175c1b406785e2a2847db41dcbc0cd53a40 Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Sat, 29 Nov 2014 01:57:54 +0100 Subject: [PATCH] Remove usages of deprecated code and bad assumptions from RdfBuilder Change-Id: I47c99c5c73aa4d555d8b1edb948477d68ba1f65a --- repo/includes/rdf/RdfBuilder.php | 45 +++++++++++++++++++------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/repo/includes/rdf/RdfBuilder.php b/repo/includes/rdf/RdfBuilder.php index e966f626ee..8c30ab21fc 100644 --- a/repo/includes/rdf/RdfBuilder.php +++ b/repo/includes/rdf/RdfBuilder.php @@ -11,9 +11,12 @@ use Wikibase\DataModel\Claim\Claim; use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; +use Wikibase\DataModel\SiteLink; use Wikibase\DataModel\Snak\PropertyValueSnak; +use Wikibase\DataModel\StatementListProvider; use Wikibase\Lib\Store\EntityLookup; /** @@ -337,7 +340,10 @@ public function addAliases( Entity $entity ) { public function addSiteLinks( Item $item ) { $entityResource = $this->getEntityResource( $item->getId() ); - foreach ( $item->getSiteLinks() as $siteLink ) { + /** + * @var SiteLink $siteLink + */ + foreach ( $item->getSiteLinkList() as $siteLink ) { $site = $this->sites->getSite( $siteLink->getSiteId() ); $languageCode = $site->getLanguageCode(); @@ -360,23 +366,26 @@ public function addSiteLinks( Item $item ) { /** * Adds all Claims/Statements from the given entity to the RDF graph. * - * @param Entity $entity + * @param EntityDocument $entity */ - public function addClaims( Entity $entity ) { - /* @var Claim $claim */ - foreach( $entity->getClaims() as $claim ) { - $this->addClaim( $entity, $claim ); + public function addClaims( EntityDocument $entity ) { + $id = $entity->getId(); + + if ( $entity instanceof StatementListProvider ) { + foreach ( $entity->getStatements() as $statement ) { + $this->addClaim( $id, $statement ); + } } } /** * Adds the given Claim from the given Entity to the RDF graph. * - * @param Entity $entity - * @param Claim $claim + * @param EntityId $entityId + * @param Claim $claim */ - public function addClaim( Entity $entity, Claim $claim ) { - $this->addMainSnak( $entity, $claim ); + private function addClaim( EntityId $entityId, Claim $claim ) { + $this->addMainSnak( $entityId, $claim ); //TODO: add qualifiers //TODO: add references @@ -385,14 +394,14 @@ public function addClaim( Entity $entity, Claim $claim ) { /** * Adds the given Claim's main Snak to the RDF graph. * - * @param Entity $entity - * @param Claim $claim + * @param EntityId $entityId + * @param Claim $claim */ - public function addMainSnak( Entity $entity, Claim $claim ) { + private function addMainSnak( EntityId $entityId, Claim $claim ) { $snak = $claim->getMainSnak(); if ( $snak instanceof PropertyValueSnak ) { - $this->addPropertyValueSnak( $entity, $claim, $snak ); + $this->addPropertyValueSnak( $entityId, $claim, $snak ); } else { //TODO: NoValueSnak, SomeValueSnak wfDebug( __METHOD__ . ": Unsupported snak type: " . get_class( $snak ) ); @@ -415,12 +424,12 @@ public function getStatementResource( Claim $claim ) { /** * Adds the given PropertyValueSnak to the RDF graph. * - * @param Entity $entity + * @param EntityId $entityId * @param PropertyValueSnak $snak - * @param Claim $claim + * @param Claim $claim */ - public function addPropertyValueSnak( Entity $entity, Claim $claim, PropertyValueSnak $snak ) { - $entityResource = $this->getEntityResource( $entity->getId() ); + private function addPropertyValueSnak( EntityId $entityId, Claim $claim, PropertyValueSnak $snak ) { + $entityResource = $this->getEntityResource( $entityId ); $propertyId = $claim->getMainSnak()->getPropertyId(); $propertyQName = $this->getEntityQName( self::NS_ENTITY, $propertyId );