Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/235993
Change subject: Use the VirtualRESTService to configure CX ...................................................................... Use the VirtualRESTService to configure CX This allows CX to use either Parsoid or RESTBase via the VRS, and to share its configuration with Visual Editor. Bug: T111490 Change-Id: I33bc150fa302d9523df92e9e8a258a19b63847f5 --- M api/ApiContentTranslationPublish.php M extension.json 2 files changed, 53 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/93/235993/1 diff --git a/api/ApiContentTranslationPublish.php b/api/ApiContentTranslationPublish.php index 7728ebb..f5366fb 100755 --- a/api/ApiContentTranslationPublish.php +++ b/api/ApiContentTranslationPublish.php @@ -24,15 +24,59 @@ protected $serviceClient; public function __construct( ApiMain $main, $name ) { - global $wgContentTranslationParsoid; parent::__construct( $main, $name ); $this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) ); - $parsoidConfig = $wgContentTranslationParsoid; - $this->serviceClient->mount( '/parsoid/', new ParsoidVirtualRESTService( array( - 'URL' => $parsoidConfig['url'], - 'prefix' => $parsoidConfig['prefix'], - 'timeout' => $parsoidConfig['timeout'], - ) ) ); + $this->serviceClient->mount( '/parsoid/', $this->getVRSObject() ); + } + + /** + * Creates the virtual REST service object to be used in CX'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->getConfig(); + // 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( 'ContentTranslationParsoid' )['url'], + 'prefix' => $config->get( 'ContentTranslationParsoid' )['prefix'], + 'domain' => $config->get( 'ContentTranslationParsoid' )['domain'], + 'timeout' => $config->get( 'ContentTranslationParsoid' )['timeout'], + ); + } + // 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 ) { diff --git a/extension.json b/extension.json index b8910ae..a8e1a8e 100644 --- a/extension.json +++ b/extension.json @@ -101,7 +101,8 @@ "ContentTranslationParsoid": { "url": "http://parsoid-lb.eqiad.wikimedia.org/", "timeout": 100000, - "prefix": "enwiki" + "prefix": "enwiki", + "domain": "en.wikipedia.org" }, "ContentTranslationDatabase": null, "ContentTranslationCluster": false, -- To view, visit https://gerrit.wikimedia.org/r/235993 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I33bc150fa302d9523df92e9e8a258a19b63847f5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits