Ejemplo n.º 1
1
 /**
  * Adds a site link to the list of site links.
  * If there already is a site link with the site id of the provided site link,
  * then that one will be overridden by the provided one.
  *
  * @deprecated since 0.8, use getSiteLinkList()->addSiteLink() instead.
  * @since 0.6
  *
  * @param SiteLink $siteLink
  */
 public function addSiteLink(SiteLink $siteLink)
 {
     if ($this->siteLinks->hasLinkWithSiteId($siteLink->getSiteId())) {
         $this->siteLinks->removeLinkWithSiteId($siteLink->getSiteId());
     }
     $this->siteLinks->addSiteLink($siteLink);
 }
Ejemplo n.º 2
0
 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);
 }
 /**
  * @see SiteLinkLookup::getItemIdForSiteLink
  *
  * @param SiteLink $siteLink
  *
  * @return ItemId|null
  */
 public function getItemIdForSiteLink(SiteLink $siteLink)
 {
     return $this->getItemIdForLink($siteLink->getSiteId(), $siteLink->getPageName());
 }
 /**
  * @param SiteLink $siteLink
  *
  * @return string
  */
 private function getHtmlForUnknownSiteLink($siteLink)
 {
     // FIXME: No need for separate template; Use 'wikibase-sitelinkview' template.
     return $this->templateFactory->render('wikibase-sitelinkview-unknown', htmlspecialchars($siteLink->getSiteId()), htmlspecialchars($siteLink->getPageName()));
 }
 private function makeSiteLinkKey(SiteLink $siteLink)
 {
     return $siteLink->getSiteId() . ':' . $siteLink->getPageName();
 }
Ejemplo n.º 6
0
 /**
  * @param EntityId|SiteLink $target
  *
  * @throws UnexpectedValueException
  * @return array
  *
  * @todo Fix duplicated code
  */
 private function getTargetParamsFromTarget($target)
 {
     if ($target instanceof EntityId) {
         return array('id' => $target->getSerialization());
     } elseif ($target instanceof SiteLink) {
         return array('site' => $target->getSiteId(), 'title' => $target->getPageName());
     } else {
         throw new UnexpectedValueException('$target needs to be an EntityId or SiteLink');
     }
 }
Ejemplo n.º 7
0
 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}");
     }
 }
 /**
  * @param SiteLink $link
  *
  * @return string The formatted link (as a wikitext link).
  */
 private function formatSiteLink(SiteLink $link)
 {
     $siteId = $link->getSiteId();
     $page = $link->getPageName();
     $site = $this->sites->getSite($link->getSiteId());
     $url = $site->getPageUrl($link->getPageName());
     return "[{$url} {$siteId}:{$page}]";
 }
Ejemplo n.º 9
0
 /**
  * @since 2.5
  *
  * @param SiteLink $link
  */
 public function setSiteLink(SiteLink $link)
 {
     $this->siteLinks[$link->getSiteId()] = $link;
 }
Ejemplo n.º 10
0
 /**
  * @since 0.1
  * @param SiteLink $siteLink
  * @returns Revision
  */
 public function getFromSiteLink(SiteLink $siteLink)
 {
     $result = $this->api->getRequest(new SimpleRequest('wbgetentities', array('sites' => $siteLink->getSiteId(), 'titles' => $siteLink->getPageName())));
     return $this->newRevisionFromResult(array_shift($result['entities']));
 }
 /**
  * @see SiteLinkLookup::getItemIdForSiteLink
  *
  * @param SiteLink $siteLink
  *
  * @return ItemId|null
  */
 public function getItemIdForSiteLink(SiteLink $siteLink)
 {
     $siteId = $siteLink->getSiteId();
     $pageName = $siteLink->getPageName();
     return $this->getItemIdForLink($siteId, $pageName);
 }
Ejemplo n.º 12
0
 private function getSerialized(SiteLink $siteLink)
 {
     return array('site' => $siteLink->getSiteId(), 'title' => $siteLink->getPageName(), 'badges' => $this->serializeBadges($siteLink->getBadges()));
 }
Ejemplo n.º 13
0
 /**
  * @dataProvider siteIdProvider
  */
 public function testGetSiteId($siteId)
 {
     $siteLink = new SiteLink($siteId, 'Wikidata');
     $this->assertEquals($siteId, $siteLink->getSiteId());
 }
Ejemplo n.º 14
0
 /**
  * @since 0.2
  * @param SiteLink $toSiteLink
  * @param SiteLink $fromSiteLink
  * @param EditInfo|null $editInfo
  *
  * @returns bool
  */
 public function link(SiteLink $toSiteLink, SiteLink $fromSiteLink, EditInfo $editInfo = null)
 {
     $params = array('tosite' => $toSiteLink->getSiteId(), 'totitle' => $toSiteLink->getPageName(), 'fromsite' => $fromSiteLink->getSiteId(), 'fromtitle' => $fromSiteLink->getPageName());
     $this->api->postRequest('wblinktitles', $params, $editInfo);
     return true;
 }