/**
  * @param AbstractRevision $revision
  * @return string
  */
 protected function decideContentFormat(AbstractRevision $revision)
 {
     if ($revision instanceof PostRevision && $revision->isTopicTitle()) {
         return 'plaintext';
     }
     $alpha = $revision->getRevisionId()->getAlphadecimal();
     if (isset($this->revisionContentFormat[$alpha])) {
         return $this->revisionContentFormat[$alpha];
     }
     return $this->contentFormat;
 }
 /**
  * @var AbstractRevision $summary
  * @var string           $timestamp
  */
 public function setRevisionTimestamp(AbstractRevision $revision, $timestamp)
 {
     $uid = $this->getTimestampId($timestamp);
     $setRevId = true;
     // We don't set the topic title postId as it was inherited from the workflow.  We only set the
     // postId for first revisions because further revisions inherit it from the parent which was
     // set appropriately.
     if ($revision instanceof PostRevision && $revision->isFirstRevision() && !$revision->isTopicTitle()) {
         $this->postIdProperty->setValue($revision, $uid);
     }
     if ($setRevId) {
         if ($revision->getRevisionId()->equals($revision->getLastContentEditId())) {
             $this->lastEditIdProperty->setValue($revision, $uid);
         }
         $this->revIdProperty->setValue($revision, $uid);
     }
 }
 /**
  * @param AbstractRevision $revision
  * @return AbstractRevision
  */
 protected function getRoot(AbstractRevision $revision)
 {
     if ($revision instanceof PostSummary) {
         $topicId = $revision->getSummaryTargetId();
     } elseif ($revision instanceof PostRevision && !$revision->isTopicTitle()) {
         try {
             $topicId = $revision->getCollection()->getWorkflowId();
         } catch (DataModelException $e) {
             // failed to locate root post (most likely in unit tests, where
             // we didn't store the tree)
             return $revision;
         }
     } else {
         // if we can't the revision it back to a root, this revision is root
         return $revision;
     }
     $collection = PostCollection::newFromId($topicId);
     return $collection->getLastRevision();
 }
 /**
  * @todo Move this to AbstractBlock and use for summary/header/etc.
  * @param AbstractRevision $revision
  * @return Message
  */
 protected function getDisallowedErrorMessage(AbstractRevision $revision)
 {
     if (in_array($this->action, array('moderate-topic', 'moderate-post'))) {
         /*
          * When failing to moderate an already moderated action (like
          * undo), show the more general "you have insufficient
          * permissions for this action" message, rather than the
          * specialized "this topic is <hidden|deleted|suppressed>" msg.
          */
         return $this->context->msg('flow-error-not-allowed');
     }
     $state = $revision->getModerationState();
     // display simple message
     // i18n messages:
     //  flow-error-not-allowed-hide,
     //  flow-error-not-allowed-reply-to-hide-topic
     //  flow-error-not-allowed-delete
     //  flow-error-not-allowed-reply-to-delete-topic
     //  flow-error-not-allowed-suppress
     //  flow-error-not-allowed-reply-to-suppress-topic
     if ($revision instanceof PostRevision) {
         $type = $revision->isTopicTitle() ? 'topic' : 'post';
     } else {
         $type = $revision->getRevisionType();
     }
     // Show a snippet of the relevant log entry if available.
     if (\LogPage::isLogType($state)) {
         // check if user has sufficient permissions to see log
         $logPage = new \LogPage($state);
         if ($this->context->getUser()->isAllowed($logPage->getRestriction())) {
             // LogEventsList::showLogExtract will write to OutputPage, but we
             // actually just want that text, to write it ourselves wherever we want,
             // so let's create an OutputPage object to then get the content from.
             $rc = new \RequestContext();
             $output = $rc->getOutput();
             // get log extract
             $entries = \LogEventsList::showLogExtract($output, array($state), $this->workflow->getArticleTitle()->getPrefixedText(), '', array('lim' => 10, 'showIfEmpty' => false, 'msgKey' => array(array("flow-error-not-allowed-{$this->action}-to-{$state}-{$type}", "flow-error-not-allowed-{$state}-extract"))));
             // check if there were any log extracts
             if ($entries) {
                 $message = new \RawMessage('$1');
                 return $message->rawParams($output->getHTML());
             }
         }
     }
     return $this->context->msg(array("flow-error-not-allowed-{$this->action}-to-{$state}-{$type}", "flow-error-not-allowed-{$state}", "flow-error-not-allowed"));
 }