/** * @since 0.2 * * @param Reference|string $reference Reference object or hash * @param Statement|StatementGuid|string $target Statement object or GUID * @param EditInfo|null $editInfo * * @throws UnexpectedValueException * @return bool */ public function set($reference, $target, EditInfo $editInfo = null) { if ($reference instanceof Reference) { $reference = $reference->getHash(); } if (!is_string($reference)) { throw new UnexpectedValueException('Could not get reference hash from $reference'); } if (is_string($target)) { $guid = $target; } else { if ($target instanceof StatementGuid) { $guid = $target->getSerialization(); } else { if ($target instanceof Statement) { $guid = $target->getGuid(); } else { throw new UnexpectedValueException('Could not get statement guid from $target'); } } } if (!is_string($guid)) { throw new UnexpectedValueException('Unexpected statement guid got from $target'); } $params = array('statement' => $guid, 'references' => $reference); $this->api->postRequest('wbremovereferences', $params, $editInfo); return true; }
/** * @since 0.2 * * @param Reference $reference new reference value * @param Statement|StatementGuid|string $statement Statement object or GUID which has the reference * @param Reference|string $targetReference target (old) reference of hash * @param EditInfo|null $editInfo * * @return bool * @throws UnexpectedValueException */ public function set(Reference $reference, $statement, $targetReference = null, EditInfo $editInfo = null) { if (is_string($statement)) { $guid = $statement; } else { if ($statement instanceof StatementGuid) { $guid = $statement->getSerialization(); } else { if ($statement instanceof Statement) { $guid = $statement->getGuid(); } else { throw new UnexpectedValueException('Could not get statement guid from $target'); } } } if (!is_string($guid)) { throw new UnexpectedValueException('Unexpected statement guid got from $target'); } $referenceSerialization = $this->referenceSerializer->serialize($reference); $params = array('statement' => $guid, 'snaks' => json_encode($referenceSerialization['snaks']), 'snaks-order' => json_encode($referenceSerialization['snaks-order'])); if (!is_null($targetReference)) { if ($targetReference instanceof Reference) { $targetReference = $reference->getHash(); } if (!is_string($targetReference)) { throw new UnexpectedValueException('Could not get reference hash from $targetReference'); } $params['reference'] = $targetReference; } $this->api->postRequest('wbsetreference', $params, $editInfo); return true; }
/** * @since 0.5 * * @param Statement $statement * @param EditInfo|null $editInfo * * @throws InvalidArgumentException * @return bool * * @todo allow setting of indexes */ public function set(Statement $statement, EditInfo $editInfo = null) { if ($statement->getGuid() === null) { throw new InvalidArgumentException('Can not set a statement that does not have a GUID'); } $params = array('claim' => $this->statementSerializer->serialize($statement)); $this->api->postRequest('wbsetclaim', $params, $editInfo); return true; }
/** * @since 0.2 * * @param Term $label * @param EntityId|Item|Property|SiteLink $target * @param EditInfo|null $editInfo * * @return bool */ public function set(Term $label, $target, EditInfo $editInfo = null) { $this->throwExceptionsOnBadTarget($target); $params = $this->getTargetParamsFromTarget($this->getEntityIdentifierFromTarget($target)); $params['language'] = $label->getLanguageCode(); $params['value'] = $label->getText(); $this->api->postRequest('wbsetlabel', $params, $editInfo); return true; }
/** * @since 0.2 * * @param AliasGroup $aliasGroup * @param EntityId|Item|Property|SiteLink $target * @param EditInfo|null $editInfo * * @return bool */ public function set(AliasGroup $aliasGroup, $target, EditInfo $editInfo = null) { $this->throwExceptionsOnBadTarget($target); $params = $this->getTargetParamsFromTarget($this->getEntityIdentifierFromTarget($target)); $params['language'] = $aliasGroup->getLanguageCode(); $params['set'] = implode('|', $aliasGroup->getAliases()); $this->api->postRequest('wbsetaliases', $params, $editInfo); return true; }
/** * @since 0.2 * * @param SiteLink $siteLink * @param EntityId|Item|Property|SiteLink $target * @param EditInfo|null $editInfo * * @return bool */ public function set(SiteLink $siteLink, $target, EditInfo $editInfo = null) { $this->throwExceptionsOnBadTarget($target); $params = $this->getTargetParamsFromTarget($this->getEntityIdentifierFromTarget($target)); $params['linksite'] = $siteLink->getSiteId(); $params['linktitle'] = $siteLink->getPageName(); $params['badges'] = implode('|', $siteLink->getBadges()); $this->api->postRequest('wbsetsitelink', $params, $editInfo); return true; }
/** * @since 0.2 * * @param Snak $mainSnak * @param EntityId|Item|Property|string $target * @param EditInfo|null $editInfo * * @return string the GUID of the claim * @throws UnexpectedValueException */ public function create(Snak $mainSnak, $target, EditInfo $editInfo = null) { if (is_string($target)) { $entityId = $target; } elseif ($target instanceof EntityId) { $entityId = $target->getSerialization(); } elseif ($target instanceof Item || $target instanceof Property) { $entityId = $target->getId()->getSerialization(); } else { throw new UnexpectedValueException('$target needs to be an EntityId, Entity or string'); } $params = array('entity' => $entityId, 'snaktype' => $mainSnak->getType(), 'property' => $mainSnak->getPropertyId()->getSerialization()); if ($mainSnak instanceof PropertyValueSnak) { $serializedDataValue = $this->dataValueSerializer->serialize($mainSnak->getDataValue()); $params['value'] = json_encode($serializedDataValue['value']); } $result = $this->api->postRequest('wbcreateclaim', $params, $editInfo); return $result['claims']['id']; }
/** * @since 0.2 * * @param Statement|StatementGuid|string $statement Statement object or GUID * @param EditInfo|null $editInfo * * @return bool * @throws UnexpectedValueException */ public function remove($statement, EditInfo $editInfo = null) { if (is_string($statement)) { $guid = $statement; } else { if ($statement instanceof StatementGuid) { $guid = $statement->getSerialization(); } else { if ($statement instanceof Statement) { $guid = $statement->getGuid(); } else { throw new UnexpectedValueException('Could not get statement guid from $statement'); } } } if (!is_string($guid)) { throw new UnexpectedValueException('Unexpected statement guid got from $statement'); } $params = array('claim' => $guid); $this->api->postRequest('wbremoveclaims', $params, $editInfo); return true; }
/** * @since 0.1 * @param Revision $revision * @param EditInfo|null $editInfo * * @throws RuntimeException * @throws InvalidArgumentException * @returns Item|Property new version of the entity */ public function save(Revision $revision, EditInfo $editInfo = null) { if (!$revision->getContent()->getData() instanceof EntityDocument) { throw new RuntimeException('Can only save Content of EntityDocuments'); } /** @var Item|Property $entity */ $entity = $revision->getContent()->getData(); $serialized = $this->entitySerializer->serialize($entity); $params = array('data' => json_encode($serialized)); $revId = $revision->getId(); if (!is_null($revId)) { $params['baserevid'] = $revId; } $entityId = $entity->getId(); if (!is_null($entityId)) { $params['id'] = $entityId->getSerialization(); // Always clear so that removing elements is possible $params['clear'] = 'true'; // Add more detail to the default "Cleared an entity" summary // Note: this is later overridden if a summary is provided in the EditInfo $params['summary'] = 'Edited a ' . $entity->getType(); } else { $params['new'] = $entity->getType(); } // If no editInfo is explicitly passed call back to the one in the revision? if ($editInfo === null) { $editInfo = $revision->getEditInfo(); } if ($editInfo->getBot()) { $params['bot'] = true; } if ($editInfo->getMinor()) { $params['minor'] = true; } $summary = $editInfo->getSummary(); if (!empty($summary)) { $params['summary'] = $summary; } $result = $this->api->postRequest('wbeditentity', $params, $editInfo); return $this->entityDeserializer->deserialize($result['entity']); }
/** * @param EntityId $from * @param EntityId $to * @param EditInfo|null $editInfo * * @return bool */ public function create(EntityId $from, EntityId $to, EditInfo $editInfo = null) { $params = array('from' => $from->__toString(), 'to' => $to->__toString()); $this->api->postRequest('wbcreateredirect', $params, $editInfo); return true; }
/** * @since 0.2 * @param Item|ItemId|string $from * @param Item|ItemId|string $to * @param EditInfo|null $editInfo * * @returns bool */ public function merge($from, $to, EditInfo $editInfo = null) { $params = array('fromid' => $this->getIdFromInput($from), 'toid' => $this->getIdFromInput($to)); $this->api->postRequest('wbmergeitems', $params, $editInfo); return true; }
/** * @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; }