MediaWiki REL1_31
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 'size' => '12', // max_length in captcha.py plus fudge factor
49 'dir' => $this->mDir,
50 'autocomplete' => 'off',
51 'autocorrect' => 'off',
52 'autocapitalize' => 'off',
53 'placeholder' => $this->mParent->msg( 'fancycaptcha-imgcaptcha-ph' )->text()
54 ];
55 $attribs += $this->getAttributes( [ 'tabindex', 'required', 'autofocus' ] );
56
57 $html = Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-container' ] )
58 . Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-and-reload' ] )
59 . Html::openElement( 'div', [ 'class' => 'fancycaptcha-image-container' ] )
60 . Html::element( 'img', [
61 'class' => 'fancycaptcha-image',
62 'src' => $this->imageUrl,
63 'alt' => ''
64 ] ) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n"
65 . Html::element( 'input', $attribs );
66
67 if ( $this->showCreateHelp ) {
68 // use raw element, the message will contain a link
69 $html .= Html::rawElement( 'small', [
70 'class' => 'mw-createacct-captcha-assisted'
71 ], $this->mParent->msg( 'createacct-imgcaptcha-help' )->parse() );
72 }
73
74 $html .= Html::closeElement( 'div' );
75
76 return $html;
77 }
78
79 public function getLabel() {
80 // slight abuse of what getLabel() should mean; $mLabel is used for the pre-label text
81 // as the actual label is always the same
82 return $this->mParent->msg( 'captcha-label' )->text() . ' '
83 . $this->mParent->msg( 'fancycaptcha-captcha' )->text();
84 }
85
86 public function getLabelHtml( $cellAttributes = [] ) {
87 $labelHtml = parent::getLabelHtml( $cellAttributes );
88 if ( $this->mLabel ) {
89 // use raw element, the message will contain a link
90 $labelHtml = Html::rawElement( 'p', [], $this->mLabel ) . $labelHtml;
91 }
92 return $labelHtml;
93 }
94}
Captcha input field for FancyCaptcha that displays a question and returns the answer.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
__construct(array $params)
Apart from normal HTMLFormField parameters, recognizes the following keys:
getLabelHtml( $cellAttributes=[])
The parent class to generate form fields.
getAttributes(array $list)
Returns the given attributes from the parameters.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:864
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2013
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2014
$params