/**
  * Gets all labels of an Entity with the specified EntityId.
  *
  * @param EntityId $entityId
  * @param string[] $languages
  *
  * @throws TermLookupException
  * @return string[]
  */
 public function getLabels(EntityId $entityId, array $languages)
 {
     foreach ($languages as $lang) {
         $this->usageAccumulator->addLabelUsage($entityId, $lang);
     }
     return $this->termLookup->getLabels($entityId, $languages);
 }
 private function testAddAndGetAllUsage()
 {
     $q3 = new ItemId('Q3');
     $this->usageAccumulator->addAllUsage($q3);
     $expected = new EntityUsage($q3, EntityUsage::ALL_USAGE);
     $usages = $this->usageAccumulator->getUsages();
     $this->assertContainsUsage($expected, $usages);
 }
 /**
  * @param string $prefixedEntityId
  *
  * @since 0.5
  * @return string|null Null if no site link found.
  */
 public function getSiteLinkPageName($prefixedEntityId)
 {
     try {
         $itemId = new ItemId($prefixedEntityId);
     } catch (InvalidArgumentException $e) {
         return null;
     }
     // @fixme the SiteLinks do not contain badges! but all we want here is page name.
     $siteLinkRows = $this->siteLinkLookup->getLinks(array($itemId->getNumericId()), array($this->siteId));
     foreach ($siteLinkRows as $siteLinkRow) {
         $siteLink = new SiteLink($siteLinkRow[0], $siteLinkRow[1]);
         $this->usageAccumulator->addTitleUsage($itemId);
         return $siteLink->getPageName();
     }
     return null;
 }
 /**
  * Get entity from prefixed ID (e.g. "Q23") and return it as serialized array.
  *
  * @since 0.5
  *
  * @param string $prefixedEntityId
  *
  * @return array|null
  */
 public function getEntity($prefixedEntityId)
 {
     $prefixedEntityId = trim($prefixedEntityId);
     $entityId = $this->entityIdParser->parse($prefixedEntityId);
     $this->usageAccumulator->addAllUsage($entityId);
     try {
         $entityObject = $this->entityLookup->getEntity($entityId);
     } catch (RevisionedUnresolvedRedirectException $ex) {
         // We probably hit a double redirect
         wfLogWarning('Encountered a UnresolvedRedirectException when trying to load ' . $prefixedEntityId);
         return null;
     }
     if ($entityObject === null) {
         return null;
     }
     $entityArr = $this->newClientEntitySerializer()->serialize($entityObject);
     // Renumber the entity as Lua uses 1-based array indexing
     $this->renumber($entityArr);
     $entityArr['schemaVersion'] = 2;
     return $entityArr;
 }
 /**
  * @param EntityId $id
  */
 private function addLabelUsage(EntityId $id)
 {
     foreach ($this->languages as $lang) {
         $this->usageAccumulator->addLabelUsage($id, $lang);
     }
 }