/** * @see ApiBase::execute * * @since 0.2 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $entityId = $this->modificationHelper->getEntityIdFromString($params['entity']); if (isset($params['baserevid'])) { $entityRevision = $this->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $propertyId = $this->modificationHelper->getEntityIdFromString($params['property']); if (!$propertyId instanceof PropertyId) { $this->errorReporter->dieError($propertyId->getSerialization() . ' does not appear to be a property ID', 'param-illegal'); } $snak = $this->modificationHelper->getSnakInstance($params, $propertyId); $summary = $this->modificationHelper->createSummary($params, $this); /* @var ChangeOpMainSnak $changeOp */ $changeOp = $this->statementChangeOpFactory->newSetMainSnakOp('', $snak); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $statement = $entity->getStatements()->getFirstStatementWithGuid($changeOp->getStatementGuid()); $status = $this->saveChanges($entity, $summary); $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->getResultBuilder()->markSuccess(); $this->getResultBuilder()->addStatement($statement); }
/** * @see ApiBase::execute * * @since 0.4 */ public function execute() { $params = $this->extractRequestParams(); $claim = $this->getClaimFromParams($params); $guid = $claim->getGuid(); if ($guid === null) { $this->errorReporter->dieError('GUID must be set when setting a claim', 'invalid-claim'); } try { $claimGuid = $this->guidParser->parse($guid); } catch (StatementGuidParsingException $ex) { $this->errorReporter->dieException($ex, 'invalid-claim'); } $entityId = $claimGuid->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $summary = $this->getSummary($params, $claim, $entity); $changeop = $this->statementChangeOpFactory->newSetStatementOp($claim, isset($params['index']) ? $params['index'] : null); $this->modificationHelper->applyChangeOp($changeop, $entity, $summary); $status = $this->saveChanges($entity, $summary); $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->getResultBuilder()->markSuccess(); $this->getResultBuilder()->addStatement($claim); }
/** * @param array $params * * @return ChangeOp[] */ private function getChangeOps(array $params) { $changeOps = array(); foreach ($params['claim'] as $guid) { $changeOps[] = $this->statementChangeOpFactory->newRemoveStatementOp($guid); } return $changeOps; }
/** * @param string $claimGuid * @param string[] $qualifierHashes * * @return ChangeOp[] */ private function getChangeOps($claimGuid, array $qualifierHashes) { $changeOps = array(); foreach ($qualifierHashes as $qualifierHash) { $changeOps[] = $this->statementChangeOpFactory->newRemoveQualifierOp($claimGuid, $qualifierHash); } return $changeOps; }
/** * @param string $guid * @param string[] $referenceHashes * * @return ChangeOp[] */ private function getChangeOps($guid, array $referenceHashes) { $changeOps = array(); foreach ($referenceHashes as $referenceHash) { $changeOps[] = $this->statementChangeOpFactory->newRemoveReferenceOp($guid, $referenceHash); } return $changeOps; }
/** * @param Reference $reference * * @return ChangeOpReference */ private function getChangeOp(Reference $reference) { $params = $this->extractRequestParams(); $guid = $params['statement']; $hash = isset($params['reference']) ? $params['reference'] : ''; $index = isset($params['index']) ? $params['index'] : null; return $this->statementChangeOpFactory->newSetReferenceOp($guid, $reference, $hash, $index); }
/** * @return ChangeOpQualifier */ private function getChangeOp() { $params = $this->extractRequestParams(); $guid = $params['claim']; $propertyId = $this->modificationHelper->getEntityIdFromString($params['property']); if (!$propertyId instanceof PropertyId) { $this->errorReporter->dieError($propertyId->getSerialization() . ' does not appear to be a property ID', 'param-illegal'); } $newQualifier = $this->modificationHelper->getSnakInstance($params, $propertyId); $snakHash = isset($params['snakhash']) ? $params['snakhash'] : ''; $changeOp = $this->statementChangeOpFactory->newSetQualifierOp($guid, $newQualifier, $snakHash); return $changeOp; }
/** * @see ApiBase::execute * * @since 0.3 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $this->logFeatureUsage('action=wbsetclaimvalue'); $guid = $params['claim']; $entityId = $this->guidParser->parse($guid)->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $claim = $this->modificationHelper->getStatementFromEntity($guid, $entity); $snak = $this->modificationHelper->getSnakInstance($params, $claim->getMainSnak()->getPropertyId()); $summary = $this->modificationHelper->createSummary($params, $this); $changeOp = $this->statementChangeOpFactory->newSetMainSnakOp($guid, $snak); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $status = $this->saveChanges($entity, $summary); $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->getResultBuilder()->markSuccess(); $this->getResultBuilder()->addStatement($claim); }
/** * Get changeops that remove all claims that have the 'remove' key in the array * * @param array[] $claims array of serialized claims * * @return ChangeOp[] */ private function getRemoveStatementChangeOps(array $claims) { $opsToReturn = array(); foreach ($claims as $claimArray) { if (array_key_exists('remove', $claimArray)) { if (array_key_exists('id', $claimArray)) { $opsToReturn[] = $this->statementChangeOpFactory->newRemoveStatementOp($claimArray['id']); } else { $this->errorReporter->dieError('Cannot remove a claim with no GUID', 'invalid-claim'); } } } return $opsToReturn; }