private function addWikipediaHtmlUrl() { $wikiId = $this->getWikiId($this->languageCode); if ($this->item->getSiteLinkList()->hasLinkWithSiteId($wikiId)) { $this->simpleItem->wikipediaHtmlUrl = $this->urlBuilder->getSiteLinkBasedRerirectUrl($wikiId, $this->item->getId()); } }
/** * @param EntityId|Item|Property $target * * @throws UnexpectedValueException * @return EntityId|SiteLink * * @todo Fix duplicated code */ private function getEntityIdentifierFromTarget($target) { if ($target instanceof Item || $target instanceof Property) { return $target->getId(); } else { return $target; } }
/** * @dataProvider getEntityProvider */ public function testGetEntity(array $expected, Item $item, EntityLookup $entityLookup) { $prefixedId = $item->getId()->getSerialization(); $entityAccessor = $this->getEntityAccessor($entityLookup); $entityArr = $entityAccessor->getEntity($prefixedId); $actual = is_array($entityArr) ? $entityArr : array(); $this->assertSameSize($expected, $actual); foreach ($expected as $expectedKey) { $this->assertArrayHasKey($expectedKey, $actual); } }
public function invalidArgumentProvider() { $item = new Item(new ItemId('Q42')); $guidGenerator = new GuidGenerator(); $validGuid = $guidGenerator->newGuid($item->getId()); $validRank = 1; $args = array(); $args[] = array(123, $validRank); $args[] = array($validGuid, ':-)'); return $args; }
/** * @param Item $item * @param PropertyId $propertyId */ private function addStatements(Item $item, PropertyId $propertyId) { if (!$item->getId()) { $this->save($item); } /** @var Statement[] $statements */ $statements[0] = new Statement(new PropertyNoValueSnak($propertyId)); $statements[1] = new Statement(new PropertyNoValueSnak($propertyId)); $statements[2] = new Statement(new PropertySomeValueSnak($propertyId)); $statements[3] = new Statement(new PropertyValueSnak($propertyId, new StringValue('o_O'))); foreach ($statements as $key => $statement) { $statement->setGuid($item->getId()->getSerialization() . '$D8404CDA-56A1-4334-AF13-A3290BCD9CL' . $key); $item->getStatements()->addStatement($statement); } }
protected function makeChangeOpsMerge(Item $fromItem, Item $toItem, array $ignoreConflicts = array(), $siteLookup = null) { if ($siteLookup === null) { $siteLookup = MockSiteStore::newFromTestSites(); } // A validator which makes sure that no site link is for page 'DUPE' $siteLinkUniquenessValidator = $this->getMock('Wikibase\\Repo\\Validators\\EntityValidator'); $siteLinkUniquenessValidator->expects($this->any())->method('validateEntity')->will($this->returnCallback(function (Item $item) { $siteLinks = $item->getSiteLinkList(); foreach ($siteLinks as $siteLink) { if ($siteLink->getPageName() === 'DUPE') { return Result::newError(array(Error::newError('SiteLink conflict'))); } } return Result::newSuccess(); })); $constraintProvider = $this->getMockBuilder('Wikibase\\Repo\\Validators\\EntityConstraintProvider')->disableOriginalConstructor()->getMock(); $constraintProvider->expects($this->any())->method('getUpdateValidators')->will($this->returnValue(array($siteLinkUniquenessValidator))); $changeOpFactoryProvider = new ChangeOpFactoryProvider($constraintProvider, $this->mockProvider->getMockGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser($toItem->getId()), $this->mockProvider->getMockSnakValidator(), $this->mockProvider->getMockTermValidatorFactory(), $siteLookup); return new ChangeOpsMerge($fromItem, $toItem, $ignoreConflicts, $constraintProvider, $changeOpFactoryProvider, $siteLookup); }
private function generateStatementsChangeOps() { if (!in_array('statement', $this->ignoreConflicts)) { foreach ($this->toItem->getStatements()->toArray() as $toStatement) { $this->checkIsLink($toStatement, $this->fromItem->getId()); } } foreach ($this->fromItem->getStatements()->toArray() as $fromStatement) { if (!in_array('statement', $this->ignoreConflicts)) { $this->checkIsLink($fromStatement, $this->toItem->getId()); } $this->fromChangeOps->add($this->getStatementChangeOpFactory()->newRemoveStatementOp($fromStatement->getGuid())); $toStatement = clone $fromStatement; $toStatement->setGuid(null); $toMergeToStatement = $this->findEquivalentStatement($toStatement); if ($toMergeToStatement) { $this->generateReferencesChangeOps($toStatement, $toMergeToStatement); } else { $this->toChangeOps->add($this->getStatementChangeOpFactory()->newSetStatementOp($toStatement)); } } }
/** * @see SiteLinkConflictLookup::getConflictsForItem * * @param Item $item * @param DatabaseBase|null $db * * @return array[] */ public function getConflictsForItem(Item $item, DatabaseBase $db = null) { $siteLinks = $item->getSiteLinkList(); if ($siteLinks->isEmpty()) { return array(); } if ($db) { $dbr = $db; } else { $dbr = $this->getConnection(DB_SLAVE); } $anyOfTheLinks = ''; /** @var SiteLink $siteLink */ foreach ($siteLinks as $siteLink) { if ($anyOfTheLinks !== '') { $anyOfTheLinks .= "\nOR "; } $anyOfTheLinks .= '('; $anyOfTheLinks .= 'ips_site_id=' . $dbr->addQuotes($siteLink->getSiteId()); $anyOfTheLinks .= ' AND '; $anyOfTheLinks .= 'ips_site_page=' . $dbr->addQuotes($siteLink->getPageName()); $anyOfTheLinks .= ')'; } // TODO: $anyOfTheLinks might get very large and hit some size limit imposed // by the database. We could chop it up of we know that size limit. // For MySQL, it's select @@max_allowed_packet. $conflictingLinks = $dbr->select('wb_items_per_site', array('ips_site_id', 'ips_site_page', 'ips_item_id'), "({$anyOfTheLinks}) AND ips_item_id != " . (int) $item->getId()->getNumericId(), __METHOD__); $conflicts = array(); foreach ($conflictingLinks as $link) { $conflicts[] = array('siteId' => $link->ips_site_id, 'itemId' => (int) $link->ips_item_id, 'sitePage' => $link->ips_site_page); } if (!$db) { $this->releaseConnection($dbr); } return $conflicts; }
/** * Adds the site links of the given item to the RDF graph. * * @param Item $item */ public function addSiteLinks(Item $item) { $entityLName = $this->vocabulary->getEntityLName($item->getId()); /** @var SiteLink $siteLink */ foreach ($item->getSiteLinkList() as $siteLink) { if (!$this->isSiteIncluded($siteLink->getSiteId())) { continue; } // FIXME: we should check the site exists using hasGlobalId here before asuming it does $site = $this->siteLookup->getSite($siteLink->getSiteId()); // XXX: ideally, we'd use https if the target site supports it. $baseUrl = str_replace('$1', rawurlencode($siteLink->getPageName()), $site->getLinkPath()); // $site->getPageUrl( $siteLink->getPageName() ); if (!parse_url($baseUrl, PHP_URL_SCHEME)) { $url = "http:" . $baseUrl; } else { $url = $baseUrl; } $this->writer->about($url)->a(RdfVocabulary::NS_SCHEMA_ORG, 'Article')->say(RdfVocabulary::NS_SCHEMA_ORG, 'about')->is(RdfVocabulary::NS_ENTITY, $entityLName)->say(RdfVocabulary::NS_SCHEMA_ORG, 'inLanguage')->text($this->vocabulary->getCanonicalLanguageCode($site->getLanguageCode())); foreach ($siteLink->getBadges() as $badge) { $this->writer->say(RdfVocabulary::NS_ONTOLOGY, 'badge')->is(RdfVocabulary::NS_ENTITY, $this->vocabulary->getEntityLName($badge)); } } }
/** * @param Item $fromItem * @param Item $toItem * @param string|null $summary * @param bool $bot * * @return array A list of exactly two EntityRevision objects. The first one represents the * modified source item, the second one represents the modified target item. */ private function attemptSaveMerge(Item $fromItem, Item $toItem, $summary, $bot) { $toSummary = $this->getSummary('to', $toItem->getId(), $summary); $fromRev = $this->saveEntity($fromItem, $toSummary, $bot); $fromSummary = $this->getSummary('from', $fromItem->getId(), $summary); $toRev = $this->saveEntity($toItem, $fromSummary, $bot); return array($fromRev, $toRev); }
private function newItemWithClaim($snak) { $item = new Item(new ItemId('Q123')); $item->getStatements()->addNewStatement($snak, null, null, $item->getId()->getSerialization() . '$D8494TYA-25E4-4334-AG03-A3290BCT9CQP'); return $item; }
/** * @depends testSaveLinksOfItem * @dataProvider itemProvider */ public function testClear(Item $item) { $this->assertTrue($this->siteLinkTable->clear() !== false); $this->assertEmpty($this->siteLinkTable->getSiteLinksForItem($item->getId())); }
/** * Builds and returns the HTML representing a WikibaseEntity's site-links. * * @since 0.1 * * @param Item $item the entity to render * * @return string HTML */ protected function getHtmlForSiteLinks(Item $item) { return $this->siteLinksView->getHtml($item->getSiteLinks(), $item->getId(), $this->siteLinkGroups); }
/** * @see SiteLinkStore::saveLinksOfItem * * @param Item $item * * @return bool */ public function saveLinksOfItem(Item $item) { $itemId = $item->getId(); $this->deleteLinksOfItem($itemId); foreach ($item->getSiteLinks() as $siteLink) { $this->indexByLink($itemId, $siteLink); $this->indexByItemId($itemId, $siteLink); } return true; }
private function addIdToSerialization(Item $item, array &$serialization) { $id = $item->getId(); if ($id !== null) { $serialization['id'] = $id->getSerialization(); } }
private function addIdLinks() { $this->simpleItem->ids['wikidata'] = $this->item->getId()->getSerialization(); $this->addIdLinkForLanguage(self::MAIN_LANGUAGE); $this->addIdLinkForLanguage($this->languageCode); }
public function testEmptyConstructor() { $item = new Item(); $this->assertNull($item->getId()); $this->assertTrue($item->getFingerprint()->isEmpty()); $this->assertTrue($item->getSiteLinkList()->isEmpty()); $this->assertTrue($item->getStatements()->isEmpty()); }
private function makeNewItemWithClaim($itemIdString, $snak) { $item = new Item(new ItemId($itemIdString)); $item->getStatements()->addNewStatement($snak, null, null, $this->mockProvider->getGuidGenerator()->newGuid($item->getId())); return $item; }
private function newItemWithClaim($itemIdString, $snak) { $item = new Item(new ItemId($itemIdString)); $item->getStatements()->addNewStatement($snak, null, null, $item->getId()->getSerialization() . '$D8404CDA-25E4-4334-AG93-A3290BCD9C0P'); return $item; }
/** * Save the new version of the given item. * * @param Item $item * @param User $user * * @return bool */ private function saveChanges(Item $item, User $user) { $summary = $this->getSummary(); $itemId = $item->getId(); $summaryString = $this->summaryFormatter->formatSummary($summary); $editEntity = $this->editEntityFactory->newEditEntity($user, $item, true); $status = $editEntity->attemptSave($summaryString, EDIT_UPDATE, false, $this->entityStore->isWatching($user, $itemId)); if (!$status->isOK()) { wfDebugLog('UpdateRepo', __FUNCTION__ . ': attemptSave for ' . $itemId->getSerialization() . ' failed: ' . $status->getMessage()->text()); } return $status->isOK(); }
/** * Internal callback for deleting a list of links. * * @note: this is public only because it acts as a callback, there should be no * reason to call this directly! * * @since 0.5 * * @param Item $item * @param SiteLink[] $links * @param DatabaseBase $dbw * * @return boolean Success indicator */ public function deleteLinksInternal(Item $item, array $links, DatabaseBase $dbw) { wfDebugLog(__CLASS__, __FUNCTION__ . ': deleting links for ' . $item->getId()->getSerialization()); $siteIds = array(); foreach ($links as $siteLink) { $siteIds[] = $siteLink->getSiteId(); } $success = $dbw->delete($this->table, array('ips_item_id' => $item->getId()->getNumericId(), 'ips_site_id' => $siteIds), __METHOD__); return $success; }
private function buildResult(Item $item = null, Status $status) { if ($item !== null) { $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'entity'); $this->resultBuilder->addBasicEntityInformation($item->getId(), 'entity'); } $this->resultBuilder->markSuccess($status->isOK()); }
/** * @param Item $item */ public function doTestValidRequestMultiple(Item $item) { $guids = array(); /** @var Statement $statement */ foreach ($item->getStatements() as $statement) { $guids[] = $statement->getGuid(); } $this->makeTheRequest($guids); /** @var Item $obtainedItem */ $obtainedItem = WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity($item->getId()); $this->assertTrue($obtainedItem->getStatements()->isEmpty()); }