Hard-deprecate Content::getParserOutput and AbstractContent::fillParserOutput.

Use ContentRenderer::getParserOutput instead.
Extensions defining a content model should override ContentHandler::fillParserOutput.
Update tests.

Bug: T287158
Change-Id: I1c71a8429806f1813a39f5807256b2eb9fb9901f
This commit is contained in:
Roman Stolar 2021-10-21 15:04:01 +03:00
parent 4a371b7e04
commit 957697e1e0
7 changed files with 56 additions and 34 deletions

View file

@ -213,9 +213,10 @@ because of Phabricator reports.
* The following methods from the User class now trigger deprecation warnings:
- ::blockedBy
- ::getBlockId
* Content::getParserOutput() was deprecated.
Use ContentRenderer::getParserOutput and override
ContentHandler::fillParserOutput instead.
* Content::getParserOutput and AbstractContent::fillParserOutput
was hard-deprecated, use ContentRenderer::getParserOutput instead.
Extensions defining a content model should
override ContentHandler::fillParserOutput.
* Article::doDelete() was deprecated. Use WikiPage::doDeleteArticleReal if
you only need to delete the article. If you also need things to happen
with OutputPage, you may want to check the hooks in DeleteAction instead.

View file

@ -519,7 +519,7 @@ abstract class AbstractContent implements Content {
* ContentGetParserOutput hook.
*
* @since 1.24
* @deprecated since 1.38. Use ContentRenderer::getParserOutput instead.
* @deprecated since 1.38. Hard-deprecated since 1.38. Use ContentRenderer::getParserOutput instead.
* Extensions defining a content model should override ContentHandler::fillParserOutput.
* @param Title $title Context title for parsing
* @param int|null $revId Revision ID being rendered
@ -531,15 +531,18 @@ abstract class AbstractContent implements Content {
public function getParserOutput( Title $title, $revId = null,
ParserOptions $options = null, $generateHtml = true
) {
wfDeprecated( __METHOD__, '1.38' );
$detectGPODeprecatedOverride = MWDebug::detectDeprecatedOverride(
$this,
self::class,
'getParserOutput'
'getParserOutput',
'1.38'
);
$detectFPODeprecatedOverride = MWDebug::detectDeprecatedOverride(
$this,
self::class,
'fillParserOutput'
'fillParserOutput',
'1.38'
);
if ( $detectGPODeprecatedOverride || $detectFPODeprecatedOverride ) {
@ -585,7 +588,7 @@ abstract class AbstractContent implements Content {
* This placeholder implementation always throws an exception.
*
* @since 1.24
* @deprecated since 1.37. Use ContentHandler::fillParserOutput instead.
* @deprecated since 1.38. Hard-deprecated since 1.38. Use ContentHandler::fillParserOutput instead.
* @param Title $title Context title for parsing
* @param int|null $revId ID of the revision being rendered.
* See Parser::parse() for the ramifications.
@ -598,6 +601,7 @@ abstract class AbstractContent implements Content {
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput &$output
) {
wfDeprecated( __METHOD__, '1.38' );
$cpoParams = new ContentParseParams( $title, $revId, $options, $generateHtml );
return $this->getContentHandler()->fillParserOutputInternal( $this, $cpoParams, $output );
}

View file

@ -268,7 +268,7 @@ interface Content {
* @note To control which options are used in the cache key for the
* generated parser output, implementations of this method
* may call ParserOutput::recordOption() on the output object.
* @deprecated since 1.38. Use ContentRenderer::getParserOutput
* @deprecated since 1.38. Hard-deprecated since 1.38. Use ContentRenderer::getParserOutput
* and override ContentHandler::fillParserOutput.
* @param Title $title The page title to use as a context for rendering.
* @param int|null $revId ID of the revision being rendered.

View file

@ -1635,12 +1635,14 @@ abstract class ContentHandler {
$detectGPODeprecatedOverride = MWDebug::detectDeprecatedOverride(
$content,
AbstractContent::class,
'getParserOutput'
'getParserOutput',
'1.38'
);
$detectFPODeprecatedOverride = MWDebug::detectDeprecatedOverride(
$content,
AbstractContent::class,
'fillParserOutput'
'fillParserOutput',
'1.38'
);
if ( $detectGPODeprecatedOverride || $detectFPODeprecatedOverride ) {
return $this->callDeprecatedContentGPO( $content, $cpoParams );

View file

@ -7,6 +7,7 @@ use InvalidArgumentException;
use LogicException;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Page\PageReference;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\MutableRevisionSlots;
use MediaWiki\Revision\RenderedRevision;
@ -22,7 +23,6 @@ use MediaWikiIntegrationTestCase;
use ParserOptions;
use ParserOutput;
use PHPUnit\Framework\MockObject\MockObject;
use Title;
use TitleValue;
use Wikimedia\TestingAccessWrapper;
use WikitextContent;
@ -544,13 +544,15 @@ class RenderedRevisionTest extends MediaWikiIntegrationTestCase {
}
public function testNoHtml() {
/** @var MockObject|Content $mockContent */
$mockContent = $this->getMockBuilder( WikitextContent::class )
$content = new WikitextContent( 'whatever' );
/** @var MockObject|ContentRenderer $mockContentRenderer */
$mockContentRenderer = $this->getMockBuilder( ContentRenderer::class )
->onlyMethods( [ 'getParserOutput' ] )
->setConstructorArgs( [ 'Whatever' ] )
->disableOriginalConstructor()
->getMock();
$mockContent->method( 'getParserOutput' )
->willReturnCallback( function ( Title $title, $revId = null,
$mockContentRenderer->method( 'getParserOutput' )
->willReturnCallback( function ( Content $content, PageReference $page, $revId = null,
ParserOptions $options = null, $generateHtml = true
) {
if ( !$generateHtml ) {
@ -564,14 +566,14 @@ class RenderedRevisionTest extends MediaWikiIntegrationTestCase {
$rev = new MutableRevisionRecord(
PageIdentityValue::localIdentity( 7, NS_MAIN, 'RenderTestPage' )
);
$rev->setContent( SlotRecord::MAIN, $mockContent );
$rev->setContent( 'aux', $mockContent );
$rev->setContent( SlotRecord::MAIN, $content );
$rev->setContent( 'aux', $content );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = new RenderedRevision(
$rev,
$options,
$this->contentRenderer,
$mockContentRenderer,
$this->combinerCallback
);

View file

@ -6,8 +6,10 @@ use CommentStoreComment;
use Content;
use LogicException;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Page\PageReference;
use MediaWiki\Revision\MainSlotRoleHandler;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\RevisionRecord;
@ -21,7 +23,6 @@ use MediaWikiIntegrationTestCase;
use ParserOptions;
use ParserOutput;
use PHPUnit\Framework\MockObject\MockObject;
use Title;
use TitleFactory;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\IDatabase;
@ -65,10 +66,16 @@ class RevisionRendererTest extends MediaWikiIntegrationTestCase {
/**
* @param int $maxRev
* @param bool $usePrimary
* @param ContentRenderer|null $contentRenderer
* @return RevisionRenderer
*/
private function newRevisionRenderer( $maxRev = 100, $usePrimary = false ) {
private function newRevisionRenderer(
$maxRev = 100,
$usePrimary = false,
$contentRenderer = null
) {
$dbIndex = $usePrimary ? DB_PRIMARY : DB_REPLICA;
$cr = $contentRenderer ?? $this->getServiceContainer()->getContentRenderer();
/** @var ILoadBalancer|MockObject $lb */
$lb = $this->createMock( ILoadBalancer::class );
@ -100,7 +107,7 @@ class RevisionRendererTest extends MediaWikiIntegrationTestCase {
} );
$roleReg->defineRoleWithModel( 'aux', CONTENT_MODEL_WIKITEXT );
return new RevisionRenderer( $lb, $roleReg, $this->getServiceContainer()->getContentRenderer() );
return new RevisionRenderer( $lb, $roleReg, $cr );
}
private function selectFieldCallback( $table, $fields, $cond, $maxRev ) {
@ -436,13 +443,15 @@ class RevisionRendererTest extends MediaWikiIntegrationTestCase {
}
public function testGetRenderedRevision_noHtml() {
/** @var MockObject|Content $mockContent */
$mockContent = $this->getMockBuilder( WikitextContent::class )
$content = new WikitextContent( 'Whatever' );
/** @var MockObject|ContentRenderer $mockContentRenderer */
$mockContentRenderer = $this->getMockBuilder( ContentRenderer::class )
->onlyMethods( [ 'getParserOutput' ] )
->setConstructorArgs( [ 'Whatever' ] )
->disableOriginalConstructor()
->getMock();
$mockContent->method( 'getParserOutput' )
->willReturnCallback( function ( Title $title, $revId = null,
$mockContentRenderer->method( 'getParserOutput' )
->willReturnCallback( function ( Content $content, PageReference $page, $revId = null,
ParserOptions $options = null, $generateHtml = true
) {
if ( !$generateHtml ) {
@ -453,11 +462,11 @@ class RevisionRendererTest extends MediaWikiIntegrationTestCase {
}
} );
$renderer = $this->newRevisionRenderer();
$renderer = $this->newRevisionRenderer( 100, false, $mockContentRenderer );
$rev = new MutableRevisionRecord( $this->fakePage );
$rev->setContent( SlotRecord::MAIN, $mockContent );
$rev->setContent( 'aux', $mockContent );
$rev->setContent( SlotRecord::MAIN, $content );
$rev->setContent( 'aux', $content );
// NOTE: we are testing the private combineSlotOutput() callback here.
$rr = $renderer->getRenderedRevision( $rev );

View file

@ -1,5 +1,6 @@
<?php
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Edit\PreparedEdit;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageIdentity;
@ -2041,16 +2042,19 @@ more stuff
public function testNewPageUpdater() {
$user = $this->getTestUser()->getUser();
$page = $this->newPage( __METHOD__, __METHOD__ );
$content = new WikitextContent( 'Hello World' );
/** @var Content $content */
$content = $this->getMockBuilder( WikitextContent::class )
->setConstructorArgs( [ 'Hello World' ] )
/** @var ContentRenderer $contentRenderer */
$contentRenderer = $this->getMockBuilder( ContentRenderer::class )
->onlyMethods( [ 'getParserOutput' ] )
->disableOriginalConstructor()
->getMock();
$content->expects( $this->once() )
$contentRenderer->expects( $this->once() )
->method( 'getParserOutput' )
->willReturn( new ParserOutput( 'HTML' ) );
$this->setService( 'ContentRenderer', $contentRenderer );
$preparedEditBefore = $page->prepareContentForEdit( $content, null, $user );
// provide context, so the cache can be kept in place