53 $mparams = array_merge( [
55 'url' =>
'http://localhost:7231/',
56 'domain' =>
'localhost',
58 'forwardCookies' =>
false,
60 'parsoidCompat' =>
false,
64 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
65 $mparams[
'url'] .=
'/';
70 $mparams[
'domain'] = preg_replace(
71 '/^(https?:\/\/)?([^\/:]+?)(:\d+)?\/?$/',
75 parent::__construct( $mparams );
78 public function onRequests( array $reqs, Closure $idGenFunc ) {
79 if ( $this->params[
'parsoidCompat'] ) {
84 foreach ( $reqs as $key => $req ) {
85 if ( $this->params[
'fixedUrl'] ) {
86 $version = explode(
'/', $req[
'url'] )[1];
88 str_replace(
'#version#', $version, $this->params[
'url'] ) .
89 preg_replace(
'#^local/v./#',
'', $req[
'url'] );
92 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
94 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
98 if ( $this->params[
'HTTPProxy'] ) {
99 $req[
'proxy'] = $this->params[
'HTTPProxy'];
101 if ( $this->params[
'timeout'] !=
null ) {
102 $req[
'reqTimeout'] = $this->params[
'timeout'];
104 if ( $this->params[
'forwardCookies'] ) {
105 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
107 $result[$key] = $req;
122 foreach ( $reqs as $key => $req ) {
123 $version = explode(
'/', $req[
'url'] )[1];
124 if ( $version ===
'v3' ) {
127 throw new Exception(
"Only Parsoid v3 is supported." );
153 $parts = explode(
'/', $req[
'url'] );
162 if ( $targetWiki !==
'local' ) {
163 throw new Exception(
"Only 'local' target wiki is currently supported" );
164 } elseif ( $version !==
'v3' ) {
165 throw new Exception(
"Version mismatch: should not happen." );
168 $req[
'url'] = preg_replace(
'#^local/v3/#', $this->params[
'domain'] .
'/v1/', $req[
'url'] );
170 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
172 if ( $this->params[
'HTTPProxy'] ) {
173 $req[
'proxy'] = $this->params[
'HTTPProxy'];
175 if ( $this->params[
'timeout'] !=
null ) {
176 $req[
'reqTimeout'] = $this->params[
'timeout'];
178 if ( $this->params[
'forwardCookies'] ) {
179 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];