26use InvalidArgumentException;
30use Psr\Log\LoggerInterface;
31use 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->forUser );
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];
264 $this->revision->getId(),
280 if ( $rev->
getId() === $this->revision->getId() ) {
284 if ( $this->revision->getId() ) {
285 throw new LogicException(
'RenderedRevision already has a revision with ID '
286 . $this->revision->getId() .
', can\'t update to revision with ID ' . $rev->
getId() );
289 if ( !$this->revision->getSlots()->hasSameContent( $rev->
getSlots() ) ) {
290 throw new LogicException(
'Cannot update to a revision with different content!' );
296 $this->revision->getPageId(),
297 $this->revision->getId(),
298 $this->revision->getTimestamp()
320 if ( $this->revisionOutput ) {
322 $this->revisionOutput,
327 $this->revisionOutput =
null;
330 $this->saveParseLogger->debug( __METHOD__ .
": no prepared revision output" );
333 foreach ( $this->slotsOutput as $role => $output ) {
340 unset( $this->slotsOutput[$role] );
381 if ( $this->revision->isReadyForInsertion() || !$this->revision->getId() ) {
383 $oldCallback = $this->options->getCurrentRevisionRecordCallback();
384 $this->options->setCurrentRevisionRecordCallback(
385 function (
Title $parserTitle, $parser =
null ) use (
$title, $oldCallback ) {
387 return $this->revision;
389 return call_user_func( $oldCallback, $parserTitle, $parser );
416 $varyMsg = __METHOD__ .
": cannot use prepared output for '{title}'";
417 $context = [
'title' => $this->title->getPrefixedText() ];
419 if ( $out->
getFlag(
'vary-revision' ) ) {
421 $logger->info(
"$varyMsg (vary-revision)", $context );
424 $out->
getFlag(
'vary-revision-id' )
425 && $actualRevId !==
false
428 $logger->info(
"$varyMsg (vary-revision-id and wrong ID)", $context );
431 $out->
getFlag(
'vary-revision-timestamp' )
432 && $actualRevTimestamp !==
false
433 && ( $actualRevTimestamp ===
true ||
436 $logger->info(
"$varyMsg (vary-revision-timestamp and wrong timestamp)", $context );
439 $out->
getFlag(
'vary-page-id' )
440 && $actualPageId !==
false
443 $logger->info(
"$varyMsg (vary-page-id and wrong ID)", $context );
445 } elseif ( $out->
getFlag(
'vary-revision-exists' ) ) {
449 $logger->info(
"$varyMsg (vary-revision-exists)", $context );
452 $out->
getFlag(
'vary-revision-sha1' ) &&
457 $logger->info(
"$varyMsg (vary-revision-sha1 with wrong SHA-1)", $context );
468 $logger->debug( __METHOD__ .
": reusing prepared output for '{title}'", $context );
Set options of the Parser.
getSpeculativeRevIdUsed()
getRevisionTimestampUsed()
getRevisionUsedSha1Base36()
getSpeculativePageIdUsed()
Represents a title within MediaWiki.
equals(LinkTarget $title)
Compare with another title.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Base interface for content objects.