MediaWiki  1.34.0
HTMLFancyCaptchaField.php
Go to the documentation of this file.
1 <?php
2 
9  protected $imageUrl;
10 
12  protected $showCreateHelp;
13 
14  protected $mClass = 'captcha';
15 
22  public function __construct( array $params ) {
23  parent::__construct( $params );
24  $this->imageUrl = $params['imageUrl'];
25  $this->showCreateHelp = !empty( $params['showCreateHelp'] );
26  }
27 
28  public function getInputHTML( $value ) {
29  $out = $this->mParent->getOutput();
30 
31  // Uses addModuleStyles so it is loaded even when JS is disabled.
32  $out->addModuleStyles( 'ext.confirmEdit.fancyCaptcha.styles' );
33 
34  // Loaded only for clients with JS enabled
35  $out->addModules( 'ext.confirmEdit.fancyCaptcha' );
36 
37  $captchaReload = Html::element(
38  'small',
39  [ 'class' => 'confirmedit-captcha-reload fancycaptcha-reload' ],
40  $this->mParent->msg( 'fancycaptcha-reload-text' )->text()
41  );
42 
43  $attribs = [
44  'type' => 'text',
45  'id' => $this->mID,
46  'name' => $this->mName,
47  'class' => 'mw-ui-input',
48  // max_length in captcha.py plus fudge factor
49  'size' => '12',
50  'dir' => $this->mDir,
51  'autocomplete' => 'off',
52  'autocorrect' => 'off',
53  'autocapitalize' => 'off',
54  'placeholder' => $this->mParent->msg( 'fancycaptcha-imgcaptcha-ph' )->text()
55  ];
56  $attribs += $this->getAttributes( [ 'tabindex', 'required', 'autofocus' ] );
57 
58  $html = Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-container' ] )
59  . Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-and-reload' ] )
60  . Html::openElement( 'div', [ 'class' => 'fancycaptcha-image-container' ] )
61  . Html::element( 'img', [
62  'class' => 'fancycaptcha-image',
63  'src' => $this->imageUrl,
64  'alt' => ''
65  ] ) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n"
66  . Html::element( 'input', $attribs );
67 
68  if ( $this->showCreateHelp ) {
69  // use raw element, the message will contain a link
70  $html .= Html::rawElement( 'small', [
71  'class' => 'mw-createacct-captcha-assisted'
72  ], $this->mParent->msg( 'createacct-imgcaptcha-help' )->parse() );
73  }
74 
75  $html .= Html::closeElement( 'div' );
76 
77  return $html;
78  }
79 
80  public function getLabel() {
81  // slight abuse of what getLabel() should mean; $mLabel is used for the pre-label text
82  // as the actual label is always the same
83  return $this->mParent->msg( 'captcha-label' )->text() . ' '
84  . $this->mParent->msg( 'fancycaptcha-captcha' )->text();
85  }
86 
87  public function getLabelHtml( $cellAttributes = [] ) {
88  $labelHtml = parent::getLabelHtml( $cellAttributes );
89  if ( $this->mLabel ) {
90  // use raw element, the message will contain a link
91  $labelHtml = Html::rawElement( 'p', [], $this->mLabel ) . $labelHtml;
92  }
93  return $labelHtml;
94  }
95 }
HTMLFancyCaptchaField\__construct
__construct(array $params)
Apart from normal HTMLFormField parameters, recognizes the following keys:
Definition: HTMLFancyCaptchaField.php:22
HTMLFormField\$mDir
$mDir
Definition: HTMLFormField.php:14
HTMLFormField\$mName
$mName
Definition: HTMLFormField.php:13
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
HTMLFancyCaptchaField\$showCreateHelp
bool $showCreateHelp
Definition: HTMLFancyCaptchaField.php:12
HTMLFormField\$mID
$mID
Definition: HTMLFormField.php:16
HTMLFancyCaptchaField\$mClass
$mClass
Definition: HTMLFancyCaptchaField.php:14
HTMLFancyCaptchaField
Captcha input field for FancyCaptcha that displays a question and returns the answer.
Definition: HTMLFancyCaptchaField.php:7
HTMLFancyCaptchaField\getLabel
getLabel()
Definition: HTMLFancyCaptchaField.php:80
HTMLFancyCaptchaField\getLabelHtml
getLabelHtml( $cellAttributes=[])
Definition: HTMLFancyCaptchaField.php:87
HTMLFancyCaptchaField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLFancyCaptchaField.php:28
HTMLFancyCaptchaField\$imageUrl
string $imageUrl
Definition: HTMLFancyCaptchaField.php:9
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:998