0,
'iw_api' => '/w/api.php',
'iw_url' => ''
];
$this->overrideConfigValue(
MainConfigNames::InterwikiCache,
ClassicInterwikiLookup::buildCdbHash( [
[
'iw_prefix' => 'en',
'iw_url' => 'https://en.wikipedia.org/wiki/$1',
'iw_wikiid' => 'enwiki',
] + $defaults,
[
'iw_prefix' => 'google',
'iw_url' => 'https://google.com/?q=$1',
'iw_wikiid' => 'google',
] + $defaults,
] )
);
// Limit reporting affects the options used
$this->overrideConfigValue(
MainConfigNames::EnableParserLimitReporting,
true
);
}
public static function provideGetParserOutput() {
$commonOptions = [
'collapsibleSections',
'disableContentConversion',
'interfaceMessage',
'isPreview',
'maxIncludeSize',
'suppressSectionEditLinks',
'useParsoid',
'wrapclass',
'expensiveParserFunctionLimit',
'maxPPExpandDepth',
'maxPPNodeCount',
];
$commonParsoidOptions = array_merge( $commonOptions, [
// Currently no options specific to parsoid parses
] );
$commonLegacyOptions = array_merge( $commonOptions, [
'disableTitleConversion',
'suppressTOC',
'targetLanguage',
] );
$parsoidVersion =
'data-mw-parsoid-version="' . Parsoid::version() . '" ' .
'data-mw-html-version="' . Parsoid::defaultHTMLVersion() . '"';
yield 'Basic render' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "hello ''world''\n",
'expectedHtml' => '
",
'expectedFields' => [
'Links' => [
],
'Sections' => [
],
'UsedOptions' => $commonLegacyOptions,
],
];
yield 'Basic Parsoid render' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "hello ''world''\n",
'expectedHtml' => "",
'expectedFields' => [
'Links' => [
],
'Sections' => [
],
'UsedOptions' => $commonParsoidOptions,
],
'options' => [ 'useParsoid' => true, 'suppressSectionEditLinks' => true ],
];
yield 'Parsoid render (redirect page)' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "#REDIRECT [[Main Page]]",
'expectedHtml' => "",
'expectedFields' => [
'Links' => [
[ 'Main_Page' => 0 ],
],
'Sections' => [
],
'UsedOptions' => $commonParsoidOptions,
],
'options' => [ 'useParsoid' => true, 'suppressSectionEditLinks' => true ],
];
yield 'Parsoid render (section edit links)' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "== Hello ==",
'expectedHtml' => "',
'expectedFields' => [
'Links' => [
],
'Sections' => [
[
'toclevel' => 1,
'level' => '2',
'line' => 'Hello',
'number' => '1',
'index' => '1',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 0,
'anchor' => 'Hello',
'linkAnchor' => 'Hello',
],
],
'UsedOptions' => $commonParsoidOptions,
],
'options' => [ 'useParsoid' => true ],
];
yield 'Links' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "[[title that does not really exist]]",
'expectedHtml' => null,
'expectedFields' => [
'Links' => [
[ 'Title_that_does_not_really_exist' => 0, ],
],
'Sections' => [
],
],
];
yield 'TOC' => [
'title' => 'WikitextContentTest_testGetParserOutput',
'model' => CONTENT_MODEL_WIKITEXT,
'text' => "==One==\n==Two==\n==Three==\n==Four==\nFive
\n===Six+Seven %2525===",
'expectedHtml' => null,
'expectedFields' => [
'Links' => [
],
'Sections' => [
[
'toclevel' => 1,
'level' => '2',
'line' => 'One',
'number' => '1',
'index' => '1',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 0,
'anchor' => 'One',
'linkAnchor' => 'One',
],
[
'toclevel' => 1,
'level' => '2',
'line' => 'Two',
'number' => '2',
'index' => '2',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 8,
'anchor' => 'Two',
'linkAnchor' => 'Two',
],
[
'toclevel' => 1,
'level' => '2',
'line' => 'Three',
'number' => '3',
'index' => '3',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 16,
'anchor' => 'Three',
'linkAnchor' => 'Three',
],
[
'toclevel' => 1,
'level' => '2',
'line' => 'Four',
'number' => '4',
'index' => '4',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 26,
'anchor' => 'Four',
'linkAnchor' => 'Four',
],
[
'toclevel' => 1,
'level' => '2',
'line' => 'Five',
'number' => '5',
'index' => '',
'fromtitle' => false,
'byteoffset' => null,
'anchor' => 'Five',
'linkAnchor' => 'Five',
],
[
'toclevel' => 2,
'level' => '3',
'line' => 'Six+Seven %2525',
'number' => '5.1',
'index' => '5',
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
'byteoffset' => 49,
'anchor' => 'Six+Seven_%2525',
'linkAnchor' => 'Six+Seven_%252525',
],
],
],
];
}
/**
* @dataProvider provideGetParserOutput
*/
public function testGetParserOutput( $title, $model, $text, $expectedHtml,
$expectedFields = null, $options = null
) {
$this->overrideConfigValues( [
MainConfigNames::ScriptPath => '/w',
MainConfigNames::Script => '/w/index.php',
MainConfigNames::FragmentMode => [ 'html5' ],
] );
$parserOptions = null;
if ( $options ) {
$parserOptions = ParserOptions::newFromAnon();
foreach ( $options as $key => $val ) {
$parserOptions->setOption( $key, $val );
}
}
parent::testGetParserOutput(
$title, $model, $text, $expectedHtml, $expectedFields, $parserOptions
);
}
/**
* @dataProvider provideMakeRedirectContent
* @param LinkTarget $target
* @param string $expectedWT Serialized wikitext form of the content object built
* @param string $expectedTarget Expected target string in the HTML redirect
*/
public function testMakeRedirectContent( LinkTarget $target, string $expectedWT, string $expectedTarget ) {
$handler = $this->getServiceContainer()->getContentHandlerFactory()
->getContentHandler( CONTENT_MODEL_WIKITEXT );
$content = $handler->makeRedirectContent( Title::newFromLinkTarget( $target ) );
$this->assertEquals( $expectedWT, $content->serialize() );
// Check that an appropriate redirect header was added to the
// ParserOutput
$parserOutput = $handler->getParserOutput(
$content,
new ContentParseParams( Title::newMainPage() )
);
$redirectHeader = $parserOutput->getRedirectHeader();
$this->assertStringContainsString( '', $redirectHeader );
$this->assertMatchesRegularExpression( '!
]+>' . $expectedTarget . '!', $redirectHeader );
}
public static function provideMakeRedirectContent() {
return [
[ new TitleValue( NS_MAIN, 'Hello' ), '#REDIRECT [[Hello]]', 'Hello' ],
[ new TitleValue( NS_TEMPLATE, 'Hello' ), '#REDIRECT [[Template:Hello]]', 'Template:Hello' ],
[ new TitleValue( NS_MAIN, 'Hello', 'section' ), '#REDIRECT [[Hello#section]]', 'Hello#section' ],
[ new TitleValue( NS_USER, 'John doe', 'section' ), '#REDIRECT [[User:John doe#section]]', 'User:John doe#section' ],
[ new TitleValue( NS_MEDIAWIKI, 'FOOBAR' ), '#REDIRECT [[MediaWiki:FOOBAR]]', 'MediaWiki:FOOBAR' ],
[ new TitleValue( NS_CATEGORY, 'Foo' ), '#REDIRECT [[:Category:Foo]]', 'Category:Foo' ],
[ new TitleValue( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]', 'en:Foo' ],
[ new TitleValue( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]', 'en:Foo' ],
[
new TitleValue( NS_MAIN, 'Bar', 'fragment', 'google' ),
'#REDIRECT [[google:Bar#fragment]]',
'google:Bar#fragment'
],
];
}
}