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