mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 17:14:42 +00:00
Merge "Move parseWikitextFragment up to ApiParsoidTrait"
This commit is contained in:
commit
5c75faed31
|
@ -240,7 +240,7 @@ trait ApiParsoidTrait {
|
||||||
* @param string|null $etag The ETag to set in the HTTP request header
|
* @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'
|
* @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
|
Title $title, string $html, int $oldid = null, string $etag = null
|
||||||
) : array {
|
) : array {
|
||||||
$data = [ 'html' => $html, 'scrub_wikitext' => 1 ];
|
$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
|
* Get the page language from a title, using the content language as fallback on special pages
|
||||||
*
|
*
|
||||||
|
|
|
@ -44,32 +44,6 @@ class ApiVisualEditor extends ApiBase {
|
||||||
->serialize( 'text/x-wiki' );
|
->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
|
* Provide the preload content for a page being created from another page
|
||||||
*
|
*
|
||||||
|
@ -170,7 +144,7 @@ class ApiVisualEditor extends ApiBase {
|
||||||
'@phan-var WikitextContent $newSectionContent';
|
'@phan-var WikitextContent $newSectionContent';
|
||||||
$wikitext = $newSectionContent->getText();
|
$wikitext = $newSectionContent->getText();
|
||||||
}
|
}
|
||||||
$response = $this->parseWikitextFragment(
|
$response = $this->transformWikitext(
|
||||||
$title, $wikitext, false, $oldid, $stash
|
$title, $wikitext, false, $oldid, $stash
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,7 +223,7 @@ class ApiVisualEditor extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $content !== '' && $params['paction'] !== 'wikitext' ) {
|
if ( $content !== '' && $params['paction'] !== 'wikitext' ) {
|
||||||
$response = $this->parseWikitextFragment( $title, $content, false, null, true );
|
$response = $this->transformWikitext( $title, $content, false, null, true );
|
||||||
$content = $response['body'];
|
$content = $response['body'];
|
||||||
$restbaseHeaders = $response['headers'];
|
$restbaseHeaders = $response['headers'];
|
||||||
}
|
}
|
||||||
|
@ -553,7 +527,7 @@ class ApiVisualEditor extends ApiBase {
|
||||||
if ( $params['pst'] ) {
|
if ( $params['pst'] ) {
|
||||||
$wikitext = $this->pstWikitext( $title, $wikitext );
|
$wikitext = $this->pstWikitext( $title, $wikitext );
|
||||||
}
|
}
|
||||||
$content = $this->parseWikitextFragment(
|
$content = $this->transformWikitext(
|
||||||
$title, $wikitext, $bodyOnly
|
$title, $wikitext, $bodyOnly
|
||||||
)['body'];
|
)['body'];
|
||||||
if ( $content === false ) {
|
if ( $content === false ) {
|
||||||
|
|
|
@ -186,7 +186,7 @@ class ApiVisualEditorEdit extends ApiBase {
|
||||||
} else {
|
} else {
|
||||||
$html = $params['html'];
|
$html = $params['html'];
|
||||||
}
|
}
|
||||||
$wikitext = $this->postHTML(
|
$wikitext = $this->transformHTML(
|
||||||
$title, $html, $parserParams['oldid'] ?? null, $params['etag'] ?? null
|
$title, $html, $parserParams['oldid'] ?? null, $params['etag'] ?? null
|
||||||
)['body'];
|
)['body'];
|
||||||
return $wikitext;
|
return $wikitext;
|
||||||
|
|
Loading…
Reference in a new issue