ApiParse: Add 'parsoid' option
Allow requesting parsoid-format output from the action=parse API. Change-Id: Iba9197491fd85e95b981206b63e43b470aac957c
This commit is contained in:
parent
2caf69797c
commit
07a7ac0c88
4 changed files with 35 additions and 0 deletions
|
|
@ -754,6 +754,9 @@ class ApiParse extends ApiBase {
|
|||
if ( $params['wrapoutputclass'] !== '' ) {
|
||||
$popts->setWrapOutputClass( $params['wrapoutputclass'] );
|
||||
}
|
||||
if ( $params['parsoid'] ) {
|
||||
$popts->setUseParsoid();
|
||||
}
|
||||
|
||||
$reset = null;
|
||||
$suppressCache = false;
|
||||
|
|
@ -1071,6 +1074,7 @@ class ApiParse extends ApiBase {
|
|||
],
|
||||
],
|
||||
'wrapoutputclass' => 'mw-parser-output',
|
||||
'parsoid' => false, // since 1.41
|
||||
'pst' => false,
|
||||
'onlypst' => false,
|
||||
'effectivelanglinks' => [
|
||||
|
|
|
|||
|
|
@ -409,6 +409,7 @@
|
|||
"apihelp-parse-paramvalue-prop-parsewarnings": "Gives the warnings that occurred while parsing content (as wikitext).",
|
||||
"apihelp-parse-paramvalue-prop-parsewarningshtml": "Gives the warnings that occurred while parsing content (as HTML).",
|
||||
"apihelp-parse-param-wrapoutputclass": "CSS class to use to wrap the parser output.",
|
||||
"apihelp-parse-param-parsoid": "Generate HTML conforming to the [[mw:Specs/HTML|MediaWiki DOM spec]] using [[mw:Parsoid|Parsoid]].",
|
||||
"apihelp-parse-param-pst": "Do a pre-save transform on the input before parsing it. Only valid when used with text.",
|
||||
"apihelp-parse-param-onlypst": "Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with <var>$1text</var>.",
|
||||
"apihelp-parse-param-effectivelanglinks": "Includes language links supplied by extensions (for use with <kbd>$1prop=langlinks</kbd>).",
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@
|
|||
"apihelp-parse-paramvalue-prop-parsewarnings": "See also → MediaWiki:Apihelp-parse-paramvalue-prop-parsewarningshtml\n{{doc-apihelp-paramvalue|parse|prop|parsewarnings}}",
|
||||
"apihelp-parse-paramvalue-prop-parsewarningshtml": "{{doc-apihelp-paramvalue|parse|prop|parsewarningshtml}}",
|
||||
"apihelp-parse-param-wrapoutputclass": "{{doc-apihelp-param|parse|wrapoutputclass}}",
|
||||
"apihelp-parse-param-parsoid": "{{doc-apihelp-param|parse|parsoid}}",
|
||||
"apihelp-parse-param-pst": "{{doc-apihelp-param|parse|pst}}",
|
||||
"apihelp-parse-param-onlypst": "{{doc-apihelp-param|parse|onlypst}}",
|
||||
"apihelp-parse-param-effectivelanglinks": "{{doc-apihelp-param|parse|effectivelanglinks}}",
|
||||
|
|
|
|||
|
|
@ -585,6 +585,35 @@ class ApiParseTest extends ApiTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/** @dataProvider providerTestParsoid */
|
||||
public function testParsoid( $parsoid, $existing, $expected ) {
|
||||
# For simplicity, ensure that [[Foo]] isn't a redlink.
|
||||
$this->editPage( "Foo", __FUNCTION__ );
|
||||
$res = $this->doApiRequest( [
|
||||
# check that we're using the contents of 'text' not the contents of
|
||||
# [[<title>]] by using pre-existing title __CLASS__ sometimes
|
||||
'title' => $existing ? __CLASS__ : 'Bar',
|
||||
'action' => 'parse',
|
||||
'text' => "[[Foo]]",
|
||||
'contentmodel' => 'wikitext',
|
||||
'parsoid' => $parsoid ?: null,
|
||||
'disablelimitreport' => true,
|
||||
] );
|
||||
|
||||
$this->assertParsedToRegexp( $expected, $res );
|
||||
}
|
||||
|
||||
public function providerTestParsoid() {
|
||||
// Legacy parses, with and without pre-existing content.
|
||||
$expected = '!^<p><a href="[^"]*" title="Foo">Foo</a>\n</p>$!';
|
||||
yield [ false, false, $expected ];
|
||||
yield [ false, true, $expected ];
|
||||
// Parsoid parses, with and without pre-existing content.
|
||||
$expected = '!^<section[^>]*><p[^>]*><a rel="mw:WikiLink" href="./Foo" title="Foo"[^>]*>Foo</a></p></section>!';
|
||||
yield [ true, false, $expected ];
|
||||
yield [ true, true, $expected ];
|
||||
}
|
||||
|
||||
public function testHeadHtml() {
|
||||
$res = $this->doApiRequest( [
|
||||
'action' => 'parse',
|
||||
|
|
|
|||
Loading…
Reference in a new issue