use InvalidArgumentException;
use LogicException;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\Storage\SuppressedDataException;
use ParserOptions;
use ParserOutput;
use Psr\Log\LoggerInterface;
use Revision;
use Title;
use User;
+use Content;
use Wikimedia\Assert\Assert;
/**
return $this->options;
}
+ /**
+ * Sets a ParserOutput to be returned by getRevisionParserOutput().
+ *
+ * @note For internal use by RevisionRenderer only! This method may be modified
+ * or removed without notice per the deprecation policy.
+ *
+ * @internal
+ *
+ * @param ParserOutput $output
+ */
+ public function setRevisionParserOutput( ParserOutput $output ) {
+ $this->revisionOutput = $output;
+
+ // If there is only one slot, we assume that the combined output is identical
+ // with the main slot's output. This is intended to prevent a redundant re-parse of
+ // the content in case getSlotParserOutput( SlotRecord::MAIN ) is called, for instance
+ // from ContentHandler::getSecondaryDataUpdates.
+ if ( $this->revision->getSlotRoles() === [ SlotRecord::MAIN ] ) {
+ $this->slotsOutput[ SlotRecord::MAIN ] = $output;
+ }
+ }
+
/**
* @param array $hints Hints given as an associative array. Known keys:
* - 'generate-html' => bool: Whether the caller is interested in output HTML (as opposed
'Access to the content has been suppressed for this audience'
);
} else {
- $output = $content->getParserOutput(
- $this->title,
- $this->revision->getId(),
- $this->options,
- $withHtml
- );
+ $output = $this->getSlotParserOutputUncached( $content, $withHtml );
if ( $withHtml && !$output->hasText() ) {
throw new LogicException(
return $this->slotsOutput[$role];
}
+ /**
+ * @note This method exist to make duplicate parses easier to see during profiling
+ * @param Content $content
+ * @param bool $withHtml
+ * @return ParserOutput
+ */
+ private function getSlotParserOutputUncached( Content $content, $withHtml ) {
+ return $content->getParserOutput(
+ $this->title,
+ $this->revision->getId(),
+ $this->options,
+ $withHtml
+ );
+ }
+
/**
* Updates the RevisionRecord after the revision has been saved. This can be used to discard
* and cached ParserOutput so parser functions like {{REVISIONTIMESTAMP}} or {{REVISIONID}}