mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-30 19:04:29 +00:00
81d0c7bcd4
Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: I325f5bab163cddf76dbf8d5a6eca35a7ed7b6df7
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\ConfirmEdit\hCaptcha;
|
|
|
|
use MediaWiki\Html\Html;
|
|
use MediaWiki\HTMLForm\HTMLFormField;
|
|
|
|
class HTMLHCaptchaField extends HTMLFormField {
|
|
/** @var string Public key parameter to be passed to hCaptcha. */
|
|
protected $key;
|
|
|
|
/** @var string Error returned by hCaptcha in the previous round. */
|
|
protected $error;
|
|
|
|
/**
|
|
* Parameters:
|
|
* - key: (string, required) Public key
|
|
* - error: (string) Error from previous round
|
|
* @param array $params
|
|
*/
|
|
public function __construct( array $params ) {
|
|
$params += [ 'error' => null ];
|
|
parent::__construct( $params );
|
|
|
|
$this->key = $params['key'];
|
|
$this->error = $params['error'];
|
|
|
|
$this->mName = 'h-captcha-response';
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getInputHTML( $value ) {
|
|
$out = $this->mParent->getOutput();
|
|
|
|
$out->addHeadItem(
|
|
'h-captcha',
|
|
"<script src=\"https://hcaptcha.com/1/api.js\" async defer></script>"
|
|
);
|
|
HCaptcha::addCSPSources( $out->getCSP() );
|
|
return Html::element( 'div', [
|
|
'class' => [
|
|
'h-captcha',
|
|
'mw-confirmedit-captcha-fail' => (bool)$this->error,
|
|
],
|
|
'data-sitekey' => $this->key,
|
|
] );
|
|
}
|
|
}
|