Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 155 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
PFTokensInput | |
0.00% |
0 / 155 |
|
0.00% |
0 / 12 |
1892 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultPropTypes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOtherPropTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultPropTypeLists | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherPropTypeListsHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOtherCargoTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypeLists | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherCargoTypeListsHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHTML | |
0.00% |
0 / 102 |
|
0.00% |
0 / 1 |
1056 | |||
getParameters | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
2 | |||
getHtmlText | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @ingroup PF |
5 | */ |
6 | |
7 | use MediaWiki\MediaWikiServices; |
8 | |
9 | /** |
10 | * @ingroup PFFormInput |
11 | */ |
12 | class PFTokensInput extends PFFormInput { |
13 | |
14 | public static function getName(): string { |
15 | return 'tokens'; |
16 | } |
17 | |
18 | public static function getDefaultPropTypes() { |
19 | return []; |
20 | } |
21 | |
22 | public static function getOtherPropTypesHandled() { |
23 | return [ '_txt', '_wpg' ]; |
24 | } |
25 | |
26 | public static function getDefaultPropTypeLists() { |
27 | return [ |
28 | '_wpg' => [ 'is_list' => true, 'size' => 100 ] |
29 | ]; |
30 | } |
31 | |
32 | public static function getOtherPropTypeListsHandled() { |
33 | return [ '_txt' ]; |
34 | } |
35 | |
36 | public static function getDefaultCargoTypes() { |
37 | return []; |
38 | } |
39 | |
40 | public static function getOtherCargoTypesHandled() { |
41 | return [ 'Page', 'String' ]; |
42 | } |
43 | |
44 | public static function getDefaultCargoTypeLists() { |
45 | return [ |
46 | 'Page' => [ 'is_list' => true, 'size' => 100 ] |
47 | ]; |
48 | } |
49 | |
50 | public static function getOtherCargoTypeListsHandled() { |
51 | return [ 'String' ]; |
52 | } |
53 | |
54 | public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, array $other_args ) { |
55 | global $wgPageFormsTabIndex, $wgPageFormsFieldNum, $wgPageFormsEDSettings; |
56 | |
57 | $other_args['is_list'] = true; |
58 | |
59 | if ( array_key_exists( 'values from external data', $other_args ) ) { |
60 | $autocompleteSettings = 'external data'; |
61 | $remoteDataType = null; |
62 | if ( array_key_exists( 'origName', $other_args ) ) { |
63 | $name = $other_args['origName']; |
64 | } else { |
65 | $name = $input_name; |
66 | } |
67 | $wgPageFormsEDSettings[$name] = []; |
68 | if ( $other_args['values from external data'] != null ) { |
69 | $wgPageFormsEDSettings[$name]['title'] = $other_args['values from external data']; |
70 | } |
71 | if ( array_key_exists( 'image', $other_args ) ) { |
72 | $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); |
73 | $image_param = $other_args['image']; |
74 | $wgPageFormsEDSettings[$name]['image'] = $image_param; |
75 | global $edgValues; |
76 | for ( $i = 0; $i < count( $edgValues[$image_param] ); $i++ ) { |
77 | $image = $edgValues[$image_param][$i]; |
78 | if ( strpos( $image, "http" ) !== 0 ) { |
79 | $file = $repoGroup->findFile( $image ); |
80 | if ( $file ) { |
81 | $url = $file->getFullUrl(); |
82 | $edgValues[$image_param][$i] = $url; |
83 | } else { |
84 | $edgValues[$image_param][$i] = ""; |
85 | } |
86 | } |
87 | } |
88 | } |
89 | if ( array_key_exists( 'description', $other_args ) ) { |
90 | $wgPageFormsEDSettings[$name]['description'] = $other_args['description']; |
91 | } |
92 | if ( array_key_exists( 'delimiter', $other_args ) ) { |
93 | $delimiter = $other_args['delimiter']; |
94 | } else { |
95 | $delimiter = ','; |
96 | } |
97 | } else { |
98 | list( $autocompleteSettings, $remoteDataType, $delimiter ) = PFValuesUtils::setAutocompleteValues( $other_args, true ); |
99 | } |
100 | |
101 | if ( is_array( $cur_value ) ) { |
102 | $cur_value = implode( $delimiter, $cur_value ); |
103 | } |
104 | |
105 | $className = 'pfTokens '; |
106 | $className .= ( $is_mandatory ) ? 'mandatoryField' : 'createboxInput'; |
107 | if ( array_key_exists( 'class', $other_args ) ) { |
108 | $className .= ' ' . $other_args['class']; |
109 | } |
110 | $input_id = 'input_' . $wgPageFormsFieldNum; |
111 | |
112 | if ( array_key_exists( 'size', $other_args ) ) { |
113 | $size = intval( $other_args['size'] ); |
114 | if ( $size == 0 ) { |
115 | $size = 100; |
116 | } |
117 | } else { |
118 | $size = 100; |
119 | } |
120 | |
121 | $inputAttrs = [ |
122 | 'id' => $input_id, |
123 | 'name' => $input_name . '[]', |
124 | 'class' => $className, |
125 | 'style' => 'width:' . $size * 6 . 'px', |
126 | 'multiple' => 'multiple', |
127 | 'value' => $cur_value, |
128 | 'size' => 1, |
129 | 'data-size' => $size * 6 . 'px', |
130 | 'tabindex' => $wgPageFormsTabIndex, |
131 | 'autocompletesettings' => $autocompleteSettings, |
132 | ]; |
133 | if ( array_key_exists( 'origName', $other_args ) ) { |
134 | $inputAttrs['origName'] = $other_args['origName']; |
135 | } |
136 | if ( array_key_exists( 'existing values only', $other_args ) ) { |
137 | $inputAttrs['existingvaluesonly'] = 'true'; |
138 | } |
139 | if ( $remoteDataType !== null ) { |
140 | $inputAttrs['autocompletedatatype'] = $remoteDataType; |
141 | } |
142 | if ( $is_disabled ) { |
143 | $inputAttrs['disabled'] = true; |
144 | } |
145 | if ( array_key_exists( 'maxlength', $other_args ) ) { |
146 | $inputAttrs['maxlength'] = $other_args['maxlength']; |
147 | } |
148 | if ( array_key_exists( 'placeholder', $other_args ) ) { |
149 | $inputAttrs['placeholder'] = $other_args['placeholder']; |
150 | } |
151 | if ( array_key_exists( 'max values', $other_args ) ) { |
152 | $inputAttrs['maxvalues'] = $other_args['max values']; |
153 | } |
154 | |
155 | // This code adds predefined tokens in the form of <options> |
156 | |
157 | $cur_values = PFValuesUtils::getValuesArray( $cur_value, $delimiter ); |
158 | $optionsText = ''; |
159 | |
160 | $possible_values = $other_args['possible_values']; |
161 | if ( $possible_values == null ) { |
162 | // If it's a Boolean property, display 'Yes' and 'No' |
163 | // as the values. |
164 | if ( array_key_exists( 'property_type', $other_args ) && $other_args['property_type'] == '_boo' ) { |
165 | $possible_values = [ |
166 | PFUtils::getWordForYesOrNo( true ), |
167 | PFUtils::getWordForYesOrNo( false ), |
168 | ]; |
169 | } else { |
170 | $possible_values = []; |
171 | } |
172 | } |
173 | |
174 | foreach ( $cur_values as $current_value ) { |
175 | if ( $current_value !== '' ) { |
176 | $optionAttrs = [ 'value' => $current_value, 'selected' => 'selected' ]; |
177 | $optionLabel = $current_value; |
178 | $optionsText .= Html::element( 'option', $optionAttrs, $optionLabel ); |
179 | } |
180 | } |
181 | |
182 | $text = "\n\t" . Html::rawElement( 'select', $inputAttrs, $optionsText ) . "\n"; |
183 | $text .= Html::hidden( $input_name . '[is_list]', 1 ); |
184 | |
185 | if ( array_key_exists( 'uploadable', $other_args ) && $other_args['uploadable'] == true ) { |
186 | if ( array_key_exists( 'default filename', $other_args ) ) { |
187 | $default_filename = $other_args['default filename']; |
188 | } else { |
189 | $default_filename = ''; |
190 | } |
191 | |
192 | $text .= PFTextInput::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args ); |
193 | } |
194 | |
195 | $spanID = 'span_' . $wgPageFormsFieldNum; |
196 | $spanClass = 'inputSpan'; |
197 | if ( $is_mandatory ) { |
198 | $spanClass .= ' mandatoryFieldSpan'; |
199 | } |
200 | |
201 | if ( array_key_exists( 'show on select', $other_args ) ) { |
202 | $spanClass .= ' pfShowIfSelected'; |
203 | PFFormUtils::setShowOnSelect( $other_args['show on select'], $spanID ); |
204 | } |
205 | |
206 | $spanAttrs = [ |
207 | 'id' => $spanID, |
208 | 'class' => $spanClass, |
209 | 'data-input-type' => 'tokens' |
210 | ]; |
211 | $text = "\n" . Html::rawElement( 'span', $spanAttrs, $text ); |
212 | |
213 | return $text; |
214 | } |
215 | |
216 | public static function getParameters() { |
217 | $params = parent::getParameters(); |
218 | $params[] = [ |
219 | 'name' => 'size', |
220 | 'type' => 'int', |
221 | 'description' => wfMessage( 'pf_forminputs_size' )->text() |
222 | ]; |
223 | $params[] = [ |
224 | 'name' => 'placeholder', |
225 | 'type' => 'string', |
226 | 'description' => wfMessage( 'pf_forminputs_placeholder' )->text() |
227 | ]; |
228 | $params[] = [ |
229 | 'name' => 'existing values only', |
230 | 'type' => 'boolean', |
231 | 'description' => wfMessage( 'pf_forminputs_existingvaluesonly' )->text() |
232 | ]; |
233 | $params[] = [ |
234 | 'name' => 'max values', |
235 | 'type' => 'int', |
236 | 'description' => wfMessage( 'pf_forminputs_maxvalues' )->text() |
237 | ]; |
238 | $params = array_merge( $params, PFTextWithAutocompleteInput::getAutocompletionParameters() ); |
239 | $params[] = [ |
240 | 'name' => 'uploadable', |
241 | 'type' => 'boolean', |
242 | 'description' => wfMessage( 'pf_forminputs_uploadable' )->text() |
243 | ]; |
244 | $params[] = [ |
245 | 'name' => 'default filename', |
246 | 'type' => 'string', |
247 | 'description' => wfMessage( 'pf_forminputs_defaultfilename' )->text() |
248 | ]; |
249 | |
250 | return $params; |
251 | } |
252 | |
253 | /** |
254 | * Returns the HTML code to be included in the output page for this input. |
255 | * @return string |
256 | */ |
257 | public function getHtmlText(): string { |
258 | return self::getHTML( |
259 | $this->mCurrentValue, |
260 | $this->mInputName, |
261 | $this->mIsMandatory, |
262 | $this->mIsDisabled, |
263 | $this->mOtherArgs |
264 | ); |
265 | } |
266 | } |