/** * @see ValueFormatter::format * * Format an EntityIdValue * * @since 0.5 * * @param EntityIdValue $value * * @throws InvalidArgumentException * @return string Either plain text, wikitext or HTML, depending on the EntityIdFormatter * provided. */ public function format($value) { if (!$value instanceof EntityIdValue) { throw new InvalidArgumentException('Data value type mismatch. Expected an EntityIdValue.'); } return $this->entityIdFormatter->formatEntityId($value->getEntityId()); }
private function formatIfEntityId($value) { try { return $this->idFormatter->formatEntityId($this->idParser->parse($value)); } catch (EntityIdParsingException $ex) { return $value; } }
/** * @param string $idString * * @return string HTML */ private function getBadgeLinkElement($idString) { try { $itemId = new ItemId($idString); } catch (InvalidArgumentException $ex) { return htmlspecialchars($idString); } return $this->entityIdFormatter->formatEntityId($itemId); }
/** * Formats a row for display. * * @param PropertyId $propertyId * * @return string */ protected function formatRow($propertyId) { $title = $this->titleLookup->getTitleForId($propertyId); if (!$title->exists()) { return $this->entityIdFormatter->formatEntityId($propertyId); } $labelTerm = $this->labelDescriptionLookup->getLabel($propertyId); $row = Html::rawElement('a', array('title' => $title ? $title->getPrefixedText() : $propertyId->getSerialization(), 'href' => $title ? $title->getLocalURL() : ''), Html::rawElement('span', array('class' => 'wb-itemlink'), Html::element('span', array('class' => 'wb-itemlink-label', 'lang' => $labelTerm ? $labelTerm->getLanguageCode() : ''), $labelTerm ? $labelTerm->getText() : '') . ($labelTerm ? ' ' : '') . Html::element('span', array('class' => 'wb-itemlink-id'), '(' . $propertyId->getSerialization() . ')'))); return $row; }
private function getHtmlForBadges(SiteLink $siteLink) { $html = ''; foreach ($siteLink->getBadges() as $badge) { $serialization = $badge->getSerialization(); $classes = Sanitizer::escapeClass($serialization); if (!empty($this->badgeItems[$serialization])) { $classes .= ' ' . Sanitizer::escapeClass($this->badgeItems[$serialization]); } $html .= $this->templateFactory->render('wb-badge', $classes, $this->entityIdFormatter->formatEntityId($badge), $badge); } return $this->templateFactory->render('wikibase-badgeselector', $html); }
/** * @param Snak $snak * * @return string */ private function makePropertyLink(Snak $snak) { $propertyId = $snak->getPropertyId(); $propertyLink = $this->propertyIdFormatter->formatEntityId($propertyId); return $propertyLink; }
/** * @param Statement[] $statements * * @return string HTML */ private function getHtmlForStatementGroupView(array $statements) { $propertyId = $statements[0]->getMainSnak()->getPropertyId(); $addStatementHtml = $this->editSectionGenerator->getAddStatementToGroupSection($propertyId); return $this->templateFactory->render('wikibase-statementgroupview', $this->propertyIdFormatter->formatEntityId($propertyId), $this->getHtmlForStatementListView($statements, $addStatementHtml), $propertyId->getSerialization()); }
/** * @param EntityId $entityId * * @return string The formatted ID (as a wikitext link). */ private function formatEntityId(EntityId $entityId) { return $this->entityIdFormatter->formatEntityId($entityId); }
/** * Format an EntityId * * @param EntityId $value * @return string */ public function formatEntityId(EntityId $value) { $text = $this->formatter->formatEntityId($value); $escaped = call_user_func($this->escapeCallback, $text); return $escaped; }