2013-10-29 11:06:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-09-20 07:54:42 +00:00
|
|
|
use MediaWiki\Config\HashConfig;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\DerivativeContext;
|
|
|
|
|
use MediaWiki\Context\RequestContext;
|
2022-07-20 12:42:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-09-05 17:31:53 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2022-12-17 22:11:10 +00:00
|
|
|
use MediaWiki\Permissions\SimpleAuthority;
|
2023-12-11 14:59:55 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-06-25 23:03:34 +00:00
|
|
|
use MediaWiki\User\UserIdentityValue;
|
2017-11-22 13:28:52 +00:00
|
|
|
|
2013-10-29 11:06:11 +00:00
|
|
|
/**
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \DifferenceEngine
|
2013-10-29 11:06:11 +00:00
|
|
|
*
|
|
|
|
|
* @todo tests for the rest of DifferenceEngine!
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
2014-02-26 21:47:40 +00:00
|
|
|
* @group Diff
|
2013-10-29 11:06:11 +00:00
|
|
|
*
|
|
|
|
|
* @author Katie Filbert < aude.wiki@gmail.com >
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class DifferenceEngineTest extends MediaWikiIntegrationTestCase {
|
2021-02-24 05:12:55 +00:00
|
|
|
use MockTitleTrait;
|
2013-10-29 11:06:11 +00:00
|
|
|
|
|
|
|
|
protected $context;
|
|
|
|
|
|
|
|
|
|
private static $revisions;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2013-10-29 11:06:11 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
|
|
|
|
|
$this->context = new RequestContext();
|
|
|
|
|
$this->context->setTitle( $title );
|
|
|
|
|
|
2022-07-20 12:42:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DiffEngine, 'php' );
|
2021-03-07 04:41:19 +00:00
|
|
|
|
|
|
|
|
$slotRoleRegistry = $this->getServiceContainer()->getSlotRoleRegistry();
|
|
|
|
|
|
|
|
|
|
if ( !$slotRoleRegistry->isDefinedRole( 'derivedslot' ) ) {
|
|
|
|
|
$slotRoleRegistry->defineRoleWithModel(
|
|
|
|
|
'derivedslot',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
[],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
self::$revisions = $this->doEdits();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 11:06:11 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
protected function getTitle() {
|
|
|
|
|
$namespace = $this->getDefaultWikitextNS();
|
2022-07-05 22:21:30 +00:00
|
|
|
return Title::makeTitle( $namespace, 'Kitten' );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-13 17:54:49 +00:00
|
|
|
* @return int[] Revision ids
|
2013-10-29 11:06:11 +00:00
|
|
|
*/
|
|
|
|
|
protected function doEdits() {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
|
2023-06-25 23:03:34 +00:00
|
|
|
$strings = [
|
|
|
|
|
0 => "no kittens",
|
|
|
|
|
1 => "one kitten",
|
|
|
|
|
2 => "two kittens",
|
|
|
|
|
3 => "three kittens",
|
|
|
|
|
4 => "fnord kittens",
|
|
|
|
|
5 => "kitten's phone number is +1 303 503 229",
|
|
|
|
|
6 => "six kittens",
|
|
|
|
|
7 => "seven kittens",
|
|
|
|
|
];
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions = [];
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2023-06-25 23:03:34 +00:00
|
|
|
$sysop = $this->getTestSysop()->getAuthority();
|
|
|
|
|
$user = $this->getTestUser()->getAuthority();
|
|
|
|
|
foreach ( $strings as $i => $string ) {
|
2022-09-02 18:51:18 +00:00
|
|
|
$status = $this->editPage(
|
|
|
|
|
$title,
|
|
|
|
|
$string,
|
|
|
|
|
'edit page',
|
|
|
|
|
NS_MAIN,
|
2023-06-25 23:03:34 +00:00
|
|
|
$i == 6 ? $user : $sysop
|
2022-09-02 18:51:18 +00:00
|
|
|
);
|
2022-11-14 20:17:19 +00:00
|
|
|
$revisions[] = $status->getNewRevision()->getId();
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-25 23:03:34 +00:00
|
|
|
// Normal user cannot see the fnord
|
|
|
|
|
$this->revisionDelete(
|
|
|
|
|
$revisions[4],
|
|
|
|
|
[
|
|
|
|
|
RevisionRecord::DELETED_TEXT => 1,
|
|
|
|
|
],
|
|
|
|
|
'Testing'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Suppress kitten dox
|
|
|
|
|
$this->revisionDelete(
|
|
|
|
|
$revisions[5],
|
|
|
|
|
[
|
|
|
|
|
RevisionRecord::DELETED_TEXT => 1,
|
|
|
|
|
RevisionRecord::DELETED_RESTRICTED => 1,
|
|
|
|
|
],
|
|
|
|
|
'Testing'
|
|
|
|
|
);
|
|
|
|
|
|
2013-10-29 11:06:11 +00:00
|
|
|
return $revisions;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
private function expandData( $data ) {
|
|
|
|
|
if ( is_array( $data ) ) {
|
|
|
|
|
foreach ( $data as &$value ) {
|
|
|
|
|
$value = $this->expandData( $value );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( is_string( $data ) ) {
|
|
|
|
|
$data = preg_replace_callback(
|
|
|
|
|
'/rev\[([0-9]+)]/',
|
|
|
|
|
static function ( $m ) {
|
|
|
|
|
return self::$revisions[(int)$m[1]];
|
|
|
|
|
},
|
|
|
|
|
$data
|
|
|
|
|
);
|
2023-06-25 23:03:34 +00:00
|
|
|
$data = str_replace(
|
|
|
|
|
'rev[cur]',
|
|
|
|
|
self::$revisions[array_key_last( self::$revisions )],
|
|
|
|
|
$data
|
|
|
|
|
);
|
2023-06-21 02:57:16 +00:00
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
private function expandTestArgs( $args ) {
|
|
|
|
|
foreach ( $args as &$arg ) {
|
|
|
|
|
$arg = $this->expandData( $arg );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMapDiffPrevNext
|
|
|
|
|
*/
|
|
|
|
|
public function testMapDiffPrevNext( $expected, $old, $new, $message ) {
|
|
|
|
|
$this->expandTestArgs( [ &$expected, &$old, &$new, &$message ] );
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
|
|
|
|
|
$diffMap = $diffEngine->mapDiffPrevNext( $old, $new );
|
|
|
|
|
$this->assertEquals( $expected, $diffMap, $message );
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideMapDiffPrevNext() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2023-06-21 02:57:16 +00:00
|
|
|
[ [ 'rev[1]', 'rev[2]' ], 'rev[2]', 'prev', 'diff=prev' ],
|
|
|
|
|
[ [ 'rev[2]', 'rev[3]' ], 'rev[2]', 'next', 'diff=next' ],
|
|
|
|
|
[ [ 'rev[1]', 'rev[3]' ], 'rev[1]', 'rev[3]', 'diff=rev3' ]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideLoadRevision
|
|
|
|
|
*/
|
|
|
|
|
public function testLoadRevisionData( $expectedOld, $expectedNew, $expectedRet, $old, $new ) {
|
|
|
|
|
$this->expandTestArgs( [ &$expectedOld, &$expectedNew, &$expectedRet, &$old, &$new ] );
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
|
|
|
|
|
$ret = $diffEngine->loadRevisionData();
|
|
|
|
|
$ret2 = $diffEngine->loadRevisionData();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedOld, $diffEngine->getOldid() );
|
|
|
|
|
$this->assertEquals( $expectedNew, $diffEngine->getNewid() );
|
|
|
|
|
$this->assertEquals( $expectedRet, $ret );
|
|
|
|
|
$this->assertEquals( $expectedRet, $ret2 );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideLoadRevision() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2023-06-21 02:57:16 +00:00
|
|
|
'diff=prev' => [ 'rev[2]', 'rev[3]', true, 'rev[3]', 'prev' ],
|
|
|
|
|
'diff=next' => [ 'rev[2]', 'rev[3]', true, 'rev[2]', 'next' ],
|
2023-06-25 23:03:34 +00:00
|
|
|
'diff=rev[3]' => [ 'rev[1]', 'rev[3]', true, 'rev[1]', 'rev[3]' ],
|
|
|
|
|
'diff=0' => [ 'rev[1]', 'rev[cur]', true, 'rev[1]', 0 ],
|
2023-06-21 02:57:16 +00:00
|
|
|
'diff=prev&oldid=<first>' => [ false, 'rev[0]', true, 'rev[0]', 'prev' ],
|
|
|
|
|
'invalid' => [ 123456789, 'rev[1]', false, 123456789, 'rev[1]' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetOldid() {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
|
|
|
|
|
$this->assertEquals( $revs[1], $diffEngine->getOldid(), 'diff get old id' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetNewid() {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
|
|
|
|
|
$this->assertEquals( $revs[2], $diffEngine->getNewid(), 'diff get new id' );
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGenerateContentDiffBody
|
|
|
|
|
*/
|
|
|
|
|
public function testGenerateContentDiffBody(
|
2019-08-26 08:17:59 +00:00
|
|
|
array $oldContentArgs, array $newContentArgs, $expectedDiff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
2019-08-26 08:17:59 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
|
|
|
|
|
'testing-nontext' => DummyNonTextContentHandler::class,
|
|
|
|
|
] );
|
|
|
|
|
$oldContent = ContentHandler::makeContent( ...$oldContentArgs );
|
|
|
|
|
$newContent = ContentHandler::makeContent( ...$newContentArgs );
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$diff = $differenceEngine->generateContentDiffBody( $oldContent, $newContent );
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 08:17:59 +00:00
|
|
|
public static function provideGenerateContentDiffBody() {
|
|
|
|
|
$content1 = [ 'xxx', null, CONTENT_MODEL_TEXT ];
|
|
|
|
|
$content2 = [ 'yyy', null, CONTENT_MODEL_TEXT ];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'self-diff' => [ $content1, $content1, '' ],
|
|
|
|
|
'text diff' => [ $content1, $content2, '-xxx+yyy' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGenerateTextDiffBody() {
|
|
|
|
|
$oldText = "aaa\nbbb\nccc";
|
|
|
|
|
$newText = "aaa\nxxx\nccc";
|
|
|
|
|
$expectedDiff = " aaa aaa\n-bbb+xxx\n ccc ccc";
|
|
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$diff = $differenceEngine->generateTextDiffBody( $oldText, $newText );
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetContent() {
|
|
|
|
|
$oldContent = ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT );
|
|
|
|
|
$newContent = ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT );
|
|
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setContent( $oldContent, $newContent );
|
|
|
|
|
$diff = $differenceEngine->getDiffBody();
|
|
|
|
|
$this->assertSame( "Line 1:\nLine 1:\n-xxx+yyy", $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetRevisions() {
|
2023-06-21 02:57:16 +00:00
|
|
|
$rev1 = $this->getRevisionRecord( [ SlotRecord::MAIN => 'xxx' ] );
|
|
|
|
|
$rev2 = $this->getRevisionRecord( [ SlotRecord::MAIN => 'yyy' ] );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setRevisions( $rev1, $rev2 );
|
|
|
|
|
$this->assertSame( $rev1, $differenceEngine->getOldRevision() );
|
|
|
|
|
$this->assertSame( $rev2, $differenceEngine->getNewRevision() );
|
|
|
|
|
$this->assertSame( true, $differenceEngine->loadRevisionData() );
|
|
|
|
|
$this->assertSame( true, $differenceEngine->loadText() );
|
|
|
|
|
|
|
|
|
|
$differenceEngine->setRevisions( null, $rev2 );
|
|
|
|
|
$this->assertSame( null, $differenceEngine->getOldRevision() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetDiffBody
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDiffBody(
|
2023-07-03 08:27:47 +00:00
|
|
|
?array $oldSlots, ?array $newSlots, $slotDiffOptions, $expectedDiff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$oldRevision = $this->getRevisionRecord( $oldSlots );
|
|
|
|
|
$newRevision = $this->getRevisionRecord( $newSlots );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( $expectedDiff instanceof Exception ) {
|
2019-10-06 09:52:39 +00:00
|
|
|
$this->expectException( get_class( $expectedDiff ) );
|
|
|
|
|
$this->expectExceptionMessage( $expectedDiff->getMessage() );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setRevisions( $oldRevision, $newRevision );
|
2023-07-03 08:27:47 +00:00
|
|
|
if ( $slotDiffOptions !== null ) {
|
|
|
|
|
$differenceEngine->setSlotDiffOptions( $slotDiffOptions );
|
|
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( $expectedDiff instanceof Exception ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$diff = $differenceEngine->getDiffBody();
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideGetDiffBody() {
|
|
|
|
|
$main1 = [ SlotRecord::MAIN => 'xxx' ];
|
|
|
|
|
$main2 = [ SlotRecord::MAIN => 'yyy' ];
|
|
|
|
|
$slot1 = [ 'slot' => 'aaa' ];
|
|
|
|
|
$slot2 = [ 'slot' => 'bbb' ];
|
2019-01-20 23:11:59 +00:00
|
|
|
$slot3 = [ 'derivedslot' => [ 'text' => 'aaa', 'derived' => true ] ];
|
|
|
|
|
$slot4 = [ 'derivedslot' => [ 'text' => 'bbb', 'derived' => true ] ];
|
|
|
|
|
$slot5 = [ 'slot' => [ 'model' => 'testing' ] ];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'revision vs. null' => [
|
|
|
|
|
null,
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
'',
|
|
|
|
|
],
|
|
|
|
|
'revision vs. itself' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main1 + $slot1,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
'',
|
|
|
|
|
],
|
|
|
|
|
'different text in one slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main1 + $slot2,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"slotLine 1:\nLine 1:\n-aaa+bbb",
|
|
|
|
|
],
|
|
|
|
|
'different text in two slots' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main2 + $slot2,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"Line 1:\nLine 1:\n-xxx+yyy\nslotLine 1:\nLine 1:\n-aaa+bbb",
|
|
|
|
|
],
|
|
|
|
|
'new slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1,
|
|
|
|
|
$main1 + $slot1,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"slotLine 1:\nLine 1:\n- +aaa",
|
|
|
|
|
],
|
2021-03-07 04:41:19 +00:00
|
|
|
'ignored difference in derived slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot3,
|
|
|
|
|
$main1 + $slot4,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
2021-03-07 04:41:19 +00:00
|
|
|
'',
|
|
|
|
|
],
|
2019-01-20 23:11:59 +00:00
|
|
|
'incompatible slot' => [
|
|
|
|
|
$main1 + $slot5,
|
|
|
|
|
$main2 + $slot1,
|
2023-07-03 08:27:47 +00:00
|
|
|
null,
|
2019-01-20 23:11:59 +00:00
|
|
|
"Line 1:\nLine 1:\n-xxx+yyy\nslotCannot compare content models \"testing\" and \"plain text\"",
|
|
|
|
|
],
|
2023-07-03 08:27:47 +00:00
|
|
|
'invalid diff-type' => [
|
|
|
|
|
$main1,
|
|
|
|
|
$main2,
|
|
|
|
|
[ 'diff-type' => 'invalid' ],
|
|
|
|
|
"Line 1:\nLine 1:\n-xxx+yyy",
|
|
|
|
|
]
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecursion() {
|
|
|
|
|
// Set up a ContentHandler which will return a wrapped DifferenceEngine as
|
|
|
|
|
// SlotDiffRenderer, then pass it a content which uses the same ContentHandler.
|
|
|
|
|
// This tests the anti-recursion logic in DifferenceEngine::generateContentDiffBody.
|
|
|
|
|
|
|
|
|
|
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
|
|
|
|
|
->enableProxyingToOriginalMethods()
|
|
|
|
|
->getMock();
|
|
|
|
|
$customContentHandler = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'foo', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine' ] )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->getMockForAbstractClass();
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler->method( 'createDifferenceEngine' )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->willReturn( $customDifferenceEngine );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$customContent = $this->getMockBuilder( Content::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'getContentHandler' ] )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->getMockForAbstractClass();
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContent->method( 'getContentHandler' )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->willReturn( $customContentHandler );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var Content $customContent */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$customContent2 = clone $customContent;
|
|
|
|
|
|
|
|
|
|
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
2019-10-05 15:42:53 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
': could not maintain backwards compatibility. Please use a SlotDiffRenderer.'
|
|
|
|
|
);
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$slotDiffRenderer->getDiff( $customContent, $customContent2 );
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 15:39:48 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMarkPatrolledLink
|
|
|
|
|
*/
|
|
|
|
|
public function testMarkPatrolledLink( $group, $config, $expectedResult ) {
|
|
|
|
|
$this->setUserLang( 'qqx' );
|
|
|
|
|
$user = $this->getTestUser( $group )->getUser();
|
|
|
|
|
$this->context->setUser( $user );
|
|
|
|
|
if ( $config ) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$this->context->setConfig( new HashConfig( $config ) );
|
2021-05-25 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 19:09:28 +00:00
|
|
|
$page = $this->getNonexistingTestPage( 'Page1' );
|
2023-10-04 09:31:23 +00:00
|
|
|
$this->assertStatusGood( $this->editPage( $page, 'Edit1' ), 'edited a page' );
|
2021-05-25 15:39:48 +00:00
|
|
|
$rev1 = $page->getRevisionRecord();
|
2023-10-04 09:31:23 +00:00
|
|
|
$this->assertStatusGood( $this->editPage( $page, 'Edit2' ), 'edited a page' );
|
2021-05-25 15:39:48 +00:00
|
|
|
$rev2 = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context );
|
|
|
|
|
$diffEngine->setRevisions( $rev1, $rev2 );
|
|
|
|
|
|
|
|
|
|
$html = $diffEngine->markPatrolledLink();
|
|
|
|
|
$this->assertStringContainsString( $expectedResult, $html );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideMarkPatrolledLink() {
|
2021-05-25 15:39:48 +00:00
|
|
|
yield 'PatrollingEnabledUserAllowed' => [
|
|
|
|
|
'sysop',
|
2023-06-21 02:57:16 +00:00
|
|
|
[ MainConfigNames::UseRCPatrol => true, MainConfigNames::LanguageCode => 'qxx' ],
|
2021-05-25 15:39:48 +00:00
|
|
|
'Mark as patrolled'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingEnabledUserNotAllowed' => [
|
|
|
|
|
null,
|
2023-06-21 02:57:16 +00:00
|
|
|
[ MainConfigNames::UseRCPatrol => true, MainConfigNames::LanguageCode => 'qxx' ],
|
2021-05-25 15:39:48 +00:00
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingDisabledUserAllowed' => [
|
|
|
|
|
'sysop',
|
|
|
|
|
null,
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingDisabledUserNotAllowed' => [
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a HTML diff to a human-readable format and hopefully make the test less fragile.
|
2021-01-14 08:20:36 +00:00
|
|
|
* @param string $diff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getPlainDiff( $diff ) {
|
|
|
|
|
$replacements = [
|
|
|
|
|
html_entity_decode( ' ' ) => ' ',
|
|
|
|
|
html_entity_decode( '−' ) => '-',
|
|
|
|
|
];
|
2020-11-29 20:46:02 +00:00
|
|
|
// Preserve markers when stripping tags
|
|
|
|
|
$diff = str_replace( '<td class="diff-marker"></td>', ' ', $diff );
|
|
|
|
|
$diff = str_replace( '<td colspan="2"></td>', ' ', $diff );
|
|
|
|
|
$diff = preg_replace( '/data-marker="([^"]*)">/', '>$1', $diff );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return str_replace( array_keys( $replacements ), array_values( $replacements ),
|
|
|
|
|
trim( strip_tags( $diff ), "\n" ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-20 23:11:59 +00:00
|
|
|
* @param string[]|array[]|null $slots Array mapping slot role to content.
|
|
|
|
|
* If the content is a string, a normal text slot will be created. If the
|
|
|
|
|
* content is an associative array, it can have the following keys:
|
|
|
|
|
* - derived: If present and true, the slot is a derived slot
|
|
|
|
|
* - text: The serialized content
|
|
|
|
|
* - model: The content model ID
|
2023-06-21 02:57:16 +00:00
|
|
|
* @return MutableRevisionRecord|null
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
2023-06-21 02:57:16 +00:00
|
|
|
private function getRevisionRecord( $slots ) {
|
|
|
|
|
if ( $slots === null ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 23:11:59 +00:00
|
|
|
$contentHandlerFactory = $this->getServiceContainer()->getContentHandlerFactory();
|
2021-02-24 05:12:55 +00:00
|
|
|
$title = $this->makeMockTitle( __CLASS__ );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$revision = new MutableRevisionRecord( $title );
|
2019-01-20 23:11:59 +00:00
|
|
|
foreach ( $slots as $role => $info ) {
|
|
|
|
|
if ( is_string( $info ) ) {
|
|
|
|
|
$info = [
|
|
|
|
|
'text' => $info,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$info += [ 'text' => '', 'model' => CONTENT_MODEL_TEXT ];
|
|
|
|
|
|
|
|
|
|
if ( !$contentHandlerFactory->isDefinedModel( $info['model'] ) ) {
|
|
|
|
|
$contentHandlerFactory->defineContentHandler(
|
|
|
|
|
$info['model'], DummyContentHandlerForTesting::class );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent( $info['text'], null, $info['model'] );
|
|
|
|
|
if ( $info['derived'] ?? false ) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$slotRecord = SlotRecord::newDerived( $role, $content );
|
|
|
|
|
} else {
|
|
|
|
|
$slotRecord = SlotRecord::newUnsaved( $role, $content );
|
|
|
|
|
}
|
|
|
|
|
$revision->setSlot( $slotRecord );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
return $revision;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-17 22:11:10 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRevisionHeader
|
|
|
|
|
*/
|
|
|
|
|
public function testRevisionHeader( $deletedFlag, $allowedAction ) {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
2023-06-25 23:03:34 +00:00
|
|
|
if ( $deletedFlag === 'none' ) {
|
|
|
|
|
$oldRevId = $revs[1];
|
|
|
|
|
} elseif ( $deletedFlag === 'deleted' ) {
|
|
|
|
|
$oldRevId = $revs[4];
|
|
|
|
|
} elseif ( $deletedFlag === 'suppressed' ) {
|
|
|
|
|
$oldRevId = $revs[5];
|
2022-12-17 22:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context = new DerivativeContext( $this->context );
|
|
|
|
|
$context->setLanguage( 'qqx' );
|
|
|
|
|
$permissionSet = [];
|
|
|
|
|
if ( $allowedAction !== 'none' ) {
|
|
|
|
|
if ( $allowedAction === 'edit' ) {
|
|
|
|
|
$permissionSet[] = 'edit';
|
|
|
|
|
}
|
|
|
|
|
if ( $deletedFlag === 'suppressed' ) {
|
|
|
|
|
$permissionSet[] = 'suppressrevision';
|
|
|
|
|
} else {
|
|
|
|
|
$permissionSet[] = 'deletedtext';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$context->setAuthority(
|
|
|
|
|
new SimpleAuthority( $this->getTestUser()->getUser(), $permissionSet )
|
|
|
|
|
);
|
|
|
|
|
|
2023-06-25 23:03:34 +00:00
|
|
|
$diffEngine = new DifferenceEngine( $context, $oldRevId, $revs[2], 2, true, true );
|
2022-12-17 22:11:10 +00:00
|
|
|
$this->assertTrue( $diffEngine->loadRevisionData() );
|
|
|
|
|
$revisionHeaderHtml = $diffEngine->getRevisionHeader( $diffEngine->getOldRevision(), 'complete' );
|
|
|
|
|
|
|
|
|
|
// Always show the timestamp
|
|
|
|
|
$this->assertStringContainsString( '(revisionasof:', $revisionHeaderHtml );
|
|
|
|
|
|
2022-12-17 20:50:05 +00:00
|
|
|
if ( $allowedAction === 'none' ) {
|
2023-06-25 23:03:34 +00:00
|
|
|
$this->assertStringNotContainsString( 'oldid=' . $oldRevId, $revisionHeaderHtml );
|
2022-12-17 20:50:05 +00:00
|
|
|
} else {
|
2023-06-25 23:03:34 +00:00
|
|
|
$this->assertStringContainsString( 'oldid=' . $oldRevId, $revisionHeaderHtml );
|
2022-12-17 20:50:05 +00:00
|
|
|
}
|
2022-12-17 22:11:10 +00:00
|
|
|
if ( $allowedAction === 'edit' ) {
|
|
|
|
|
$this->assertStringContainsString( '(editold)', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( '(editold)', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
if ( $allowedAction === 'view' ) {
|
|
|
|
|
$this->assertStringContainsString( '(viewsourceold)', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( '(viewsourceold)', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $deletedFlag === 'none' ) {
|
|
|
|
|
$this->assertStringNotContainsString( 'history-deleted', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringContainsString( 'history-deleted', $revisionHeaderHtml );
|
|
|
|
|
}
|
2022-12-17 20:50:05 +00:00
|
|
|
if ( $deletedFlag === 'suppressed' ) {
|
2022-12-17 22:11:10 +00:00
|
|
|
$this->assertStringContainsString( 'mw-history-suppressed', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( 'mw-history-suppressed', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideRevisionHeader() {
|
2022-12-17 22:11:10 +00:00
|
|
|
return [
|
|
|
|
|
[ 'none', 'view' ],
|
|
|
|
|
[ 'none', 'edit' ],
|
|
|
|
|
[ 'deleted', 'none' ],
|
|
|
|
|
[ 'deleted', 'view' ],
|
|
|
|
|
[ 'deleted', 'edit' ],
|
|
|
|
|
[ 'suppressed', 'none' ],
|
|
|
|
|
[ 'suppressed', 'view' ],
|
|
|
|
|
[ 'suppressed', 'edit' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-06-25 23:03:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideShowDiffPage
|
|
|
|
|
* @param array $reqParams
|
|
|
|
|
* @param array $userRights
|
|
|
|
|
* @param array $expected
|
|
|
|
|
*/
|
|
|
|
|
public function testShowDiffPage( $reqParams, $userRights, $expected ) {
|
|
|
|
|
$this->expandTestArgs( [ &$reqParams, &$expected ] );
|
|
|
|
|
$context = new DerivativeContext( $this->context );
|
|
|
|
|
|
|
|
|
|
$authority = new SimpleAuthority(
|
|
|
|
|
new UserIdentityValue( 1, 'User' ),
|
|
|
|
|
$userRights
|
|
|
|
|
);
|
|
|
|
|
$context->setAuthority( $authority );
|
|
|
|
|
|
|
|
|
|
$request = new FauxRequest( $reqParams );
|
|
|
|
|
$context->setRequest( $request );
|
|
|
|
|
|
|
|
|
|
$context->setLanguage( 'qqx' );
|
|
|
|
|
|
|
|
|
|
$out = new OutputPage( $context );
|
|
|
|
|
$context->setOutput( $out );
|
|
|
|
|
|
|
|
|
|
$engine = new DifferenceEngine(
|
|
|
|
|
$context,
|
|
|
|
|
$request->getIntOrNull( 'oldid' ),
|
|
|
|
|
$request->getVal( 'diff' ),
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
$request->getInt( 'unhide' ) === 1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( isset( $expected['exception'] ) ) {
|
|
|
|
|
$this->expectException( $expected['exception'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$engine->showDiffPage( $request->getBool( 'diffonly' ) );
|
|
|
|
|
|
|
|
|
|
if ( isset( $expected['html'] ) ) {
|
|
|
|
|
$this->assertMatchesRegularExpression(
|
|
|
|
|
'{' . $expected['html'] . '}s',
|
|
|
|
|
$out->getHTML(),
|
|
|
|
|
'OutputPage::getHTML'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideShowDiffPage() {
|
|
|
|
|
$cases = [
|
|
|
|
|
'missing oldid' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => '1000000',
|
|
|
|
|
'diff' => 'prev',
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' => '\(difference-missing-revision: 1000000, 1\)',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'missing prev' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[0]',
|
|
|
|
|
'diff' => 'prev'
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'\(diff-empty\).*' .
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
'<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>no kittens'
|
2023-06-25 23:03:34 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'normal diff=prev' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[1]',
|
|
|
|
|
'diff' => 'prev'
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'\(viewsourceold\).*' .
|
|
|
|
|
'<del class="diffchange diffchange-inline">no kittens</del>.*' .
|
|
|
|
|
'<ins class="diffchange diffchange-inline">one kitten</ins>.*' .
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
'<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>one kitten',
|
2023-06-25 23:03:34 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'normal diff=number' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[0]',
|
|
|
|
|
'diff' => 'rev[1]'
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'\(viewsourceold\).*' .
|
|
|
|
|
'<del class="diffchange diffchange-inline">no kittens</del>.*' .
|
|
|
|
|
'<ins class="diffchange diffchange-inline">one kitten</ins>.*' .
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
'<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>one kitten',
|
2023-06-25 23:03:34 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'user cannot read' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[1]',
|
|
|
|
|
'diff' => 'prev',
|
|
|
|
|
],
|
|
|
|
|
'userRights' => [],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'exception' => PermissionsError::class,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'user can rollback' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[6]',
|
|
|
|
|
'diff' => 'rev[7]',
|
|
|
|
|
],
|
|
|
|
|
'userRights' => [ 'read', 'edit', 'rollback' ],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'\(editold\).*' .
|
|
|
|
|
'\(rollbacklinkcount: 1\)',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'diffonly' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[1]',
|
|
|
|
|
'diff' => 'prev',
|
|
|
|
|
'diffonly' => '1',
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'<del class="diffchange diffchange-inline">no kittens</del>.*' .
|
|
|
|
|
'<ins class="diffchange diffchange-inline">one kitten</ins>.*' .
|
|
|
|
|
'</table>$',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'deleted LHS' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[4]',
|
|
|
|
|
'diff' => 'rev[1]'
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' => '<div id="mw-diff-otitle1">.*' .
|
|
|
|
|
'<span class="history-deleted">.*' .
|
|
|
|
|
'<div id="mw-diff-ntitle1">.*' .
|
|
|
|
|
'\(rev-deleted-no-diff\)',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'deleted RHS' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[3]',
|
|
|
|
|
'diff' => 'rev[4]'
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'<div id="mw-diff-otitle1">.*' .
|
|
|
|
|
'<div id="mw-diff-ntitle1">.*' .
|
|
|
|
|
'<span class="history-deleted">.*' .
|
|
|
|
|
'\(rev-deleted-no-diff\)',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'deleted LHS can unhide' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[4]',
|
|
|
|
|
'diff' => 'rev[1]'
|
|
|
|
|
],
|
|
|
|
|
'userRights' => [ 'read', 'deletedtext' ],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'<div id="mw-diff-ntitle1">.*' .
|
|
|
|
|
'\(rev-deleted-unhide-diff:.*' .
|
|
|
|
|
'&unhide=1.*',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'deleted RHS with unhide' => [
|
|
|
|
|
'params' => [
|
|
|
|
|
'oldid' => 'rev[3]',
|
|
|
|
|
'diff' => 'rev[4]',
|
|
|
|
|
'unhide' => '1'
|
|
|
|
|
],
|
|
|
|
|
'userRights' => [ 'read', 'deletedtext' ],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'html' =>
|
|
|
|
|
'\(rev-deleted-diff-view\).*' .
|
|
|
|
|
'<del class="diffchange diffchange-inline">three </del>.*' .
|
|
|
|
|
'<ins class="diffchange diffchange-inline">fnord </ins>.*' .
|
parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==
Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.
== ImagePage ==
On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.
Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.
This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).
RECENT (T310445):
A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().
Test plan: Covered by ImagePageTest.
== Skin mainpage-title ==
RECENT (T331095, T298715):
A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.
A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.
== EditPage ==
This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.
Test Plan:
* EditPage: Default preview
1. index.php?title=Main_Page&action=edit
2. Show preview
3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
* EditPage: JS preview
1. Preferences > Editing > Show preview without reload
2. index.php?title=Main_Page&action=edit
3. Show preview
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
5. Type something and 'Show preview' again
6. Assert old element gone, new text is shown, and new element
attributes are the same as the above.
== McrUndoAction ==
Same as EditPage basically, but without the JS preview use case.
== DifferenceEngine ==
Test:
1. Open /w/index.php?title=Main_Page&diff=0
(this shows the latest diff, can do manually by viewing
/wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
== Special:ExpandTemplates ==
Test:
1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-10-04 04:45:07 +00:00
|
|
|
'<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>fnord kittens',
|
2023-06-25 23:03:34 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ( $cases as $name => $case ) {
|
|
|
|
|
yield $name => [
|
|
|
|
|
$case['params'],
|
|
|
|
|
$case['userRights'] ?? [ 'read' ],
|
|
|
|
|
$case['expected']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|