49 if ( isset( $params[
'URL'] ) ) {
51 'Using all-caps URL parameter to $wgVirtualRestConfig ' .
52 'was deprecated in MediaWiki 1.35',
'1.35'
54 $params[
'url'] = $params[
'URL'];
55 unset( $params[
'URL'] );
59 $mparams = array_merge( [
62 'domain' =>
wfParseUrl( $defaultURL )[
'host'] ??
'localhost',
64 'forwardCookies' =>
false,
68 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
69 $mparams[
'url'] .=
'/';
74 $mparams[
'domain'] = preg_replace(
75 '/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
79 parent::__construct( $mparams );
86 public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
88 foreach ( $reqs as $key => $req ) {
89 $parts = explode(
'/', $req[
'url'] );
100 if ( isset( $this->params[
'restbaseCompat'] ) && $this->params[
'restbaseCompat'] ) {
101 if ( $version !==
'v1' ) {
102 throw new Exception(
"Only RESTBase v1 API is supported." );
104 # Map RESTBase v1 API to Parsoid v3 API (pretty easy)
105 $req[
'url'] = preg_replace(
'#^local/v1/#',
'local/v3/', $req[
'url'] );
106 } elseif ( $version !==
'v3' ) {
107 throw new Exception(
"Only Parsoid v3 API is supported." );
109 if ( $targetWiki !==
'local' ) {
110 throw new Exception(
"Only 'local' target wiki is currently supported" );
112 if ( $reqType !==
'page' && $reqType !==
'transform' ) {
113 throw new Exception(
"Request action must be either 'page' or 'transform'" );
115 if ( $format !==
'html' && $format !==
'wikitext' && $format !==
'lint' ) {
116 throw new Exception(
"Request format must be 'html', 'wt' or 'lint'" );
119 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
121 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
123 if ( $this->params[
'HTTPProxy'] ) {
124 $req[
'proxy'] = $this->params[
'HTTPProxy'];
126 if ( $this->params[
'timeout'] !=
null ) {
127 $req[
'reqTimeout'] = $this->params[
'timeout'];
129 if ( $this->params[
'forwardCookies'] ) {
130 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
135 $req[
'headers'][
'Host'] = $this->params[
'domain'];
136 $result[$key] = $req;
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Virtual HTTP service client for Parsoid.
onRequests(array $reqs, Closure $idGeneratorFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.This method should mangle any of th...
__construct(array $params)
Example Parsoid v3 requests: GET /local/v3/page/html/$title/{$revision}.
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.