Exemplo 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);
 }
Exemplo n.º 2
0
 private function setSiteLinksFromSerialization(SiteLinkList $siteLinkList, array $serialization)
 {
     if (!array_key_exists('sitelinks', $serialization)) {
         return;
     }
     $this->assertAttributeIsArray($serialization, 'sitelinks');
     foreach ($serialization['sitelinks'] as $siteLinksSerialization) {
         $siteLinkList->addSiteLink($this->siteLinkDeserializer->deserialize($siteLinksSerialization));
     }
 }
 /**
  * Main method. Does the actual work and sets the result.
  *
  * @since 0.1
  */
 public function execute()
 {
     $lookup = $this->revisionLookup;
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     // Sites are already tested through allowed params ;)
     $sites = $this->siteLinkTargetProvider->getSiteList($this->siteLinkGroups);
     /** @var Site $fromSite */
     list($fromSite, $fromPage) = $this->getSiteAndNormalizedPageName($sites, $params['fromsite'], $params['fromtitle']);
     /** @var Site $toSite */
     list($toSite, $toPage) = $this->getSiteAndNormalizedPageName($sites, $params['tosite'], $params['totitle']);
     $siteLinkStore = WikibaseRepo::getDefaultInstance()->getStore()->newSiteLinkStore();
     $fromId = $siteLinkStore->getItemIdForLink($fromSite->getGlobalId(), $fromPage);
     $toId = $siteLinkStore->getItemIdForLink($toSite->getGlobalId(), $toPage);
     $siteLinkList = new SiteLinkList();
     $flags = 0;
     $item = null;
     $summary = new Summary($this->getModuleName());
     $summary->addAutoSummaryArgs($fromSite->getGlobalId() . ':' . $fromPage, $toSite->getGlobalId() . ':' . $toPage);
     //FIXME: use ChangeOps for consistency!
     // Figure out which parts to use and what to create anew
     if ($fromId === null && $toId === null) {
         // create new item
         $item = new Item();
         $toLink = new SiteLink($toSite->getGlobalId(), $toPage);
         $item->addSiteLink($toLink);
         $siteLinkList->addSiteLink($toLink);
         $fromLink = new SiteLink($fromSite->getGlobalId(), $fromPage);
         $item->addSiteLink($fromLink);
         $siteLinkList->addSiteLink($fromLink);
         $flags |= EDIT_NEW;
         $summary->setAction('create');
     } elseif ($fromId === null && $toId !== null) {
         // reuse to-site's item
         /** @var Item $item */
         $itemRev = $lookup->getEntityRevision($toId, EntityRevisionLookup::LATEST_FROM_MASTER);
         $item = $itemRev->getEntity();
         $fromLink = new SiteLink($fromSite->getGlobalId(), $fromPage);
         $item->addSiteLink($fromLink);
         $siteLinkList->addSiteLink($fromLink);
         $summary->setAction('connect');
     } elseif ($fromId !== null && $toId === null) {
         // reuse from-site's item
         /** @var Item $item */
         $itemRev = $lookup->getEntityRevision($fromId, EntityRevisionLookup::LATEST_FROM_MASTER);
         $item = $itemRev->getEntity();
         $toLink = new SiteLink($toSite->getGlobalId(), $toPage);
         $item->addSiteLink($toLink);
         $siteLinkList->addSiteLink($toLink);
         $summary->setAction('connect');
     } elseif ($fromId->equals($toId)) {
         // no-op
         $this->errorReporter->dieError('Common item detected, sitelinks are both on the same item', 'common-item');
     } else {
         // dissimilar items
         $this->errorReporter->dieError('No common item detected, unable to link titles', 'no-common-item');
     }
     $this->resultBuilder->addSiteLinkList($siteLinkList, 'entity');
     $status = $this->getAttemptSaveStatus($item, $summary, $flags);
     $this->buildResult($item, $status);
 }
Exemplo n.º 4
0
 /**
  * @param SiteLinkList $siteLinkList
  * @param string $suffix
  *
  * @return SiteLinkList
  */
 public static function getSitelinksWiteSiteIdSuffix(SiteLinkList $siteLinkList, $suffix)
 {
     $filteredSiteLinkList = new SiteLinkList();
     foreach ($siteLinkList->getIterator() as $siteLink) {
         $siteId = $siteLink->getSiteId();
         if (substr($siteId, -strlen($suffix)) == $suffix) {
             $filteredSiteLinkList->addSiteLink($siteLink);
         }
     }
     return $filteredSiteLinkList;
 }
Exemplo n.º 5
0
 public function testAddSiteLink()
 {
     $list = new SiteLinkList();
     $list->addSiteLink(new SiteLink('enwiki', 'cats'));
     $list->addSiteLink(new SiteLink('dewiki', 'katzen'));
     $this->assertTrue($list->equals(new SiteLinkList(array(new SiteLink('enwiki', 'cats'), new SiteLink('dewiki', 'katzen')))));
 }