Debian Codegraph @

extensions/ConfirmEdit/hCaptcha/includes/HTMLHCaptchaField.php

raw symbols SCIP
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 /** @var string Public key parameter to be passed to hCaptcha. */
10 protected $key;
11
12 /** @var string Error returned by hCaptcha in the previous round. */
13 protected $error;
14
15 /**
16 * Parameters:
17 * - key: (string, required) Public key
18 * - error: (string) Error from previous round
19 * @param array $params
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 * @inheritDoc
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 }