/** * string $type type of snak * @param EntityId|string $propertyId id of the property * @param \DataValues\DataValue|null $dataValue value of the property (optional) * @throws Exception */ public function __construct($type, $propertyId, \DataValues\DataValue $dataValue = null) { if (is_string($propertyId)) { $propertyId = EntityId::newFromPrefixedId($propertyId); } if (!$propertyId instanceof EntityId || $propertyId->getEntityType() !== 'property') { throw new Exception('$propertyId must be a valid property id'); } $this->type = $type; $this->propertyId = $propertyId; $this->dataValue = $dataValue; }
protected function fillData(array $data) { if (isset($data['id'])) { $this->id = EntityId::newFromPrefixedId($data['id']); } if (isset($data['lastrevid'])) { $this->lastRevisionId = $data['lastrevid']; } if (isset($data['labels'])) { $this->labels = array(); foreach ($data['labels'] as $val) { $this->labels[$val['language']] = $val['value']; } } if (isset($data['aliases'])) { $this->aliases = array(); foreach ($data['aliases'] as $lang => $value) { $this->aliases[$lang] = array(); foreach ($value as $val) { $this->aliases[$val['language']][] = $val['value']; } } } if (isset($data['descriptions'])) { $this->descriptions = array(); foreach ($data['descriptions'] as $val) { $this->descriptions[$val['language']] = $val['value']; } } if (isset($data['claims'])) { $this->claims = array(); foreach ($data['claims'] as $prop => $list) { $this->claims[$prop] = array(); foreach ($list as $val) { $claim = Claim::newFromArray($this, $val); $this->claims[$prop][$claim->getInternalId()] = $claim; } } } }
<?php /** * Basic example for the use of the libary with some small edits */ include '../include.php'; //Instance the Api object with the base domain of the wiki and the user agent. $api = new WikibaseApi('wikidata-test-repo.wikimedia.de', 'WikibasePhpLibExample/1.0'); //Instance the entity provider that allows to get entites from the wiki $entityProvider = new EntityProvider($api); //login with user:demo and test as password $api->login('demo', 'test'); //Get an entity $entity = $entityProvider->getEntityFromId(EntityId::newFromPrefixedId('Q257')); //Output the description in French echo $entity->getDescription('fr'); //Change the label in French $entity->setLabel('fr', 'Or'); //Add an alias in English $entity->addAlias('en', 'Test'); //Remove an alias $entity->removeAlias('en', 'Test2'); //Delete the sitelink in French $entity->setSitelink('frwiki', ''); //Save changes $entity->save('Test of wikibase-php-lib'); //See the updated aliases in English print_r($entity->getAlias('en')); //Log out $api->logout();
* Basic example for the use of the libary with some small edits */ include '../include.php'; // Instance the Api object with the base domain of the wiki and the user agent. $api = new WikibaseApi('wikidata-test-repo.wikimedia.de', 'WikibasePhpLibExample/0.1'); // Instance the entity provider that allows to get entites from the wiki $entityProvider = new EntityProvider($api); // login with user:demo and test as password $api->login('demo', 'test'); // Get an entity $entity = $entityProvider->getEntityFromId(EntityId::newFromPrefixedId('q82')); // Create a new statement $statement = $entity->createStatementForSnak(new Snak('value', 'p3', EntityId::newFromPrefixedId('Q22'))); // Save it $statement->save('Test of wikibase-php-lib'); // Change the main value of the statement $statement->setMainSnak(new Snak('novalue', 'p3')); // Save the change $statement->save(); // Create a reference for the statement $reference = $statement->createReferenceForSnak(new Snak('value', 'p7', EntityId::newFromPrefixedId('Q36'))); // Save the reference $reference->save('Test of reference'); // See the list of claims print_r($entity->getClaims()); // Delete the reference $reference->deleteAndSave(); // Remove the created statement $statement->deleteAndSave('End of test'); // Log out $api->logout();