From: jenkins-bot Date: Thu, 25 Aug 2016 15:04:33 +0000 (+0000) Subject: Merge "RestbaseVirtualRESTService: Support production URL layout" X-Git-Tag: 1.31.0-rc.0~5895 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=7abf23c194b6fc87bcb3da2453747638cbea64c5;hp=9c2bd36d87ca56e71d73ce69a39e75c1ae0d6407;p=lhc%2Fweb%2Fwiklou.git Merge "RestbaseVirtualRESTService: Support production URL layout" --- diff --git a/includes/libs/virtualrest/RestbaseVirtualRESTService.php b/includes/libs/virtualrest/RestbaseVirtualRESTService.php index 16c93313f2..3afbaa36da 100644 --- a/includes/libs/virtualrest/RestbaseVirtualRESTService.php +++ b/includes/libs/virtualrest/RestbaseVirtualRESTService.php @@ -44,6 +44,9 @@ class RestbaseVirtualRESTService extends VirtualRESTService { * - HTTPProxy : HTTP proxy to use (optional) * - parsoidCompat : whether to parse URL as if they were meant for Parsoid * boolean (optional) + * - fixedUrl : Do not append domain to the url. For example to use + * English Wikipedia restbase, you would this to true + * and url to https://en.wikipedia.org/api/rest_#version# */ public function __construct( array $params ) { // set up defaults and merge them with the given params @@ -54,7 +57,8 @@ class RestbaseVirtualRESTService extends VirtualRESTService { 'timeout' => 100, 'forwardCookies' => false, 'HTTPProxy' => null, - 'parsoidCompat' => false + 'parsoidCompat' => false, + 'fixedUrl' => false, ], $params ); // Ensure that the url parameter has a trailing slash. $mparams['url'] = preg_replace( @@ -81,10 +85,18 @@ class RestbaseVirtualRESTService extends VirtualRESTService { $result = []; foreach ( $reqs as $key => $req ) { - // replace /local/ with the current domain - $req['url'] = preg_replace( '#^local/#', $this->params['domain'] . '/', $req['url'] ); - // and prefix it with the service URL - $req['url'] = $this->params['url'] . $req['url']; + if ( $this->params['fixedUrl'] ) { + $version = explode( '/', $req['url'] )[1]; + $req['url'] = + str_replace( '#version#', $version, $this->params['url'] ) . + preg_replace( '#^local/v./#', '', $req['url'] ); + } else { + // replace /local/ with the current domain + $req['url'] = preg_replace( '#^local/#', $this->params['domain'] . '/', $req['url'] ); + // and prefix it with the service URL + $req['url'] = $this->params['url'] . $req['url']; + } + // set the appropriate proxy, timeout and headers if ( $this->params['HTTPProxy'] ) { $req['proxy'] = $this->params['HTTPProxy']; @@ -99,7 +111,6 @@ class RestbaseVirtualRESTService extends VirtualRESTService { } return $result; - } /**