本文整理汇总了PHP中Wikibase\DataModel\Entity\Item::addSiteLink方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::addSiteLink方法的具体用法?PHP Item::addSiteLink怎么用?PHP Item::addSiteLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Wikibase\DataModel\Entity\Item
的用法示例。
在下文中一共展示了Item::addSiteLink方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testItemSerializerWithOptionObjectsForMaps
public function testItemSerializerWithOptionObjectsForMaps()
{
$serializer = $this->buildSerializer(true);
$item = new Item();
$item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
$sitelinks = new \stdClass();
$sitelinks->enwiki = array('site' => 'enwiki', 'title' => 'Nyan Cat', 'badges' => array());
$serial = array('type' => 'item', 'labels' => array(), 'descriptions' => array(), 'aliases' => array(), 'claims' => array(), 'sitelinks' => $sitelinks);
$this->assertEquals($serial, $serializer->serialize($item));
}
示例2: deserializationProvider
public function deserializationProvider()
{
$provider = array(array(new Item(), array('type' => 'item')));
$item = new Item(new ItemId('Q42'));
$provider[] = array($item, array('type' => 'item', 'id' => 'Q42'));
$item = new Item();
$item->getFingerprint()->setLabel('en', 'foo');
$provider[] = array($item, array('type' => 'item', 'labels' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
$item = new Item();
$item->getFingerprint()->setDescription('en', 'foo');
$provider[] = array($item, array('type' => 'item', 'descriptions' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
$item = new Item();
$item->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
$provider[] = array($item, array('type' => 'item', 'aliases' => array('en' => array('lang' => 'en', 'values' => array('foo', 'bar')))));
$item = new Item();
$item->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'test');
$provider[] = array($item, array('type' => 'item', 'claims' => array('P42' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'type' => 'statement', 'rank' => 'normal')))));
$item = new Item();
$item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
$provider[] = array($item, array('type' => 'item', 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Nyan Cat', 'badges' => array()))));
return $provider;
}
示例3: entityProvider
public function entityProvider()
{
$entities = array();
$entity = new Item(new ItemId('Q42'));
$entities[] = array($entity);
$entity = new Item();
$entity->setLabels(array('en' => 'Nyan Cat', 'fr' => 'Nyan Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->setDescriptions(array('en' => 'A Nyan Cat', 'fr' => 'A Nyan Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->setAliases('en', array('Cat', 'My cat'));
$entity->setAliases('fr', array('Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'guid');
$entities[] = array($entity);
$item = new Item();
$item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
$entities[] = array($item);
$entities[] = array(Property::newFromType('string'));
return $entities;
}
示例4: execute
/**
* 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);
}
示例5: testAddSiteLinkOverridesOldLinks
public function testAddSiteLinkOverridesOldLinks()
{
$item = new Item();
$item->getSiteLinkList()->addNewSiteLink('kittens', 'foo');
$newLink = new SiteLink('kittens', 'bar');
$item->addSiteLink($newLink);
$this->assertTrue($item->getSiteLinkList()->getBySiteId('kittens')->equals($newLink));
}