use Content;
use Language;
use LogicException;
+use MediaWiki\Revision\MutableRevisionRecord;
+use MediaWiki\Revision\MainSlotRoleHandler;
+use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionRenderer;
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\User\UserIdentityValue;
+use MediaWiki\Revision\SlotRecord;
+use MediaWiki\Revision\SlotRoleRegistry;
+use MediaWiki\Storage\NameTableStore;
use MediaWikiTestCase;
+use MediaWiki\User\UserIdentityValue;
use ParserOptions;
use ParserOutput;
use PHPUnit\Framework\MockObject\MockObject;
->with( $dbIndex )
->willReturn( $db );
- return new RevisionRenderer( $lb );
+ /** @var NameTableStore|MockObject $slotRoles */
+ $slotRoles = $this->getMockBuilder( NameTableStore::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $slotRoles->method( 'getMap' )
+ ->willReturn( [] );
+
+ $roleReg = new SlotRoleRegistry( $slotRoles );
+ $roleReg->defineRole( 'main', function () {
+ return new MainSlotRoleHandler( [] );
+ } );
+ $roleReg->defineRoleWithModel( 'aux', CONTENT_MODEL_WIKITEXT );
+
+ return new RevisionRenderer( $lb, $roleReg );
}
private function selectFieldCallback( $table, $fields, $cond, $maxRev ) {
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
$text .= "* [[Link It]]\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision( $rev, $options );
$this->assertContains( 'user:Frank', $html );
$this->assertContains( 'time:20180101000003', $html );
- $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+ $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
}
public function testGetRenderedRevision_current() {
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision( $rev, $options );
$this->assertContains( 'user:Frank', $html );
$this->assertContains( 'time:20180101000003', $html );
- $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+ $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
}
public function testGetRenderedRevision_master() {
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision( $rev, $options, null, [ 'use-master' => true ] );
$this->assertContains( 'rev:21', $html );
- $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+ $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
+ }
+
+ public function testGetRenderedRevision_known() {
+ $renderer = $this->newRevisionRenderer( 100, true ); // use master
+ $title = $this->getMockTitle( 7, 21 );
+
+ $rev = new MutableRevisionRecord( $title );
+ $rev->setId( 21 ); // current!
+ $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
+ $rev->setTimestamp( '20180101000003' );
+ $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
+
+ $text = "uncached text";
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
+
+ $output = new ParserOutput( 'cached text' );
+
+ $options = ParserOptions::newCanonical( 'canonical' );
+ $rr = $renderer->getRenderedRevision(
+ $rev,
+ $options,
+ null,
+ [ 'known-revision-output' => $output ]
+ );
+
+ $this->assertSame( $output, $rr->getRevisionParserOutput() );
+ $this->assertSame( 'cached text', $rr->getRevisionParserOutput()->getText() );
+ $this->assertSame( 'cached text', $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
}
public function testGetRenderedRevision_old() {
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision( $rev, $options );
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision( $rev, $options );
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$sysop = $this->getTestUser( [ 'sysop' ] )->getUser(); // privileged!
$text .= "* user:{{REVISIONUSER}}\n";
$text .= "* time:{{REVISIONTIMESTAMP}}\n";
- $rev->setContent( 'main', new WikitextContent( $text ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
$options = ParserOptions::newCanonical( 'canonical' );
$rr = $renderer->getRenderedRevision(
$rev->setTimestamp( '20180101000003' );
$rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
- $rev->setContent( 'main', new WikitextContent( '[[Kittens]]' ) );
+ $rev->setContent( SlotRecord::MAIN, new WikitextContent( '[[Kittens]]' ) );
$rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
$rr = $renderer->getRenderedRevision( $rev );
$combinedOutput = $rr->getRevisionParserOutput();
- $mainOutput = $rr->getSlotParserOutput( 'main' );
+ $mainOutput = $rr->getSlotParserOutput( SlotRecord::MAIN );
$auxOutput = $rr->getSlotParserOutput( 'aux' );
$combinedHtml = $combinedOutput->getText();
$title = $this->getMockTitle( 7, 21 );
$rev = new MutableRevisionRecord( $title );
- $rev->setContent( 'main', $mockContent );
+ $rev->setContent( SlotRecord::MAIN, $mockContent );
$rev->setContent( 'aux', $mockContent );
// NOTE: we are testing the private combineSlotOutput() callback here.
$rr = $renderer->getRenderedRevision( $rev );
- $output = $rr->getSlotParserOutput( 'main', [ 'generate-html' => false ] );
+ $output = $rr->getSlotParserOutput( SlotRecord::MAIN, [ 'generate-html' => false ] );
$this->assertFalse( $output->hasText(), 'hasText' );
$output = $rr->getRevisionParserOutput( [ 'generate-html' => false ] );