50 if ( isset(
$params[
'URL'] ) ) {
52 'Using all-caps URL parameter to $wgVirtualRestConfig ' .
53 'was deprecated in MediaWiki 1.35',
'1.35'
60 $mparams = array_merge( [
63 'domain' =>
wfParseUrl( $defaultURL )[
'host'] ??
'localhost',
65 'forwardCookies' =>
false,
69 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
70 $mparams[
'url'] .=
'/';
75 $mparams[
'domain'] = preg_replace(
76 '/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
80 parent::__construct( $mparams );
87 public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
89 foreach ( $reqs as $key => $req ) {
90 $parts = explode(
'/', $req[
'url'] );
101 if ( isset( $this->params[
'restbaseCompat'] ) && $this->params[
'restbaseCompat'] ) {
102 if ( $version !==
'v1' ) {
103 throw new Exception(
"Only RESTBase v1 API is supported." );
105 # Map RESTBase v1 API to Parsoid v3 API (pretty easy)
106 $req[
'url'] = preg_replace(
'#^local/v1/#',
'local/v3/', $req[
'url'] );
107 } elseif ( $version !==
'v3' ) {
108 throw new Exception(
"Only Parsoid v3 API is supported." );
110 if ( $targetWiki !==
'local' ) {
111 throw new Exception(
"Only 'local' target wiki is currently supported" );
113 if ( $reqType !==
'page' && $reqType !==
'transform' ) {
114 throw new Exception(
"Request action must be either 'page' or 'transform'" );
116 if ( $format !==
'html' && $format !==
'wikitext' && $format !==
'lint' ) {
117 throw new Exception(
"Request format must be 'html', 'wt' or 'lint'" );
120 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
122 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
124 if ( $this->params[
'HTTPProxy'] ) {
125 $req[
'proxy'] = $this->params[
'HTTPProxy'];
127 if ( $this->params[
'timeout'] !=
null ) {
128 $req[
'reqTimeout'] = $this->params[
'timeout'];
130 if ( $this->params[
'forwardCookies'] ) {
131 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
136 $req[
'headers'][
'Host'] = $this->params[
'domain'];
137 $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 using $wgServer (or one of its alternatives).
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
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.
array $params
Key/value map.