@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | |
28 | 28 | private $mSelectField; |
29 | 29 | |
30 | - public function __construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs ) { |
|
31 | - parent::__construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs ); |
|
30 | + public function __construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs) { |
|
31 | + parent::__construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs); |
|
32 | 32 | |
33 | 33 | // SelectField is a simple value object - we accept creating it in the constructor |
34 | - $this->mSelectField = new SelectField( $GLOBALS['wgParser'] ); |
|
34 | + $this->mSelectField = new SelectField($GLOBALS['wgParser']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public static function getName() { |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * This is currently just a wrapper for getHTML(). |
60 | 60 | */ |
61 | 61 | public function getHtmlText() { |
62 | - return self::getHTML( $this->mCurrentValue, $this->mInputName, $this->mIsMandatory, $this->mIsDisabled, |
|
63 | - $this->mOtherArgs ); |
|
62 | + return self::getHTML($this->mCurrentValue, $this->mInputName, $this->mIsMandatory, $this->mIsDisabled, |
|
63 | + $this->mOtherArgs); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -74,35 +74,35 @@ discard block |
||
74 | 74 | * @param string[] $other_args Array of other field parameters |
75 | 75 | * @return string |
76 | 76 | */ |
77 | - public function getHTML( $cur_value = "", $input_name = "", $is_mandatory, $is_disabled, Array $other_args ) { |
|
77 | + public function getHTML($cur_value = "", $input_name = "", $is_mandatory, $is_disabled, Array $other_args) { |
|
78 | 78 | global $sfgFieldNum, $wgUser, $wgPageFormsShowOnSelect, $wgPageFormsFieldNum; |
79 | 79 | |
80 | 80 | // shortcut to the SelectField object |
81 | 81 | $selectField = $this->mSelectField; |
82 | 82 | |
83 | 83 | // get 'delimiter' before 'query' or 'function' |
84 | - $selectField->setDelimiter( $other_args ); |
|
84 | + $selectField->setDelimiter($other_args); |
|
85 | 85 | |
86 | - if ( array_key_exists( "query", $other_args ) ) { |
|
87 | - $selectField->setQuery( $other_args ); |
|
88 | - } elseif ( array_key_exists( "function", $other_args ) ) { |
|
89 | - $selectField->setFunction( $other_args ); |
|
86 | + if (array_key_exists("query", $other_args)) { |
|
87 | + $selectField->setQuery($other_args); |
|
88 | + } elseif (array_key_exists("function", $other_args)) { |
|
89 | + $selectField->setFunction($other_args); |
|
90 | 90 | } |
91 | 91 | |
92 | - if ( array_key_exists( "label", $other_args ) ) { |
|
93 | - $selectField->setLabel( $other_args ); |
|
92 | + if (array_key_exists("label", $other_args)) { |
|
93 | + $selectField->setLabel($other_args); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // parameters are only required if values needs to be retrieved dynamically |
97 | - if ( !$selectField->hasStaticValues() ) { |
|
98 | - $selectField->setSelectIsMultiple( $other_args ); |
|
99 | - $selectField->setSelectTemplate( $input_name ); |
|
100 | - $selectField->setSelectField( $input_name ); |
|
101 | - $selectField->setValueTemplate( $other_args ); |
|
102 | - $selectField->setValueField( $other_args ); |
|
103 | - $selectField->setSelectRemove( $other_args ); |
|
104 | - |
|
105 | - $item = Output::addToHeadItem( $selectField->getData() ); |
|
97 | + if (!$selectField->hasStaticValues()) { |
|
98 | + $selectField->setSelectIsMultiple($other_args); |
|
99 | + $selectField->setSelectTemplate($input_name); |
|
100 | + $selectField->setSelectField($input_name); |
|
101 | + $selectField->setValueTemplate($other_args); |
|
102 | + $selectField->setValueField($other_args); |
|
103 | + $selectField->setSelectRemove($other_args); |
|
104 | + |
|
105 | + $item = Output::addToHeadItem($selectField->getData()); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | Output::commitToParserOutput(); |
@@ -112,63 +112,63 @@ discard block |
||
112 | 112 | $extraatt = ""; |
113 | 113 | $is_list = false; |
114 | 114 | |
115 | - if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) { |
|
115 | + if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) { |
|
116 | 116 | $is_list = true; |
117 | 117 | } |
118 | 118 | |
119 | - if ( $is_list ) { |
|
119 | + if ($is_list) { |
|
120 | 120 | $extraatt = ' multiple="multiple" '; |
121 | 121 | } |
122 | 122 | |
123 | - if ( array_key_exists( "size", $other_args ) ) { |
|
123 | + if (array_key_exists("size", $other_args)) { |
|
124 | 124 | $extraatt .= " size=\"{$other_args['size']}\""; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $classes = []; |
128 | - if ( $is_mandatory ) { |
|
128 | + if ($is_mandatory) { |
|
129 | 129 | $classes[] = "mandatoryField"; |
130 | 130 | } |
131 | - if ( array_key_exists( "class", $other_args ) ) { |
|
131 | + if (array_key_exists("class", $other_args)) { |
|
132 | 132 | $classes[] = $other_args['class']; |
133 | 133 | } |
134 | 134 | $sfgFieldNum = $sfgFieldNum ? $sfgFieldNum : $wgPageFormsFieldNum; |
135 | 135 | $input_id = "input_$sfgFieldNum"; |
136 | - if ( array_key_exists( 'show on select', $other_args ) ) { |
|
136 | + if (array_key_exists('show on select', $other_args)) { |
|
137 | 137 | $classes[] = 'pfShowIfSelected'; |
138 | - foreach ( $other_args['show on select'] as $div_id => $options ) { |
|
139 | - if ( array_key_exists( $input_id, $wgPageFormsShowOnSelect ) ) { |
|
140 | - $wgPageFormsShowOnSelect[$input_id][] = array( $options, $div_id ); |
|
138 | + foreach ($other_args['show on select'] as $div_id => $options) { |
|
139 | + if (array_key_exists($input_id, $wgPageFormsShowOnSelect)) { |
|
140 | + $wgPageFormsShowOnSelect[$input_id][] = array($options, $div_id); |
|
141 | 141 | } else { |
142 | - $wgPageFormsShowOnSelect[$input_id] = array( array( $options, $div_id ) ); |
|
142 | + $wgPageFormsShowOnSelect[$input_id] = array(array($options, $div_id)); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | - if ( $classes ) { |
|
147 | - $cstr = implode( " ", $classes ); |
|
146 | + if ($classes) { |
|
147 | + $cstr = implode(" ", $classes); |
|
148 | 148 | $extraatt .= " class=\"$cstr\""; |
149 | 149 | } |
150 | 150 | |
151 | 151 | $inname = $input_name; |
152 | - if ( $is_list ) { |
|
152 | + if ($is_list) { |
|
153 | 153 | $inname .= '[]'; |
154 | 154 | } |
155 | 155 | |
156 | 156 | // TODO Use Html:: |
157 | 157 | |
158 | 158 | $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; |
159 | - $is_single_select = (!$is_list) ? 'select-sfs-single' : '' ; |
|
159 | + $is_single_select = (!$is_list) ? 'select-sfs-single' : ''; |
|
160 | 160 | $ret = "<span class=\"inputSpan select-sfs $is_single_select $spanextra\"><select name='$inname' id='input_$sfgFieldNum' $extraatt>"; |
161 | 161 | |
162 | 162 | $curvalues = null; |
163 | - if ( $cur_value ) { |
|
164 | - if ( $cur_value === 'current user' ) { |
|
163 | + if ($cur_value) { |
|
164 | + if ($cur_value === 'current user') { |
|
165 | 165 | $cur_value = $wgUser->getName(); |
166 | 166 | } |
167 | - if ( is_array( $cur_value ) ) { |
|
167 | + if (is_array($cur_value)) { |
|
168 | 168 | $curvalues = $cur_value; |
169 | 169 | } else { |
170 | 170 | // delimiter for $cur_value is always ',' - PF seems to ignore $wgPageFormsListSeparator |
171 | - $curvalues = array_map( "trim", explode( $selectField->getDelimiter(), $cur_value ) ); |
|
171 | + $curvalues = array_map("trim", explode($selectField->getDelimiter(), $cur_value)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | } else { |
@@ -177,38 +177,38 @@ discard block |
||
177 | 177 | |
178 | 178 | |
179 | 179 | $labelArray = []; |
180 | - if ( array_key_exists( "label", $other_args ) && $curvalues ) { |
|
180 | + if (array_key_exists("label", $other_args) && $curvalues) { |
|
181 | 181 | // $labelArray = $this->getLabels( $curvalues ); |
182 | 182 | } |
183 | 183 | |
184 | 184 | // TODO handle empty value case. |
185 | 185 | $ret .= "<option></option>"; |
186 | 186 | |
187 | - if ( $selectField->hasStaticValues() ) { |
|
187 | + if ($selectField->hasStaticValues()) { |
|
188 | 188 | |
189 | 189 | $values = $selectField->getValues(); |
190 | 190 | |
191 | - if ( array_key_exists( "label", $other_args ) && $values ) { |
|
192 | - $labelArray = $this->getLabels( $values ); |
|
191 | + if (array_key_exists("label", $other_args) && $values) { |
|
192 | + $labelArray = $this->getLabels($values); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( is_array( $values ) ) { |
|
195 | + if (is_array($values)) { |
|
196 | 196 | |
197 | - foreach ( $values as $val ) { |
|
197 | + foreach ($values as $val) { |
|
198 | 198 | |
199 | 199 | $selected = ""; |
200 | 200 | |
201 | - if ( array_key_exists( $val, $labelArray ) ) { |
|
201 | + if (array_key_exists($val, $labelArray)) { |
|
202 | 202 | |
203 | - if ( in_array( $labelArray[ $val ][0], $curvalues ) ) { |
|
203 | + if (in_array($labelArray[$val][0], $curvalues)) { |
|
204 | 204 | $selected = " selected='selected'"; |
205 | 205 | } |
206 | 206 | |
207 | - $ret.="<option".$selected." value='".$labelArray[ $val ][0]."'>".$labelArray[ $val ][1]."</option>"; |
|
207 | + $ret .= "<option".$selected." value='".$labelArray[$val][0]."'>".$labelArray[$val][1]."</option>"; |
|
208 | 208 | |
209 | 209 | } else { |
210 | 210 | |
211 | - if ( in_array( $val, $curvalues ) ) { |
|
211 | + if (in_array($val, $curvalues)) { |
|
212 | 212 | $selected = " selected='selected'"; |
213 | 213 | } |
214 | 214 | |
@@ -218,22 +218,22 @@ discard block |
||
218 | 218 | } |
219 | 219 | } else { |
220 | 220 | |
221 | - foreach ( $curvalues as $cur ) { |
|
221 | + foreach ($curvalues as $cur) { |
|
222 | 222 | $selected = ""; |
223 | 223 | |
224 | - if ( array_key_exists( $cur, $labelArray ) ) { |
|
224 | + if (array_key_exists($cur, $labelArray)) { |
|
225 | 225 | |
226 | - if ( in_array( $labelArray[ $cur ][0], $curvalues ) ) { |
|
226 | + if (in_array($labelArray[$cur][0], $curvalues)) { |
|
227 | 227 | $selected = " selected='selected'"; |
228 | 228 | } |
229 | 229 | |
230 | - $ret.="<option".$selected." value='".$labelArray[ $cur ][0]."'>".$labelArray[ $cur ][1]."</option>"; |
|
230 | + $ret .= "<option".$selected." value='".$labelArray[$cur][0]."'>".$labelArray[$cur][1]."</option>"; |
|
231 | 231 | |
232 | 232 | } else { |
233 | - if ( in_array( $cur, $curvalues ) ) { |
|
233 | + if (in_array($cur, $curvalues)) { |
|
234 | 234 | $selected = " selected='selected'"; |
235 | 235 | } |
236 | - $ret.="<option".$selected.">$cur</option>"; |
|
236 | + $ret .= "<option".$selected.">$cur</option>"; |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | $ret .= "</select></span>"; |
243 | 243 | $ret .= "<span id=\"info_$sfgFieldNum\" class=\"errorMessage\"></span>"; |
244 | 244 | |
245 | - if ( $other_args["is_list"] ) { |
|
246 | - $hiddenname = $input_name . '[is_list]'; |
|
245 | + if ($other_args["is_list"]) { |
|
246 | + $hiddenname = $input_name.'[is_list]'; |
|
247 | 247 | $ret .= "<input type='hidden' name='$hiddenname' value='1' />"; |
248 | 248 | } |
249 | 249 | |
@@ -251,49 +251,49 @@ discard block |
||
251 | 251 | } |
252 | 252 | |
253 | 253 | |
254 | - private function getLabels( $labels ) { |
|
254 | + private function getLabels($labels) { |
|
255 | 255 | |
256 | - $labelArray = [ ]; |
|
256 | + $labelArray = []; |
|
257 | 257 | |
258 | - if ( is_array( $labels ) ) { |
|
259 | - foreach ( $labels as $label ) { |
|
258 | + if (is_array($labels)) { |
|
259 | + foreach ($labels as $label) { |
|
260 | 260 | |
261 | 261 | $labelKey = $label; |
262 | 262 | $labelValue = $label; |
263 | 263 | |
264 | 264 | // Tricky thing if ( ) already in name |
265 | - if ( strpos( $label, ")" ) && strpos( $label, "(" ) ) { |
|
265 | + if (strpos($label, ")") && strpos($label, "(")) { |
|
266 | 266 | |
267 | 267 | // Check Break |
268 | 268 | $openBr = 0; |
269 | 269 | $doneBr = 0; |
270 | 270 | $num = 0; |
271 | 271 | |
272 | - $labelArr = str_split ( $label ); |
|
272 | + $labelArr = str_split($label); |
|
273 | 273 | |
274 | - $end = count( $labelArr ) - 1; |
|
274 | + $end = count($labelArr) - 1; |
|
275 | 275 | $iter = $end; |
276 | 276 | |
277 | 277 | $endBr = $end; |
278 | 278 | $startBr = 0; |
279 | 279 | |
280 | - while ( $doneBr == 0 && $iter >= 0 ) { |
|
280 | + while ($doneBr == 0 && $iter >= 0) { |
|
281 | 281 | |
282 | - $char = $labelArr[ $iter ]; |
|
282 | + $char = $labelArr[$iter]; |
|
283 | 283 | |
284 | - if ( $char == ")" ) { |
|
284 | + if ($char == ")") { |
|
285 | 285 | $openBr = $openBr - 1; |
286 | 286 | |
287 | - if ( $num == 0 ) { |
|
287 | + if ($num == 0) { |
|
288 | 288 | $endBr = $iter; |
289 | 289 | $num = $num + 1; |
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - if ( $char == "(" ) { |
|
293 | + if ($char == "(") { |
|
294 | 294 | $openBr = $openBr + 1; |
295 | 295 | |
296 | - if ( $num > 0 && $openBr == 0 ) { |
|
296 | + if ($num > 0 && $openBr == 0) { |
|
297 | 297 | $startBr = $iter; |
298 | 298 | $doneBr = 1; |
299 | 299 | } |
@@ -303,12 +303,12 @@ discard block |
||
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | - $labelValue = implode( "", array_slice( $labelArr, $startBr+1, $endBr-$startBr-1 ) ); |
|
307 | - $labelKey = implode( "", array_slice( $labelArr, 0, $startBr-1 ) ); |
|
306 | + $labelValue = implode("", array_slice($labelArr, $startBr + 1, $endBr - $startBr - 1)); |
|
307 | + $labelKey = implode("", array_slice($labelArr, 0, $startBr - 1)); |
|
308 | 308 | |
309 | 309 | } |
310 | 310 | |
311 | - $labelArray[ $label ] = [ $labelKey, $labelValue ] ; |
|
311 | + $labelArray[$label] = [$labelKey, $labelValue]; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | } |