Add $wgHCaptchaProxy

Bug: T252427
Change-Id: Ia062edb5e619ef3782ad92ab0b7859770f8b5bdd
This commit is contained in:
Reedy 2020-05-11 17:39:37 +01:00
parent 8dc308a156
commit 96f348b64b
2 changed files with 19 additions and 9 deletions

View file

@ -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": ""

View file

@ -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';