/** * @since 0.2 * * @param Term $label * @param EntityId|Item|Property|SiteLink $target * @param EditInfo|null $editInfo * * @return bool */ public function set(Term $label, $target, EditInfo $editInfo = null) { $this->throwExceptionsOnBadTarget($target); $params = $this->getTargetParamsFromTarget($this->getEntityIdentifierFromTarget($target)); $params['language'] = $label->getLanguageCode(); $params['value'] = $label->getText(); $this->api->postRequest('wbsetlabel', $params, $editInfo); return true; }
/** * @param Term $term * * @return array */ private function getSerialized(Term $term) { $result = array('language' => $term->getLanguageCode(), 'value' => $term->getText()); if ($term instanceof TermFallback) { $result['language'] = $term->getActualLanguageCode(); $result['source'] = $term->getSourceLanguageCode(); } return $result; }
protected function buildRequest(Term $term, $entityType) { return new SimpleRequest('wbsearchentities', array('search' => $term->getText(), 'language' => $term->getLanguageCode(), 'type' => $entityType, 'limit' => 50)); }
private function buildGetEntityIdForTermQuery(Term $term) { $expr = new Expr(); $expr->field('sterms.' . $term->getLanguageCode())->equals($this->documentBuilder->cleanTextForSearch($term->getText())); return $expr->getQuery(); }
private function getCacheId(Term $term, $entityType) { return self::CACHE_ID_PREFIX . WIKIBASE_DATAMODEL_VERSION . '-' . $entityType . '-' . $term->getLanguageCode() . '-' . hash('md5', $term->getText()); }
/** * Returns HTML representing the matched term in the search language (or an appropriate fallback). * The matched text and language are wrapped using the wikibase-itemlink-userlang-wrapper message. * If the matched term has the same text as the display label, an empty string is returned. * * @param Term|null $match * @param Term|null $label * * @return string HTML */ private function getMatchHtml(Term $match = null, Term $label = null) { if (!$match) { return ''; } if ($label && $label->getText() == $match->getText()) { return ''; } $text = $match->getText(); $language = $this->languageNameLookup->getName($match->getLanguageCode()); $matchElement = $descriptionElement = Html::element('span', array('class' => 'wb-itemlink-match'), wfMessage('wikibase-itemlink-userlang-wrapper')->params($language, $text)->text()); return $matchElement; }
public function testConstructorSetsFields() { $term = new Term('foo', 'bar'); $this->assertEquals('foo', $term->getLanguageCode()); $this->assertEquals('bar', $term->getText()); }