2012-04-18 13:02:21 +00:00
|
|
|
<?php
|
2019-05-28 14:04:23 +00:00
|
|
|
|
2024-08-08 09:14:35 +00:00
|
|
|
use MediaWiki\Content\ContentHandler;
|
2024-05-19 13:25:51 +00:00
|
|
|
use MediaWiki\Content\CssContentHandler;
|
2024-05-17 11:31:13 +00:00
|
|
|
use MediaWiki\Content\JavaScriptContentHandler;
|
2024-05-20 15:00:43 +00:00
|
|
|
use MediaWiki\Content\JsonContent;
|
2024-05-21 13:31:18 +00:00
|
|
|
use MediaWiki\Content\JsonContentHandler;
|
2024-05-20 01:26:55 +00:00
|
|
|
use MediaWiki\Content\TextContentHandler;
|
2021-10-22 12:48:23 +00:00
|
|
|
use MediaWiki\Content\ValidationParams;
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
|
|
|
|
use MediaWiki\Content\WikitextContentHandler;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2022-08-24 12:55:03 +00:00
|
|
|
use MediaWiki\Languages\LanguageNameUtils;
|
2023-09-15 15:10:09 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2022-07-20 12:42:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-05-12 10:26:57 +00:00
|
|
|
use MediaWiki\Page\Hook\OpportunisticLinksUpdateHook;
|
2021-10-22 12:48:23 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
|
|
|
|
use MediaWiki\Page\PageIdentityValue;
|
2022-12-09 12:28:41 +00:00
|
|
|
use MediaWiki\Parser\MagicWordFactory;
|
2024-06-13 21:11:26 +00:00
|
|
|
use MediaWiki\Parser\ParserOutput;
|
2022-05-27 16:38:32 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\ParsoidParserFactory;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-08-24 12:55:03 +00:00
|
|
|
use MediaWiki\Title\TitleFactory;
|
[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
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2022-08-24 12:55:03 +00:00
|
|
|
use Wikimedia\UUID\GlobalIdGenerator;
|
2012-04-18 13:02:21 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
2016-05-16 20:24:10 +00:00
|
|
|
* @group Database
|
2024-08-11 11:08:16 +00:00
|
|
|
* @covers \MediaWiki\Content\ContentHandler
|
2012-05-13 22:02:29 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class ContentHandlerTest extends MediaWikiIntegrationTestCase {
|
2012-04-18 13:02:21 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2013-03-22 16:44:34 +00:00
|
|
|
parent::setUp();
|
2012-09-12 11:43:52 +00:00
|
|
|
|
2022-07-20 12:42:41 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::ExtraNamespaces => [
|
2012-10-20 01:51:15 +00:00
|
|
|
12312 => 'Dummy',
|
|
|
|
|
12313 => 'Dummy_talk',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-10-20 01:51:15 +00:00
|
|
|
// The below tests assume that namespaces not mentioned here (Help, User, MediaWiki, ..)
|
|
|
|
|
// default to CONTENT_MODEL_WIKITEXT.
|
2022-07-20 12:42:41 +00:00
|
|
|
MainConfigNames::NamespaceContentModels => [
|
2012-10-20 01:51:15 +00:00
|
|
|
12312 => 'testing',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2022-07-20 12:42:41 +00:00
|
|
|
MainConfigNames::ContentHandlers => [
|
2022-08-24 12:55:03 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT => [
|
|
|
|
|
'class' => WikitextContentHandler::class,
|
|
|
|
|
'services' => [
|
|
|
|
|
'TitleFactory',
|
|
|
|
|
'ParserFactory',
|
|
|
|
|
'GlobalIdGenerator',
|
|
|
|
|
'LanguageNameUtils',
|
2023-09-15 15:10:09 +00:00
|
|
|
'LinkRenderer',
|
2022-08-24 12:55:03 +00:00
|
|
|
'MagicWordFactory',
|
2022-05-27 16:38:32 +00:00
|
|
|
'ParsoidParserFactory',
|
2022-08-24 12:55:03 +00:00
|
|
|
],
|
|
|
|
|
],
|
2018-01-13 00:02:09 +00:00
|
|
|
CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_JSON => JsonContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_CSS => CssContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_TEXT => TextContentHandler::class,
|
|
|
|
|
'testing' => DummyContentHandlerForTesting::class,
|
2021-02-07 13:10:36 +00:00
|
|
|
'testing-callbacks' => static function ( $modelId ) {
|
2016-02-05 13:40:39 +00:00
|
|
|
return new DummyContentHandlerForTesting( $modelId );
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
] );
|
2012-04-26 10:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-16 20:24:10 +00:00
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
$this->insertPage( 'Not_Main_Page', 'This is not a main page' );
|
|
|
|
|
$this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetDefaultModelFor() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'Help:Foo', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.json', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.json', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ],
|
|
|
|
|
[ 'User:Foo/bar.css', CONTENT_MODEL_CSS ],
|
|
|
|
|
[ 'User:Foo/bar.json', CONTENT_MODEL_JSON ],
|
|
|
|
|
[ 'User:Foo/bar.json.nope', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ],
|
|
|
|
|
[ 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ],
|
|
|
|
|
[ 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.json', CONTENT_MODEL_JSON ],
|
|
|
|
|
[ 'MediaWiki:Foo.JSON', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
];
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDefaultModelFor
|
|
|
|
|
*/
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testGetDefaultModelFor( $title, $expectedModelId ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2024-08-08 09:14:35 +00:00
|
|
|
$this->hideDeprecated( 'MediaWiki\\Content\\ContentHandler::getDefaultModelFor' );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-10-20 01:51:15 +00:00
|
|
|
|
|
|
|
|
public static function dataGetLocalizedName() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ null, null ],
|
|
|
|
|
[ "xyzzy", null ],
|
2012-05-13 22:02:29 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// XXX: depends on content language
|
2016-02-17 09:09:32 +00:00
|
|
|
[ CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ],
|
|
|
|
|
];
|
2012-05-13 22:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-19 12:45:25 +00:00
|
|
|
/**
|
2012-06-25 21:30:51 +00:00
|
|
|
* @dataProvider dataGetLocalizedName
|
2012-06-19 12:45:25 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetLocalizedName( $id, $expected ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
$name = ContentHandler::getLocalizedName( $id );
|
2012-06-19 12:45:25 +00:00
|
|
|
|
2012-06-25 21:30:51 +00:00
|
|
|
if ( $expected ) {
|
|
|
|
|
$this->assertNotNull( $name, "no name found for content model $id" );
|
2013-01-28 10:27:15 +00:00
|
|
|
$this->assertTrue( preg_match( $expected, $name ) > 0,
|
2012-10-20 01:51:15 +00:00
|
|
|
"content model name for #$id did not match pattern $expected"
|
|
|
|
|
);
|
2012-06-25 21:30:51 +00:00
|
|
|
} else {
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertEquals( $id, $name, "localization of unknown model $id should have "
|
2012-10-20 01:51:15 +00:00
|
|
|
. "fallen back to use the model id directly."
|
|
|
|
|
);
|
2012-06-19 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetPageLanguage() {
|
2012-06-26 14:37:42 +00:00
|
|
|
global $wgLanguageCode;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ "Main", $wgLanguageCode ],
|
|
|
|
|
[ "Dummy:Foo", $wgLanguageCode ],
|
|
|
|
|
[ "MediaWiki:common.js", 'en' ],
|
|
|
|
|
[ "User:Foo/common.js", 'en' ],
|
|
|
|
|
[ "MediaWiki:common.css", 'en' ],
|
|
|
|
|
[ "User:Foo/common.css", 'en' ],
|
|
|
|
|
[ "User:Foo", $wgLanguageCode ],
|
|
|
|
|
];
|
2012-06-26 14:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetPageLanguage
|
|
|
|
|
*/
|
|
|
|
|
public function testGetPageLanguage( $title, $expected ) {
|
2021-10-08 20:29:30 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2022-01-12 20:13:39 +00:00
|
|
|
$this->getServiceContainer()->getLinkCache()->addBadLinkObj( $title );
|
2012-06-26 14:37:42 +00:00
|
|
|
|
2022-01-12 20:13:39 +00:00
|
|
|
$handler = $this->getServiceContainer()
|
2021-05-28 20:22:01 +00:00
|
|
|
->getContentHandlerFactory()
|
|
|
|
|
->getContentHandler( $title->getContentModel() );
|
2012-06-26 14:37:42 +00:00
|
|
|
$lang = $handler->getPageLanguage( $title );
|
|
|
|
|
|
2019-03-06 12:23:06 +00:00
|
|
|
$this->assertInstanceOf( Language::class, $lang );
|
2021-10-08 20:29:30 +00:00
|
|
|
$this->assertEquals( $expected, $lang->getCode() );
|
2012-06-26 14:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 22:41:52 +00:00
|
|
|
public function testGetContentText_Null() {
|
2024-08-08 09:14:35 +00:00
|
|
|
$this->hideDeprecated( 'MediaWiki\\Content\\ContentHandler::getContentText' );
|
2013-03-22 14:16:35 +00:00
|
|
|
$content = null;
|
2012-04-25 16:35:36 +00:00
|
|
|
$text = ContentHandler::getContentText( $content );
|
2019-09-17 14:28:35 +00:00
|
|
|
$this->assertSame( '', $text );
|
2013-03-22 14:16:35 +00:00
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2024-01-25 22:41:52 +00:00
|
|
|
public function testGetContentText_TextContent() {
|
2024-08-08 09:14:35 +00:00
|
|
|
$this->hideDeprecated( 'MediaWiki\\Content\\ContentHandler::getContentText' );
|
2012-04-25 16:35:36 +00:00
|
|
|
$content = new WikitextContent( "hello world" );
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
2018-11-08 15:19:23 +00:00
|
|
|
$this->assertEquals( $content->getText(), $text );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 22:41:52 +00:00
|
|
|
public function testGetContentText_NonTextContent() {
|
2024-08-08 09:14:35 +00:00
|
|
|
$this->hideDeprecated( 'MediaWiki\\Content\\ContentHandler::getContentText' );
|
2012-04-25 16:35:36 +00:00
|
|
|
$content = new DummyContentForTesting( "hello world" );
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertNull( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataMakeContent() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', null, null, CONTENT_MODEL_WIKITEXT, false ],
|
|
|
|
|
[ 'hallo', 'MediaWiki:Test.js', null, null, CONTENT_MODEL_JAVASCRIPT, false ],
|
2021-10-20 02:08:02 +00:00
|
|
|
[ 'hallo', 'Dummy:Test', null, null, "testing", false ],
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'Help:Test',
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_FORMAT_WIKITEXT,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'MediaWiki:Test.js',
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_FORMAT_JAVASCRIPT,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2021-10-20 02:08:02 +00:00
|
|
|
[ 'hallo', 'Dummy:Test', null, "testing", "testing", false ],
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, false ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'MediaWiki:Test.js',
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
serialize( 'hallo' ),
|
|
|
|
|
'Dummy:Test',
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT, "testing", null, true ],
|
|
|
|
|
[ 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS, "testing", null, true ],
|
|
|
|
|
[ 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT, "testing", null, true ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataMakeContent
|
|
|
|
|
*/
|
2014-04-24 16:06:21 +00:00
|
|
|
public function testMakeContent( $data, $title, $modelId, $format,
|
2018-11-08 15:19:23 +00:00
|
|
|
$expectedModelId, $shouldFail
|
2014-04-24 16:06:21 +00:00
|
|
|
) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2022-01-12 20:13:39 +00:00
|
|
|
$this->getServiceContainer()->getLinkCache()->addBadLinkObj( $title );
|
2012-04-25 16:35:36 +00:00
|
|
|
try {
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = ContentHandler::makeContent( $data, $title, $modelId, $format );
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
if ( $shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent should have failed!" );
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, $content->getModel(), 'bad model id' );
|
2018-11-08 15:19:23 +00:00
|
|
|
$this->assertEquals( $data, $content->serialize(), 'bad serialized data' );
|
2012-04-25 16:35:36 +00:00
|
|
|
} catch ( MWException $ex ) {
|
2013-02-14 13:10:38 +00:00
|
|
|
if ( !$shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
|
2013-03-25 23:27:14 +00:00
|
|
|
} else {
|
2013-02-14 13:10:38 +00:00
|
|
|
// dummy, so we don't get the "test did not perform any assertions" message.
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
2024-07-21 18:16:16 +00:00
|
|
|
* getAutoSummary() should set "Created blank page" summary if we save an empy string.
|
2014-07-27 12:18:26 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetAutosummary() {
|
2018-07-25 14:57:23 +00:00
|
|
|
$this->setContentLang( 'en' );
|
2014-09-27 09:53:02 +00:00
|
|
|
|
2014-07-27 12:18:26 +00:00
|
|
|
$content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( NS_HELP, 'Test' );
|
2014-07-27 12:18:26 +00:00
|
|
|
// Create a new content object with no content
|
2017-11-09 11:13:16 +00:00
|
|
|
$newContent = ContentHandler::makeContent( '', $title, CONTENT_MODEL_WIKITEXT, null );
|
2014-07-27 12:18:26 +00:00
|
|
|
// first check, if we become a blank page created summary with the right bitmask
|
|
|
|
|
$autoSummary = $content->getAutosummary( null, $newContent, 97 );
|
2022-02-08 05:12:43 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
wfMessage( 'autosumm-newblank' )->inContentLanguage()->text(),
|
|
|
|
|
$autoSummary
|
|
|
|
|
);
|
2014-07-27 12:18:26 +00:00
|
|
|
// now check, what we become with another bitmask
|
|
|
|
|
$autoSummary = $content->getAutosummary( null, $newContent, 92 );
|
2021-01-30 12:51:38 +00:00
|
|
|
$this->assertSame( '', $autoSummary );
|
2014-07-27 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 11:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Test software tag that is added when content model of the page changes
|
|
|
|
|
*/
|
|
|
|
|
public function testGetChangeTag() {
|
2022-07-20 12:42:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::SoftwareTags, [ 'mw-contentmodelchange' => true ] );
|
2017-11-09 11:13:16 +00:00
|
|
|
$wikitextContentHandler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
// Create old content object with javascript content model
|
|
|
|
|
$oldContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_JAVASCRIPT, null );
|
|
|
|
|
// Create new content object with wikitext content model
|
|
|
|
|
$newContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_WIKITEXT, null );
|
|
|
|
|
// Get the tag for this edit
|
|
|
|
|
$tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent, EDIT_UPDATE );
|
2021-01-30 12:51:38 +00:00
|
|
|
$this->assertSame( 'mw-contentmodelchange', $tag );
|
2017-11-09 11:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-15 15:19:58 +00:00
|
|
|
public function testSupportsCategories() {
|
|
|
|
|
$handler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
$this->assertTrue( $handler->supportsCategories(), 'content model supports categories' );
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 08:26:22 +00:00
|
|
|
public function testSupportsDirectEditing() {
|
|
|
|
|
$handler = new DummyContentHandlerForTesting( CONTENT_MODEL_JSON );
|
|
|
|
|
$this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 17:28:20 +00:00
|
|
|
public static function dummyHookHandler( $foo, &$text, $bar ) {
|
|
|
|
|
if ( $text === null || $text === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$text = strtoupper( $text );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-05 13:40:39 +00:00
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideGetModelForID() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2018-01-13 00:02:09 +00:00
|
|
|
[ CONTENT_MODEL_WIKITEXT, WikitextContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_JAVASCRIPT, JavaScriptContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_JSON, JsonContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_CSS, CssContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_TEXT, TextContentHandler::class ],
|
|
|
|
|
[ 'testing', DummyContentHandlerForTesting::class ],
|
|
|
|
|
[ 'testing-callbacks', DummyContentHandlerForTesting::class ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2016-02-05 13:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetModelForID
|
|
|
|
|
*/
|
|
|
|
|
public function testGetModelForID( $modelId, $handlerClass ) {
|
2023-11-20 10:32:09 +00:00
|
|
|
$handler = $this->getServiceContainer()->getContentHandlerFactory()
|
|
|
|
|
->getContentHandler( $modelId );
|
2016-02-05 13:40:39 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf( $handlerClass, $handler );
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 17:22:09 +00:00
|
|
|
public function testGetFieldsForSearchIndex() {
|
|
|
|
|
$searchEngine = $this->newSearchEngine();
|
|
|
|
|
|
2023-11-20 10:32:09 +00:00
|
|
|
$handler = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->onlyMethods(
|
|
|
|
|
[ 'serializeContent', 'unserializeContent', 'makeEmptyContent' ]
|
|
|
|
|
)
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
2016-08-09 17:22:09 +00:00
|
|
|
|
|
|
|
|
$fields = $handler->getFieldsForSearchIndex( $searchEngine );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'category', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'external_link', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'outgoing_link', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'template', $fields );
|
2017-01-26 19:15:03 +00:00
|
|
|
$this->assertArrayHasKey( 'content_model', $fields );
|
2016-08-09 17:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function newSearchEngine() {
|
2022-07-14 12:42:07 +00:00
|
|
|
$searchEngine = $this->createMock( SearchEngine::class );
|
2016-08-09 17:22:09 +00:00
|
|
|
|
2021-04-22 08:40:46 +00:00
|
|
|
$searchEngine->method( 'makeSearchFieldMapping' )
|
2022-06-05 23:39:02 +00:00
|
|
|
->willReturnCallback( static function ( $name, $type ) {
|
2016-08-09 17:22:09 +00:00
|
|
|
return new DummySearchIndexFieldDefinition( $name, $type );
|
2022-06-05 23:39:02 +00:00
|
|
|
} );
|
2016-08-09 17:22:09 +00:00
|
|
|
|
|
|
|
|
return $searchEngine;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-16 20:24:10 +00:00
|
|
|
public function testDataIndexFields() {
|
2018-01-13 00:02:09 +00:00
|
|
|
$mockEngine = $this->createMock( SearchEngine::class );
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Not_Main_Page' );
|
2022-06-26 21:21:02 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2016-05-16 20:24:10 +00:00
|
|
|
|
|
|
|
|
$this->setTemporaryHook( 'SearchDataForIndex',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function (
|
2017-02-25 21:53:36 +00:00
|
|
|
&$fields,
|
|
|
|
|
ContentHandler $handler,
|
|
|
|
|
WikiPage $page,
|
|
|
|
|
ParserOutput $output,
|
|
|
|
|
SearchEngine $engine
|
|
|
|
|
) {
|
2016-05-16 20:24:10 +00:00
|
|
|
$fields['testDataField'] = 'test content';
|
|
|
|
|
} );
|
|
|
|
|
|
2022-09-19 06:54:15 +00:00
|
|
|
$revision = $page->getRevisionRecord();
|
2022-12-15 00:21:58 +00:00
|
|
|
$output = $page->getContentHandler()->getParserOutputForIndexing( $page, null, $revision );
|
2022-09-19 06:54:15 +00:00
|
|
|
$data = $page->getContentHandler()->getDataForSearchIndex( $page, $output, $mockEngine, $revision );
|
2016-05-16 20:24:10 +00:00
|
|
|
$this->assertArrayHasKey( 'text', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'text_bytes', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'language', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'testDataField', $data );
|
|
|
|
|
$this->assertEquals( 'test content', $data['testDataField'] );
|
2017-01-26 19:15:03 +00:00
|
|
|
$this->assertEquals( 'wikitext', $data['content_model'] );
|
2016-05-16 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testParserOutputForIndexing() {
|
2023-05-12 10:26:57 +00:00
|
|
|
$opportunisticUpdateHook =
|
|
|
|
|
$this->createMock( OpportunisticLinksUpdateHook::class );
|
|
|
|
|
// WikiPage::triggerOpportunisticLinksUpdate should not be triggered when
|
|
|
|
|
// getParserOutputForIndexing is called
|
|
|
|
|
$opportunisticUpdateHook->expects( $this->never() )
|
|
|
|
|
->method( 'onOpportunisticLinksUpdate' )
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
$this->setTemporaryHook( 'OpportunisticLinksUpdate', $opportunisticUpdateHook );
|
|
|
|
|
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Smithee' );
|
2022-06-26 21:21:02 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2022-09-19 06:54:15 +00:00
|
|
|
$revision = $page->getRevisionRecord();
|
2016-05-16 20:24:10 +00:00
|
|
|
|
2022-09-19 06:54:15 +00:00
|
|
|
$out = $page->getContentHandler()->getParserOutputForIndexing( $page, null, $revision );
|
2016-05-16 20:24:10 +00:00
|
|
|
$this->assertInstanceOf( ParserOutput::class, $out );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( 'one who smiths', $out->getRawText() );
|
2016-05-16 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-31 05:31:30 +00:00
|
|
|
public function testGetContentModelsHook() {
|
2021-02-07 13:10:36 +00:00
|
|
|
$this->setTemporaryHook( 'GetContentModels', static function ( &$models ) {
|
2017-01-31 05:31:30 +00:00
|
|
|
$models[] = 'Ferrari';
|
|
|
|
|
} );
|
2024-08-08 09:14:35 +00:00
|
|
|
$this->hideDeprecated( 'MediaWiki\\Content\\ContentHandler::getContentModels' );
|
2017-01-31 05:31:30 +00:00
|
|
|
$this->assertContains( 'Ferrari', ContentHandler::getContentModels() );
|
|
|
|
|
}
|
[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 testGetSlotDiffRenderer_default() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test default renderer
|
2022-08-24 12:55:03 +00:00
|
|
|
$contentHandler = new WikitextContentHandler(
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
$this->createMock( TitleFactory::class ),
|
|
|
|
|
$this->createMock( ParserFactory::class ),
|
|
|
|
|
$this->createMock( GlobalIdGenerator::class ),
|
|
|
|
|
$this->createMock( LanguageNameUtils::class ),
|
2023-09-15 15:10:09 +00:00
|
|
|
$this->createMock( LinkRenderer::class ),
|
2022-05-27 16:38:32 +00:00
|
|
|
$this->createMock( MagicWordFactory::class ),
|
|
|
|
|
$this->createMock( ParsoidParserFactory::class )
|
2022-08-24 12:55:03 +00:00
|
|
|
);
|
[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 = $contentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertInstanceOf( TextSlotDiffRenderer::class, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetSlotDiffRenderer_bc() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test B/C renderer
|
2022-07-14 12:42:07 +00:00
|
|
|
$customDifferenceEngine = $this->createMock( DifferenceEngine::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
|
|
|
// hack to track object identity across cloning
|
|
|
|
|
$customDifferenceEngine->objectId = 12345;
|
|
|
|
|
$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
|
|
|
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertInstanceOf( DifferenceEngineSlotDiffRenderer::class, $slotDiffRenderer );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$customDifferenceEngine->objectId,
|
|
|
|
|
TestingAccessWrapper::newFromObject( $slotDiffRenderer )->differenceEngine->objectId
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetSlotDiffRenderer_nobc() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test that B/C renderer does not get used when getSlotDiffRendererInternal is overridden
|
2022-07-14 12:42:07 +00:00
|
|
|
$customDifferenceEngine = $this->createMock( DifferenceEngine::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
|
|
|
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'bar', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine', 'getSlotDiffRendererInternal' ] )
|
[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
|
|
|
$customContentHandler2->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 );
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler2->method( 'getSlotDiffRendererInternal' )
|
[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( $customSlotDiffRenderer );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler2 */
|
2023-08-24 19:46:21 +00:00
|
|
|
$this->hideDeprecated( 'ContentHandler::getSlotDiffRendererInternal' );
|
[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 = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetSlotDiffRenderer_hook() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test that the hook handler takes precedence
|
2022-07-14 12:42:07 +00:00
|
|
|
$customDifferenceEngine = $this->createMock( DifferenceEngine::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
|
|
|
$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
|
|
|
|
|
|
|
|
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'bar', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine', 'getSlotDiffRendererInternal' ] )
|
[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
|
|
|
$customContentHandler2->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 );
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler2->method( 'getSlotDiffRendererInternal' )
|
[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( $customSlotDiffRenderer );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler2 */
|
[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
|
|
|
|
|
|
|
|
$customSlotDiffRenderer2 = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$this->setTemporaryHook( 'GetSlotDiffRenderer',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function ( $handler, &$slotDiffRenderer ) use ( $customSlotDiffRenderer2 ) {
|
[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 = $customSlotDiffRenderer2;
|
|
|
|
|
} );
|
|
|
|
|
|
2023-08-24 19:46:21 +00:00
|
|
|
$this->hideDeprecated( 'ContentHandler::getSlotDiffRendererInternal' );
|
[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 = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
|
2023-08-24 19:46:21 +00:00
|
|
|
|
|
|
|
|
$this->hideDeprecated( 'ContentHandler::getSlotDiffRendererInternal' );
|
[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 = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function providerGetPageViewLanguage() {
|
2020-03-25 09:37:37 +00:00
|
|
|
yield [ NS_FILE, 'sr', 'sr-ec', 'sr-ec' ];
|
|
|
|
|
yield [ NS_FILE, 'sr', 'sr', 'sr' ];
|
|
|
|
|
yield [ NS_MEDIAWIKI, 'sr-ec', 'sr', 'sr-ec' ];
|
|
|
|
|
yield [ NS_MEDIAWIKI, 'sr', 'sr-ec', 'sr' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
* Superseded by OutputPageTest::testGetJsVarsAboutPageLang
|
|
|
|
|
*
|
2020-03-25 09:37:37 +00:00
|
|
|
* @dataProvider providerGetPageViewLanguage
|
|
|
|
|
*/
|
|
|
|
|
public function testGetPageViewLanguage( $namespace, $lang, $variant, $expected ) {
|
2021-03-09 17:28:59 +00:00
|
|
|
$contentHandler = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
2020-03-25 09:37:37 +00:00
|
|
|
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( $namespace, 'SimpleTitle' );
|
2020-03-25 09:37:37 +00:00
|
|
|
|
2022-07-20 12:42:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DefaultLanguageVariant, $variant );
|
2020-03-25 09:37:37 +00:00
|
|
|
|
|
|
|
|
$this->setUserLang( $lang );
|
|
|
|
|
$this->setContentLang( $lang );
|
|
|
|
|
|
|
|
|
|
$pageViewLanguage = $contentHandler->getPageViewLanguage( $title );
|
|
|
|
|
$this->assertEquals( $expected, $pageViewLanguage->getCode() );
|
|
|
|
|
}
|
2021-10-22 12:48:23 +00:00
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideValidateSave() {
|
2021-10-22 12:48:23 +00:00
|
|
|
yield 'wikitext' => [
|
|
|
|
|
new WikitextContent( 'hello world' ),
|
|
|
|
|
true
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'valid json' => [
|
|
|
|
|
new JsonContent( '{ "0": "bar" }' ),
|
|
|
|
|
true
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'invalid json' => [
|
|
|
|
|
new JsonContent( 'foo' ),
|
|
|
|
|
false
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideValidateSave
|
|
|
|
|
*/
|
|
|
|
|
public function testValidateSave( $content, $expectedResult ) {
|
|
|
|
|
$page = new PageIdentityValue( 0, 1, 'Foo', PageIdentity::LOCAL );
|
2022-01-12 20:13:39 +00:00
|
|
|
$contentHandlerFactory = $this->getServiceContainer()->getContentHandlerFactory();
|
2021-10-22 12:48:23 +00:00
|
|
|
$contentHandler = $contentHandlerFactory->getContentHandler( $content->getModel() );
|
|
|
|
|
$validateParams = new ValidationParams( $page, 0 );
|
|
|
|
|
|
|
|
|
|
$status = $contentHandler->validateSave( $content, $validateParams );
|
2022-12-04 19:09:28 +00:00
|
|
|
$this->assertEquals( $expectedResult, $status->isOK() );
|
2021-10-22 12:48:23 +00:00
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
}
|