| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\ConfirmEdit\FancyCaptcha; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use MediaWiki\HTMLForm\HTMLFormField; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class HTMLFancyCaptchaField extends HTMLFormField { |
| 13 |
|
| 14 |
protected $imageUrl; |
| 15 |
|
| 16 |
|
| 17 |
protected $showCreateHelp; |
| 18 |
|
| 19 |
|
| 20 |
protected $mClass = 'captcha'; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function __construct( array $params ) { |
| 29 |
parent::__construct( $params ); |
| 30 |
$this->imageUrl = $params['imageUrl']; |
| 31 |
$this->showCreateHelp = !empty( $params['showCreateHelp'] ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function getInputHTML( $value ) { |
| 38 |
$out = $this->mParent->getOutput(); |
| 39 |
|
| 40 |
|
| 41 |
$out->addModuleStyles( [ 'codex-styles', 'ext.confirmEdit.fancyCaptcha.styles' ] ); |
| 42 |
|
| 43 |
|
| 44 |
$out->addModules( 'ext.confirmEdit.fancyCaptcha' ); |
| 45 |
|
| 46 |
$captchaReload = Html::element( |
| 47 |
'small', |
| 48 |
[ 'class' => 'confirmedit-captcha-reload fancycaptcha-reload' ], |
| 49 |
$this->mParent->msg( 'fancycaptcha-reload-text' )->text() |
| 50 |
); |
| 51 |
|
| 52 |
$attribs = [ |
| 53 |
'type' => 'text', |
| 54 |
'id' => $this->mID, |
| 55 |
'name' => $this->mName, |
| 56 |
'class' => 'cdx-text-input__input', |
| 57 |
|
| 58 |
'size' => '12', |
| 59 |
'dir' => $this->mDir, |
| 60 |
'autocomplete' => 'off', |
| 61 |
'autocorrect' => 'off', |
| 62 |
'autocapitalize' => 'off', |
| 63 |
'placeholder' => $this->mParent->msg( 'fancycaptcha-imgcaptcha-ph' )->text() |
| 64 |
]; |
| 65 |
$attribs += $this->getAttributes( [ 'tabindex', 'required', 'autofocus' ] ); |
| 66 |
|
| 67 |
$html = Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-container' ] ) |
| 68 |
. Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-and-reload' ] ) |
| 69 |
. Html::openElement( 'div', [ 'class' => 'fancycaptcha-image-container' ] ) |
| 70 |
. Html::element( 'img', [ |
| 71 |
'class' => 'fancycaptcha-image', |
| 72 |
'src' => $this->imageUrl, |
| 73 |
'alt' => '' |
| 74 |
] ) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n" |
| 75 |
. Html::openElement( 'div', [ 'class' => 'cdx-text-input' ] ) |
| 76 |
. Html::element( 'input', $attribs ) . Html::closeElement( 'div' ); |
| 77 |
|
| 78 |
if ( $this->showCreateHelp ) { |
| 79 |
|
| 80 |
$html .= Html::rawElement( 'small', [ |
| 81 |
'class' => 'mw-createacct-captcha-assisted' |
| 82 |
], $this->mParent->msg( 'createacct-imgcaptcha-help' )->parse() ); |
| 83 |
} |
| 84 |
|
| 85 |
$html .= Html::closeElement( 'div' ); |
| 86 |
|
| 87 |
return $html; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public function getLabel() { |
| 94 |
|
| 95 |
|
| 96 |
return $this->mParent->msg( 'captcha-label' )->escaped() . ' ' |
| 97 |
. $this->mParent->msg( 'fancycaptcha-captcha' )->escaped(); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function getLabelHtml( $cellAttributes = [] ) { |
| 104 |
$labelHtml = parent::getLabelHtml( $cellAttributes ); |
| 105 |
if ( $this->mLabel ) { |
| 106 |
|
| 107 |
$labelHtml = Html::rawElement( 'p', [], $this->mLabel ) . $labelHtml; |
| 108 |
} |
| 109 |
return $labelHtml; |
| 110 |
} |
| 111 |
} |