MediaWiki REL1_37
HTMLButtonField.php
Go to the documentation of this file.
1<?php
2
24 protected $buttonType = 'button';
25 protected $buttonLabel = null;
26
28 protected $mFlags = [];
29
30 protected $mFormnovalidate = false;
31
36 public function __construct( $info ) {
37 $info['nodata'] = true;
38
39 $this->setShowEmptyLabel( false );
40
41 parent::__construct( $info );
42
43 if ( isset( $info['flags'] ) ) {
44 $this->mFlags = $info['flags'];
45 }
46
47 if ( isset( $info['formnovalidate'] ) ) {
48 $this->mFormnovalidate = $info['formnovalidate'];
49 }
50
51 # Generate the label from a message, if possible
52 if ( isset( $info['buttonlabel-message'] ) ) {
53 $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
54 } elseif ( isset( $info['buttonlabel'] ) ) {
55 if ( $info['buttonlabel'] === '&#160;' || $info['buttonlabel'] === "\u{00A0}" ) {
56 // Apparently some things set &nbsp directly and in an odd format
57 $this->buttonLabel = "\u{00A0}";
58 } else {
59 $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
60 }
61 } elseif ( isset( $info['buttonlabel-raw'] ) ) {
62 $this->buttonLabel = $info['buttonlabel-raw'];
63 }
64 }
65
66 public function getInputHTML( $value ) {
67 $flags = '';
68 $prefix = 'mw-htmlform-';
69 if ( $this->mParent instanceof VFormHTMLForm ||
70 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
71 ) {
72 $prefix = 'mw-ui-';
73 // add mw-ui-button separately, so the descriptor doesn't need to set it
74 $flags .= ' ' . $prefix . 'button';
75 }
76 foreach ( $this->mFlags as $flag ) {
77 $flags .= ' ' . $prefix . $flag;
78 }
79 $attr = [
80 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
81 'id' => $this->mID,
82 'type' => $this->buttonType,
83 'name' => $this->mName,
84 'value' => $this->getDefault(),
85 'formnovalidate' => $this->mFormnovalidate,
86 ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
87
88 if ( $this->isBadIE() ) {
89 return Html::element( 'input', $attr );
90 } else {
91 return Html::rawElement( 'button', $attr,
92 $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
93 }
94 }
95
102 public function getInputOOUI( $value ) {
103 return new OOUI\ButtonInputWidget( [
104 'name' => $this->mName,
105 'value' => $this->getDefault(),
106 'label' => !$this->isBadIE() && $this->buttonLabel
107 ? new OOUI\HtmlSnippet( $this->buttonLabel )
108 : $this->getDefault(),
109 'type' => $this->buttonType,
110 'classes' => [ 'mw-htmlform-submit', $this->mClass ],
111 'id' => $this->mID,
112 'flags' => $this->mFlags,
113 'useInputTag' => $this->isBadIE(),
114 ] + OOUI\Element::configFromHtmlAttributes(
115 $this->getAttributes( [ 'disabled', 'tabindex' ] )
116 ) );
117 }
118
123 protected function needsLabel() {
124 return false;
125 }
126
136 public function validate( $value, $alldata ) {
137 return true;
138 }
139
144 private function isBadIE() {
145 $request = $this->mParent
146 ? $this->mParent->getRequest()
147 : RequestContext::getMain()->getRequest();
148 return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
149 }
150}
Adds a generic button inline to the form.
array $mFlags
Flags to add to OOUI Button widget.
getInputOOUI( $value)
Get the OOUI widget for this field.
isBadIE()
IE<8 has bugs with <button>, so we'll need to avoid them.
validate( $value, $alldata)
Button cannot be invalid.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
The parent class to generate form fields.
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
getAttributes(array $list)
Returns the given attributes from the parameters.
setShowEmptyLabel( $show)
Tell the field whether to generate a separate label element if its label is blank.
Compact stacked vertical format for forms.