Cover incomplete revision case in RenderedRevision.
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 3 Sep 2018 13:34:12 +0000 (15:34 +0200)
committerJforrester <jforrester@wikimedia.org>
Tue, 11 Sep 2018 15:25:11 +0000 (15:25 +0000)
This introduces a check that allows magic words like {{REVISIONUSER}}
to still work even when an incomplete fake RevisonRecord is provided to
RevisionRenderer. In such a case, the revision is loaded from the database
if needed. This lets old code that only has access to a Content object for
rendering use that Content object in a fake RevisionRecord, instead of
having to load the full revision from the database in all cases.

Bug: T174035
Change-Id: I658eab97a8282b8943baf7968f3256da35789ec1

includes/Revision/RenderedRevision.php
tests/phpunit/includes/Revision/RenderedRevisionTest.php
tests/phpunit/includes/Revision/RevisionRendererTest.php

index 0c052d1..ba40a81 100644 (file)
@@ -95,7 +95,11 @@ class RenderedRevision {
         * but should use a RevisionRenderer instead.
         *
         * @param Title $title
-        * @param RevisionRecord $revision
+        * @param RevisionRecord $revision The revision to render. The content for rendering will be
+        *        taken from this RevisionRecord. However, if the RevisionRecord is not complete
+        *        according isReadyForInsertion(), but a revision ID is known, the parser may load
+        *        the revision from the database if it needs revision meta data to handle magic
+        *        words like {{REVISIONUSER}}.
         * @param ParserOptions $options
         * @param callable $combineOutput Callback for combining slot output into revision output.
         *        Signature: function ( RenderedRevision $this ): ParserOutput.
@@ -287,19 +291,50 @@ class RenderedRevision {
        private function setRevisionInternal( RevisionRecord $revision ) {
                $this->revision = $revision;
 
-               // Make sure the parser uses the correct Revision object
-               $title = $this->title;
-               $oldCallback = $this->options->getCurrentRevisionCallback();
-               $this->options->setCurrentRevisionCallback(
-                       function ( Title $parserTitle, $parser = false ) use ( $title, $oldCallback ) {
-                               if ( $parserTitle->equals( $title ) ) {
-                                       $legacyRevision = new Revision( $this->revision );
-                                       return $legacyRevision;
-                               } else {
-                                       return call_user_func( $oldCallback, $parserTitle, $parser );
+               // Force the parser to use  $this->revision to resolve magic words like {{REVISIONUSER}}
+               // if the revision is either known to be complete, or it doesn't have a revision ID set.
+               // If it's incomplete and we have a revision ID, the parser can do better by loading
+               // the revision from the database if needed to handle a magic word.
+               //
+               // The following considerations inform the logic described above:
+               //
+               // 1) If we have a saved revision already loaded, we want the parser to use it, instead of
+               // loading it again.
+               //
+               // 2) If the revision is a fake that wraps some kind of synthetic content, such as an
+               // error message from Article, it should be used directly and things like {{REVISIONUSER}}
+               // should not expected to work, since there may not even be an actual revision to
+               // refer to.
+               //
+               // 3) If the revision is a fake constructed around a Title, a Content object, and
+               // a revision ID, to provide backwards compatibility to code that has access to those
+               // but not to a complete RevisionRecord for rendering, then we want the Parser to
+               // load the actual revision from the database when it encounters a magic word like
+               // {{REVISIONUSER}}, but we don't want to load that revision ahead of time just in case.
+               //
+               // 4) Previewing an edit to a template should use the submitted unsaved
+               // MutableRevisionRecord for self-transclusions in the template's documentation (see T7278).
+               // That revision would be complete except for the ID field.
+               //
+               // 5) Pre-save transform would provide a RevisionRecord that has all meta-data but is
+               // incomplete due to not yet having content set. However, since it doesn't have a revision
+               // ID either, the below code would still force it to be used, allowing
+               // {{subst::REVISIONUSER}} to function as expected.
+
+               if ( $this->revision->isReadyForInsertion() || !$this->revision->getId() ) {
+                       $title = $this->title;
+                       $oldCallback = $this->options->getCurrentRevisionCallback();
+                       $this->options->setCurrentRevisionCallback(
+                               function ( Title $parserTitle, $parser = false ) use ( $title, $oldCallback ) {
+                                       if ( $title->equals( $parserTitle ) ) {
+                                               $legacyRevision = new Revision( $this->revision );
+                                               return $legacyRevision;
+                                       } else {
+                                               return call_user_func( $oldCallback, $parserTitle, $parser );
+                                       }
                                }
-                       }
-               );
+                       );
+               }
        }
 
        /**
index a2a9d09..bea0b49 100644 (file)
@@ -6,7 +6,11 @@ use Content;
 use Language;
 use MediaWiki\Revision\RenderedRevision;
 use MediaWiki\Storage\MutableRevisionRecord;
+use MediaWiki\Storage\MutableRevisionSlots;
+use MediaWiki\Storage\RevisionArchiveRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\RevisionStoreRecord;
 use MediaWiki\Storage\SuppressedDataException;
 use MediaWiki\User\UserIdentityValue;
 use MediaWikiTestCase;
@@ -15,6 +19,7 @@ use ParserOutput;
 use PHPUnit\Framework\MockObject\MockObject;
 use Title;
 use User;
+use Wikimedia\TestingAccessWrapper;
 use WikitextContent;
 
 /**
@@ -86,13 +91,13 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                        ->will( $this->returnValue( NS_MAIN ) );
                $mock->expects( $this->any() )
                        ->method( 'getText' )
-                       ->will( $this->returnValue( __CLASS__ ) );
+                       ->will( $this->returnValue( 'RenderTestPage' ) );
                $mock->expects( $this->any() )
                        ->method( 'getPrefixedText' )
-                       ->will( $this->returnValue( __CLASS__ ) );
+                       ->will( $this->returnValue( 'RenderTestPage' ) );
                $mock->expects( $this->any() )
                        ->method( 'getDBkey' )
-                       ->will( $this->returnValue( __CLASS__ ) );
+                       ->will( $this->returnValue( 'RenderTestPage' ) );
                $mock->expects( $this->any() )
                        ->method( 'getArticleID' )
                        ->will( $this->returnValue( $articleId ) );
@@ -111,7 +116,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $mock->expects( $this->any() )
                        ->method( 'equals' )
                        ->willReturnCallback( function ( Title $other ) use ( $mock ) {
-                               return $mock->getArticleID() === $other->getArticleID();
+                               return $mock->getPrefixedText() === $other->getPrefixedText();
                        } );
                $mock->expects( $this->any() )
                        ->method( 'userCan' )
@@ -122,21 +127,66 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                return $mock;
        }
 
-       public function testGetRevisionParserOutput_new() {
-               $title = $this->getMockTitle( 7, 21 );
+       /**
+        * @param string $class
+        * @param Title $title
+        * @param null|int $id
+        * @param int $visibility
+        * @return RevisionRecord
+        */
+       private function getMockRevision(
+               $class,
+               $title,
+               $id = null,
+               $visibility = 0,
+               array $content = null
+       ) {
+               $frank = new UserIdentityValue( 9, 'Frank', 0 );
+
+               if ( !$content ) {
+                       $text = "";
+                       $text .= "* page:{{PAGENAME}}!\n";
+                       $text .= "* rev:{{REVISIONID}}!\n";
+                       $text .= "* user:{{REVISIONUSER}}!\n";
+                       $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
+                       $text .= "* [[Link It]]\n";
+
+                       $content = [ 'main' => new WikitextContent( $text ) ];
+               }
 
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
+               /** @var MockObject|RevisionRecord $mock */
+               $mock = $this->getMockBuilder( $class )
+                       ->disableOriginalConstructor()
+                       ->setMethods( [
+                               'getId',
+                               'getPageId',
+                               'getPageAsLinkTarget',
+                               'getUser',
+                               'getVisibility',
+                               'getTimestamp',
+                       ] )->getMock();
+
+               $mock->method( 'getId' )->willReturn( $id );
+               $mock->method( 'getPageId' )->willReturn( $title->getArticleID() );
+               $mock->method( 'getPageAsLinkTarget' )->willReturn( $title );
+               $mock->method( 'getUser' )->willReturn( $frank );
+               $mock->method( 'getVisibility' )->willReturn( $visibility );
+               $mock->method( 'getTimestamp' )->willReturn( '20180101000003' );
+
+               /** @var object $mockAccess */
+               $mockAccess = TestingAccessWrapper::newFromObject( $mock );
+               $mockAccess->mSlots = new MutableRevisionSlots();
+
+               foreach ( $content as $role => $cnt ) {
+                       $mockAccess->mSlots->setContent( $role, $cnt );
+               }
 
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
-               $text .= "* [[Link It]]\n";
+               return $mock;
+       }
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+       public function testGetRevisionParserOutput_new() {
+               $title = $this->getMockTitle( 0, 21 );
+               $rev = $this->getMockRevision( RevisionStoreRecord::class, $title );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -148,26 +198,33 @@ class RenderedRevisionTest extends MediaWikiTestCase {
 
                $html = $rr->getRevisionParserOutput()->getText();
 
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
        }
 
-       public function testGetRevisionParserOutput_current() {
-               $title = $this->getMockTitle( 7, 21 );
+       public function testGetRevisionParserOutput_previewWithSelfTransclusion() {
+               $title = $this->getMockTitle( 0, 21 );
+               $name = $title->getPrefixedText();
 
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setId( 21 ); // current!
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
+               $text = "(ONE)<includeonly>(TWO)</includeonly><noinclude>#{{:$name}}#</noinclude>";
 
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
+               $content = [
+                       'main' => new WikitextContent( $text )
+               ];
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev = $this->getMockRevision( RevisionStoreRecord::class, $title, null, 0, $content );
+
+               $options = ParserOptions::newCanonical( 'canonical' );
+               $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
+
+               $html = $rr->getRevisionParserOutput()->getText();
+               $this->assertContains( '(ONE)#(ONE)(TWO)#', $html );
+       }
+
+       public function testGetRevisionParserOutput_current() {
+               $title = $this->getMockTitle( 7, 21 );
+               $rev = $this->getMockRevision( RevisionStoreRecord::class, $title, 21 );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -179,29 +236,39 @@ class RenderedRevisionTest extends MediaWikiTestCase {
 
                $html = $rr->getRevisionParserOutput()->getText();
 
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'rev:21', $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:21!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
 
                $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
        }
 
        public function testGetRevisionParserOutput_old() {
                $title = $this->getMockTitle( 7, 21 );
+               $rev = $this->getMockRevision( RevisionStoreRecord::class, $title, 11 );
 
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setId( 11 ); // old!
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
+               $options = ParserOptions::newCanonical( 'canonical' );
+               $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
 
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
+               $this->assertFalse( $rr->isContentDeleted(), 'isContentDeleted' );
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $this->assertSame( $rev, $rr->getRevision() );
+               $this->assertSame( $options, $rr->getOptions() );
+
+               $html = $rr->getRevisionParserOutput()->getText();
+
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:11!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
+
+               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+       }
+
+       public function testGetRevisionParserOutput_archive() {
+               $title = $this->getMockTitle( 7, 21 );
+               $rev = $this->getMockRevision( RevisionArchiveRecord::class, $title, 11 );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -213,30 +280,22 @@ class RenderedRevisionTest extends MediaWikiTestCase {
 
                $html = $rr->getRevisionParserOutput()->getText();
 
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'rev:11', $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:11!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
 
                $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
        }
 
        public function testGetRevisionParserOutput_suppressed() {
                $title = $this->getMockTitle( 7, 21 );
-
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setId( 11 ); // old!
-               $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
-
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
-
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev = $this->getMockRevision(
+                       RevisionStoreRecord::class,
+                       $title,
+                       11,
+                       RevisionRecord::DELETED_TEXT
+               );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -247,20 +306,12 @@ class RenderedRevisionTest extends MediaWikiTestCase {
 
        public function testGetRevisionParserOutput_privileged() {
                $title = $this->getMockTitle( 7, 21 );
-
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setId( 11 ); // old!
-               $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
-
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
-
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev = $this->getMockRevision(
+                       RevisionStoreRecord::class,
+                       $title,
+                       11,
+                       RevisionRecord::DELETED_TEXT
+               );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $sysop = $this->getTestUser( [ 'sysop' ] )->getUser(); // privileged!
@@ -281,30 +332,22 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $html = $rr->getRevisionParserOutput()->getText();
 
                // Suppressed content should be visible for sysops
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'rev:11', $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:11!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
 
                $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
        }
 
        public function testGetRevisionParserOutput_raw() {
                $title = $this->getMockTitle( 7, 21 );
-
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setId( 11 ); // old!
-               $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
-
-               $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
-
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev = $this->getMockRevision(
+                       RevisionStoreRecord::class,
+                       $title,
+                       11,
+                       RevisionRecord::DELETED_TEXT
+               );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision(
@@ -323,23 +366,22 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $html = $rr->getRevisionParserOutput()->getText();
 
                // Suppressed content should be visible for sysops
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'rev:11', $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:11!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
 
                $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
        }
 
        public function testGetRevisionParserOutput_multi() {
-               $title = $this->getMockTitle( 7, 21 );
-
-               $rev = new MutableRevisionRecord( $title );
-               $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
-               $rev->setTimestamp( '20180101000003' );
+               $content = [
+                       'main' => new WikitextContent( '[[Kittens]]' ),
+                       'aux' => new WikitextContent( '[[Goats]]' ),
+               ];
 
-               $rev->setContent( 'main', new WikitextContent( '[[Kittens]]' ) );
-               $rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
+               $title = $this->getMockTitle( 7, 21 );
+               $rev = $this->getMockRevision( RevisionStoreRecord::class, $title, 11, 0, $content );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -369,6 +411,77 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertFalse( isset( $auxLinks[NS_MAIN]['Kittens'] ), 'no main links in aux' );
        }
 
+       public function testGetRevisionParserOutput_incompleteNoId() {
+               $title = $this->getMockTitle( 7, 21 );
+
+               $rev = new MutableRevisionRecord( $title );
+
+               $text = "";
+               $text .= "* page:{{PAGENAME}}!\n";
+               $text .= "* rev:{{REVISIONID}}!\n";
+               $text .= "* user:{{REVISIONUSER}}!\n";
+               $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
+
+               $rev->setContent( 'main', new WikitextContent( $text ) );
+
+               $options = ParserOptions::newCanonical( 'canonical' );
+               $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
+
+               // MutableRevisionRecord without ID should be used by the parser.
+               // USeful for fake
+               $html = $rr->getRevisionParserOutput()->getText();
+
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:!', $html );
+               $this->assertContains( 'user:!', $html );
+               $this->assertContains( 'time:!', $html );
+       }
+
+       public function testGetRevisionParserOutput_incompleteWithId() {
+               $title = $this->getMockTitle( 7, 21 );
+
+               $rev = new MutableRevisionRecord( $title );
+               $rev->setId( 21 );
+
+               $text = "";
+               $text .= "* page:{{PAGENAME}}!\n";
+               $text .= "* rev:{{REVISIONID}}!\n";
+               $text .= "* user:{{REVISIONUSER}}!\n";
+               $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
+
+               $rev->setContent( 'main', new WikitextContent( $text ) );
+
+               $actualRevision = $this->getMockRevision(
+                       RevisionStoreRecord::class,
+                       $title,
+                       21,
+                       RevisionRecord::DELETED_TEXT
+               );
+
+               $options = ParserOptions::newCanonical( 'canonical' );
+               $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
+
+               // MutableRevisionRecord with ID should not be used by the parser,
+               // revision should be loaded instead!
+               $revisionStore = $this->getMockBuilder( RevisionStore::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $revisionStore->expects( $this->once() )
+                       ->method( 'getKnownCurrentRevision' )
+                       ->with( $title, 0 )
+                       ->willReturn( $actualRevision );
+
+               $this->setService( 'RevisionStore', $revisionStore );
+
+               $html = $rr->getRevisionParserOutput()->getText();
+
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:21!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
+       }
+
        public function testNoHtml() {
                /** @var MockObject|Content $mockContent */
                $mockContent = $this->getMockBuilder( WikitextContent::class )
@@ -409,10 +522,10 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $rev = new MutableRevisionRecord( $title );
 
                $text = "";
-               $text .= "* page:{{PAGENAME}}\n";
-               $text .= "* rev:{{REVISIONID}}\n";
-               $text .= "* user:{{REVISIONUSER}}\n";
-               $text .= "* time:{{REVISIONTIMESTAMP}}\n";
+               $text .= "* page:{{PAGENAME}}!\n";
+               $text .= "* rev:{{REVISIONID}}!\n";
+               $text .= "* user:{{REVISIONUSER}}!\n";
+               $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
 
                $rev->setContent( 'main', new WikitextContent( $text ) );
                $rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
@@ -441,10 +554,10 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $html = $updatedOutput->getText();
 
                $this->assertNotSame( $firstOutput, $updatedOutput, 'Reset merged' );
-               $this->assertContains( 'page:' . __CLASS__, $html );
-               $this->assertContains( 'rev:23', $html );
-               $this->assertContains( 'user:Frank', $html );
-               $this->assertContains( 'time:20180101000003', $html );
+               $this->assertContains( 'page:RenderTestPage!', $html );
+               $this->assertContains( 'rev:23!', $html );
+               $this->assertContains( 'user:Frank!', $html );
+               $this->assertContains( 'time:20180101000003!', $html );
                $this->assertContains( 'Goats', $html );
 
                $rr->updateRevision( $savedRev ); // should do nothing
index ea195f1..28052ff 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace MediaWiki\Tests\Revision;
 
+use CommentStoreComment;
 use Content;
 use Language;
 use LogicException;
@@ -143,6 +144,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev = new MutableRevisionRecord( $title );
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -179,6 +181,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setId( 21 ); // current!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -214,6 +217,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setId( 21 ); // current!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -243,6 +247,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setId( 11 ); // old!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -279,6 +284,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -303,6 +309,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -341,6 +348,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setVisibility( RevisionRecord::DELETED_TEXT ); // suppressed!
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $text = "";
                $text .= "* page:{{PAGENAME}}\n";
@@ -381,6 +389,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev = new MutableRevisionRecord( $title );
                $rev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
                $rev->setTimestamp( '20180101000003' );
+               $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
                $rev->setContent( 'main', new WikitextContent( '[[Kittens]]' ) );
                $rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );