mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-13 18:07:00 +00:00
hCaptcha: Variablise api and verify urls
Bug: T378207 Change-Id: I62b7a418be4cb3a4a51937ae331a4aad22dc5732
This commit is contained in:
parent
cd607319c2
commit
106a63e3b4
|
@ -18,7 +18,7 @@
|
|||
"value": "MediaWiki\\Extension\\ConfirmEdit\\hCaptcha\\HCaptcha"
|
||||
},
|
||||
"HCaptchaProxy": {
|
||||
"description": "Proxy to use for outbound PHP web requests to hCaptcha servers",
|
||||
"description": "Proxy to use for outbound PHP web requests to hCaptcha servers (HCaptchaVerifyUrl)",
|
||||
"value": false
|
||||
},
|
||||
"HCaptchaSiteKey": {
|
||||
|
@ -32,6 +32,14 @@
|
|||
"HCaptchaSendRemoteIP": {
|
||||
"description": "Whether to send the client's IP address to hCaptcha",
|
||||
"value": false
|
||||
},
|
||||
"HCaptchaApiUrl": {
|
||||
"description": "Url that the hCaptcha JS is loaded from; may want to use https://cn1.hcaptcha.com/1/api.js?endpoint=https://cn1.hcaptcha.com&assethost=https://assets-cn1.hcaptcha.com&imghost=https://imgs-cn1.hcaptcha.com&reportapi=https://reportapi-cn1.hcaptcha.com for Chinese visitors",
|
||||
"value": "https://js.hcaptcha.com/1/api.js"
|
||||
},
|
||||
"HCaptchaVerifyUrl": {
|
||||
"description": "Url that the hCaptcha requested is verified against; may want to use https://cn1.hcaptcha.com/siteverify if server is in China",
|
||||
"value": "https://api.hcaptcha.com/siteverify"
|
||||
}
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
|
|
|
@ -56,10 +56,11 @@ class HCaptcha extends SimpleCaptcha {
|
|||
'data-sitekey' => $this->siteKey
|
||||
] );
|
||||
|
||||
$url = $this->hCaptchaConfig->get( 'HCaptchaApiUrl' );
|
||||
return [
|
||||
'html' => $output,
|
||||
'headitems' => [
|
||||
"<script src=\"https://hcaptcha.com/1/api.js\" async defer></script>"
|
||||
"<script src=\"$url\" async defer></script>"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ class HCaptcha extends SimpleCaptcha {
|
|||
$sendRemoteIp = $this->hCaptchaConfig->get( 'HCaptchaSendRemoteIP' );
|
||||
$proxy = $this->hCaptchaConfig->get( 'HCaptchaProxy' );
|
||||
|
||||
$url = 'https://hcaptcha.com/siteverify';
|
||||
$url = $this->hCaptchaConfig->get( 'HCaptchaVerifyUrl' );
|
||||
$data = [
|
||||
'secret' => $secretKey,
|
||||
'response' => $token,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\hCaptcha;
|
||||
|
||||
use MediaWiki\Context\RequestContext;
|
||||
use MediaWiki\Html\Html;
|
||||
use MediaWiki\HTMLForm\HTMLFormField;
|
||||
|
||||
|
@ -15,7 +16,7 @@ class HTMLHCaptchaField extends HTMLFormField {
|
|||
/**
|
||||
* Parameters:
|
||||
* - key: (string, required) Public key
|
||||
* - error: (string) Error from previous round
|
||||
* - error: (string) Error from the previous captcha round
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( array $params ) {
|
||||
|
@ -32,9 +33,11 @@ class HTMLHCaptchaField extends HTMLFormField {
|
|||
public function getInputHTML( $value ) {
|
||||
$out = $this->mParent->getOutput();
|
||||
|
||||
// TODO: Inject config/similar...
|
||||
$url = RequestContext::getMain()->getConfig()->get( 'HCaptchaApiUrl' );
|
||||
$out->addHeadItem(
|
||||
'h-captcha',
|
||||
"<script src=\"https://hcaptcha.com/1/api.js\" async defer></script>"
|
||||
"<script src=\"$url\" async defer></script>"
|
||||
);
|
||||
HCaptcha::addCSPSources( $out->getCSP() );
|
||||
return Html::element( 'div', [
|
||||
|
|
|
@ -20,7 +20,7 @@ class ResourceLoaderHooks {
|
|||
) {
|
||||
return [
|
||||
'hCaptchaSiteKey' => $config->get( 'HCaptchaSiteKey' ),
|
||||
'hCaptchaScriptURL' => 'https://js.hcaptcha.com/1/api.js',
|
||||
'hCaptchaScriptURL' => $config->get( 'HCaptchaApiUrl' )
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue