1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
<?php
/**
* File holding the SFTextInput class
*
* @file
* @ingroup SF
*/
/**
* The SFTextInput class.
*
* @ingroup SFFormInput
*/
class SFTextInput extends SFFormInput {
public static function getName() {
return 'text';
}
public static function getDefaultPropTypes() {
$defaultPropTypes = array(
'_num' => array( 'field_type' => 'number' ),
'_uri' => array( 'field_type' => 'URL' ),
'_ema' => array( 'field_type' => 'email' )
);
if ( defined( 'SMWDataItem::TYPE_STRING' ) ) {
// SMW < 1.9
$defaultPropTypes['_str'] = array( 'field_type' => 'string' );
} else {
$defaultPropTypes['_txt'] = array( 'field_type' => 'text' );
}
return $defaultPropTypes;
}
public static function getOtherPropTypesHandled() {
return array( '_wpg', '_geo' );
}
public static function getDefaultPropTypeLists() {
$defaultPropTypeLists = array(
'_num' => array( 'field_type' => 'number', 'is_list' => 'true', 'size' => '100' ),
'_uri' => array( 'field_type' => 'URL', 'is_list' => 'true' ),
'_ema' => array( 'field_type' => 'email', 'is_list' => 'true' )
);
if ( defined( 'SMWDataItem::TYPE_STRING' ) ) {
// SMW < 1.9
$defaultPropTypeLists['_str'] = array( 'field_type' => 'string', 'is_list' => 'true', 'size' => '100' );
} else {
$defaultPropTypeLists['_txt'] = array( 'field_type' => 'text', 'is_list' => 'true', 'size' => '100' );
}
return $defaultPropTypeLists;
}
public static function getOtherPropTypeListsHandled() {
return array( '_wpg' );
}
/**
* Gets the HTML for the preview image or null if there is none.
*
* @since 2.3.3
*
* @param string $imageName
*
* @return string|null
*/
protected static function getPreviewImage( $imageName ) {
$previewImage = null;
$imageTitle = Title::newFromText( $imageName, NS_FILE );
if ( !is_object( $imageTitle ) ) {
return $previewImage;
}
$api = new ApiMain( new FauxRequest( array(
'action' => 'query',
'format' => 'json',
'prop' => 'imageinfo',
'iiprop' => 'url',
'titles' => $imageTitle->getFullText(),
'iiurlwidth' => 200
), true ), true );
$api->execute();
$result = $api->getResultData();
$url = false;
if ( array_key_exists( 'query', $result ) && array_key_exists( 'pages', $result['query'] ) ) {
foreach ( $result['query']['pages'] as $page ) {
if ( array_key_exists( 'imageinfo', $page ) ) {
foreach ( $page['imageinfo'] as $imageInfo ) {
$url = $imageInfo['thumburl'];
break;
}
}
}
}
if ( $url !== false ) {
$previewImage = Html::element(
'img',
array( 'src' => $url )
);
}
return $previewImage;
}
public static function uploadableHTML( $input_id, $delimiter = null, $default_filename = null, $cur_value = '', $other_args = array() ) {
$upload_window_page = SpecialPageFactory::getPage( 'UploadWindow' );
$query_string = "sfInputID=$input_id";
if ( $delimiter != null ) {
$query_string .= "&sfDelimiter=$delimiter";
}
if ( $default_filename != null ) {
$query_string .= "&wpDestFile=$default_filename";
}
$upload_window_url = $upload_window_page->getTitle()->getFullURL( $query_string );
$upload_label = wfMessage( 'upload' )->text();
// We need to set the size by default.
$style = "width:650 height:500";
$cssClasses = array( 'sfFancyBox', 'sfUploadable' );
$showPreview = array_key_exists( 'image preview', $other_args );
if ( $showPreview ) {
$cssClasses[] = 'sfImagePreview';
}
$linkAttrs = array(
'href' => $upload_window_url,
'class' => implode( ' ', $cssClasses ),
// The 'title' parameter sets the label below the
// window; we're leaving it blank, because otherwise
// it can by mistaken by users for a button, leading
// to confusion.
//'title' => $upload_label,
'rev' => $style,
'data-input-id' => $input_id
);
$text = "\t" . Html::element( 'a', $linkAttrs, $upload_label ) . "\n";
if ( $showPreview ) {
$text .= Html::rawElement(
'div',
array( 'id' => $input_id . '_imagepreview', 'class' => 'sfImagePreviewWrapper' ),
self::getPreviewImage( $cur_value )
);
}
return $text;
}
public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
global $sfgTabIndex, $sfgFieldNum;
// For backward compatibility with pre-SF-2.1 forms
if ( array_key_exists( 'autocomplete field type', $other_args ) &&
! array_key_exists( 'no autocomplete', $other_args ) ) {
return SFTextWithAutocompleteInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
}
$className = 'createboxInput';
if ( $is_mandatory ) {
$className .= ' mandatoryField';
}
if ( array_key_exists( 'class', $other_args ) ) {
$className .= ' ' . $other_args['class'];
}
$input_id = "input_$sfgFieldNum";
// Set size based on pre-set size, or field type - if field
// type is set, possibly add validation too.
// (This special handling should only be done if the field
// holds a single value, not a list of values.)
$size = 35;
$inputType = '';
if ( array_key_exists( 'field_type', $other_args ) &&
( !array_key_exists( 'is_list', $other_args ) ||
!$other_args['is_list'] ) ) {
if ( $other_args['field_type'] == 'number' ) {
$size = 10;
$inputType = 'number';
} elseif ( $other_args['field_type'] == 'URL' ) {
$size = 100;
$inputType = 'URL';
} elseif ( $other_args['field_type'] == 'email' ) {
$size = 45;
$inputType = 'email';
}
}
if ( array_key_exists( 'size', $other_args ) ) {
$size = $other_args['size'];
}
$inputAttrs = array(
'id' => $input_id,
'tabindex' => $sfgTabIndex,
'class' => $className,
'size' => $size
);
if ( $is_disabled ) {
$inputAttrs['disabled'] = 'disabled';
}
if ( array_key_exists( 'maxlength', $other_args ) ) {
$inputAttrs['maxlength'] = $other_args['maxlength'];
}
if ( array_key_exists( 'placeholder', $other_args ) ) {
$inputAttrs['placeholder'] = $other_args['placeholder'];
}
$text = Html::input( $input_name, $cur_value, 'text', $inputAttrs );
if ( array_key_exists( 'uploadable', $other_args ) && $other_args['uploadable'] == true ) {
if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) {
if ( array_key_exists( 'delimiter', $other_args ) ) {
$delimiter = $other_args['delimiter'];
} else {
$delimiter = ',';
}
} else {
$delimiter = null;
}
if ( array_key_exists( 'default filename', $other_args ) ) {
$default_filename = $other_args['default filename'];
} else {
$default_filename = '';
}
$text .= self::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args );
}
$spanClass = 'inputSpan';
if ( $inputType !== '' ) {
$spanClass .= " {$inputType}Input";
}
if ( $is_mandatory ) {
$spanClass .= ' mandatoryFieldSpan';
}
$text = Html::rawElement( 'span', array( 'class' => $spanClass ), $text );
return $text;
}
public static function getParameters() {
$params = parent::getParameters();
$params[] = array(
'name' => 'size',
'type' => 'int',
'description' => wfMessage( 'sf_forminputs_size' )->text()
);
$params[] = array(
'name' => 'maxlength',
'type' => 'int',
'description' => wfMessage( 'sf_forminputs_maxlength' )->text()
);
$params[] = array(
'name' => 'placeholder',
'type' => 'string',
'description' => wfMessage( 'sf_forminputs_placeholder' )->text()
);
$params[] = array(
'name' => 'uploadable',
'type' => 'boolean',
'description' => wfMessage( 'sf_forminputs_uploadable' )->text()
);
$params[] = array(
'name' => 'default filename',
'type' => 'string',
'description' => wfMessage( 'sf_forminputs_defaultfilename' )->text()
);
return $params;
}
/**
* Returns the HTML code to be included in the output page for this input.
*/
public function getHtmlText() {
return self::getHTML(
$this->mCurrentValue,
$this->mInputName,
$this->mIsMandatory,
$this->mIsDisabled,
$this->mOtherArgs
);
}
}
|