public function testNewLabelDescriptionLookup()
 {
     $factory = new LanguageFallbackLabelDescriptionLookupFactory(new LanguageFallbackChainFactory(), $this->getTermLookupMock(), $this->getTermBufferMock());
     $labelDescriptionLookup = $factory->newLabelDescriptionLookup(Language::factory('en-gb'), array(new ItemId('Q123'), new ItemId('Q456')));
     $label = $labelDescriptionLookup->getLabel(new ItemId('Q123'));
     $this->assertEquals('Q123\'s label', $label->getText());
     $this->assertEquals('en-gb', $label->getLanguageCode());
     $this->assertEquals('en', $label->getActualLanguageCode());
 }
 /**
  * @see DifferenceEngine::__construct
  *
  * @param IContextSource|null $context
  * @param int $old
  * @param int $new
  * @param int $rcid
  * @param bool $refreshCache
  * @param bool $unhide
  */
 public function __construct($context = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false, $unhide = false)
 {
     parent::__construct($context, $old, $new, $rcid, $refreshCache, $unhide);
     $langCode = $this->getLanguage()->getCode();
     //TODO: proper injection
     $options = new FormatterOptions(array(ValueFormatter::OPT_LANG => $langCode));
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $termLookup = new EntityRetrievingTermLookup($wikibaseRepo->getEntityLookup());
     $labelDescriptionLookupFactory = new LanguageFallbackLabelDescriptionLookupFactory($wikibaseRepo->getLanguageFallbackChainFactory(), $termLookup);
     $labelDescriptionLookup = $labelDescriptionLookupFactory->newLabelDescriptionLookup($this->getLanguage(), array());
     $htmlFormatterFactory = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory();
     $this->entityIdFormatter = $htmlFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
     $formatterFactory = $wikibaseRepo->getSnakFormatterFactory();
     $this->detailedSnakFormatter = $formatterFactory->getSnakFormatter(SnakFormatter::FORMAT_HTML_DIFF, $options);
     $this->terseSnakFormatter = $formatterFactory->getSnakFormatter(SnakFormatter::FORMAT_HTML, $options);
     // @fixme inject!
     $this->diffVisualizer = new EntityDiffVisualizer($this->getContext(), new ClaimDiffer(new OrderedListDiffer(new ComparableComparer())), new ClaimDifferenceVisualizer(new DifferencesSnakVisualizer($this->entityIdFormatter, $this->detailedSnakFormatter, $this->terseSnakFormatter, $langCode), $langCode), $wikibaseRepo->getSiteStore(), $this->entityIdFormatter);
 }
 private function getOptionsArray()
 {
     /** @var ItemId[] $badgeItemIds */
     $badgeItemIds = array_map(function ($badgeId) {
         return new ItemId($badgeId);
     }, $this->badgeIds);
     $labelLookup = $this->labelDescriptionLookupFactory->newLabelDescriptionLookup($this->getLanguage(), $badgeItemIds);
     $options = array();
     foreach ($this->badgeIds as $badgeId) {
         $label = $labelLookup->getLabel(new ItemId($badgeId));
         // show plain id if no label has been found
         $label = $label === null ? $badgeId : $label->getText();
         $options[$label] = $badgeId;
     }
     return $options;
 }
 /**
  * Returns the HTML containing a checkbox for each badge.
  *
  * @return string
  */
 private function getHtmlForBadges()
 {
     $options = '';
     /** @var ItemId[] $badgeItemIds */
     $badgeItemIds = array_map(function ($badgeId) {
         return new ItemId($badgeId);
     }, array_keys($this->badgeItems));
     $labelLookup = $this->labelDescriptionLookupFactory->newLabelDescriptionLookup($this->getLanguage(), $badgeItemIds);
     foreach ($badgeItemIds as $badgeId) {
         $idSerialization = $badgeId->getSerialization();
         $name = 'badge-' . $idSerialization;
         $label = $labelLookup->getLabel($badgeId);
         $label = $label === null ? $idSerialization : $label->getText();
         $options .= Html::rawElement('div', array('class' => 'wb-label'), Html::check($name, in_array($idSerialization, $this->badges), array('id' => $name)) . Html::label($label, $name));
     }
     return $options;
 }