Merge "Make the comment in the beginning of LanguageFi.php shorter"
[lhc/web/wiklou.git] / includes / htmlform / HTMLButtonField.php
1 <?php
2
3 /**
4 * Adds a generic button inline to the form. Does not do anything, you must add
5 * click handling code in JavaScript. Use a HTMLSubmitField if you merely
6 * wish to add a submit button to a form.
7 *
8 * @since 1.22
9 */
10 class HTMLButtonField extends HTMLFormField {
11 protected $buttonType = 'button';
12
13 /** @var array $mFlags Flags to add to OOUI Button widget */
14 protected $mFlags = array();
15
16 public function __construct( $info ) {
17 $info['nodata'] = true;
18 if ( isset( $info['flags'] ) ) {
19 $this->mFlags = $info['flags'];
20 }
21 parent::__construct( $info );
22 }
23
24 public function getInputHTML( $value ) {
25 $flags = '';
26 $prefix = 'mw-htmlform-';
27 if ( $this->mParent instanceof VFormHTMLForm ||
28 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
29 ) {
30 $prefix = 'mw-ui-';
31 // add mw-ui-button separately, so the descriptor doesn't need to set it
32 $flags .= ' ' . $prefix . 'button';
33 }
34 foreach ( $this->mFlags as $flag ) {
35 $flags .= ' ' . $prefix . $flag;
36 }
37 $attr = array(
38 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
39 'id' => $this->mID,
40 ) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
41
42 return Html::input( $this->mName, $value, $this->buttonType, $attr );
43 }
44
45 /**
46 * Get the OOUI widget for this field.
47 * @param string $value
48 * @return OOUI\\ButtonInputWidget
49 */
50 public function getInputOOUI( $value ) {
51 return new OOUI\ButtonInputWidget( array(
52 'name' => $this->mName,
53 'value' => $value,
54 'label' => $value,
55 'type' => $this->buttonType,
56 'classes' => array( 'mw-htmlform-submit', $this->mClass ),
57 'id' => $this->mID,
58 'flags' => $this->mFlags,
59 ) + $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ) );
60 }
61
62 protected function needsLabel() {
63 return false;
64 }
65
66 /**
67 * Button cannot be invalid
68 *
69 * @param string $value
70 * @param array $alldata
71 *
72 * @return bool
73 */
74 public function validate( $value, $alldata ) {
75 return true;
76 }
77 }