/** * @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; }
/** * @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; }
/** * @see Comparable::equals * * @param mixed $target * * @return bool */ public function equals($target) { if ($this === $target) { return true; } return $target instanceof self && parent::equals($target) && $this->actualLanguageCode === $target->actualLanguageCode && $this->sourceLanguageCode === $target->sourceLanguageCode; }
protected function buildRequest(Term $term, $entityType) { return new SimpleRequest('wbsearchentities', array('search' => $term->getText(), 'language' => $term->getLanguageCode(), 'type' => $entityType, 'limit' => 50)); }
/** * @since 0.7.4 * * @param Term $term * * @return boolean */ public function hasTerm(Term $term) { return array_key_exists($term->getLanguageCode(), $this->terms) && $this->terms[$term->getLanguageCode()]->equals($term); }
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 testGivenSimilarFallbackObject_equalsReturnsFalse() { $term = new Term('de', 'foo'); $termFallback = new TermFallback('de', 'foo', 'en', null); $this->assertFalse($term->equals($termFallback)); }