/**
  * @param Revision $revision
  *
  * @return array
  */
 private function getParamsFromRevision(Revision $revision)
 {
     $params = array('undo' => $revision->getId(), 'token' => $this->api->getToken());
     if (!is_null($revision->getPageIdentifier()->getId())) {
         $params['pageid'] = $revision->getPageIdentifier()->getId();
     } else {
         $params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
     }
     return $params;
 }
Example #2
0
 /**
  * @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());
 }
Example #5
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param array $extraParams
  *
  * @return bool
  */
 public function deleteFromRevision(Revision $revision, array $extraParams = [])
 {
     $this->api->postRequest(new SimpleRequest('delete', $this->getDeleteParams($revision->getPageIdentifier(), $extraParams)));
     return true;
 }
 /**
  * @param Revision $revision
  *
  * @return Page
  *
  * @throws InvalidArgumentException
  */
 public function getFromRevision(Revision $revision)
 {
     return $this->getFromPageIdentifier($revision->getPageIdentifier());
 }
 /**
  * @param Revision $revision
  *
  * @returns string
  */
 private function getTokenForRevision(Revision $revision)
 {
     $result = $this->api->postRequest(new SimpleRequest('query', array('list' => 'recentchanges', 'rcstart' => $revision->getTimestamp(), 'rcend' => $revision->getTimestamp(), 'rctoken' => 'patrol')));
     $result = array_shift($result['query']['recentchanges']);
     return $result['patroltoken'];
 }
 /**
  * @since 0.5
  *
  * @param Revision $revision
  *
  * @return bool
  */
 public function delete(Revision $revision)
 {
     $params = array('type' => 'revision', 'hide' => 'content', 'token' => $this->api->getToken('delete'), 'ids' => $revision->getId());
     $this->api->postRequest(new SimpleRequest('revisiondelete', $params));
     return true;
 }
Example #9
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param QueryOptions|null $options
  *
  * @return Page
  */
 public function getFromRevision(Revision $revision, QueryOptions $options = null)
 {
     if (is_null($options)) {
         $options = new QueryOptions();
     }
     $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(array('revids' => $revision->getId()), $options)));
     $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages']));
     $revisions->addRevision($revision);
     return new Page(new PageIdentifier(new Title($result['title'], $result['ns']), $result['pageid']), $revisions);
 }
 /**
  * @param Revision $revision
  *
  * @returns string
  */
 private function getTokenForRevision(Revision $revision)
 {
     $result = $this->api->postRequest(new SimpleRequest('query', array('prop' => 'revisions', 'revids' => $revision->getId(), 'rvtoken' => 'rollback')));
     $result = array_shift($result['query']['pages']);
     return $result['revisions'][0]['rollbacktoken'];
 }
Example #11
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param array $extraParams
  *
  * @return Page
  */
 public function getFromRevision(Revision $revision, array $extraParams = [])
 {
     $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(['revids' => $revision->getId()], $extraParams)));
     $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages']));
     $revisions->addRevision($revision);
     return new Page(new PageIdentifier(new Title($result['title'], $result['ns']), $result['pageid']), $revisions);
 }
Example #12
0
 /**
  * @param Revision $revision
  *
  * @return bool
  */
 public function hasRevision(Revision $revision)
 {
     return array_key_exists($revision->getId(), $this->revisions);
 }
Example #13
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param DeleteOptions|null $options
  *
  * @return bool
  */
 public function deleteFromRevision(Revision $revision, DeleteOptions $options = null)
 {
     $this->api->postRequest(new SimpleRequest('delete', $this->getDeleteParams($revision->getPageIdentifier(), $options)));
     return true;
 }