private function replaceBadgeItemsInSiteLink(SiteLink $siteLink)
 {
     $newBadges = array();
     foreach ($siteLink->getBadges() as $badge) {
         $localId = $this->entityMappingStore->getLocalId($badge->getSerialization());
         $newBadges[] = new ItemId($localId);
     }
     return new SiteLink($siteLink->getSiteId(), $siteLink->getPageName(), $newBadges);
 }
 /**
  * @since 0.2
  *
  * @param SiteLink $siteLink
  * @param EntityId|Item|Property|SiteLink $target
  * @param EditInfo|null $editInfo
  *
  * @return bool
  */
 public function set(SiteLink $siteLink, $target, EditInfo $editInfo = null)
 {
     $this->throwExceptionsOnBadTarget($target);
     $params = $this->getTargetParamsFromTarget($this->getEntityIdentifierFromTarget($target));
     $params['linksite'] = $siteLink->getSiteId();
     $params['linktitle'] = $siteLink->getPageName();
     $params['badges'] = implode('|', $siteLink->getBadges());
     $this->api->postRequest('wbsetsitelink', $params, $editInfo);
     return true;
 }
 private function getHtmlForBadges(SiteLink $siteLink)
 {
     $html = '';
     foreach ($siteLink->getBadges() as $badge) {
         $serialization = $badge->getSerialization();
         $classes = Sanitizer::escapeClass($serialization);
         if (!empty($this->badgeItems[$serialization])) {
             $classes .= ' ' . Sanitizer::escapeClass($this->badgeItems[$serialization]);
         }
         $html .= $this->templateFactory->render('wb-badge', $classes, $this->entityIdFormatter->formatEntityId($badge), $badge);
     }
     return $this->templateFactory->render('wikibase-badgeselector', $html);
 }
 private function generateSitelinksChangeOpsWithConflict(SiteLink $fromSiteLink)
 {
     $siteId = $fromSiteLink->getSiteId();
     $toSiteLink = $this->toItem->getSiteLink($siteId);
     $fromPageName = $fromSiteLink->getPageName();
     $toPageName = $toSiteLink->getPageName();
     if ($fromPageName !== $toPageName) {
         $site = $this->getSite($siteId);
         $fromPageName = $site->normalizePageName($fromPageName);
         $toPageName = $site->normalizePageName($toPageName);
     }
     if ($fromPageName === $toPageName) {
         $this->fromChangeOps->add($this->getSiteLinkChangeOpFactory()->newRemoveSiteLinkOp($siteId));
         $this->toChangeOps->add($this->getSiteLinkChangeOpFactory()->newSetSiteLinkOp($siteId, $fromPageName, array_unique(array_merge($fromSiteLink->getBadges(), $toSiteLink->getBadges()))));
     } elseif (!in_array('sitelink', $this->ignoreConflicts)) {
         throw new ChangeOpException("Conflicting sitelinks for {$siteId}");
     }
 }
 private function getSerialized(SiteLink $siteLink)
 {
     return array('site' => $siteLink->getSiteId(), 'title' => $siteLink->getPageName(), 'badges' => $this->serializeBadges($siteLink->getBadges()));
 }
Beispiel #6
0
 public function testCanConstructWithItemIdSet()
 {
     $badgesArray = array(new ItemId('Q36'), new ItemId('Q149'));
     $badges = new ItemIdSet($badgesArray);
     $siteLink = new SiteLink('foo', 'bar', $badges);
     $this->assertEquals($badgesArray, $siteLink->getBadges());
 }
 /**
  * @param SiteLink $siteLink
  */
 public function processSiteLink(SiteLink $siteLink)
 {
     foreach ($siteLink->getBadges() as $badge) {
         $this->entityIds[$badge->getSerialization()] = $badge;
     }
 }