ApiParse: Ignore 'contentformat' param when the query is based on page

The 'contentformat' param should only have effects when the parsing
is based on the 'text' param, as what the document described.

Bug: T206253
Change-Id: Ia12b8697e515c6ba89ea81f085292d1ef018bf58
This commit is contained in:
Func 2022-03-03 23:22:01 +08:00
parent 5339aa645b
commit 845bf42aa9
2 changed files with 14 additions and 3 deletions

View file

@ -201,9 +201,6 @@ class ApiParse extends ApiBase {
$pageid = $params['pageid'];
$oldid = $params['oldid'];
$model = $params['contentmodel'];
$format = $params['contentformat'];
$prop = array_fill_keys( $params['prop'], true );
if ( isset( $params['section'] ) ) {
@ -220,6 +217,7 @@ class ApiParse extends ApiBase {
// TODO: Does this still need $wgTitle?
global $wgTitle;
$format = null;
$redirValues = null;
$needContent = isset( $prop['wikitext'] ) ||
@ -302,6 +300,9 @@ class ApiParse extends ApiBase {
);
}
} else { // Not $oldid, $pageid, $page. Hence based on $text
$model = $params['contentmodel'];
$format = $params['contentformat'];
$titleObj = Title::newFromText( $title );
if ( !$titleObj || $titleObj->isExternal() ) {
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );

View file

@ -960,4 +960,14 @@ class ApiParseTest extends ApiTestCase {
] );
}
public function testIgnoreFormatUsingPage() {
$res = $this->doApiRequest( [
'action' => 'parse',
'page' => __CLASS__,
'prop' => 'wikitext',
'contentformat' => 'text/plain',
] );
$this->assertArrayHasKey( 'wikitext', $res[0]['parse'] );
}
}