MediaWiki  1.29.1
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  global $wgEnableAPI;
30 
31  $out = $this->mParent->getOutput();
32 
33  // Uses addModuleStyles so it is loaded when JS is disabled.
34  $out->addModuleStyles( 'ext.confirmEdit.fancyCaptcha.styles' );
35 
36  if ( $wgEnableAPI ) {
37  // Loaded only if JS is enabled
38  $out->addModules( 'ext.confirmEdit.fancyCaptcha' );
39 
40  $captchaReload = Html::element(
41  'small',
42  [ 'class' => 'confirmedit-captcha-reload fancycaptcha-reload' ],
43  $this->mParent->msg( 'fancycaptcha-reload-text' )->text()
44  );
45  } else {
46  $captchaReload = '';
47  }
48 
49  $attribs = [
50  'type' => 'text',
51  'id' => $this->mID,
52  'name' => $this->mName,
53  'class' => 'mw-ui-input',
54  'size' => '12', // max_length in captcha.py plus fudge factor
55  'dir' => $this->mDir,
56  'autocomplete' => 'off',
57  'autocorrect' => 'off',
58  'autocapitalize' => 'off',
59  'placeholder' => $this->mParent->msg( 'fancycaptcha-imgcaptcha-ph' )->text()
60  ];
61  $attribs += $this->getAttributes( [ 'tabindex', 'required', 'autofocus' ] );
62 
63  $html = Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-container' ] )
64  . Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-and-reload' ] )
65  . Html::openElement( 'div', [ 'class' => 'fancycaptcha-image-container' ] )
66  . Html::element( 'img', [
67  'class' => 'fancycaptcha-image',
68  'src' => $this->imageUrl,
69  'alt' => ''
70  ] ) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n"
71  . Html::element( 'input', $attribs );
72 
73  if ( $this->showCreateHelp ) {
74  // use raw element, the message will contain a link
75  $html .= Html::rawElement( 'small', [
76  'class' => 'mw-createacct-captcha-assisted'
77  ], $this->mParent->msg( 'createacct-imgcaptcha-help' )->parse() );
78  }
79 
80  $html .= Html::closeElement( 'div' );
81 
82  return $html;
83  }
84 
85  public function getLabel() {
86  // slight abuse of what getLabel() should mean; $mLabel is used for the pre-label text
87  // as the actual label is always the same
88  return $this->mParent->msg( 'captcha-label' )->text() . ' '
89  . $this->mParent->msg( 'fancycaptcha-captcha' )->text();
90  }
91 
92  public function getLabelHtml( $cellAttributes = [] ) {
93  $labelHtml = parent::getLabelHtml( $cellAttributes );
94  if ( $this->mLabel ) {
95  // use raw element, the message will contain a link
96  $labelHtml = Html::rawElement( 'p', [], $this->mLabel ) . $labelHtml;
97  }
98  return $labelHtml;
99  }
100 }
$params
$params
Definition: styleTest.css.php:40
HTMLFancyCaptchaField\__construct
__construct(array $params)
Apart from normal HTMLFormField parameters, recognizes the following keys:
Definition: HTMLFancyCaptchaField.php:22
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
HTMLFormField\$mDir
$mDir
Definition: HTMLFormField.php:13
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
$html
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:1956
HTMLFormField\$mName
$mName
Definition: HTMLFormField.php:12
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
$attribs
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:1956
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
HTMLFancyCaptchaField\$showCreateHelp
bool $showCreateHelp
Definition: HTMLFancyCaptchaField.php:12
HTMLFormField\$mID
$mID
Definition: HTMLFormField.php:15
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
$value
$value
Definition: styleTest.css.php:45
HTMLFancyCaptchaField\getLabel
getLabel()
Definition: HTMLFancyCaptchaField.php:85
HTMLFancyCaptchaField\getLabelHtml
getLabelHtml( $cellAttributes=[])
Definition: HTMLFancyCaptchaField.php:92
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
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
array
the array() calling protocol came about after MediaWiki 1.4rc1.
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:997
$out
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:783