mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 10:48:42 +00:00
Use RESTBase v1 API
This requires https://gerrit.wikimedia.org/r/214351 in core, which adds support for emulating the RESTBase v1 API to the ParsoidVirtualRESTService. $wgVisualEditorPrefix is now deprecated. Parsoid is configured using VRS (preferred) or $wgVisualEditorDomain, which defaults to $wgCanonicalServer. This bumps our MW-core dependency to 1.26wmf21. Bug: T110780 Change-Id: I9175ac8db8310f0c9574c8272b5e39932557d57e
This commit is contained in:
parent
3adfa82ace
commit
96e330650d
|
@ -29,7 +29,7 @@ class ApiVisualEditor extends ApiBase {
|
|||
parent::__construct( $main, $name );
|
||||
$this->veConfig = $config;
|
||||
$this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) );
|
||||
$this->serviceClient->mount( '/parsoid/', $this->getVRSObject() );
|
||||
$this->serviceClient->mount( '/restbase/', $this->getVRSObject() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,20 +53,22 @@ class ApiVisualEditor extends ApiBase {
|
|||
if ( isset( $vrs['modules'] ) && isset( $vrs['modules']['restbase'] ) ) {
|
||||
// if restbase is available, use it
|
||||
$params = $vrs['modules']['restbase'];
|
||||
$params['parsoidCompat'] = false; // backward compatibility
|
||||
$class = 'RestbaseVirtualRESTService';
|
||||
// remove once VE generates restbase paths
|
||||
$params['parsoidCompat'] = true;
|
||||
} elseif ( isset( $vrs['modules'] ) && isset( $vrs['modules']['parsoid'] ) ) {
|
||||
// there's a global parsoid config, use it next
|
||||
$params = $vrs['modules']['parsoid'];
|
||||
$params['restbaseCompat'] = true;
|
||||
} else {
|
||||
// no global modules defined, fall back to old defaults
|
||||
$params = array(
|
||||
'URL' => $config->get( 'VisualEditorParsoidURL' ),
|
||||
'prefix' => $config->get( 'VisualEditorParsoidPrefix' ),
|
||||
'domain' => $config->get( 'VisualEditorParsoidDomain' ),
|
||||
'timeout' => $config->get( 'VisualEditorParsoidTimeout' ),
|
||||
'HTTPProxy' => $config->get( 'VisualEditorParsoidHTTPProxy' ),
|
||||
'forwardCookies' => $config->get( 'VisualEditorParsoidForwardCookies' )
|
||||
'forwardCookies' => $config->get( 'VisualEditorParsoidForwardCookies' ),
|
||||
'restbaseCompat' => true
|
||||
);
|
||||
}
|
||||
// merge the global and service-specific params
|
||||
|
@ -83,10 +85,10 @@ class ApiVisualEditor extends ApiBase {
|
|||
return new $class( $params );
|
||||
}
|
||||
|
||||
private function requestParsoid( $method, $path, $params ) {
|
||||
private function requestRestbase( $method, $path, $params ) {
|
||||
$request = array(
|
||||
'method' => $method,
|
||||
'url' => '/parsoid/local/v1/' . $path
|
||||
'url' => '/restbase/local/v1/' . $path
|
||||
);
|
||||
if ( $method === 'GET' ) {
|
||||
$request['query'] = $params;
|
||||
|
@ -151,12 +153,15 @@ class ApiVisualEditor extends ApiBase {
|
|||
if ( $parserParams['oldid'] === 0 ) {
|
||||
$parserParams['oldid'] = '';
|
||||
}
|
||||
return $this->requestParsoid(
|
||||
$path = 'transform/html/to/wikitext/' . urlencode( $title->getPrefixedDBkey() );
|
||||
if ( $parserParams['oldid'] ) {
|
||||
$path .= '/' . $parserParams['oldid'];
|
||||
}
|
||||
return $this->requestRestbase(
|
||||
'POST',
|
||||
'transform/html/to/wikitext/' . urlencode( $title->getPrefixedDBkey() ),
|
||||
$path,
|
||||
array(
|
||||
'html' => $html,
|
||||
'oldid' => $parserParams['oldid'],
|
||||
'scrubWikitext' => 1,
|
||||
)
|
||||
);
|
||||
|
@ -173,12 +178,12 @@ class ApiVisualEditor extends ApiBase {
|
|||
}
|
||||
|
||||
protected function parseWikitextFragment( $title, $wikitext ) {
|
||||
return $this->requestParsoid(
|
||||
return $this->requestRestbase(
|
||||
'POST',
|
||||
'transform/wikitext/to/html/' . urlencode( $title->getPrefixedDBkey() ),
|
||||
array(
|
||||
'wikitext' => $wikitext,
|
||||
'body' => 1,
|
||||
'bodyOnly' => 1,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -334,12 +339,12 @@ class ApiVisualEditor extends ApiBase {
|
|||
$baseTimestamp = $latestRevision->getTimestamp();
|
||||
$oldid = intval( $parserParams['oldid'] );
|
||||
|
||||
// If requested, request HTML from Parsoid
|
||||
// If requested, request HTML from Parsoid/RESTBase
|
||||
if ( $params['paction'] === 'parse' ) {
|
||||
$content = $this->requestParsoid(
|
||||
$content = $this->requestRestbase(
|
||||
'GET',
|
||||
'page/' . urlencode( $title->getPrefixedDBkey() ) . '/html',
|
||||
$parserParams
|
||||
'page/html/' . urlencode( $title->getPrefixedDBkey() ) . '/' . $oldid,
|
||||
array()
|
||||
);
|
||||
if ( $content === false ) {
|
||||
$this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' );
|
||||
|
|
|
@ -17,7 +17,7 @@ class VisualEditorHooks {
|
|||
// parties who attempt to install VisualEditor onto non-alpha wikis, as
|
||||
// this should have no impact on deploying to Wikimedia's wiki cluster;
|
||||
// is fine for release tarballs because 1.22wmf11 < 1.22alpha < 1.22.0.
|
||||
wfUseMW( '1.26wmf12' );
|
||||
wfUseMW( '1.26wmf21' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
"blueprint"
|
||||
],
|
||||
"VisualEditorParsoidPrefix": "localhost",
|
||||
"VisualEditorParsoidDomain": "localhost",
|
||||
"VisualEditorDisableForAnons": false,
|
||||
"VisualEditorPluginModules": [],
|
||||
"VisualEditorParsoidForwardCookies": false,
|
||||
|
|
Loading…
Reference in a new issue