Skip to content

Commit

Permalink
Replace uses of deprecated ParserOutput::getText()
Browse files Browse the repository at this point in the history
Bug: T293512
Change-Id: I6c675f7f4fe17449dfb0ac9cf9372880f642b888
  • Loading branch information
ihurbainpalatin committed Dec 3, 2024
1 parent 9b28c09 commit fb04300
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion client/includes/Api/ApiFormatReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function setAllowDataAccessInUserLanguage( $value ) {
public function testPropertyParserFunction_byPropertyLabel() {
$result = $this->parseWikitextToHtml( '{{#property:LuaTestStringProperty}}' );

$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getRawText() );

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

$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getRawText() );

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

$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p>Lua&#160;:)\n</p>", $result->getRawText() );

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

$this->assertSame( "<p>Lua&#160;:), Lua&#160;:)\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p>Lua&#160;:), Lua&#160;:)\n</p>", $result->getRawText() );

$usageAccumulator = $this->newParserOutputUsageAccumulator( $result );
$this->assertArrayEquals(
Expand All @@ -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(
Expand All @@ -167,7 +167,7 @@ public function testPropertyParserFunction_byNonExistent() {

$this->assertMatchesRegularExpression(
'/<p.*class=".*wikibase-error.*">.*P2147483647.*<\/p>/',
$result->getText( [ 'unwrap' => true ] )
$result->getRawText()
);

$usageAccumulator = $this->newParserOutputUsageAccumulator( $result );
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function setAllowDataAccessInUserLanguage( $value ) {
public function testStatementsParserFunction_byPropertyLabel() {
$result = $this->parseWikitextToHtml( '{{#statements:LuaTestStringProperty}}' );

$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getRawText() );

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

$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getRawText() );

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

$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p><span><span>Lua&#160;:)</span></span>\n</p>", $result->getRawText() );

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

$this->assertSame(
"<p><span><span>Lua&#160;:)</span>, <span>Lua&#160;:)</span></span>\n</p>",
$result->getText( [ 'unwrap' => true ] )
$result->getRawText()
);

$usageAccumulator = $this->newParserOutputUsageAccumulator( $result );
Expand All @@ -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(
Expand All @@ -199,7 +199,7 @@ public function testStatementsParserFunction_unknownEntityTypeAsValue() {

$result = $this->parseWikitextToHtml( '{{#statements:P666|from=Q999}}' );

$this->assertSame( "<p><span><span>X303</span></span>\n</p>", $result->getText( [ 'unwrap' => true ] ) );
$this->assertSame( "<p><span><span>X303</span></span>\n</p>", $result->getRawText() );

$usageAccumulator = $this->newParserOutputUsageAccumulator( $result );
$this->assertArrayEquals(
Expand All @@ -213,7 +213,7 @@ public function testStatementsParserFunction_byNonExistent() {

$this->assertMatchesRegularExpression(
'/<p.*class=".*wikibase-error.*">.*P2147483645.*<\/p>/',
$result->getText( [ 'unwrap' => true ] )
$result->getRawText()
);

$usageAccumulator = $this->newParserOutputUsageAccumulator( $result );
Expand All @@ -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(
Expand All @@ -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( '&lt;maplink', $text );
}
Expand Down
15 changes: 9 additions & 6 deletions lib/includes/Formatters/CachingKartographerEmbeddingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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 = '<div id="' . $containerDivId . '">' . $parserOutput->getText() . '</div>';
$html = '<div id="' . $containerDivId . '">' . $parserOutput->getContentHolderText() . '</div>';
$html .= $this->getMapframeInitJS(
$containerDivId,
$parserOutput->getModules(),
Expand All @@ -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().
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions repo/tests/phpunit/includes/Content/ItemHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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( '<div class="redirectMsg">', $html, 'redirect message' );
$this->assertStringContainsString( '<a href="', $html, 'redirect target link' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testGetParserOutputIncludesLabelsOfRedirectEntityUsedAsStatement

$parserOutput = $entityParserOutputGenerator->getParserOutput( $revision );

$this->assertStringContainsString( 'target label', $parserOutput->getText() );
$this->assertStringContainsString( 'target label', $parserOutput->getRawText() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testGetParserOutput(
$parserOutput = $entityParserOutputGenerator->getParserOutput( $entityRevision );

$this->assertSame( 'EntityParserOutputGeneratorTestBase-TITLE', $parserOutput->getTitleText(), 'title text' );
$this->assertSame( 'EntityParserOutputGeneratorTestBase-HTML', $parserOutput->getText(), 'html text' );
$this->assertSame( 'EntityParserOutputGeneratorTestBase-HTML', $parserOutput->getRawText(), 'html text' );

/**
* @see \Wikibase\Repo\Tests\ParserOutput\FullEntityParserOutputGeneratorIntegrationTest
Expand Down

0 comments on commit fb04300

Please sign in to comment.