/** * @see SnakFormatter::format * * Formats the given Snak as an wikitext link to an authoritative resource. * The URL of that link is determined using a SnakUrlExpander. * If the snak could not be expanded into a URL, the identifier is returned as simple text. * * @param Snak $snak * * @throws ParameterTypeException if $snak is not a PropertyValueSnak, or if $snak->getDataValue() * does not return a StringValue. * @return string Wikitext */ public function formatSnak(Snak $snak) { Assert::parameterType('Wikibase\\DataModel\\Snak\\PropertyValueSnak', $snak, '$snak'); /** @var PropertyValueSnak $snak */ $id = $snak->getDataValue()->getValue(); $url = $this->urlExpander->expandUrl($snak); if ($url === null) { return wfEscapeWikiText($id); } else { return '[' . $this->escapeWikitextInUrl($url) . ' ' . wfEscapeWikiText($id) . ']'; } }
/** * @see SnakFormatter::format * * Formats the given Snak's value as a HTML link. * The URL of that link is determined using a SnakUrlExpander. * If the snak could not be expanded into a URL, the identifier is returned as simple text. * * @param Snak $snak * * @throws ParameterTypeException if $snak is not a PropertyValueSnak, or if $snak->getDataValue() * does not return a StringValue. * @return string HTML */ public function formatSnak(Snak $snak) { Assert::parameterType('Wikibase\\DataModel\\Snak\\PropertyValueSnak', $snak, '$snak'); /** @var PropertyValueSnak $snak */ $id = $snak->getDataValue()->getValue(); $url = $this->urlExpander->expandUrl($snak); $attr = array('class' => 'wb-external-id'); if ($url === null) { return Html::element('span', $attr, $id); } else { $attr['href'] = $url; return Html::element('a', $attr, $id); } }