Article::generateContentOutput: Ensure OutputPage has rev id set
This should not default to latest revision id, but Article::getRevIdFetched() if the ParserCache doesn't have the id set. Also set the revision id before calling OutputPage::addParserOutput to make sure the id is already set when the "OutputPageBeforeHTML" hook is run (which is the case in other code paths). Additionally I've made the tests more robust, by no longer manually getting the revision into parser cache. Bug: T281587 Change-Id: I999195441f9d75a7e4bde4d843ad7729cdb1bee0
This commit is contained in:
parent
5d4d08b9df
commit
929dbef76d
2 changed files with 23 additions and 13 deletions
|
|
@ -791,10 +791,11 @@ class Article implements Page {
|
|||
OutputPage $outputPage,
|
||||
array $textOptions
|
||||
) {
|
||||
$outputPage->addParserOutput( $pOutput, $textOptions );
|
||||
# Ensure that UI elements requiring revision ID have
|
||||
# the correct version information.
|
||||
$outputPage->setRevisionId( $pOutput->getCacheRevisionId() ?? $this->mPage->getLatest() );
|
||||
$outputPage->setRevisionId( $pOutput->getCacheRevisionId() ?? $this->getRevIdFetched() );
|
||||
|
||||
$outputPage->addParserOutput( $pOutput, $textOptions );
|
||||
# Preload timestamp to avoid a DB hit
|
||||
$cachedTimestamp = $pOutput->getTimestamp();
|
||||
if ( $cachedTimestamp !== null ) {
|
||||
|
|
|
|||
|
|
@ -245,6 +245,8 @@ class ArticleViewTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
$this->assertStringNotContainsString( 'id="revision-info-current"', $output->getSubtitle() );
|
||||
$this->assertStringNotContainsString( 'Test B', $this->getHtml( $output ) );
|
||||
$this->assertSame( $idA, $output->getRevisionId() );
|
||||
$this->assertSame( $revisions[1]->getTimestamp(), $output->getRevisionTimestamp() );
|
||||
}
|
||||
|
||||
public function testViewOfOldRevisionFromCache() {
|
||||
|
|
@ -258,28 +260,35 @@ class ArticleViewTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
],
|
||||
] );
|
||||
|
||||
$revisions = [];
|
||||
$page = $this->getPage( __METHOD__, [ 1 => 'Test A', 2 => 'Test B' ], $revisions );
|
||||
$idA = $revisions[1]->getId();
|
||||
|
||||
// View the revision once (to get it into the cache)
|
||||
$article = new Article( $page->getTitle(), $idA );
|
||||
$article->getContext()->getOutput()->setTitle( $page->getTitle() );
|
||||
|
||||
// Force cache
|
||||
MediaWikiServices::getInstance()
|
||||
->getParserOutputAccess()
|
||||
->getParserOutput(
|
||||
$page,
|
||||
ParserOptions::newCanonical( $article->getContext()->getUser() ),
|
||||
$revisions[1]
|
||||
);
|
||||
|
||||
$article->view();
|
||||
|
||||
// Reset the output page and view the revision again (from ParserCache)
|
||||
$article = new Article( $page->getTitle(), $idA );
|
||||
$context = RequestContext::getMain();
|
||||
$context->setOutput( new OutputPage( $context ) );
|
||||
$article->setContext( $context );
|
||||
|
||||
$outputPageBeforeHTMLRevisionId = null;
|
||||
$this->setTemporaryHook( 'OutputPageBeforeHTML',
|
||||
static function ( OutputPage $out ) use ( &$outputPageBeforeHTMLRevisionId ) {
|
||||
$outputPageBeforeHTMLRevisionId = $out->getRevisionId();
|
||||
}
|
||||
);
|
||||
|
||||
$article->view();
|
||||
$output = $article->getContext()->getOutput();
|
||||
$this->assertStringContainsString( 'Test A', $this->getHtml( $output ) );
|
||||
$this->assertSame( 1, substr_count( $output->getSubtitle(), 'class="mw-revision warningbox"' ) );
|
||||
$this->assertSame( $idA, $output->getRevisionId() );
|
||||
$this->assertSame( $revisions[1]->getTimestamp(), $output->getRevisionTimestamp() );
|
||||
$this->assertSame( $idA, $outputPageBeforeHTMLRevisionId );
|
||||
}
|
||||
|
||||
public function testViewOfCurrentRevision() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue