mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 00:00:49 +00:00
Use the RESTBase back-end if available
Change I4d4043e5052327bbd789331f1c05b607c45fe7cb introduces RESTBase's virtual REST service in the MW core, as well as $wgVirtualRestConfig, which represents the first step towards central VRS configuration. This patch modifies VE to use RESTBase instead of Parsoid, if available. RESTBase's virtual REST service transparently maps Parsoid URIs to RESTBase's, so there is no need to change them in VE for now. Note that the patch keeps full compatibility with systems/domains that do not have $wgVirtualRestConfig declared (or even with those that do not include the RESTBase virtual REST service class). This allows us to use RESTBase as the back-end only on selected domains. Bug: T89066 Change-Id: Ie7488f64868a41f28ec24ab1217c12c6249b5523
This commit is contained in:
parent
9fd753e7a7
commit
b46a2bd105
|
@ -23,18 +23,59 @@ class ApiVisualEditor extends ApiBase {
|
|||
public function __construct( ApiMain $main, $name, Config $config ) {
|
||||
parent::__construct( $main, $name );
|
||||
$this->veConfig = $config;
|
||||
$forwardCookies = false;
|
||||
if ( $config->get( 'VisualEditorParsoidForwardCookies' ) && !User::isEveryoneAllowed( 'read' ) ) {
|
||||
$forwardCookies = RequestContext::getMain()->getRequest()->getHeader( 'Cookie' );
|
||||
}
|
||||
$this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) );
|
||||
$this->serviceClient->mount( '/parsoid/', new ParsoidVirtualRESTService( array(
|
||||
'URL' => $config->get( 'VisualEditorParsoidURL' ),
|
||||
'prefix' => $config->get( 'VisualEditorParsoidPrefix' ),
|
||||
'timeout' => $config->get( 'VisualEditorParsoidTimeout' ),
|
||||
'HTTPProxy' => $config->get( 'VisualEditorParsoidHTTPProxy' ),
|
||||
'forwardCookies' => $forwardCookies,
|
||||
) ) );
|
||||
$this->serviceClient->mount( '/parsoid/', $this->getVRSObject() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the virtual REST service object to be used in VE's API calls. The
|
||||
* method determines whether to instantiate a ParsoidVirtualRESTService or a
|
||||
* RestbaseVirtualRESTService object based on configuration directives: if
|
||||
* $wgVirtualRestConfig['modules']['restbase'] is defined, RESTBase is chosen,
|
||||
* otherwise Parsoid is used (either by using the MW Core config, or the
|
||||
* VE-local one).
|
||||
*
|
||||
* @return VirtualRESTService the VirtualRESTService object to use
|
||||
*/
|
||||
private function getVRSObject() {
|
||||
// the params array to create the service object with
|
||||
$params = array();
|
||||
// the VRS class to use, defaults to Parsoid
|
||||
$class = 'ParsoidVirtualRESTService';
|
||||
$config = $this->veConfig;
|
||||
// the global virtual rest service config object, if any
|
||||
$vrs = $this->getConfig()->get( 'VirtualRestConfig' );
|
||||
if ( isset( $vrs['modules'] ) && isset( $vrs['modules']['restbase'] ) ) {
|
||||
// if restbase is available, use it
|
||||
$params = $vrs['modules']['restbase'];
|
||||
$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'];
|
||||
} else {
|
||||
// no global modules defined, fall back to old defaults
|
||||
$params = array(
|
||||
'URL' => $config->get( 'VisualEditorParsoidURL' ),
|
||||
'prefix' => $config->get( 'VisualEditorParsoidPrefix' ),
|
||||
'timeout' => $config->get( 'VisualEditorParsoidTimeout' ),
|
||||
'HTTPProxy' => $config->get( 'VisualEditorParsoidHTTPProxy' ),
|
||||
'forwardCookies' => $config->get( 'VisualEditorParsoidForwardCookies' )
|
||||
);
|
||||
}
|
||||
// merge the global and service-specific params
|
||||
if ( isset( $vrs['global'] ) ) {
|
||||
$params = array_merge( $vrs['global'], $params );
|
||||
}
|
||||
// set up cookie forwarding
|
||||
if ( $params['forwardCookies'] && !User::isEveryoneAllowed( 'read' ) ) {
|
||||
$params['forwardCookies'] = RequestContext::getMain()->getRequest()->getHeader( 'Cookie' );
|
||||
} else {
|
||||
$params['forwardCookies'] = false;
|
||||
}
|
||||
// create the VRS object and return it
|
||||
return new $class( $params );
|
||||
}
|
||||
|
||||
private function requestParsoid( $method, $path, $params ) {
|
||||
|
|
|
@ -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.25wmf20' );
|
||||
wfUseMW( '1.25wmf21' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue