/**
  * 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);
 }
 /**
  * @param EntityId $entityId
  *
  * @throws LabelDescriptionLookupException
  * @return Term|null
  */
 public function getLabel(EntityId $entityId)
 {
     $fetchLanguages = $this->languageFallbackChain->getFetchLanguageCodes();
     try {
         $labels = $this->termLookup->getLabels($entityId, $fetchLanguages);
     } catch (TermLookupException $ex) {
         throw new LabelDescriptionLookupException($entityId, $ex->getMessage(), $ex);
     }
     return $this->getTermFallback($labels, $fetchLanguages);
 }
 /**
  * @param Title $target
  * @param string &$html
  * @param array &$customAttribs
  * @param RequestContext $context
  */
 public function doOnLinkBegin(Title $target, &$html, array &$customAttribs, RequestContext $context)
 {
     $out = $context->getOutput();
     if (!$this->entityNamespaceLookup->isEntityNamespace($target->getNamespace())) {
         return;
     }
     // Only continue on pages with edit summaries (histories / diffs) or on special pages.
     // Don't run this code when accessing it through the api (eg. for parsing) as the title is
     // set to a special page dummy in api.php, see https://phabricator.wikimedia.org/T111346
     if (defined('MW_API') || !$this->shouldConvert($out->getTitle(), $context)) {
         return;
     }
     $targetText = $target->getText();
     // Handle "fake" titles for new entities as generated by
     // EditEntity::getContextForEditFilter(). For instance, a link to Property:NewProperty
     // would be replaced by a link to Special:NewProperty. This is useful in logs,
     // to indicate that the logged action occurred while creating an entity.
     if (SpecialPageFactory::exists($targetText)) {
         $target = Title::makeTitle(NS_SPECIAL, $targetText);
         $html = Linker::linkKnown($target);
         return;
     }
     if (!$target->exists()) {
         // The link points to a non-existing item.
         return;
     }
     // if custom link text is given, there is no point in overwriting it
     // but not if it is similar to the plain title
     if ($html !== null && $target->getFullText() !== $html) {
         return;
     }
     $entityId = $this->entityIdLookup->getEntityIdForTitle($target);
     if (!$entityId) {
         return;
     }
     // @todo: this re-implements the logic in LanguageFallbackLabelDescriptionLookup,
     // as that didn't support descriptions back when this code was written.
     // NOTE: keep in sync with with fallback languages in LabelPrefetchHookHandler::newFromGlobalState
     try {
         $labels = $this->termLookup->getLabels($entityId, $this->languageFallback->getFetchLanguageCodes());
         $descriptions = $this->termLookup->getDescriptions($entityId, $this->languageFallback->getFetchLanguageCodes());
     } catch (StorageException $ex) {
         // This shouldn't happen if $target->exists() return true!
         return;
     }
     $labelData = $this->getPreferredTerm($labels);
     $descriptionData = $this->getPreferredTerm($descriptions);
     $html = $this->getHtml($target, $labelData);
     $customAttribs['title'] = $this->getTitleAttribute($target, $labelData, $descriptionData);
     // add wikibase styles in all cases, so we can format the link properly:
     $out->addModuleStyles(array('wikibase.common'));
 }