Hoo man has submitted this change and it was merged. Change subject: Stop using Claims and Entity in WikibaseLuaEntityBindings ......................................................................
Stop using Claims and Entity in WikibaseLuaEntityBindings Added to StatementList in https://github.com/wmde/WikibaseDataModel/pull/295 Change-Id: Id223877bc2e740a8af366c1568cc24499479b340 --- M client/includes/scribunto/WikibaseLuaEntityBindings.php 1 file changed, 48 insertions(+), 63 deletions(-) Approvals: Hoo man: Verified; Looks good to me, approved diff --git a/client/includes/scribunto/WikibaseLuaEntityBindings.php b/client/includes/scribunto/WikibaseLuaEntityBindings.php index f90ca80..d0e343d 100644 --- a/client/includes/scribunto/WikibaseLuaEntityBindings.php +++ b/client/includes/scribunto/WikibaseLuaEntityBindings.php @@ -4,14 +4,15 @@ use Language; use Wikibase\Client\Usage\UsageAccumulator; -use Wikibase\DataModel\Claim\Claims; -use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Entity\EntityIdValue; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\DataModel\Snak\Snak; +use Wikibase\DataModel\Statement\Statement; +use Wikibase\DataModel\Statement\StatementList; use Wikibase\DataModel\StatementListProvider; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityLookup; @@ -24,7 +25,6 @@ * @licence GNU GPL v2+ * @author Marius Hoch < [email protected] > */ - class WikibaseLuaEntityBindings { /** @@ -53,7 +53,12 @@ private $language; /** - * @var Entity[] + * @var EntityIdParser + */ + private $entityIdParser; + + /** + * @var EntityDocument[] */ private $entities = array(); @@ -82,13 +87,51 @@ } /** + * Render the main Snaks belonging to a Statement (which is identified by a PropertyId). + * + * @since 0.5 + * @todo Share code with LanguageAwareRenderer. + * + * @param string $entityId + * @param string $propertyId + * @param int[]|null $acceptableRanks + * + * @return string + */ + public function formatPropertyValues( $entityId, $propertyId, array $acceptableRanks = null ) { + $propertyId = new PropertyId( $propertyId ); + + $entity = $this->getEntity( $this->entityIdParser->parse( $entityId ) ); + + if ( !( $entity instanceof StatementListProvider ) ) { + return ''; + } + + $statements = $entity->getStatements()->getWithPropertyId( $propertyId ); + + if ( $acceptableRanks === null ) { + // We only want the best claims over here, so that we only show the most + // relevant information. + $statements = $statements->getBestStatements(); + } else { + // ... unless the user passed in a table of acceptable ranks + $statements = $statements->getWithRank( $acceptableRanks ); + } + + $snakList = $statements->getMainSnaks(); + + $this->trackUsage( $snakList ); + return $this->formatSnakList( $snakList ); + } + + /** * Get the entity for the given EntityId (cached within the class). * This *might* be redundant with caching in EntityLookup, but we * don't want to rely on that (per Daniel). * * @param EntityId $entityId * - * @return Entity|null + * @return EntityDocument|null */ private function getEntity( EntityId $entityId ) { if ( !isset( $this->entities[ $entityId->getSerialization() ] ) ) { @@ -97,21 +140,6 @@ } return $this->entities[ $entityId->getSerialization() ]; - } - - /** - * Returns such Claims from $entity that have a main Snak for the property that - * is specified by $propertyId. - * - * @param StatementListProvider $statementListProvider - * @param PropertyId $propertyId - * - * @return Claims - */ - private function getClaimsForProperty( StatementListProvider $statementListProvider, PropertyId $propertyId ) { - $allClaims = new Claims( $statementListProvider->getStatements() ); - - return $allClaims->getClaimsForProperty( $propertyId ); } /** @@ -159,49 +187,6 @@ $this->usageAccumulator->addLabelUsage( $value->getEntityId() ); } } - } - - /** - * Render the main Snaks belonging to a Claim (which is identified by a PropertyId). - * - * @since 0.5 - * @todo Share code with LanguageAwareRenderer. - * - * @param string $entityId - * @param string $propertyId - * @param int[]|null $acceptableRanks - * - * @return string - */ - public function formatPropertyValues( $entityId, $propertyId, array $acceptableRanks = null ) { - $entityId = $this->entityIdParser->parse( $entityId ); - $propertyId = new PropertyId( $propertyId ); - - $entity = $this->getEntity( $entityId ); - - if ( !( $entity instanceof StatementListProvider ) ) { - return ''; - } - - $claims = $this->getClaimsForProperty( $entity, $propertyId ); - - if ( !$acceptableRanks ) { - // We only want the best claims over here, so that we only show the most - // relevant information. - $claims = $claims->getBestClaims(); - } else { - // ... unless the user passed in a table of acceptable ranks - $claims = $claims->getByRanks( $acceptableRanks ); - } - - if ( $claims->isEmpty() ) { - return ''; - } - - $snakList = $claims->getMainSnaks(); - - $this->trackUsage( $snakList ); - return $this->formatSnakList( $snakList ); } /** -- To view, visit https://gerrit.wikimedia.org/r/174299 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id223877bc2e740a8af366c1568cc24499479b340 Gerrit-PatchSet: 11 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Adrian Lang <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Hoo man <[email protected]> Gerrit-Reviewer: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
