/**
  * @param Revision $revision
  * @param EditInfo $editInfo
  *
  * @throws RuntimeException
  * @returns array
  */
 private function getEditParams(Revision $revision, EditInfo $editInfo = null)
 {
     if (!$revision->getPageIdentifier()->identifiesPage()) {
         throw new RuntimeException('$revision PageIdentifier does not identify a page');
     }
     $params = [];
     $content = $revision->getContent();
     $data = $content->getData();
     if (!is_string($data)) {
         throw new RuntimeException('Dont know how to save content of this model.');
     }
     $params['text'] = $content->getData();
     $params['md5'] = md5($content->getData());
     $timestamp = $revision->getTimestamp();
     if (!is_null($timestamp)) {
         $params['basetimestamp'] = $timestamp;
     }
     if (!is_null($revision->getPageIdentifier()->getId())) {
         $params['pageid'] = $revision->getPageIdentifier()->getId();
     } else {
         $params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
     }
     $params['token'] = $this->api->getToken();
     if ($this->api->isLoggedin()) {
         $params['assert'] = 'user';
     }
     $this->addEditInfoParams($editInfo, $params);
     return $params;
 }
 /**
  * @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']);
 }
 /**
  * @dataProvider provideValidConstruction
  */
 public function testValidConstruction($content, $pageIdentifier, $id, $editInfo, $user, $timestamp)
 {
     $rev = new Revision($content, $pageIdentifier, $id, $editInfo, $user, $timestamp);
     $this->assertEquals($content, $rev->getContent());
     if (!is_null($pageIdentifier)) {
         $this->assertEquals($pageIdentifier, $rev->getPageIdentifier());
     } else {
         $this->assertInstanceOf('\\Mediawiki\\DataModel\\PageIdentifier', $rev->getPageIdentifier());
     }
     $this->assertEquals($id, $rev->getId());
     if (!is_null($editInfo)) {
         $this->assertEquals($editInfo, $rev->getEditInfo());
     } else {
         $this->assertInstanceOf('\\Mediawiki\\DataModel\\EditInfo', $rev->getEditInfo());
     }
     $this->assertEquals($user, $rev->getUser());
     $this->assertEquals($timestamp, $rev->getTimestamp());
 }