MediaWiki REL1_31
HTMLSelectOrOtherField.php
Go to the documentation of this file.
1<?php
2
10 public function __construct( $params ) {
11 parent::__construct( $params );
12 $this->getOptions();
13 if ( !in_array( 'other', $this->mOptions, true ) ) {
14 $msg =
15 isset( $params['other'] )
16 ? $params['other']
17 : wfMessage( 'htmlform-selectorother-other' )->text();
18 // Have 'other' always as first element
19 $this->mOptions = [ $msg => 'other' ] + $this->mOptions;
20 }
21 }
22
23 public function getInputHTML( $value ) {
24 $valInSelect = false;
25
26 if ( $value !== false ) {
27 $value = strval( $value );
28 $valInSelect = in_array(
30 );
31 }
32
33 $selected = $valInSelect ? $value : 'other';
34
35 $select = new XmlSelect( $this->mName, $this->mID, $selected );
36 $select->addOptions( $this->getOptions() );
37
38 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
39
40 $tbAttribs = [ 'id' => $this->mID . '-other', 'size' => $this->getSize() ];
41
42 if ( !empty( $this->mParams['disabled'] ) ) {
43 $select->setAttribute( 'disabled', 'disabled' );
44 $tbAttribs['disabled'] = 'disabled';
45 }
46
47 if ( isset( $this->mParams['tabindex'] ) ) {
48 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
49 $tbAttribs['tabindex'] = $this->mParams['tabindex'];
50 }
51
52 $select = $select->getHTML();
53
54 if ( isset( $this->mParams['maxlength'] ) ) {
55 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
56 }
57
58 if ( $this->mClass !== '' ) {
59 $tbAttribs['class'] = $this->mClass;
60 }
61
62 $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
63
64 return "$select<br />\n$textbox";
65 }
66
67 protected function shouldInfuseOOUI() {
68 return true;
69 }
70
71 protected function getOOUIModules() {
72 return [ 'mediawiki.widgets.SelectWithInputWidget' ];
73 }
74
75 public function getInputOOUI( $value ) {
76 $this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SelectWithInputWidget.styles' );
77
78 $valInSelect = false;
79 if ( $value !== false ) {
80 $value = strval( $value );
81 $valInSelect = in_array(
83 );
84 }
85
86 # DropdownInput
87 $dropdownAttribs = [
88 'name' => $this->mName,
89 'options' => $this->getOptionsOOUI(),
90 'value' => $valInSelect ? $value : 'other',
91 'class' => [ 'mw-htmlform-select-or-other' ],
92 ];
93
94 $allowedParams = [
95 'disabled',
96 'tabindex',
97 ];
98
99 $dropdownAttribs += OOUI\Element::configFromHtmlAttributes(
100 $this->getAttributes( $allowedParams )
101 );
102
103 # TextInput
104 $textAttribs = [
105 'name' => $this->mName . '-other',
106 'size' => $this->getSize(),
107 'value' => $valInSelect ? '' : $value,
108 ];
109
110 $allowedParams = [
111 'required',
112 'autofocus',
113 'multiple',
114 'disabled',
115 'tabindex',
116 'maxlength',
117 ];
118
119 $textAttribs += OOUI\Element::configFromHtmlAttributes(
120 $this->getAttributes( $allowedParams )
121 );
122
123 if ( $this->mClass !== '' ) {
124 $textAttribs['classes'] = [ $this->mClass ];
125 }
126 if ( $this->mPlaceholder !== '' ) {
127 $textAttribs['placeholder'] = $this->mPlaceholder;
128 }
129
130 return $this->getInputWidget( [
131 'id' => $this->mID,
132 'textinput' => $textAttribs,
133 'dropdowninput' => $dropdownAttribs,
134 'or' => true,
135 ] );
136 }
137
138 public function getInputWidget( $params ) {
140 }
141
147 public function loadDataFromRequest( $request ) {
148 if ( $request->getCheck( $this->mName ) ) {
149 $val = $request->getText( $this->mName );
150
151 if ( $val === 'other' ) {
152 $val = $request->getText( $this->mName . '-other' );
153 }
154
155 return $val;
156 } else {
157 return $this->getDefault();
158 }
159 }
160}
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
getOptions()
Fetch the array of options from the field's parameters.
getAttributes(array $list)
Returns the given attributes from the parameters.
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
Select dropdown field, with an additional "other" textbox.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
shouldInfuseOOUI()
Whether the field should be automatically infused.
<input> field.
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:26
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
$params