diff --git a/hCaptcha/extension.json b/hCaptcha/extension.json index 040afcae5..862b59fa1 100644 --- a/hCaptcha/extension.json +++ b/hCaptcha/extension.json @@ -20,6 +20,10 @@ "CaptchaClass": { "value": "MediaWiki\\Extensions\\ConfirmEdit\\hCaptcha\\HCaptcha" }, + "HCaptchaProxy" : { + "description": "Proxy to use for outbound PHP web requests to hCaptcha servers", + "value": false + }, "HCaptchaSiteKey": { "description": "Sitekey from hCaptcha (requires creating an account)", "value": "" diff --git a/hCaptcha/includes/HCaptcha.php b/hCaptcha/includes/HCaptcha.php index e87a54870..af28e337a 100644 --- a/hCaptcha/includes/HCaptcha.php +++ b/hCaptcha/includes/HCaptcha.php @@ -8,8 +8,8 @@ use ConfirmEditHooks; use FormatJson; use Html; use MediaWiki\Auth\AuthenticationRequest; +use MediaWiki\MediaWikiServices; use Message; -use MWHttpRequest; use RawMessage; use SimpleCaptcha; use Status; @@ -82,7 +82,7 @@ class HCaptcha extends SimpleCaptcha { * @return bool */ protected function passCaptcha( $_, $token ) { - global $wgRequest, $wgHCaptchaSecretKey, $wgHCaptchaSendRemoteIP; + global $wgRequest, $wgHCaptchaSecretKey, $wgHCaptchaSendRemoteIP, $wgHCaptchaProxy; $url = 'https://hcaptcha.com/siteverify'; $data = [ @@ -92,13 +92,19 @@ class HCaptcha extends SimpleCaptcha { if ( $wgHCaptchaSendRemoteIP ) { $data['remoteip'] = $wgRequest->getIP(); } - $request = MWHttpRequest::factory( - $url, - [ - 'method' => 'POST', - 'postData' => $data, - ] - ); + + $options = [ + 'method' => 'POST', + 'postData' => $data, + ]; + + if ( $wgHCaptchaProxy ) { + $options['proxy'] = $wgHCaptchaProxy; + } + + $request = MediaWikiServices::getInstance()->getHttpRequestFactory() + ->create( $url, $options, __METHOD__ ); + $status = $request->execute(); if ( !$status->isOK() ) { $this->error = 'http';