26use InvalidArgumentException;
31use Psr\Log\LoggerInterface;
32use Psr\Log\NullLogger;
34use Wikimedia\Assert\Assert;
121 $this->saveParseLogger =
new NullLogger();
124 throw new InvalidArgumentException(
125 'User must be specified when setting audience to FOR_THIS_USER'
172 $this->revisionOutput = $output;
192 $withHtml = $hints[
'generate-html'] ??
true;
194 if ( !$this->revisionOutput
195 || ( $withHtml && !$this->revisionOutput->hasText() )
197 $output = call_user_func( $this->combineOutput, $this, $hints );
199 Assert::postcondition(
201 'Callback did not return a ParserOutput object!'
204 $this->revisionOutput = $output;
222 $withHtml = $hints[
'generate-html'] ??
true;
224 if ( !isset( $this->slotsOutput[ $role ] )
225 || ( $withHtml && !$this->slotsOutput[ $role ]->hasText() )
227 $content = $this->revision->getContent( $role, $this->audience, $this->performer );
231 'Access to the content has been suppressed for this audience'
237 if ( $withHtml && !$output->hasText() ) {
238 throw new LogicException(
239 'HTML generation was requested, but '
241 .
'::getParserOutput() returns a ParserOutput with no text set.'
246 $this->options->registerWatcher(
null );
249 $this->slotsOutput[ $role ] = $output;
252 return $this->slotsOutput[$role];
262 $parserOutput =
$content->getParserOutput(
264 $this->revision->getId(),
269 $parserOutput->setCacheRevisionId( $this->revision->getId() );
270 $parserOutput->setTimestamp( $this->revision->getTimestamp() );
271 return $parserOutput;
284 if ( $rev->
getId() === $this->revision->getId() ) {
288 if ( $this->revision->getId() ) {
289 throw new LogicException(
'RenderedRevision already has a revision with ID '
290 . $this->revision->getId() .
', can\'t update to revision with ID ' . $rev->
getId() );
293 if ( !$this->revision->getSlots()->hasSameContent( $rev->
getSlots() ) ) {
294 throw new LogicException(
'Cannot update to a revision with different content!' );
300 $this->revision->getPageId(),
301 $this->revision->getId(),
302 $this->revision->getTimestamp()
324 if ( $this->revisionOutput ) {
326 $this->revisionOutput,
331 $this->revisionOutput =
null;
334 $this->saveParseLogger->debug( __METHOD__ .
": no prepared revision output" );
337 foreach ( $this->slotsOutput as $role => $output ) {
344 unset( $this->slotsOutput[$role] );
385 if ( $this->revision->isReadyForInsertion() || !$this->revision->getId() ) {
387 $oldCallback = $this->options->getCurrentRevisionRecordCallback();
388 $this->options->setCurrentRevisionRecordCallback(
389 function (
Title $parserTitle, $parser =
null ) use (
$title, $oldCallback ) {
391 return $this->revision;
393 return call_user_func( $oldCallback, $parserTitle, $parser );
420 $varyMsg = __METHOD__ .
": cannot use prepared output for '{title}'";
421 $context = [
'title' => $this->title->getPrefixedText() ];
423 if ( $out->
getFlag(
'vary-revision' ) ) {
425 $logger->info(
"$varyMsg (vary-revision)", $context );
428 $out->
getFlag(
'vary-revision-id' )
429 && $actualRevId !==
false
432 $logger->info(
"$varyMsg (vary-revision-id and wrong ID)", $context );
435 $out->
getFlag(
'vary-revision-timestamp' )
436 && $actualRevTimestamp !==
false
437 && ( $actualRevTimestamp ===
true ||
440 $logger->info(
"$varyMsg (vary-revision-timestamp and wrong timestamp)", $context );
443 $out->
getFlag(
'vary-page-id' )
444 && $actualPageId !==
false
447 $logger->info(
"$varyMsg (vary-page-id and wrong ID)", $context );
449 } elseif ( $out->
getFlag(
'vary-revision-exists' ) ) {
453 $logger->info(
"$varyMsg (vary-revision-exists)", $context );
456 $out->
getFlag(
'vary-revision-sha1' ) &&
461 $logger->info(
"$varyMsg (vary-revision-sha1 with wrong SHA-1)", $context );
472 $logger->debug( __METHOD__ .
": reusing prepared output for '{title}'", $context );
Set options of the Parser.
getSpeculativeRevIdUsed()
getRevisionTimestampUsed()
getRevisionUsedSha1Base36()
getSpeculativePageIdUsed()
Represents a title within MediaWiki.
equals(object $other)
Compares with another Title.
Base interface for content objects.