diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php |
first commit
Diffstat (limited to 'www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php')
-rw-r--r-- | www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php b/www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php new file mode 100644 index 00000000..0859f066 --- /dev/null +++ b/www/wiki/extensions/ConfirmEdit/ReCaptcha/HTMLReCaptchaField.php @@ -0,0 +1,51 @@ +<?php + +/** + * Creates a ReCaptcha widget. Does not return any data; handling the data submitted by the + * widget is callers' responsibility. + */ +class HTMLReCaptchaField extends HTMLFormField { + /** @var string Public key parameter to be passed to ReCaptcha. */ + protected $key; + + /** @var string Theme parameter to be passed to ReCaptcha. */ + protected $theme; + + /** @var bool Use secure connection to ReCaptcha. */ + protected $secure; + + /** @var string Error returned by ReCaptcha in the previous round. */ + protected $error; + + /** + * Parameters: + * - key: (string, required) ReCaptcha public key + * - theme: (string, required) ReCaptcha theme + * - secure: (bool) Use secure connection to ReCaptcha + * - error: (string) ReCaptcha error from previous round + * @param array $params + */ + public function __construct( array $params ) { + $params += [ + 'secure' => true, + 'error' => null, + ]; + parent::__construct( $params ); + + $this->key = $params['key']; + $this->theme = $params['theme']; + $this->secure = $params['secure']; + $this->error = $params['error']; + } + + public function getInputHTML( $value ) { + $attribs = $this->getAttributes( [ 'tabindex' ] ) + [ 'theme' => $this->theme ]; + $js = 'var RecaptchaOptions = ' . Xml::encodeJsVar( $attribs ); + $widget = recaptcha_get_html( $this->key, $this->error, $this->secure ); + return Html::inlineScript( $js ) . $widget; + } + + public function skipLoadData( $request ) { + return true; + } +} |