2020-09-30 19:25:29 +00:00
|
|
|
<?php
|
2024-07-09 15:36:08 +00:00
|
|
|
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
2020-11-18 00:26:53 +00:00
|
|
|
use MediaWiki\Json\JsonCodec;
|
2024-03-02 00:56:06 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2020-11-17 20:34:43 +00:00
|
|
|
use MediaWiki\Logger\Spi as LoggerSpi;
|
2022-08-01 19:14:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2024-07-30 17:13:18 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-05-12 10:26:57 +00:00
|
|
|
use MediaWiki\Page\Hook\OpportunisticLinksUpdateHook;
|
2024-02-18 13:33:18 +00:00
|
|
|
use MediaWiki\Page\PageRecord;
|
2020-09-30 19:25:29 +00:00
|
|
|
use MediaWiki\Page\ParserOutputAccess;
|
2024-02-18 13:33:18 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2023-03-23 14:48:49 +00:00
|
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
2024-06-13 21:11:26 +00:00
|
|
|
use MediaWiki\Parser\ParserOutput;
|
2020-12-04 15:28:25 +00:00
|
|
|
use MediaWiki\Parser\RevisionOutputCache;
|
2023-12-15 15:52:25 +00:00
|
|
|
use MediaWiki\PoolCounter\PoolCounter;
|
2024-02-18 13:33:18 +00:00
|
|
|
use MediaWiki\PoolCounter\PoolCounterWork;
|
2020-09-30 19:25:29 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2024-02-18 13:33:18 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2020-09-30 19:25:29 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-11-13 12:04:35 +00:00
|
|
|
use MediaWiki\Revision\RevisionRenderer;
|
2022-04-14 20:54:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2020-09-30 19:25:29 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-08-25 12:29:41 +00:00
|
|
|
use MediaWiki\Status\Status;
|
2024-06-13 21:11:26 +00:00
|
|
|
use MediaWiki\Title\TitleFormatter;
|
2023-08-19 03:35:06 +00:00
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2020-09-30 19:25:29 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2024-07-09 13:37:44 +00:00
|
|
|
use Wikimedia\ObjectCache\EmptyBagOStuff;
|
|
|
|
|
use Wikimedia\ObjectCache\HashBagOStuff;
|
2024-02-18 13:33:18 +00:00
|
|
|
use Wikimedia\Rdbms\ChronologyProtector;
|
|
|
|
|
use Wikimedia\Rdbms\ILBFactory;
|
2024-03-15 11:18:10 +00:00
|
|
|
use Wikimedia\Stats\StatsFactory;
|
2022-04-06 08:01:52 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Page\ParserOutputAccess
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class ParserOutputAccessTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
public int $actualCallsToPoolWorkArticleView = 0;
|
|
|
|
|
public int $expectedCallsToPoolWorkArticleView = 0;
|
|
|
|
|
|
|
|
|
|
public function tearDown(): void {
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$this->expectedCallsToPoolWorkArticleView,
|
|
|
|
|
$this->actualCallsToPoolWorkArticleView,
|
|
|
|
|
'Calls to newPoolWorkArticleView'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:25:29 +00:00
|
|
|
private function getHtml( $value ) {
|
|
|
|
|
if ( $value instanceof StatusValue ) {
|
|
|
|
|
$value = $value->getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $value instanceof ParserOutput ) {
|
2024-07-30 17:13:18 +00:00
|
|
|
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline();
|
|
|
|
|
$value = $pipeline->run( $value, $this->getParserOptions(), [] )->getContentHolderText();
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 12:04:35 +00:00
|
|
|
$html = preg_replace( '/<!--.*?-->/s', '', $value );
|
2023-03-24 03:21:20 +00:00
|
|
|
$html = trim( preg_replace( '/[\r\n]{2,}/', "\n", $html ) );
|
|
|
|
|
$html = trim( preg_replace( '/\s{2,}/', ' ', $html ) );
|
2020-09-30 19:25:29 +00:00
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertContainsHtml( $needle, $actual, $msg = '' ) {
|
|
|
|
|
$this->assertNotNull( $actual );
|
|
|
|
|
|
|
|
|
|
if ( $actual instanceof StatusValue ) {
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $actual, 'isOK' );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString( $needle, $this->getHtml( $actual ), $msg );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertSameHtml( $expected, $actual, $msg = '' ) {
|
|
|
|
|
$this->assertNotNull( $actual );
|
|
|
|
|
|
|
|
|
|
if ( $actual instanceof StatusValue ) {
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $actual, 'isOK' );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $this->getHtml( $expected ), $this->getHtml( $actual ), $msg );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertNotSameHtml( $expected, $actual, $msg = '' ) {
|
|
|
|
|
$this->assertNotNull( $actual );
|
|
|
|
|
|
|
|
|
|
if ( $actual instanceof StatusValue ) {
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $actual, 'isOK' );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertNotSame( $this->getHtml( $expected ), $this->getHtml( $actual ), $msg );
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 20:10:05 +00:00
|
|
|
private function getParserCache( $bag = null ) {
|
2020-10-23 00:17:31 +00:00
|
|
|
$parserCache = new ParserCache(
|
2023-10-23 20:10:05 +00:00
|
|
|
'test',
|
2020-10-23 00:17:31 +00:00
|
|
|
$bag ?: new HashBagOStuff(),
|
2021-02-03 22:08:25 +00:00
|
|
|
'19900220000000',
|
2020-10-23 00:17:31 +00:00
|
|
|
$this->getServiceContainer()->getHookContainer(),
|
2020-11-18 00:26:53 +00:00
|
|
|
new JsonCodec(),
|
2024-03-15 11:18:10 +00:00
|
|
|
StatsFactory::newNull(),
|
2021-03-24 14:05:44 +00:00
|
|
|
new NullLogger(),
|
|
|
|
|
$this->getServiceContainer()->getTitleFactory(),
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
$this->getServiceContainer()->getWikiPageFactory(),
|
|
|
|
|
$this->getServiceContainer()->getGlobalIdGenerator()
|
2020-10-23 00:17:31 +00:00
|
|
|
);
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
return $parserCache;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
private function getRevisionOutputCache( $bag = null, $expiry = 3600 ) {
|
|
|
|
|
$wanCache = new WANObjectCache( [ 'cache' => $bag ?: new HashBagOStuff() ] );
|
|
|
|
|
$revisionOutputCache = new RevisionOutputCache(
|
|
|
|
|
'test',
|
|
|
|
|
$wanCache,
|
|
|
|
|
$expiry,
|
2021-02-03 22:08:25 +00:00
|
|
|
'19900220000000',
|
2020-12-04 15:28:25 +00:00
|
|
|
new JsonCodec(),
|
2024-03-15 11:18:10 +00:00
|
|
|
StatsFactory::newNull(),
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
new NullLogger(),
|
|
|
|
|
$this->getServiceContainer()->getGlobalIdGenerator()
|
2020-12-04 15:28:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $revisionOutputCache;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:25:29 +00:00
|
|
|
/**
|
|
|
|
|
* @param ParserCache|null $parserCache
|
2020-12-04 15:28:25 +00:00
|
|
|
* @param RevisionOutputCache|null $revisionOutputCache
|
2020-11-13 12:04:35 +00:00
|
|
|
* @param int|bool $maxRenderCalls
|
2020-09-30 19:25:29 +00:00
|
|
|
*
|
|
|
|
|
* @return ParserOutputAccess
|
2020-11-13 12:04:35 +00:00
|
|
|
* @throws Exception
|
2020-09-30 19:25:29 +00:00
|
|
|
*/
|
2020-11-13 12:04:35 +00:00
|
|
|
private function getParserOutputAccessWithCache(
|
|
|
|
|
$parserCache = null,
|
2020-12-04 15:28:25 +00:00
|
|
|
$revisionOutputCache = null,
|
2020-11-13 12:04:35 +00:00
|
|
|
$maxRenderCalls = false
|
2024-02-18 13:33:18 +00:00
|
|
|
): ParserOutputAccess {
|
|
|
|
|
return $this->getParserOutputAccess( [
|
|
|
|
|
'parserCache' => $parserCache ?? new HashBagOStuff(),
|
|
|
|
|
'revisionOutputCache' => $revisionOutputCache ?? new HashBagOStuff(),
|
|
|
|
|
'maxRenderCalls' => $maxRenderCalls
|
|
|
|
|
] );
|
2023-03-23 14:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-02-18 13:33:18 +00:00
|
|
|
* @param array $options
|
2023-03-23 14:48:49 +00:00
|
|
|
*
|
|
|
|
|
* @return ParserOutputAccess
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2024-02-18 13:33:18 +00:00
|
|
|
private function getParserOutputAccess( array $options = [] ): ParserOutputAccess {
|
|
|
|
|
$parserCacheFactory = $options['parserCacheFactory'] ?? null;
|
|
|
|
|
$maxRenderCalls = $options['maxRenderCalls'] ?? null;
|
|
|
|
|
$parserCache = $options['parserCache'] ?? null;
|
|
|
|
|
$revisionOutputCache = $options['revisionOutputCache'] ?? null;
|
|
|
|
|
$expectPoolCounterCalls = $options['expectPoolCounterCalls'] ?? 0;
|
|
|
|
|
|
|
|
|
|
if ( !$parserCacheFactory ) {
|
|
|
|
|
if ( !$parserCache instanceof ParserCache ) {
|
|
|
|
|
$parserCache = $this->getParserCache(
|
|
|
|
|
$parserCache ?? new EmptyBagOStuff()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$revisionOutputCache instanceof RevisionOutputCache ) {
|
|
|
|
|
$revisionOutputCache = $this->getRevisionOutputCache(
|
|
|
|
|
$revisionOutputCache ?? new EmptyBagOStuff()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parserCacheFactory = $this->createMock( ParserCacheFactory::class );
|
|
|
|
|
|
|
|
|
|
$parserCacheFactory->method( 'getParserCache' )
|
|
|
|
|
->willReturn( $parserCache );
|
|
|
|
|
|
|
|
|
|
$parserCacheFactory->method( 'getRevisionOutputCache' )
|
|
|
|
|
->willReturn( $revisionOutputCache );
|
|
|
|
|
}
|
2020-11-13 12:04:35 +00:00
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$revRenderer = $this->getServiceContainer()->getRevisionRenderer();
|
2020-11-13 12:04:35 +00:00
|
|
|
if ( $maxRenderCalls ) {
|
|
|
|
|
$realRevRenderer = $revRenderer;
|
2024-02-18 13:33:18 +00:00
|
|
|
|
2020-11-13 12:04:35 +00:00
|
|
|
$revRenderer =
|
|
|
|
|
$this->createNoOpMock( RevisionRenderer::class, [ 'getRenderedRevision' ] );
|
|
|
|
|
|
|
|
|
|
$revRenderer->expects( $this->atMost( $maxRenderCalls ) )
|
|
|
|
|
->method( 'getRenderedRevision' )
|
|
|
|
|
->willReturnCallback( [ $realRevRenderer, 'getRenderedRevision' ] );
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$mock = new class (
|
|
|
|
|
$parserCacheFactory,
|
|
|
|
|
$this->getServiceContainer()->getRevisionLookup(),
|
|
|
|
|
$revRenderer,
|
2024-08-16 12:38:06 +00:00
|
|
|
$this->getServiceContainer()->getStatsFactory(),
|
2024-02-18 13:33:18 +00:00
|
|
|
$this->getServiceContainer()->getDBLoadBalancerFactory(),
|
|
|
|
|
$this->getServiceContainer()->getChronologyProtector(),
|
2024-03-02 00:56:06 +00:00
|
|
|
LoggerFactory::getProvider(),
|
2024-02-18 13:33:18 +00:00
|
|
|
$this->getServiceContainer()->getWikiPageFactory(),
|
|
|
|
|
$this->getServiceContainer()->getTitleFormatter(),
|
|
|
|
|
$this
|
|
|
|
|
) extends ParserOutputAccess {
|
|
|
|
|
private ParserOutputAccessTest $test;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
ParserCacheFactory $parserCacheFactory,
|
|
|
|
|
RevisionLookup $revisionLookup,
|
|
|
|
|
RevisionRenderer $revisionRenderer,
|
2024-08-16 12:38:06 +00:00
|
|
|
StatsFactory $statsFactory,
|
2024-02-18 13:33:18 +00:00
|
|
|
ILBFactory $lbFactory,
|
|
|
|
|
ChronologyProtector $chronologyProtector,
|
|
|
|
|
LoggerSpi $loggerSpi,
|
|
|
|
|
WikiPageFactory $wikiPageFactory,
|
|
|
|
|
TitleFormatter $titleFormatter,
|
|
|
|
|
ParserOutputAccessTest $test
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct(
|
|
|
|
|
$parserCacheFactory,
|
|
|
|
|
$revisionLookup,
|
|
|
|
|
$revisionRenderer,
|
2024-08-16 12:38:06 +00:00
|
|
|
$statsFactory,
|
2024-02-18 13:33:18 +00:00
|
|
|
$lbFactory,
|
|
|
|
|
$chronologyProtector,
|
|
|
|
|
$loggerSpi,
|
|
|
|
|
$wikiPageFactory,
|
|
|
|
|
$titleFormatter
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->test = $test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function newPoolWorkArticleView(
|
|
|
|
|
PageRecord $page,
|
|
|
|
|
ParserOptions $parserOptions,
|
|
|
|
|
RevisionRecord $revision,
|
|
|
|
|
int $options
|
|
|
|
|
): PoolCounterWork {
|
|
|
|
|
$this->test->actualCallsToPoolWorkArticleView++;
|
|
|
|
|
return parent::newPoolWorkArticleView( $page, $parserOptions, $revision, $options );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$this->expectedCallsToPoolWorkArticleView += $expectPoolCounterCalls;
|
|
|
|
|
|
|
|
|
|
return $mock;
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param WikiPage $page
|
|
|
|
|
* @param string $text
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionRecord
|
|
|
|
|
*/
|
|
|
|
|
private function makeFakeRevision( WikiPage $page, $text ) {
|
|
|
|
|
// construct fake revision with no ID
|
|
|
|
|
$content = new WikitextContent( $text );
|
|
|
|
|
$rev = new MutableRevisionRecord( $page->getTitle() );
|
|
|
|
|
$rev->setPageId( $page->getId() );
|
|
|
|
|
$rev->setContent( SlotRecord::MAIN, $content );
|
|
|
|
|
|
|
|
|
|
return $rev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return ParserOptions
|
|
|
|
|
*/
|
|
|
|
|
private function getParserOptions() {
|
2022-06-16 13:22:24 +00:00
|
|
|
return ParserOptions::newFromAnon();
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 10:26:57 +00:00
|
|
|
/**
|
|
|
|
|
* Install OpportunisticLinksUpdateHook to inspect whether WikiPage::triggerOpportunisticLinksUpdate
|
|
|
|
|
* is called or not, the hook implementation will return false disabling the
|
|
|
|
|
* WikiPage::triggerOpportunisticLinksUpdate to proceed completely.
|
|
|
|
|
* @param bool $called whether WikiPage::triggerOpportunisticLinksUpdate is expected to be called or not
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function installOpportunisticUpdateHook( bool $called ): void {
|
|
|
|
|
$opportunisticUpdateHook =
|
|
|
|
|
$this->createMock( OpportunisticLinksUpdateHook::class );
|
|
|
|
|
// WikiPage::triggerOpportunisticLinksUpdate is not called by default
|
|
|
|
|
$opportunisticUpdateHook->expects( $this->exactly( $called ? 1 : 0 ) )
|
|
|
|
|
->method( 'onOpportunisticLinksUpdate' )
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
$this->setTemporaryHook( 'OpportunisticLinksUpdate', $opportunisticUpdateHook );
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:25:29 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that we can get rendered output for the latest revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForLatestRevision() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'parserCache' => new HashBagOStuff()
|
|
|
|
|
] );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
2023-05-12 10:26:57 +00:00
|
|
|
// WikiPage::triggerOpportunisticLinksUpdate is not called by default
|
|
|
|
|
$this->installOpportunisticUpdateHook( false );
|
2020-09-30 19:25:29 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
2024-02-18 13:33:18 +00:00
|
|
|
|
|
|
|
|
$this->assertNotNull( $access->getCachedParserOutput( $page, $parserOptions ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that we can get rendered output for the latest revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForLatestRevisionUsingPoolCounter() {
|
|
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'expectPoolCounterCalls' => 1
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
// WikiPage::triggerOpportunisticLinksUpdate is not called by default
|
|
|
|
|
$this->installOpportunisticUpdateHook( false );
|
|
|
|
|
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 10:26:57 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that we can get rendered output for the latest revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForLatestRevisionWithLinksUpdate() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2023-05-12 10:26:57 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
// With ParserOutputAccess::OPT_LINKS_UPDATE WikiPage::triggerOpportunisticLinksUpdate can be called
|
|
|
|
|
$this->installOpportunisticUpdateHook( true );
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions, null, ParserOutputAccess::OPT_LINKS_UPDATE );
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that we can get rendered output for the latest revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForLatestRevisionWithLinksUpdateWithPoolCounter() {
|
|
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'expectPoolCounterCalls' => 1
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
// With ParserOutputAccess::OPT_LINKS_UPDATE WikiPage::triggerOpportunisticLinksUpdate can be called
|
|
|
|
|
$this->installOpportunisticUpdateHook( true );
|
|
|
|
|
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_LINKS_UPDATE | ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:25:29 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that cached output in the ParserCache will be used for the latest revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionUseCached() {
|
2020-11-13 12:04:35 +00:00
|
|
|
// Allow only one render call, use default caches
|
2020-12-04 15:28:25 +00:00
|
|
|
$access = $this->getParserOutputAccessWithCache( null, null, 1 );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
2020-11-13 12:04:35 +00:00
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
2020-11-13 12:04:35 +00:00
|
|
|
// The second call should use cached output
|
2020-09-30 19:25:29 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
2020-11-13 12:04:35 +00:00
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that cached output in the ParserCache will not be used
|
|
|
|
|
* for the latest revision if the FORCE_PARSE option is given.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionForceParse() {
|
|
|
|
|
$parserCache = $this->getParserCache( new HashBagOStuff() );
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache( $parserCache );
|
|
|
|
|
|
2022-06-16 13:22:24 +00:00
|
|
|
$parserOptions = ParserOptions::newFromAnon();
|
2020-09-30 19:25:29 +00:00
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
// Put something else into the cache, so we'd notice if it got used
|
|
|
|
|
$cachedOutput = new ParserOutput( 'Cached Text' );
|
|
|
|
|
$parserCache->save( $cachedOutput, $page, $parserOptions );
|
|
|
|
|
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FORCE_PARSE
|
|
|
|
|
);
|
|
|
|
|
$this->assertNotSameHtml( $cachedOutput, $status );
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $status );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that an error is reported if the latest revision cannot be loaded.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionCantLoad() {
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$revisionStore = $this->createNoOpMock(
|
|
|
|
|
RevisionStore::class,
|
2021-04-03 02:12:43 +00:00
|
|
|
[ 'getRevisionByTitle', 'getKnownCurrentRevision', 'getRevisionById' ]
|
2020-09-30 19:25:29 +00:00
|
|
|
);
|
|
|
|
|
$revisionStore->method( 'getRevisionById' )->willReturn( null );
|
|
|
|
|
$revisionStore->method( 'getRevisionByTitle' )->willReturn( null );
|
|
|
|
|
$revisionStore->method( 'getKnownCurrentRevision' )->willReturn( false );
|
|
|
|
|
$this->setService( 'RevisionStore', $revisionStore );
|
|
|
|
|
$this->setService( 'RevisionLookup', $revisionStore );
|
|
|
|
|
|
|
|
|
|
$page->clear();
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
2023-10-19 10:42:53 +00:00
|
|
|
$this->assertStatusError( 'missing-revision', $status );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getCachedParserOutput() will return previously generated output.
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCachedParserOutput() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertNull( $output );
|
|
|
|
|
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertNotNull( $output );
|
|
|
|
|
$this->assertContainsHtml( 'Hello <i>World</i>!', $output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getCachedParserOutput() will not return output for current revision when
|
|
|
|
|
* a fake revision with no ID is supplied.
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCachedParserOutputForFakeRevision() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
|
|
|
|
|
$rev = $this->makeFakeRevision( $page, 'fake text' );
|
|
|
|
|
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
$this->assertNull( $output );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getPageOutput() will place the generated output for the latest revision
|
|
|
|
|
* in the parser cache.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionIsCached() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
|
|
|
|
|
$cachedOutput = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'World', $cachedOutput );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that the cache for the current revision is split on parser options.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionCacheSplit() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
2022-06-16 13:22:24 +00:00
|
|
|
$frenchOptions = ParserOptions::newFromAnon();
|
2020-09-30 19:25:29 +00:00
|
|
|
$frenchOptions->setUserLang( 'fr' );
|
|
|
|
|
|
2022-06-16 13:22:24 +00:00
|
|
|
$tongaOptions = ParserOptions::newFromAnon();
|
2020-09-30 19:25:29 +00:00
|
|
|
$tongaOptions->setUserLang( 'to' );
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Test {{int:ok}}!' );
|
|
|
|
|
|
|
|
|
|
$frenchResult = $access->getParserOutput( $page, $frenchOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Test', $frenchResult );
|
|
|
|
|
|
2021-11-21 16:23:11 +00:00
|
|
|
// Check that French output was cached
|
2020-09-30 19:25:29 +00:00
|
|
|
$cachedFrenchOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $frenchOptions );
|
|
|
|
|
$this->assertNotNull( $cachedFrenchOutput, 'French output should be in the cache' );
|
|
|
|
|
|
|
|
|
|
// check that we don't get the French output when asking for Tonga
|
|
|
|
|
$cachedTongaOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $tongaOptions );
|
|
|
|
|
$this->assertNull( $cachedTongaOutput, 'Tonga output should not be in the cache yet' );
|
|
|
|
|
|
|
|
|
|
// check that we can generate the Tonga output, and it's different from French
|
|
|
|
|
$tongaResult = $access->getParserOutput( $page, $tongaOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Test', $tongaResult );
|
|
|
|
|
$this->assertNotSameHtml(
|
|
|
|
|
$frenchResult,
|
|
|
|
|
$tongaResult,
|
|
|
|
|
'Tonga output should be different from French'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// check that the Tonga output is cached
|
|
|
|
|
$cachedTongaOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $tongaOptions );
|
|
|
|
|
$this->assertNotNull( $cachedTongaOutput, 'Tonga output should be in the cache' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getPageOutput() will place the generated output in the parser cache if the
|
|
|
|
|
* latest revision is passed explicitly. In other words, thins ensures that the current
|
|
|
|
|
* revision won't get treated like an old revision.
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionIsDetectedAndCached() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
2022-11-14 20:17:19 +00:00
|
|
|
$rev = $this->editPage( $page, 'Hello \'\'World\'\'!' )->getNewRevision();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
// When $rev is passed, it should be detected to be the latest revision.
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
|
|
|
|
|
$cachedOutput = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'World', $cachedOutput );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getPageOutput() will generate output for an old revision, and
|
|
|
|
|
* that we still have the output for the current revision cached afterwards.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForOldRevision() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
2022-11-14 20:17:19 +00:00
|
|
|
$firstRev = $this->editPage( $page, 'First' )->getNewRevision();
|
|
|
|
|
$secondRev = $this->editPage( $page, 'Second' )->getNewRevision();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
// output is for the second revision (write to ParserCache)
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Second', $status );
|
|
|
|
|
|
|
|
|
|
// output is for the first revision (not written to ParserCache)
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions, $firstRev );
|
|
|
|
|
$this->assertContainsHtml( 'First', $status );
|
|
|
|
|
|
|
|
|
|
// Latest revision is still the one in the ParserCache
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Second', $output );
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that getPageOutput() will generate output for an old revision, and
|
|
|
|
|
* that we still have the output for the current revision cached afterwards.
|
|
|
|
|
*/
|
|
|
|
|
public function testOutputForOldRevisionUsingPoolCounter() {
|
|
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'expectPoolCounterCalls' => 2,
|
|
|
|
|
'parserCache' => new HashBagOStuff(),
|
|
|
|
|
'revisionOutputCache' => new HashBagOStuff()
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$firstRev = $this->editPage( $page, 'First' )->getNewRevision();
|
|
|
|
|
$secondRev = $this->editPage( $page, 'Second' )->getNewRevision();
|
|
|
|
|
|
|
|
|
|
// output is for the second revision (write to ParserCache)
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'Second', $status );
|
|
|
|
|
|
|
|
|
|
// output is for the first revision (not written to ParserCache)
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
$firstRev,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'First', $status );
|
|
|
|
|
|
|
|
|
|
// Latest revision is still the one in the ParserCache
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'Second', $output );
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:25:29 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that trying to get output for a suppressed old revision is denied.
|
|
|
|
|
*/
|
|
|
|
|
public function testOldRevisionSuppressedDenied() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
2022-11-14 20:17:19 +00:00
|
|
|
$firstRev = $this->editPage( $page, 'First' )->getNewRevision();
|
|
|
|
|
$secondRev = $this->editPage( $page, 'Second' )->getNewRevision();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$this->revisionDelete( $firstRev );
|
|
|
|
|
$firstRev =
|
|
|
|
|
$this->getServiceContainer()->getRevisionStore()->getRevisionById( $firstRev->getId() );
|
|
|
|
|
|
|
|
|
|
// output is for the first revision denied
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions, $firstRev );
|
2023-10-19 10:42:53 +00:00
|
|
|
$this->assertStatusError( 'missing-revision-permission', $status );
|
2020-09-30 19:25:29 +00:00
|
|
|
// TODO: Once PoolWorkArticleView properly reports errors, check that the correct error
|
|
|
|
|
// is propagated.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getting output for a suppressed old revision is possible when NO_AUDIENCE_CHECK
|
|
|
|
|
* is set.
|
|
|
|
|
*/
|
|
|
|
|
public function testOldRevisionSuppressedAllowed() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
2022-11-14 20:17:19 +00:00
|
|
|
$firstRev = $this->editPage( $page, 'First' )->getNewRevision();
|
|
|
|
|
$secondRev = $this->editPage( $page, 'Second' )->getNewRevision();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$this->revisionDelete( $firstRev );
|
|
|
|
|
$firstRev =
|
|
|
|
|
$this->getServiceContainer()->getRevisionStore()->getRevisionById( $firstRev->getId() );
|
|
|
|
|
|
|
|
|
|
// output is for the first revision (even though it's suppressed)
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
$firstRev,
|
|
|
|
|
ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'First', $status );
|
2020-12-04 15:28:25 +00:00
|
|
|
|
|
|
|
|
// even though the output was generated, it wasn't cached, since it's not public
|
|
|
|
|
$cachedOutput = $access->getCachedParserOutput( $page, $parserOptions, $firstRev );
|
|
|
|
|
$this->assertNull( $cachedOutput );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that output for an old revision is fetched from the secondary parser cache if possible.
|
|
|
|
|
*/
|
|
|
|
|
public function testOldRevisionUseCached() {
|
2020-11-13 12:04:35 +00:00
|
|
|
// Allow only one render call, use default caches
|
2020-12-04 15:28:25 +00:00
|
|
|
$access = $this->getParserOutputAccessWithCache( null, null, 1 );
|
2020-11-13 12:04:35 +00:00
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'First' );
|
|
|
|
|
$oldRev = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$this->editPage( $page, 'Second' );
|
|
|
|
|
|
|
|
|
|
$firstStatus = $access->getParserOutput( $page, $parserOptions, $oldRev );
|
|
|
|
|
|
|
|
|
|
// The second call should use cached output
|
|
|
|
|
$secondStatus = $access->getParserOutput( $page, $parserOptions, $oldRev );
|
|
|
|
|
$this->assertSameHtml( $firstStatus, $secondStatus );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that output for an old revision is fetched from the secondary parser cache if possible.
|
|
|
|
|
*/
|
|
|
|
|
public function testOldRevisionDisableCached() {
|
|
|
|
|
// Use default caches, but expiry 0 for the secondary cache
|
2020-12-04 15:28:25 +00:00
|
|
|
$access = $this->getParserOutputAccessWithCache(
|
|
|
|
|
null,
|
|
|
|
|
$this->getRevisionOutputCache( null, 0 )
|
|
|
|
|
);
|
2020-11-13 12:04:35 +00:00
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'First' );
|
|
|
|
|
$oldRev = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$this->editPage( $page, 'Second' );
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions, $oldRev );
|
|
|
|
|
|
|
|
|
|
// Should not be cached!
|
|
|
|
|
$cachedOutput = $access->getCachedParserOutput( $page, $parserOptions, $oldRev );
|
|
|
|
|
$this->assertNull( $cachedOutput );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that the secondary cache for output for old revisions is split on parser options.
|
|
|
|
|
*/
|
|
|
|
|
public function testOldRevisionCacheSplit() {
|
2020-11-13 12:04:35 +00:00
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
2022-06-16 13:22:24 +00:00
|
|
|
$frenchOptions = ParserOptions::newFromAnon();
|
2020-11-13 12:04:35 +00:00
|
|
|
$frenchOptions->setUserLang( 'fr' );
|
|
|
|
|
|
2022-06-16 13:22:24 +00:00
|
|
|
$tongaOptions = ParserOptions::newFromAnon();
|
2020-11-13 12:04:35 +00:00
|
|
|
$tongaOptions->setUserLang( 'to' );
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Test {{int:ok}}!' );
|
|
|
|
|
$oldRev = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$this->editPage( $page, 'Latest Test' );
|
|
|
|
|
|
|
|
|
|
$frenchResult = $access->getParserOutput( $page, $frenchOptions, $oldRev );
|
|
|
|
|
$this->assertContainsHtml( 'Test', $frenchResult );
|
|
|
|
|
|
2021-11-21 16:23:11 +00:00
|
|
|
// Check that French output was cached
|
2020-11-13 12:04:35 +00:00
|
|
|
$cachedFrenchOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $frenchOptions, $oldRev );
|
|
|
|
|
$this->assertNotNull( $cachedFrenchOutput, 'French output should be in the cache' );
|
|
|
|
|
|
|
|
|
|
// check that we don't get the French output when asking for Tonga
|
|
|
|
|
$cachedTongaOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $tongaOptions, $oldRev );
|
|
|
|
|
$this->assertNull( $cachedTongaOutput, 'Tonga output should not be in the cache yet' );
|
|
|
|
|
|
|
|
|
|
// check that we can generate the Tonga output, and it's different from French
|
|
|
|
|
$tongaResult = $access->getParserOutput( $page, $tongaOptions, $oldRev );
|
|
|
|
|
$this->assertContainsHtml( 'Test', $tongaResult );
|
|
|
|
|
$this->assertNotSameHtml(
|
|
|
|
|
$frenchResult,
|
|
|
|
|
$tongaResult,
|
|
|
|
|
'Tonga output should be different from French'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// check that the Tonga output is cached
|
|
|
|
|
$cachedTongaOutput =
|
|
|
|
|
$access->getCachedParserOutput( $page, $tongaOptions, $oldRev );
|
|
|
|
|
$this->assertNotNull( $cachedTongaOutput, 'Tonga output should be in the cache' );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-08 20:55:13 +00:00
|
|
|
* Tests that a RevisionRecord with no ID can be rendered if OPT_NO_CACHE is set.
|
2020-09-30 19:25:29 +00:00
|
|
|
*/
|
|
|
|
|
public function testFakeRevisionNoCache() {
|
|
|
|
|
$access = $this->getParserOutputAccessWithCache();
|
|
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage( __METHOD__ );
|
|
|
|
|
$rev = $this->makeFakeRevision( $page, 'fake text' );
|
|
|
|
|
|
|
|
|
|
// Render fake
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$fakeResult = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
$rev,
|
|
|
|
|
ParserOutputAccess::OPT_NO_CACHE
|
|
|
|
|
);
|
|
|
|
|
$this->assertContainsHtml( 'fake text', $fakeResult );
|
|
|
|
|
|
|
|
|
|
// check that fake output isn't cached
|
|
|
|
|
$cachedOutput = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
if ( $cachedOutput ) {
|
|
|
|
|
// we may have a cache entry for original edit
|
|
|
|
|
$this->assertNotSameHtml( $fakeResult, $cachedOutput );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-02-11 12:47:28 +00:00
|
|
|
* Tests that a RevisionRecord with no ID cannot be rendered if OPT_NO_CACHE is not set.
|
2020-09-30 19:25:29 +00:00
|
|
|
*/
|
|
|
|
|
public function testFakeRevisionError() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage( __METHOD__ );
|
|
|
|
|
$rev = $this->makeFakeRevision( $page, 'fake text' );
|
|
|
|
|
|
|
|
|
|
// Render should fail
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that trying to render a RevisionRecord for another page will throw an exception.
|
|
|
|
|
*/
|
|
|
|
|
public function testPageIdMismatchError() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page1 = $this->getExistingTestPage( __METHOD__ . '-1' );
|
|
|
|
|
$page2 = $this->getExistingTestPage( __METHOD__ . '-2' );
|
|
|
|
|
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$access->getParserOutput( $page1, $parserOptions, $page2->getRevisionRecord() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that trying to render a non-existing page will be reported as an error.
|
|
|
|
|
*/
|
|
|
|
|
public function testNonExistingPage() {
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
2023-10-19 10:42:53 +00:00
|
|
|
$this->assertStatusError( 'nopagetext', $status );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Status $status
|
|
|
|
|
* @param bool $fastStale
|
|
|
|
|
*/
|
2024-03-01 19:00:23 +00:00
|
|
|
private function setPoolCounterFactory( $status, $fastStale = false ) {
|
2024-07-09 15:36:08 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::PoolCounterConf, [
|
|
|
|
|
'ArticleView' => [
|
|
|
|
|
'class' => MockPoolCounterFailing::class,
|
|
|
|
|
'fastStale' => $fastStale,
|
|
|
|
|
'mockAcquire' => $status,
|
|
|
|
|
'mockRelease' => Status::newGood( PoolCounter::RELEASED ),
|
2024-03-01 19:00:23 +00:00
|
|
|
],
|
|
|
|
|
] );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function providePoolWorkDirty() {
|
2020-09-30 19:25:29 +00:00
|
|
|
yield [ Status::newGood( PoolCounter::QUEUE_FULL ), false, 'view-pool-overload' ];
|
|
|
|
|
yield [ Status::newGood( PoolCounter::TIMEOUT ), false, 'view-pool-overload' ];
|
|
|
|
|
yield [ Status::newGood( PoolCounter::TIMEOUT ), true, 'view-pool-contention' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that under some circumstances, stale cache entries will be returned, but get
|
|
|
|
|
* flagged as "dirty".
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providePoolWorkDirty
|
|
|
|
|
*/
|
|
|
|
|
public function testPoolWorkDirty( $status, $fastStale, $expectedMessage ) {
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::ParserCacheExpireTime => 60,
|
|
|
|
|
] );
|
|
|
|
|
$this->setPoolCounterFactory( Status::newGood( PoolCounter::LOCKED ), $fastStale );
|
2020-09-30 19:25:29 +00:00
|
|
|
MWTimestamp::setFakeTime( '2020-04-04T01:02:03' );
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'expectPoolCounterCalls' => 2,
|
|
|
|
|
'parserCache' => new HashBagOStuff()
|
|
|
|
|
] );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
2024-03-01 19:00:23 +00:00
|
|
|
$result = $access->getParserOutput(
|
2024-02-18 13:33:18 +00:00
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->assertContainsHtml( 'World', $result, 'fresh result' );
|
2024-02-18 13:33:18 +00:00
|
|
|
|
2022-04-06 08:01:52 +00:00
|
|
|
$testingAccess = TestingAccessWrapper::newFromObject( $access );
|
2023-11-08 15:55:11 +00:00
|
|
|
$testingAccess->localCache->clear();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->setPoolCounterFactory( $status, $fastStale );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
// expire parser cache
|
|
|
|
|
MWTimestamp::setFakeTime( '2020-05-05T01:02:03' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
2024-02-18 13:33:18 +00:00
|
|
|
$cachedResult = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->assertContainsHtml( 'World', $cachedResult, 'cached result' );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusWarning( $expectedMessage, $cachedResult );
|
|
|
|
|
$this->assertStatusWarning( 'view-pool-dirty-output', $cachedResult );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that a failure to acquire a work lock will be reported as an error if no
|
|
|
|
|
* stale output can be returned.
|
|
|
|
|
*/
|
|
|
|
|
public function testPoolWorkTimeout() {
|
2022-08-01 19:14:41 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::ParserCacheExpireTime => 60,
|
|
|
|
|
] );
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->setPoolCounterFactory( Status::newGood( PoolCounter::TIMEOUT ) );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'expectPoolCounterCalls' => 1
|
|
|
|
|
] );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
2024-02-18 13:33:18 +00:00
|
|
|
$result = $access->getParserOutput(
|
|
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParserOutputAccess::OPT_FOR_ARTICLE_VIEW
|
|
|
|
|
);
|
2023-10-19 10:42:53 +00:00
|
|
|
$this->assertStatusError( 'pool-timeout', $result );
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that a PoolCounter error does not prevent output from being generated.
|
|
|
|
|
*/
|
|
|
|
|
public function testPoolWorkError() {
|
2022-08-01 19:14:41 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::ParserCacheExpireTime => 60,
|
|
|
|
|
] );
|
2024-03-01 19:00:23 +00:00
|
|
|
$this->setPoolCounterFactory( Status::newFatal( 'some-error' ) );
|
2020-09-30 19:25:29 +00:00
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess();
|
2020-09-30 19:25:29 +00:00
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, 'Hello \'\'World\'\'!' );
|
|
|
|
|
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
$result = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( 'World', $result );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 14:48:49 +00:00
|
|
|
public function testParsoidCacheSplit() {
|
|
|
|
|
$parserCacheFactory = $this->createMock( ParserCacheFactory::class );
|
|
|
|
|
$revisionOutputCache = $this->getRevisionOutputCache( new HashBagOStuff() );
|
|
|
|
|
$caches = [
|
|
|
|
|
$this->getParserCache( new HashBagOStuff() ),
|
|
|
|
|
$this->getParserCache( new HashBagOStuff() ),
|
|
|
|
|
];
|
|
|
|
|
$calls = [];
|
|
|
|
|
$parserCacheFactory
|
|
|
|
|
->method( 'getParserCache' )
|
|
|
|
|
->willReturnCallback( static function ( $cacheName ) use ( &$calls, $caches ) {
|
|
|
|
|
static $cacheList = [];
|
|
|
|
|
$calls[] = $cacheName;
|
|
|
|
|
$which = array_search( $cacheName, $cacheList );
|
|
|
|
|
if ( $which === false ) {
|
|
|
|
|
$which = count( $cacheList );
|
|
|
|
|
$cacheList[] = $cacheName;
|
|
|
|
|
}
|
|
|
|
|
return $caches[$which];
|
|
|
|
|
} );
|
|
|
|
|
$parserCacheFactory
|
|
|
|
|
->method( 'getRevisionOutputCache' )
|
|
|
|
|
->willReturn( $revisionOutputCache );
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'parserCacheFactory' => $parserCacheFactory
|
|
|
|
|
] );
|
2023-03-23 14:48:49 +00:00
|
|
|
$parserOptions0 = $this->getParserOptions();
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions0 );
|
|
|
|
|
$this->assertNull( $output );
|
|
|
|
|
// $calls[0] will remember what cache name we used.
|
|
|
|
|
$this->assertCount( 1, $calls );
|
|
|
|
|
|
|
|
|
|
$parserOptions1 = $this->getParserOptions();
|
|
|
|
|
$parserOptions1->setUseParsoid();
|
|
|
|
|
$output = $access->getCachedParserOutput( $page, $parserOptions1 );
|
|
|
|
|
$this->assertNull( $output );
|
|
|
|
|
$this->assertCount( 2, $calls );
|
|
|
|
|
// Check that we used a different cache name this time.
|
|
|
|
|
$this->assertNotEquals( $calls[1], $calls[0], "Should use different caches" );
|
|
|
|
|
|
|
|
|
|
// Try this again, with actual content.
|
|
|
|
|
$calls = [];
|
|
|
|
|
$this->editPage( $page, "__NOTOC__" );
|
|
|
|
|
$status0 = $access->getParserOutput( $page, $parserOptions0 );
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
$this->assertContainsHtml( '<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"></div>', $status0 );
|
2023-03-23 14:48:49 +00:00
|
|
|
$status1 = $access->getParserOutput( $page, $parserOptions1 );
|
|
|
|
|
$this->assertContainsHtml( '<meta property="mw:PageProp/notoc"', $status1 );
|
|
|
|
|
$this->assertNotSameHtml( $status0, $status1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testParsoidRevisionCacheSplit() {
|
|
|
|
|
$parserCacheFactory = $this->createMock( ParserCacheFactory::class );
|
|
|
|
|
$parserCache = $this->getParserCache( new HashBagOStuff() );
|
|
|
|
|
$caches = [
|
|
|
|
|
$this->getRevisionOutputCache( new HashBagOStuff() ),
|
|
|
|
|
$this->getRevisionOutputCache( new HashBagOStuff() ),
|
|
|
|
|
];
|
|
|
|
|
$calls = [];
|
|
|
|
|
$parserCacheFactory
|
|
|
|
|
->method( 'getParserCache' )
|
|
|
|
|
->willReturn( $parserCache );
|
|
|
|
|
$parserCacheFactory
|
|
|
|
|
->method( 'getRevisionOutputCache' )
|
|
|
|
|
->willReturnCallback( static function ( $cacheName ) use ( &$calls, $caches ) {
|
|
|
|
|
static $cacheList = [];
|
|
|
|
|
$calls[] = $cacheName;
|
|
|
|
|
$which = array_search( $cacheName, $cacheList );
|
|
|
|
|
if ( $which === false ) {
|
|
|
|
|
$which = count( $cacheList );
|
|
|
|
|
$cacheList[] = $cacheName;
|
|
|
|
|
}
|
|
|
|
|
return $caches[$which];
|
|
|
|
|
} );
|
|
|
|
|
|
2024-02-18 13:33:18 +00:00
|
|
|
$access = $this->getParserOutputAccess( [
|
|
|
|
|
'parserCacheFactory' => $parserCacheFactory
|
|
|
|
|
] );
|
2023-03-23 14:48:49 +00:00
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$firstRev = $this->editPage( $page, 'First __NOTOC__' )->getNewRevision();
|
|
|
|
|
$secondRev = $this->editPage( $page, 'Second __NOTOC__' )->getNewRevision();
|
|
|
|
|
|
|
|
|
|
$parserOptions0 = $this->getParserOptions();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions0, $firstRev );
|
|
|
|
|
$this->assertContainsHtml( 'First', $status );
|
|
|
|
|
// Check that we used the "not parsoid" revision cache
|
2023-11-23 08:28:31 +00:00
|
|
|
$this->assertNotEmpty( $calls );
|
2023-03-23 14:48:49 +00:00
|
|
|
$notParsoid = $calls[0];
|
|
|
|
|
$this->assertEquals( array_fill( 0, count( $calls ), $notParsoid ), $calls );
|
|
|
|
|
|
|
|
|
|
$calls = [];
|
|
|
|
|
$parserOptions1 = $this->getParserOptions();
|
|
|
|
|
$parserOptions1->setUseParsoid();
|
|
|
|
|
$status = $access->getParserOutput( $page, $parserOptions1, $firstRev );
|
|
|
|
|
$this->assertContainsHtml( 'First', $status );
|
|
|
|
|
$this->assertContainsHtml( '<meta property="mw:PageProp/notoc"', $status );
|
2023-11-23 08:28:31 +00:00
|
|
|
$this->assertNotEmpty( $calls );
|
2023-03-23 14:48:49 +00:00
|
|
|
$parsoid = $calls[0];
|
|
|
|
|
$this->assertNotEquals( $notParsoid, $parsoid, "Should use different caches" );
|
|
|
|
|
$this->assertEquals( array_fill( 0, count( $calls ), $parsoid ), $calls );
|
|
|
|
|
}
|
2020-09-30 19:25:29 +00:00
|
|
|
}
|