Merge "Move parseWikitextFragment up to ApiParsoidTrait"

This commit is contained in:
jenkins-bot 2020-07-27 17:01:13 +00:00 committed by Gerrit Code Review
commit 5c75faed31
3 changed files with 31 additions and 31 deletions

View file

@ -240,7 +240,7 @@ trait ApiParsoidTrait {
* @param string|null $etag The ETag to set in the HTTP request header
* @return array The RESTbase server's response, 'code', 'reason', 'headers' and 'body'
*/
protected function postHTML(
protected function transformHTML(
Title $title, string $html, int $oldid = null, string $etag = null
) : array {
$data = [ 'html' => $html, 'scrub_wikitext' => 1 ];
@ -271,6 +271,32 @@ trait ApiParsoidTrait {
);
}
/**
* Transform wikitext to HTML via Parsoid through RESTbase. Wrapper for ::postData().
*
* @param Title $title The title of the page to use as the parsing context
* @param string $wikitext The wikitext fragment to parse
* @param bool $bodyOnly Whether to provide only the contents of the `<body>` tag
* @param int|null $oldid What oldid revision, if any, to base the request from (default: `null`)
* @param bool $stash Whether to stash the result in the server-side cache (default: `false`)
* @return array The RESTbase server's response, 'code', 'reason', 'headers' and 'body'
*/
protected function transformWikitext(
Title $title, string $wikitext, bool $bodyOnly, int $oldid = null, bool $stash = false
) : array {
return $this->requestRestbase(
$title,
'POST',
'transform/wikitext/to/html/' . urlencode( $title->getPrefixedDBkey() ) .
( $oldid === null ? '' : '/' . $oldid ),
[
'wikitext' => $wikitext,
'body_only' => $bodyOnly ? 1 : 0,
'stash' => $stash ? 1 : 0
]
);
}
/**
* Get the page language from a title, using the content language as fallback on special pages
*

View file

@ -44,32 +44,6 @@ class ApiVisualEditor extends ApiBase {
->serialize( 'text/x-wiki' );
}
/**
* Provide the RESTbase-parsed HTML of a given fragment of wikitext
*
* @param Title $title The title of the page to use as the parsing context
* @param string $wikitext The wikitext fragment to parse
* @param bool $bodyOnly Whether to provide only the contents of the `<body>` tag
* @param int|null $oldid What oldid revision, if any, to base the request from (default: `null`)
* @param bool $stash Whether to stash the result in the server-side cache (default: `false`)
* @return array The RESTbase server's response, 'code', 'reason', 'headers' and 'body'
*/
protected function parseWikitextFragment(
Title $title, $wikitext, $bodyOnly, $oldid = null, $stash = false
) {
return $this->requestRestbase(
$title,
'POST',
'transform/wikitext/to/html/' . urlencode( $title->getPrefixedDBkey() ) .
( $oldid === null ? '' : '/' . $oldid ),
[
'wikitext' => $wikitext,
'body_only' => $bodyOnly ? 1 : 0,
'stash' => $stash ? 1 : 0
]
);
}
/**
* Provide the preload content for a page being created from another page
*
@ -170,7 +144,7 @@ class ApiVisualEditor extends ApiBase {
'@phan-var WikitextContent $newSectionContent';
$wikitext = $newSectionContent->getText();
}
$response = $this->parseWikitextFragment(
$response = $this->transformWikitext(
$title, $wikitext, false, $oldid, $stash
);
} else {
@ -249,7 +223,7 @@ class ApiVisualEditor extends ApiBase {
}
if ( $content !== '' && $params['paction'] !== 'wikitext' ) {
$response = $this->parseWikitextFragment( $title, $content, false, null, true );
$response = $this->transformWikitext( $title, $content, false, null, true );
$content = $response['body'];
$restbaseHeaders = $response['headers'];
}
@ -553,7 +527,7 @@ class ApiVisualEditor extends ApiBase {
if ( $params['pst'] ) {
$wikitext = $this->pstWikitext( $title, $wikitext );
}
$content = $this->parseWikitextFragment(
$content = $this->transformWikitext(
$title, $wikitext, $bodyOnly
)['body'];
if ( $content === false ) {

View file

@ -186,7 +186,7 @@ class ApiVisualEditorEdit extends ApiBase {
} else {
$html = $params['html'];
}
$wikitext = $this->postHTML(
$wikitext = $this->transformHTML(
$title, $html, $parserParams['oldid'] ?? null, $params['etag'] ?? null
)['body'];
return $wikitext;