| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\ConfirmEdit\hCaptcha; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use MediaWiki\HTMLForm\HTMLFormField; |
| 7 |
|
| 8 |
class HTMLHCaptchaField extends HTMLFormField { |
| 9 |
|
| 10 |
protected $key; |
| 11 |
|
| 12 |
|
| 13 |
protected $error; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function __construct( array $params ) { |
| 22 |
$params += [ 'error' => null ]; |
| 23 |
parent::__construct( $params ); |
| 24 |
|
| 25 |
$this->key = $params['key']; |
| 26 |
$this->error = $params['error']; |
| 27 |
|
| 28 |
$this->mName = 'h-captcha-response'; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function getInputHTML( $value ) { |
| 35 |
$out = $this->mParent->getOutput(); |
| 36 |
|
| 37 |
$out->addHeadItem( |
| 38 |
'h-captcha', |
| 39 |
"<script src=\"https://hcaptcha.com/1/api.js\" async defer></script>" |
| 40 |
); |
| 41 |
HCaptcha::addCSPSources( $out->getCSP() ); |
| 42 |
return Html::element( 'div', [ |
| 43 |
'class' => [ |
| 44 |
'h-captcha', |
| 45 |
'mw-confirmedit-captcha-fail' => (bool)$this->error, |
| 46 |
], |
| 47 |
'data-sitekey' => $this->key, |
| 48 |
] ); |
| 49 |
} |
| 50 |
} |