Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormFieldWithButton.php
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 = '';
8
9 /** @var string|integer $mButtonId Element ID for the button in this field */
10 protected $mButtonId = '';
11
12 /** @var string $mButtonName Name the button in this field */
13 protected $mButtonName = '';
14
15 /** @var string $mButtonType Type of the button in this field (e.g. button or submit) */
16 protected $mButtonType = 'submit';
17
18 /** @var string $mButtonType Value for the button in this field */
19 protected $mButtonValue;
20
21 public function __construct( $info ) {
22 if ( isset( $info['buttonclass'] ) ) {
23 $this->mButtonClass = $info['buttonclass'];
24 }
25 if ( isset( $info['buttonid'] ) ) {
26 $this->mButtonId = $info['buttonid'];
27 }
28 if ( isset( $info['buttonname'] ) ) {
29 $this->mButtonName = $info['buttonname'];
30 }
31 if ( isset( $info['buttondefault'] ) ) {
32 $this->mButtonValue = $info['buttondefault'];
33 }
34 if ( isset( $info['buttontype'] ) ) {
35 $this->mButtonType = $info['buttontype'];
36 }
37 parent::__construct( $info );
38 }
39
40 public function getInputHTML( $value ) {
41 $attr = array(
42 'class' => 'mw-htmlform-submit ' . $this->mButtonClass,
43 'id' => $this->mButtonId,
44 ) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
45
46 return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr );
47 }
48
49 /**
50 * Combines the passed element with a button.
51 * @param String $element Element to combine the button with.
52 * @return String
53 */
54 public function getElement( $element ) {
55 return $element . '&#160;' . $this->getInputHTML( '' );
56 }
57 }