private function addEntityToOutput(EntityRevision $entityRevision, $name)
 {
     $entityId = $entityRevision->getEntity()->getId();
     $revisionId = $entityRevision->getRevisionId();
     $this->resultBuilder->addBasicEntityInformation($entityId, $name);
     $this->resultBuilder->setValue($name, 'lastrevid', (int) $revisionId);
 }
 /**
  * @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->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->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->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->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->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->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->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->addStatement($claim);
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     $guid = $params['claim'];
     $entityId = $this->guidParser->parse($guid)->getEntityId();
     if (isset($params['baserevid'])) {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId);
     }
     $entity = $entityRevision->getEntity();
     $summary = $this->modificationHelper->createSummary($params, $this);
     $claim = $this->modificationHelper->getStatementFromEntity($guid, $entity);
     $qualifierHashes = $this->getQualifierHashesFromParams($params, $claim);
     $changeOps = new ChangeOps();
     $changeOps->add($this->getChangeOps($guid, $qualifierHashes));
     try {
         $changeOps->apply($entity, $summary);
     } catch (ChangeOpException $e) {
         $this->errorReporter->dieException($e, 'failed-save');
     }
     $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $entityId = $this->getEntityId($params);
     if (isset($params['baserevid'])) {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId);
     }
     $entity = $entityRevision->getEntity();
     if ($entity instanceof StatementListProvider) {
         $this->assertStatementListContainsGuids($entity->getStatements(), $params['claim']);
     }
     $summary = $this->modificationHelper->createSummary($params, $this);
     $changeOps = new ChangeOps();
     $changeOps->add($this->getChangeOps($params));
     try {
         $changeOps->apply($entity, $summary);
     } catch (ChangeOpException $e) {
         $this->errorReporter->dieException($e, 'failed-save');
     }
     $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->setList(null, 'claims', $params['claim'], 'claim');
 }
 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());
 }
 /**
  * Adds the given EntityRevision to the API result.
  *
  * @param string|null $sourceEntityId
  * @param EntityRevision|null $entityRevision
  * @param array $params
  */
 private function handleEntity($sourceEntityId, EntityRevision $entityRevision = null, array $params = array())
 {
     if ($entityRevision === null) {
         $this->resultBuilder->addMissingEntity($sourceEntityId, array('id' => $sourceEntityId));
     } else {
         list($languageCodeFilter, $fallbackChains) = $this->getLanguageCodesAndFallback($params);
         $this->resultBuilder->addEntityRevision($sourceEntityId, $entityRevision, $this->getPropsFromParams($params), $params['sitefilter'], $languageCodeFilter, $fallbackChains);
     }
 }
 /**
  * Tries to normalize the given page title against the given client site.
  * Updates $title accordingly and adds the normalization to the API output.
  *
  * @param string &$title
  * @param Site $site
  */
 public function normalizeTitle(&$title, Site $site)
 {
     $normalizedTitle = $site->normalizePageName($title);
     if ($normalizedTitle !== false && $normalizedTitle !== $title) {
         // @todo this should not be in the helper but in the module itself...
         $this->resultBuilder->addNormalizedTitle($title, $normalizedTitle);
         //XXX: the below is an ugly hack as we pass title by reference...
         $title = $normalizedTitle;
     }
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     list($idString, $guid) = $this->getIdentifiers($params);
     try {
         $entityId = $this->idParser->parse($idString);
     } catch (EntityIdParsingException $e) {
         $this->errorReporter->dieException($e, 'param-invalid');
     }
     /** @var EntityId $entityId */
     $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, EntityRevisionLookup::LATEST_FROM_SLAVE);
     $entity = $entityRevision->getEntity();
     $statements = $this->getStatements($entity, $guid);
     $this->resultBuilder->addStatements($statements, null, $params['props']);
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     $entityId = $this->guidParser->parse($params['claim'])->getEntityId();
     if (isset($params['baserevid'])) {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId);
     }
     $entity = $entityRevision->getEntity();
     $summary = $this->modificationHelper->createSummary($params, $this);
     $statement = $this->modificationHelper->getStatementFromEntity($params['claim'], $entity);
     if (isset($params['snakhash'])) {
         $this->validateQualifierHash($statement, $params['snakhash']);
     }
     $changeOp = $this->getChangeOp();
     $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary);
     $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->addStatement($statement);
 }
 /**
  * @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->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->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->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->addStatement($claim);
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     $entityId = $this->guidParser->parse($params['statement'])->getEntityId();
     if (isset($params['baserevid'])) {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId);
     }
     $entity = $entityRevision->getEntity();
     $summary = $this->modificationHelper->createSummary($params, $this);
     $claim = $this->modificationHelper->getStatementFromEntity($params['statement'], $entity);
     if (isset($params['reference'])) {
         $this->validateReferenceHash($claim, $params['reference']);
     }
     if (isset($params['snaks-order'])) {
         $snaksOrder = $this->getArrayFromParam($params['snaks-order'], 'snaks-order');
     } else {
         $snaksOrder = array();
     }
     $deserializer = $this->deserializerFactory->newSnakListDeserializer();
     /** @var SnakList $snakList */
     try {
         $snakList = $deserializer->deserialize($this->getArrayFromParam($params['snaks'], 'snaks'));
     } catch (DeserializationException $e) {
         $this->errorReporter->dieError('Failed to get reference from reference Serialization ' . $e->getMessage(), 'snak-instantiation-failure');
     }
     $snakList->orderByProperty($snaksOrder);
     $newReference = new Reference($snakList);
     $changeOp = $this->getChangeOp($newReference);
     $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary);
     $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE);
     $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->resultBuilder->markSuccess();
     $this->resultBuilder->addReference($newReference);
 }
 /**
  * Pushes the given $entity into the ApiResult held by the ApiMain module
  * returned by newApiMain(). Calling $printer->execute() later will output this
  * result, if $printer was generated from that same ApiMain module, as
  * createApiPrinter() does.
  *
  * @param EntityRevision $entityRevision The entity to convert ot an ApiResult
  * @param ApiFormatBase $printer The output printer that will be used for serialization.
  *   Used to provide context for generating the ApiResult, and may also be manipulated
  *   to fine-tune the output.
  *
  * @return ApiResult
  */
 private function generateApiResult(EntityRevision $entityRevision, ApiFormatBase $printer)
 {
     $res = $printer->getResult();
     // Make sure result is empty. May still be full if this
     // function gets called multiple times during testing, etc.
     $res->reset();
     $resultBuilder = new ResultBuilder($res, $this->entityTitleLookup, $this->serializerFactory, $this->siteStore, $this->propertyLookup, false);
     $resultBuilder->addEntityRevision(null, $entityRevision);
     return $res;
 }