Merge "Add $wgHCaptchaProxy"

This commit is contained in:
jenkins-bot 2020-05-12 20:22:59 +00:00 committed by Gerrit Code Review
commit d607c71936
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';