Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / htmlform / fields / HTMLFormFieldWithButton.php
blobbcb07bd1c2e6f58f7fff6d7e38804f2ccb434e45
1 <?php
2 /**
3 * Enables HTMLFormField elements to be build with a button.
4 */
5 class HTMLFormFieldWithButton extends HTMLFormField {
6 /** @var string $mButtonClass CSS class for the button in this field */
7 protected $mButtonClass = '';
9 /** @var string|integer $mButtonId Element ID for the button in this field */
10 protected $mButtonId = '';
12 /** @var string $mButtonName Name the button in this field */
13 protected $mButtonName = '';
15 /** @var string $mButtonType Type of the button in this field (e.g. button or submit) */
16 protected $mButtonType = 'submit';
18 /** @var string $mButtonType Value for the button in this field */
19 protected $mButtonValue;
21 /** @var string $mButtonType Value for the button in this field */
22 protected $mButtonFlags = [ 'progressive' ];
24 public function __construct( $info ) {
25 if ( isset( $info['buttonclass'] ) ) {
26 $this->mButtonClass = $info['buttonclass'];
28 if ( isset( $info['buttonid'] ) ) {
29 $this->mButtonId = $info['buttonid'];
31 if ( isset( $info['buttonname'] ) ) {
32 $this->mButtonName = $info['buttonname'];
34 if ( isset( $info['buttondefault'] ) ) {
35 $this->mButtonValue = $info['buttondefault'];
37 if ( isset( $info['buttontype'] ) ) {
38 $this->mButtonType = $info['buttontype'];
40 if ( isset( $info['buttonflags'] ) ) {
41 $this->mButtonFlags = $info['buttonflags'];
43 parent::__construct( $info );
46 public function getInputHTML( $value ) {
47 $attr = [
48 'class' => 'mw-htmlform-submit ' . $this->mButtonClass,
49 'id' => $this->mButtonId,
50 ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
52 return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr );
55 public function getInputOOUI( $value ) {
56 return new OOUI\ButtonInputWidget( [
57 'name' => $this->mButtonName,
58 'value' => $this->mButtonValue,
59 'type' => $this->mButtonType,
60 'label' => $this->mButtonValue,
61 'flags' => $this->mButtonFlags,
62 ] + OOUI\Element::configFromHtmlAttributes(
63 $this->getAttributes( [ 'disabled', 'tabindex' ] )
64 ) );
67 /**
68 * Combines the passed element with a button.
69 * @param String $element Element to combine the button with.
70 * @return String
72 public function getElement( $element ) {
73 return $element . '&#160;' . $this->getInputHTML( '' );