diff --git a/client/includes/Api/ApiFormatReference.php b/client/includes/Api/ApiFormatReference.php index 9972624e54..d6da2dc274 100644 --- a/client/includes/Api/ApiFormatReference.php +++ b/client/includes/Api/ApiFormatReference.php @@ -83,7 +83,7 @@ public function execute() { $parserOptions = ParserOptions::newFromContext( $this ); $parser = $this->parserFactory->getInstance(); $parser->parse( $wikitext, Title::makeTitle( 0, 'API' ), $parserOptions ); - $html = $parser->getOutput()->getText(); + $html = $parser->getOutput()->runOutputPipeline( $parserOptions, [] )->getContentHolderText(); $this->getResult()->addValue( $this->getModulePath(), 'html', $html ); break; default: diff --git a/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/PropertyParserFunctionIntegrationTest.php b/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/PropertyParserFunctionIntegrationTest.php index a7bc6bf521..e3d70e11f0 100644 --- a/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/PropertyParserFunctionIntegrationTest.php +++ b/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/PropertyParserFunctionIntegrationTest.php @@ -105,7 +105,7 @@ private function setAllowDataAccessInUserLanguage( $value ) { public function testPropertyParserFunction_byPropertyLabel() { $result = $this->parseWikitextToHtml( '{{#property:LuaTestStringProperty}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -117,7 +117,7 @@ public function testPropertyParserFunction_byPropertyLabel() { public function testPropertyParserFunction_byPropertyId() { $result = $this->parseWikitextToHtml( '{{#property:P342}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -129,7 +129,7 @@ public function testPropertyParserFunction_byPropertyId() { public function testPropertyParserFunction_arbitraryAccess() { $result = $this->parseWikitextToHtml( '{{#property:P342|from=Q32488}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -141,7 +141,7 @@ public function testPropertyParserFunction_arbitraryAccess() { public function testPropertyParserFunction_multipleValues() { $result = $this->parseWikitextToHtml( '{{#property:P342|from=Q32489}}' ); - $this->assertSame( "

Lua :), Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :), Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -153,7 +153,7 @@ public function testPropertyParserFunction_multipleValues() { public function testPropertyParserFunction_arbitraryAccessNotFound() { $result = $this->parseWikitextToHtml( '{{#property:P342|from=Q1234567}}' ); - $this->assertSame( '', $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( '', $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -167,7 +167,7 @@ public function testPropertyParserFunction_byNonExistent() { $this->assertMatchesRegularExpression( '/.*P2147483647.*<\/p>/', - $result->getText( [ 'unwrap' => true ] ) + $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); @@ -183,7 +183,7 @@ public function testPropertyParserFunction_pageNotConnected() { 'A page not connected to an item' ); - $this->assertSame( '', $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( '', $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( diff --git a/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/StatementsParserFunctionIntegrationTest.php b/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/StatementsParserFunctionIntegrationTest.php index 028c9c181f..e5a21dc8de 100644 --- a/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/StatementsParserFunctionIntegrationTest.php +++ b/client/tests/phpunit/integration/includes/DataAccess/ParserFunctions/StatementsParserFunctionIntegrationTest.php @@ -123,7 +123,7 @@ private function setAllowDataAccessInUserLanguage( $value ) { public function testStatementsParserFunction_byPropertyLabel() { $result = $this->parseWikitextToHtml( '{{#statements:LuaTestStringProperty}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -135,7 +135,7 @@ public function testStatementsParserFunction_byPropertyLabel() { public function testStatementsParserFunction_byPropertyId() { $result = $this->parseWikitextToHtml( '{{#statements:P342}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -147,7 +147,7 @@ public function testStatementsParserFunction_byPropertyId() { public function testStatementsParserFunction_arbitraryAccess() { $result = $this->parseWikitextToHtml( '{{#statements:P342|from=Q32488}}' ); - $this->assertSame( "

Lua :)\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

Lua :)\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -161,7 +161,7 @@ public function testStatementsParserFunction_multipleValues() { $this->assertSame( "

Lua :), Lua :)\n

", - $result->getText( [ 'unwrap' => true ] ) + $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); @@ -174,7 +174,7 @@ public function testStatementsParserFunction_multipleValues() { public function testStatementsParserFunction_arbitraryAccessNotFound() { $result = $this->parseWikitextToHtml( '{{#statements:P342|from=Q1234567}}' ); - $this->assertSame( '', $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( '', $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -199,7 +199,7 @@ public function testStatementsParserFunction_unknownEntityTypeAsValue() { $result = $this->parseWikitextToHtml( '{{#statements:P666|from=Q999}}' ); - $this->assertSame( "

X303\n

", $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( "

X303\n

", $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -213,7 +213,7 @@ public function testStatementsParserFunction_byNonExistent() { $this->assertMatchesRegularExpression( '/.*P2147483645.*<\/p>/', - $result->getText( [ 'unwrap' => true ] ) + $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); @@ -229,7 +229,7 @@ public function testStatementsParserFunction_pageNotConnected() { 'A page not connected to an item' ); - $this->assertSame( '', $result->getText( [ 'unwrap' => true ] ) ); + $this->assertSame( '', $result->getRawText() ); $usageAccumulator = $this->newParserOutputUsageAccumulator( $result ); $this->assertArrayEquals( @@ -242,7 +242,7 @@ public function testStatementsParserFunction_maplink() { $this->markTestSkippedIfExtensionNotLoaded( 'Kartographer' ); $result = $this->parseWikitextToHtml( '{{#statements:P625|from=Q32489}}' ); - $text = $result->getText( [ 'unwrap' => true ] ); + $text = $result->getRawText(); $this->assertStringContainsString( 'class="mw-kartographer-maplink"', $text ); $this->assertStringNotContainsString( '<maplink', $text ); } diff --git a/lib/includes/Formatters/CachingKartographerEmbeddingHandler.php b/lib/includes/Formatters/CachingKartographerEmbeddingHandler.php index d225ed5dc3..e44e20fe16 100644 --- a/lib/includes/Formatters/CachingKartographerEmbeddingHandler.php +++ b/lib/includes/Formatters/CachingKartographerEmbeddingHandler.php @@ -58,12 +58,14 @@ public function getHtml( GlobeCoordinateValue $value, Language $language ) { $cacheKey = $this->getCacheKey( $value, $language ); if ( !$this->cache->has( $cacheKey ) ) { + $parserOptions = $this->getParserOptions( $language ); $parserOutput = $this->parser->parse( $this->getWikiText( $value ), RequestContext::getMain()->getTitle() ?? Title::makeTitle( NS_SPECIAL, 'BlankPage' ), - $this->getParserOptions( $language ) + $parserOptions ); - $this->cache->set( $this->getCacheKey( $value, $language ), $parserOutput->getText() ); + $this->cache->set( $this->getCacheKey( $value, $language ), $parserOutput->runOutputPipeline( $parserOptions, [] ) + ->getContentHolderText() ); } return $this->cache->get( $cacheKey ); } @@ -87,7 +89,7 @@ public function getPreviewHtml( GlobeCoordinateValue $value, Language $language $containerDivId = 'wb-globeCoordinateValue-preview-' . base_convert( (string)mt_rand( 1, PHP_INT_MAX ), 10, 36 ); - $html = '
' . $parserOutput->getText() . '
'; + $html = '
' . $parserOutput->getContentHolderText() . '
'; $html .= $this->getMapframeInitJS( $containerDivId, $parserOutput->getModules(), @@ -98,7 +100,7 @@ public function getPreviewHtml( GlobeCoordinateValue $value, Language $language } /** - * Get a ParserOutput with metadata for all the given GlobeCoordinateValues. + * Get a postprocessed ParserOutput with metadata for all the given GlobeCoordinateValues. * * ATTENTION: This ParserOutput will generally only contain useable metadata, for * getting the html for a certain GlobeCoordinateValue, please use self::getHtml(). @@ -117,11 +119,12 @@ public function getParserOutput( array $values, Language $language ) { $wikiText .= $this->getWikiText( $value ); } + $parserOptions = $this->getParserOptions( $language ); return $this->parser->parse( $wikiText, RequestContext::getMain()->getTitle() ?? Title::makeTitle( NS_SPECIAL, 'BlankPage' ), - $this->getParserOptions( $language ) - ); + $parserOptions + )->runOutputPipeline( $parserOptions, [] ); } private function getParserOptions( Language $language ): ParserOptions { diff --git a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php index 03905887d1..6434670381 100644 --- a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php +++ b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php @@ -4,6 +4,7 @@ use BadMethodCallException; use DataValues\StringValue; +use MediaWiki\Parser\ParserOptions; use MediaWiki\Parser\ParserOutput; use MediaWiki\Title\Title; use Wikibase\DataModel\Entity\EntityDocument; @@ -334,9 +335,10 @@ public function testGetParserOutput_redirect() { $content = $this->newRedirectContent( new ItemId( 'Q5' ), new ItemId( 'Q123' ) ); $contentRenderer = $this->getServiceContainer()->getContentRenderer(); $title = Title::makeTitle( NS_MAIN, 'Foo' ); - $parserOutput = $contentRenderer->getParserOutput( $content, $title ); + $parserOptions = ParserOptions::newFromAnon(); + $parserOutput = $contentRenderer->getParserOutput( $content, $title, null, $parserOptions ); - $html = $parserOutput->getText(); + $html = $parserOutput->runOutputPipeline( $parserOptions, [] )->getRawText(); $this->assertStringContainsString( '
', $html, 'redirect message' ); $this->assertStringContainsString( '