/** * Recursively get the data for all children. This will add the revision's * content to the results array, with the post ID as key. * * @param PostRevision|PostSummary $revision * @return array */ public function getRevisionsData($revision) { // make sure we don't parse text that isn't meant to be parsed (e.g. // topic titles are never meant to be parsed from wikitext to html) $format = $revision->isFormatted() ? 'html' : 'wikitext'; // store type of revision so we can also search for very specific types // (e.g. titles only) // possible values will be: // * title // * post // * post-summary $type = $revision->getRevisionType(); if (method_exists($revision, 'isTopicTitle') && $revision->isTopicTitle()) { $type = 'title'; } $data = array(); if ($this->permissions->isAllowed($revision, 'view')) { $data[] = array('id' => $revision->getCollectionId()->getAlphadecimal(), 'text' => trim(Sanitizer::stripAllTags($revision->getContent($format))), 'source_text' => $revision->getContent('wikitext'), 'moderation_state' => $revision->getModerationState(), 'timestamp' => $revision->getCollectionId()->getTimestamp(TS_ISO_8601), 'update_timestamp' => $revision->getRevisionId()->getTimestamp(TS_ISO_8601), 'type' => $type); } if ($revision instanceof PostRevision) { // get data from all child posts too foreach ($revision->getChildren() as $child) { $data = array_merge($data, $this->getRevisionsData($child)); } } return $data; }