MediaWiki REL1_31
HTMLButtonField.php
Go to the documentation of this file.
1<?php
2
27 protected $buttonType = 'button';
28 protected $buttonLabel = null;
29
31 protected $mFlags = [];
32
33 protected $mFormnovalidate = false;
34
35 public function __construct( $info ) {
36 $info['nodata'] = true;
37 if ( isset( $info['flags'] ) ) {
38 $this->mFlags = $info['flags'];
39 }
40
41 if ( isset( $info['formnovalidate'] ) ) {
42 $this->mFormnovalidate = $info['formnovalidate'];
43 }
44
45 # Generate the label from a message, if possible
46 if ( isset( $info['buttonlabel-message'] ) ) {
47 $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
48 } elseif ( isset( $info['buttonlabel'] ) ) {
49 if ( $info['buttonlabel'] === '&#160;' ) {
50 // Apparently some things set &nbsp directly and in an odd format
51 $this->buttonLabel = '&#160;';
52 } else {
53 $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
54 }
55 } elseif ( isset( $info['buttonlabel-raw'] ) ) {
56 $this->buttonLabel = $info['buttonlabel-raw'];
57 }
58
59 $this->setShowEmptyLabel( false );
60
61 parent::__construct( $info );
62 }
63
64 public function getInputHTML( $value ) {
65 $flags = '';
66 $prefix = 'mw-htmlform-';
67 if ( $this->mParent instanceof VFormHTMLForm ||
68 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
69 ) {
70 $prefix = 'mw-ui-';
71 // add mw-ui-button separately, so the descriptor doesn't need to set it
72 $flags .= ' ' . $prefix . 'button';
73 }
74 foreach ( $this->mFlags as $flag ) {
75 $flags .= ' ' . $prefix . $flag;
76 }
77 $attr = [
78 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
79 'id' => $this->mID,
80 'type' => $this->buttonType,
81 'name' => $this->mName,
82 'value' => $this->getDefault(),
83 'formnovalidate' => $this->mFormnovalidate,
84 ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
85
86 if ( $this->isBadIE() ) {
87 return Html::element( 'input', $attr );
88 } else {
89 return Html::rawElement( 'button', $attr,
90 $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
91 }
92 }
93
99 public function getInputOOUI( $value ) {
100 return new OOUI\ButtonInputWidget( [
101 'name' => $this->mName,
102 'value' => $this->getDefault(),
103 'label' => !$this->isBadIE() && $this->buttonLabel
104 ? new OOUI\HtmlSnippet( $this->buttonLabel )
105 : $this->getDefault(),
106 'type' => $this->buttonType,
107 'classes' => [ 'mw-htmlform-submit', $this->mClass ],
108 'id' => $this->mID,
109 'flags' => $this->mFlags,
110 'useInputTag' => $this->isBadIE(),
111 ] + OOUI\Element::configFromHtmlAttributes(
112 $this->getAttributes( [ 'disabled', 'tabindex' ] )
113 ) );
114 }
115
116 protected function needsLabel() {
117 return false;
118 }
119
128 public function validate( $value, $alldata ) {
129 return true;
130 }
131
136 private function isBadIE() {
137 $request = $this->mParent
138 ? $this->mParent->getRequest()
139 : RequestContext::getMain()->getRequest();
140 return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
141 }
142}
Adds a generic button inline to the form.
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.
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.
static getMain()
Get the RequestContext object associated with the main request.
Compact stacked vertical format for forms.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2806