/**
  * @dataProvider getNameProvider
  */
 public function testGetName($lang, $in, $expected)
 {
     if ($in !== null && !\ExtensionRegistry::getInstance()->isLoaded('CLDR')) {
         $this->markTestSkipped('CLDR extension required for full language name support');
     }
     $languageNameLookup = new LanguageNameLookup($in);
     $name = $languageNameLookup->getName($lang);
     $this->assertSame($expected, $name);
 }
 /**
  * @see ValueFormatter::format
  *
  * @param MonolingualTextValue $value
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 public function format($value)
 {
     if (!$value instanceof MonolingualTextValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a MonolingualTextValue.');
     }
     $text = $value->getText();
     $languageCode = $value->getLanguageCode();
     $languageName = $this->languageNameLookup->getName($languageCode);
     $msg = wfMessage('wikibase-monolingualtext')->params(wfEscapeWikiText($text), wfEscapeWikiText($languageCode), wfEscapeWikiText($languageName));
     return $msg->parse();
 }
 /**
  * @param array $siteLinkForTable
  * @param bool $isSpecialGroup
  *
  * @return string
  */
 private function getHtmlForSiteLink($siteLinkForTable, $isSpecialGroup)
 {
     /** @var Site $site */
     $site = $siteLinkForTable['site'];
     /** @var SiteLink $siteLink */
     $siteLink = $siteLinkForTable['siteLink'];
     if ($site->getDomain() === '') {
         return $this->getHtmlForUnknownSiteLink($siteLink);
     }
     $languageCode = $site->getLanguageCode();
     $siteId = $siteLink->getSiteId();
     // FIXME: this is a quickfix to allow a custom site-name for the site groups which are
     // special according to the specialSiteLinkGroups setting
     if ($isSpecialGroup) {
         // FIXME: not escaped?
         $siteNameMsg = wfMessage('wikibase-sitelinks-sitename-' . $siteId);
         $siteName = $siteNameMsg->exists() ? $siteNameMsg->parse() : $siteId;
     } else {
         // TODO: get an actual site name rather then just the language
         $siteName = htmlspecialchars($this->languageNameLookup->getName($languageCode));
     }
     // TODO: for non-JS, also set the dir attribute on the link cell;
     // but do not build language objects for each site since it causes too much load
     // and will fail when having too much site links
     return $this->templateFactory->render('wikibase-sitelinkview', htmlspecialchars($siteId), $languageCode, 'auto', htmlspecialchars($siteId), $siteName, $this->getHtmlForPage($siteLink, $site));
 }
 private function getHtmlForFallbackIndicator(TermFallback $term)
 {
     $requestedLanguage = $term->getLanguageCode();
     $actualLanguage = $term->getActualLanguageCode();
     $sourceLanguage = $term->getSourceLanguageCode();
     // FIXME: TermFallback should either return equal values or null
     $sourceLanguage = $sourceLanguage === null ? $actualLanguage : $sourceLanguage;
     $isInRequestedLanguage = $actualLanguage === $requestedLanguage;
     $isInSourceLanguage = $actualLanguage === $sourceLanguage;
     if ($isInRequestedLanguage && $isInSourceLanguage) {
         // This is neither a fallback nor a transliteration
         return '';
     }
     $sourceLanguageName = $this->languageNameLookup->getName($sourceLanguage);
     $actualLanguageName = $this->languageNameLookup->getName($actualLanguage);
     // Generate indicator text
     if ($isInSourceLanguage) {
         $text = $sourceLanguageName;
     } else {
         $text = wfMessage('wikibase-language-fallback-transliteration-hint', $sourceLanguageName, $actualLanguageName)->text();
     }
     // Generate HTML class names
     $classes = 'wb-language-fallback-indicator';
     if (!$isInSourceLanguage) {
         $classes .= ' wb-language-fallback-transliteration';
     }
     if (!$isInRequestedLanguage && $this->getBaseLanguage($actualLanguage) === $this->getBaseLanguage($requestedLanguage)) {
         $classes .= ' wb-language-fallback-variant';
     }
     $attributes = array('class' => $classes);
     $html = Html::element('sup', $attributes, $text);
     return $html;
 }
 /**
  * @param Fingerprint $fingerprint
  * @param string $languageCode
  * @param Title|null $title
  *
  * @return string HTML
  */
 private function getEntityTermsForLanguageView(Fingerprint $fingerprint, $languageCode, Title $title = null)
 {
     $languageName = $this->languageNameLookup->getName($languageCode);
     $labels = $fingerprint->getLabels();
     $descriptions = $fingerprint->getDescriptions();
     $hasLabel = $labels->hasTermForLanguage($languageCode);
     $hasDescription = $descriptions->hasTermForLanguage($languageCode);
     return $this->templateFactory->render('wikibase-entitytermsforlanguageview', 'tr', 'td', $languageCode, $this->templateFactory->render('wikibase-entitytermsforlanguageview-language', htmlspecialchars($title === null ? '#' : $title->getLocalURL(array('setlang' => $languageCode))), htmlspecialchars($languageName)), $this->templateFactory->render('wikibase-labelview', $hasLabel ? '' : 'wb-empty', htmlspecialchars($hasLabel ? $labels->getByLanguage($languageCode)->getText() : $this->msg('wikibase-label-empty')->text()), ''), $this->templateFactory->render('wikibase-descriptionview', $hasDescription ? '' : 'wb-empty', htmlspecialchars($hasDescription ? $descriptions->getByLanguage($languageCode)->getText() : $this->msg('wikibase-description-empty')->text()), '', ''), $this->getAliasesView($fingerprint->getAliasGroups(), $languageCode), '');
 }
 /**
  * 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;
 }
 /**
  * @param MediaWikiSite $site
  * @param string[] $specialGroups
  *
  * @return string[]
  */
 private function getSiteDetails(MediaWikiSite $site, array $specialGroups)
 {
     $languageNameLookup = new LanguageNameLookup();
     $group = $site->getGroup();
     // FIXME: quickfix to allow a custom site-name / handling for the site groups which are
     // special according to the specialSiteLinkGroups setting
     if (in_array($group, $specialGroups)) {
         $languageNameMsg = wfMessage('wikibase-sitelinks-sitename-' . $site->getGlobalId());
         $languageName = $languageNameMsg->exists() ? $languageNameMsg->parse() : $site->getGlobalId();
         $groupName = 'special';
     } else {
         $languageName = $languageNameLookup->getName($site->getLanguageCode());
         $groupName = $group;
     }
     // Use protocol relative URIs, as it's safe to assume that all wikis support the same protocol
     list($pageUrl, $apiUrl) = preg_replace("/^https?:/i", '', array($site->getPageUrl(), $site->getFileUrl('api.php')));
     //TODO: figure out which name is best
     //$localIds = $site->getLocalIds();
     //$name = empty( $localIds['equivalent'] ) ? $site->getGlobalId() : $localIds['equivalent'][0];
     return array('shortName' => $languageName, 'name' => $languageName, 'id' => $site->getGlobalId(), 'pageUrl' => $pageUrl, 'apiUrl' => $apiUrl, 'languageCode' => $site->getLanguageCode(), 'group' => $groupName);
 }