@@ -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 $wgPageFormsFieldNum, $wgUser; |
| 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,51 +112,51 @@ 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 | - if ( $classes ) { |
|
| 135 | - $cstr = implode( " ", $classes ); |
|
| 134 | + if ($classes) { |
|
| 135 | + $cstr = implode(" ", $classes); |
|
| 136 | 136 | $extraatt .= " class=\"$cstr\""; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $inname = $input_name; |
| 140 | - if ( $is_list ) { |
|
| 140 | + if ($is_list) { |
|
| 141 | 141 | $inname .= '[]'; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // TODO Use Html:: |
| 145 | 145 | |
| 146 | 146 | $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; |
| 147 | - $is_single_select = (!$is_list) ? 'select-sfs-single' : '' ; |
|
| 147 | + $is_single_select = (!$is_list) ? 'select-sfs-single' : ''; |
|
| 148 | 148 | $ret = "<span class=\"inputSpan select-sfs $is_single_select $spanextra\"><select name='$inname' id='input_$wgPageFormsFieldNum' $extraatt>"; |
| 149 | 149 | |
| 150 | 150 | $curvalues = null; |
| 151 | - if ( $cur_value ) { |
|
| 152 | - if ( $cur_value === 'current user' ) { |
|
| 151 | + if ($cur_value) { |
|
| 152 | + if ($cur_value === 'current user') { |
|
| 153 | 153 | $cur_value = $wgUser->getName(); |
| 154 | 154 | } |
| 155 | - if ( is_array( $cur_value ) ) { |
|
| 155 | + if (is_array($cur_value)) { |
|
| 156 | 156 | $curvalues = $cur_value; |
| 157 | 157 | } else { |
| 158 | 158 | // delimiter for $cur_value is always ',' - PF seems to ignore $wgPageFormsListSeparator |
| 159 | - $curvalues = array_map( "trim", explode( $selectField->getDelimiter(), $cur_value ) ); |
|
| 159 | + $curvalues = array_map("trim", explode($selectField->getDelimiter(), $cur_value)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | } else { |
@@ -165,38 +165,38 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | |
| 167 | 167 | $labelArray = []; |
| 168 | - if ( array_key_exists( "label", $other_args ) && $curvalues ) { |
|
| 168 | + if (array_key_exists("label", $other_args) && $curvalues) { |
|
| 169 | 169 | // $labelArray = $this->getLabels( $curvalues ); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // TODO handle empty value case. |
| 173 | 173 | $ret .= "<option></option>"; |
| 174 | 174 | |
| 175 | - if ( $selectField->hasStaticValues() ) { |
|
| 175 | + if ($selectField->hasStaticValues()) { |
|
| 176 | 176 | |
| 177 | 177 | $values = $selectField->getValues(); |
| 178 | 178 | |
| 179 | - if ( array_key_exists( "label", $other_args ) && $values ) { |
|
| 180 | - $labelArray = $this->getLabels( $values ); |
|
| 179 | + if (array_key_exists("label", $other_args) && $values) { |
|
| 180 | + $labelArray = $this->getLabels($values); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( is_array( $values ) ) { |
|
| 183 | + if (is_array($values)) { |
|
| 184 | 184 | |
| 185 | - foreach ( $values as $val ) { |
|
| 185 | + foreach ($values as $val) { |
|
| 186 | 186 | |
| 187 | 187 | $selected = ""; |
| 188 | 188 | |
| 189 | - if ( array_key_exists( $val, $labelArray ) ) { |
|
| 189 | + if (array_key_exists($val, $labelArray)) { |
|
| 190 | 190 | |
| 191 | - if ( in_array( $labelArray[ $val ][0], $curvalues ) ) { |
|
| 191 | + if (in_array($labelArray[$val][0], $curvalues)) { |
|
| 192 | 192 | $selected = " selected='selected'"; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - $ret.="<option".$selected." value='".$labelArray[ $val ][0]."'>".$labelArray[ $val ][1]."</option>"; |
|
| 195 | + $ret .= "<option".$selected." value='".$labelArray[$val][0]."'>".$labelArray[$val][1]."</option>"; |
|
| 196 | 196 | |
| 197 | 197 | } else { |
| 198 | 198 | |
| 199 | - if ( in_array( $val, $curvalues ) ) { |
|
| 199 | + if (in_array($val, $curvalues)) { |
|
| 200 | 200 | $selected = " selected='selected'"; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -206,22 +206,22 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | } else { |
| 208 | 208 | |
| 209 | - foreach ( $curvalues as $cur ) { |
|
| 209 | + foreach ($curvalues as $cur) { |
|
| 210 | 210 | $selected = ""; |
| 211 | 211 | |
| 212 | - if ( array_key_exists( $cur, $labelArray ) ) { |
|
| 212 | + if (array_key_exists($cur, $labelArray)) { |
|
| 213 | 213 | |
| 214 | - if ( in_array( $labelArray[ $cur ][0], $curvalues ) ) { |
|
| 214 | + if (in_array($labelArray[$cur][0], $curvalues)) { |
|
| 215 | 215 | $selected = " selected='selected'"; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $ret.="<option".$selected." value='".$labelArray[ $cur ][0]."'>".$labelArray[ $cur ][1]."</option>"; |
|
| 218 | + $ret .= "<option".$selected." value='".$labelArray[$cur][0]."'>".$labelArray[$cur][1]."</option>"; |
|
| 219 | 219 | |
| 220 | 220 | } else { |
| 221 | - if ( in_array( $cur, $curvalues ) ) { |
|
| 221 | + if (in_array($cur, $curvalues)) { |
|
| 222 | 222 | $selected = " selected='selected'"; |
| 223 | 223 | } |
| 224 | - $ret.="<option".$selected.">$cur</option>"; |
|
| 224 | + $ret .= "<option".$selected.">$cur</option>"; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | $ret .= "</select></span>"; |
| 231 | 231 | $ret .= "<span id=\"info_$wgPageFormsFieldNum\" class=\"errorMessage\"></span>"; |
| 232 | 232 | |
| 233 | - if ( $other_args["is_list"] ) { |
|
| 234 | - $hiddenname = $input_name . '[is_list]'; |
|
| 233 | + if ($other_args["is_list"]) { |
|
| 234 | + $hiddenname = $input_name.'[is_list]'; |
|
| 235 | 235 | $ret .= "<input type='hidden' name='$hiddenname' value='1' />"; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -239,49 +239,49 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
| 242 | - private function getLabels( $labels ) { |
|
| 242 | + private function getLabels($labels) { |
|
| 243 | 243 | |
| 244 | - $labelArray = [ ]; |
|
| 244 | + $labelArray = []; |
|
| 245 | 245 | |
| 246 | - if ( is_array( $labels ) ) { |
|
| 247 | - foreach ( $labels as $label ) { |
|
| 246 | + if (is_array($labels)) { |
|
| 247 | + foreach ($labels as $label) { |
|
| 248 | 248 | |
| 249 | 249 | $labelKey = $label; |
| 250 | 250 | $labelValue = $label; |
| 251 | 251 | |
| 252 | 252 | // Tricky thing if ( ) already in name |
| 253 | - if ( strpos( $label, ")" ) && strpos( $label, "(" ) ) { |
|
| 253 | + if (strpos($label, ")") && strpos($label, "(")) { |
|
| 254 | 254 | |
| 255 | 255 | // Check Break |
| 256 | 256 | $openBr = 0; |
| 257 | 257 | $doneBr = 0; |
| 258 | 258 | $num = 0; |
| 259 | 259 | |
| 260 | - $labelArr = str_split ( $label ); |
|
| 260 | + $labelArr = str_split($label); |
|
| 261 | 261 | |
| 262 | - $end = count( $labelArr ) - 1; |
|
| 262 | + $end = count($labelArr) - 1; |
|
| 263 | 263 | $iter = $end; |
| 264 | 264 | |
| 265 | 265 | $endBr = $end; |
| 266 | 266 | $startBr = 0; |
| 267 | 267 | |
| 268 | - while ( $doneBr == 0 && $iter >= 0 ) { |
|
| 268 | + while ($doneBr == 0 && $iter >= 0) { |
|
| 269 | 269 | |
| 270 | - $char = $labelArr[ $iter ]; |
|
| 270 | + $char = $labelArr[$iter]; |
|
| 271 | 271 | |
| 272 | - if ( $char == ")" ) { |
|
| 272 | + if ($char == ")") { |
|
| 273 | 273 | $openBr = $openBr - 1; |
| 274 | 274 | |
| 275 | - if ( $num == 0 ) { |
|
| 275 | + if ($num == 0) { |
|
| 276 | 276 | $endBr = $iter; |
| 277 | 277 | $num = $num + 1; |
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( $char == "(" ) { |
|
| 281 | + if ($char == "(") { |
|
| 282 | 282 | $openBr = $openBr + 1; |
| 283 | 283 | |
| 284 | - if ( $num > 0 && $openBr == 0 ) { |
|
| 284 | + if ($num > 0 && $openBr == 0) { |
|
| 285 | 285 | $startBr = $iter; |
| 286 | 286 | $doneBr = 1; |
| 287 | 287 | } |
@@ -291,12 +291,12 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $labelValue = implode( "", array_slice( $labelArr, $startBr+1, $endBr-$startBr-1 ) ); |
|
| 295 | - $labelKey = implode( "", array_slice( $labelArr, 0, $startBr-1 ) ); |
|
| 294 | + $labelValue = implode("", array_slice($labelArr, $startBr + 1, $endBr - $startBr - 1)); |
|
| 295 | + $labelKey = implode("", array_slice($labelArr, 0, $startBr - 1)); |
|
| 296 | 296 | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $labelArray[ $label ] = [ $labelKey, $labelValue ] ; |
|
| 299 | + $labelArray[$label] = [$labelKey, $labelValue]; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | } |