MediaWiki REL1_35
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
32 /*
33 * @stable to call
34 */
35 public function __construct( $info ) {
36 $info['nodata'] = true;
37
38 $this->setShowEmptyLabel( false );
39
40 parent::__construct( $info );
41
42 if ( isset( $info['flags'] ) ) {
43 $this->mFlags = $info['flags'];
44 }
45
46 if ( isset( $info['formnovalidate'] ) ) {
47 $this->mFormnovalidate = $info['formnovalidate'];
48 }
49
50 # Generate the label from a message, if possible
51 if ( isset( $info['buttonlabel-message'] ) ) {
52 $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
53 } elseif ( isset( $info['buttonlabel'] ) ) {
54 if ( $info['buttonlabel'] === '&#160;' || $info['buttonlabel'] === "\u{00A0}" ) {
55 // Apparently some things set &nbsp directly and in an odd format
56 $this->buttonLabel = "\u{00A0}";
57 } else {
58 $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
59 }
60 } elseif ( isset( $info['buttonlabel-raw'] ) ) {
61 $this->buttonLabel = $info['buttonlabel-raw'];
62 }
63 }
64
65 public function getInputHTML( $value ) {
66 $flags = '';
67 $prefix = 'mw-htmlform-';
68 if ( $this->mParent instanceof VFormHTMLForm ||
69 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
70 ) {
71 $prefix = 'mw-ui-';
72 // add mw-ui-button separately, so the descriptor doesn't need to set it
73 $flags .= ' ' . $prefix . 'button';
74 }
75 foreach ( $this->mFlags as $flag ) {
76 $flags .= ' ' . $prefix . $flag;
77 }
78 $attr = [
79 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
80 'id' => $this->mID,
81 'type' => $this->buttonType,
82 'name' => $this->mName,
83 'value' => $this->getDefault(),
84 'formnovalidate' => $this->mFormnovalidate,
85 ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
86
87 if ( $this->isBadIE() ) {
88 return Html::element( 'input', $attr );
89 } else {
90 return Html::rawElement( 'button', $attr,
91 $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
92 }
93 }
94
101 public function getInputOOUI( $value ) {
102 return new OOUI\ButtonInputWidget( [
103 'name' => $this->mName,
104 'value' => $this->getDefault(),
105 'label' => !$this->isBadIE() && $this->buttonLabel
106 ? new OOUI\HtmlSnippet( $this->buttonLabel )
107 : $this->getDefault(),
108 'type' => $this->buttonType,
109 'classes' => [ 'mw-htmlform-submit', $this->mClass ],
110 'id' => $this->mID,
111 'flags' => $this->mFlags,
112 'useInputTag' => $this->isBadIE(),
113 ] + OOUI\Element::configFromHtmlAttributes(
114 $this->getAttributes( [ 'disabled', 'tabindex' ] )
115 ) );
116 }
117
122 protected function needsLabel() {
123 return false;
124 }
125
135 public function validate( $value, $alldata ) {
136 return true;
137 }
138
143 private function isBadIE() {
144 $request = $this->mParent
145 ? $this->mParent->getRequest()
146 : RequestContext::getMain()->getRequest();
147 return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
148 }
149}
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.
__construct( $info)
Initialise the object.
isBadIE()
IE<8 has bugs with <button>, so we'll need to avoid them.
validate( $value, $alldata)
Button cannot be invalid Stable to override.
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 Stable to override.
setShowEmptyLabel( $show)
Tell the field whether to generate a separate label element if its label is blank.
getDefault()
Stable to override.
Compact stacked vertical format for forms.