25use InvalidArgumentException;
29use Psr\Log\LoggerInterface;
30use Psr\Log\NullLogger;
35use Wikimedia\Assert\Assert;
122 $this->saveParseLogger =
new NullLogger();
125 throw new InvalidArgumentException(
126 'User must be specified when setting audience to FOR_THIS_USER'
173 $this->revisionOutput = $output;
193 $withHtml = $hints[
'generate-html'] ??
true;
195 if ( !$this->revisionOutput
196 || ( $withHtml && !$this->revisionOutput->hasText() )
198 $output = call_user_func( $this->combineOutput, $this, $hints );
200 Assert::postcondition(
202 'Callback did not return a ParserOutput object!'
205 $this->revisionOutput = $output;
223 $withHtml = $hints[
'generate-html'] ??
true;
225 if ( !isset( $this->slotsOutput[ $role ] )
226 || ( $withHtml && !$this->slotsOutput[ $role ]->hasText() )
228 $content = $this->revision->getContent( $role, $this->audience, $this->forUser );
232 'Access to the content has been suppressed for this audience'
238 if ( $withHtml && !$output->hasText() ) {
239 throw new LogicException(
240 'HTML generation was requested, but '
242 .
'::getParserOutput() returns a ParserOutput with no text set.'
247 $this->options->registerWatcher(
null );
250 $this->slotsOutput[ $role ] = $output;
253 return $this->slotsOutput[$role];
265 $this->revision->getId(),
281 if ( $rev->
getId() === $this->revision->getId() ) {
285 if ( $this->revision->getId() ) {
286 throw new LogicException(
'RenderedRevision already has a revision with ID '
287 . $this->revision->getId(),
', can\'t update to revision with ID ' . $rev->
getId() );
290 if ( !$this->revision->getSlots()->hasSameContent( $rev->
getSlots() ) ) {
291 throw new LogicException(
'Cannot update to a revision with different content!' );
297 $this->revision->getPageId(),
298 $this->revision->getId(),
299 $this->revision->getTimestamp()
321 if ( $this->revisionOutput ) {
323 $this->revisionOutput,
328 $this->revisionOutput =
null;
331 $this->saveParseLogger->debug( __METHOD__ .
": no prepared revision output" );
334 foreach ( $this->slotsOutput as $role => $output ) {
341 unset( $this->slotsOutput[$role] );
382 if ( $this->revision->isReadyForInsertion() || !$this->revision->getId() ) {
384 $oldCallback = $this->options->getCurrentRevisionCallback();
385 $this->options->setCurrentRevisionCallback(
386 function (
Title $parserTitle, $parser =
false ) use (
$title, $oldCallback ) {
388 $legacyRevision = new Revision( $this->revision );
389 return $legacyRevision;
391 return call_user_func( $oldCallback, $parserTitle, $parser );
418 $varyMsg = __METHOD__ .
": cannot use prepared output for '{title}'";
419 $context = [
'title' => $this->title->getPrefixedText() ];
421 if ( $out->
getFlag(
'vary-revision' ) ) {
423 $logger->info(
"$varyMsg (vary-revision)",
$context );
426 $out->
getFlag(
'vary-revision-id' )
427 && $actualRevId !==
false
430 $logger->info(
"$varyMsg (vary-revision-id and wrong ID)",
$context );
433 $out->
getFlag(
'vary-revision-timestamp' )
434 && $actualRevTimestamp !==
false
435 && ( $actualRevTimestamp ===
true ||
438 $logger->info(
"$varyMsg (vary-revision-timestamp and wrong timestamp)",
$context );
441 $out->
getFlag(
'vary-page-id' )
442 && $actualPageId !==
false
445 $logger->info(
"$varyMsg (vary-page-id and wrong ID)",
$context );
447 } elseif ( $out->
getFlag(
'vary-revision-exists' ) ) {
451 $logger->info(
"$varyMsg (vary-revision-exists)",
$context );
454 $out->
getFlag(
'vary-revision-sha1' ) &&
459 $logger->info(
"$varyMsg (vary-revision-sha1 with wrong SHA-1)",
$context );
470 $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.