Merge "Don't check namespace in SpecialWantedtemplates"
[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 parent::__construct( $info );
21 }
22
23 public function getInputHTML( $value ) {
24 $flags = '';
25 $prefix = 'mw-htmlform-';
26 if ( $this->mParent instanceof VFormHTMLForm ||
27 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
28 ) {
29 $prefix = 'mw-ui-';
30 // add mw-ui-button separately, so the descriptor doesn't need to set it
31 $flags .= ' ' . $prefix.'button';
32 }
33 foreach ( $this->mFlags as $flag ) {
34 $flags .= ' ' . $prefix . $flag;
35 }
36 $attr = array(
37 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
38 'id' => $this->mID,
39 ) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
40
41 return Html::input( $this->mName, $value, $this->buttonType, $attr );
42 }
43
44 /**
45 * Get the OOUI widget for this field.
46 * @param string $value
47 * @return OOUI\\ButtonInputWidget
48 */
49 public function getInputOOUI( $value ) {
50 return new OOUI\ButtonInputWidget( array(
51 'name' => $this->mName,
52 'value' => $value,
53 'label' => $value,
54 'type' => $this->buttonType,
55 'classes' => array( 'mw-htmlform-submit', $this->mClass ),
56 'id' => $this->mID,
57 'flags' => $this->mFlags,
58 ) + $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ) );
59 }
60
61 protected function needsLabel() {
62 return false;
63 }
64
65 /**
66 * Button cannot be invalid
67 *
68 * @param string $value
69 * @param array $alldata
70 *
71 * @return bool
72 */
73 public function validate( $value, $alldata ) {
74 return true;
75 }
76 }