r93112 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93111‎ | r93112 | r93113 >
Date:20:57, 25 July 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
split SF_FormInputs.php, introduce some new methods
Modified paths:
  • /trunk/extensions/SemanticForms/SemanticForms.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_AutoeditAPI.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (deleted) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormUtils.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_CategoriesInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_CategoryInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxesInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_DateInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_DateTimeInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_DropdownInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_EnumInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_ListBoxInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_MultiEnumInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_RadioButtonInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php (added) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_YearInput.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/SemanticForms.php
@@ -141,20 +141,6 @@
142142 $wgAutoloadClasses['SFTemplateInForm'] = $sfgIP . '/includes/SF_FormClasses.php';
143143 $wgAutoloadClasses['SFFormField'] = $sfgIP . '/includes/SF_FormField.php';
144144 $wgAutoloadClasses['SFFormPrinter'] = $sfgIP . '/includes/SF_FormPrinter.php';
145 -$wgAutoloadClasses['SFTextInput'] = $sfgIP . '/includes/SF_FormInputs.php';
146 -$wgAutoloadClasses['SFTextAreaInput'] = $sfgIP . '/includes/SF_FormInputs.php';
147 -$wgAutoloadClasses['SFTextWithAutocompleteInput'] = $sfgIP . '/includes/SF_FormInputs.php';
148 -$wgAutoloadClasses['SFTextAreaWithAutocompleteInput'] = $sfgIP . '/includes/SF_FormInputs.php';
149 -$wgAutoloadClasses['SFCheckboxInput'] = $sfgIP . '/includes/SF_FormInputs.php';
150 -$wgAutoloadClasses['SFDateInput'] = $sfgIP . '/includes/SF_FormInputs.php';
151 -$wgAutoloadClasses['SFDateTimeInput'] = $sfgIP . '/includes/SF_FormInputs.php';
152 -$wgAutoloadClasses['SFDropdownInput'] = $sfgIP . '/includes/SF_FormInputs.php';
153 -$wgAutoloadClasses['SFRadioButtonInput'] = $sfgIP . '/includes/SF_FormInputs.php';
154 -$wgAutoloadClasses['SFListBoxInput'] = $sfgIP . '/includes/SF_FormInputs.php';
155 -$wgAutoloadClasses['SFCheckboxesInput'] = $sfgIP . '/includes/SF_FormInputs.php';
156 -$wgAutoloadClasses['SFComboBoxInput'] = $sfgIP . '/includes/SF_FormInputs.php';
157 -$wgAutoloadClasses['SFCategoryInput'] = $sfgIP . '/includes/SF_FormInputs.php';
158 -$wgAutoloadClasses['SFCategoriesInput'] = $sfgIP . '/includes/SF_FormInputs.php';
159145 $wgAutoloadClasses['SFFormUtils'] = $sfgIP . '/includes/SF_FormUtils.php';
160146 $wgAutoloadClasses['SFFormEditTab'] = $sfgIP . '/includes/SF_FormEditTab.php';
161147 $wgAutoloadClasses['SFFormEditPage'] = $sfgIP . '/includes/SF_FormEditPage.php';
@@ -163,6 +149,27 @@
164150 $wgAutoloadClasses['SFParserFunctions'] = $sfgIP . '/includes/SF_ParserFunctions.php';
165151 $wgAutoloadClasses['SFAutocompleteAPI'] = $sfgIP . '/includes/SF_AutocompleteAPI.php';
166152 $wgAutoloadClasses['SFAutoeditAPI'] = $sfgIP . '/includes/SF_AutoeditAPI.php';
 153+
 154+// FormInputs
 155+$wgAutoloadClasses['SFFormInput'] = $sfgIP . '/includes/forminputs/SF_FormInput.php';
 156+$wgAutoloadClasses['SFTextInput'] = $sfgIP . '/includes/forminputs/SF_TextInput.php';
 157+$wgAutoloadClasses['SFTextWithAutocompleteInput'] = $sfgIP . '/includes/forminputs/SF_TextWithAutocompleteInput.php';
 158+$wgAutoloadClasses['SFTextAreaInput'] = $sfgIP . '/includes/forminputs/SF_TextAreaInput.php';
 159+$wgAutoloadClasses['SFTextAreaWithAutocompleteInput'] = $sfgIP . '/includes/forminputs/SF_TextAreaWithAutocompleteInput.php';
 160+$wgAutoloadClasses['SFEnumInput'] = $sfgIP . '/includes/forminputs/SF_EnumInput.php';
 161+$wgAutoloadClasses['SFMultiEnumInput'] = $sfgIP . '/includes/forminputs/SF_MultiEnumInput.php';
 162+$wgAutoloadClasses['SFCheckboxInput'] = $sfgIP . '/includes/forminputs/SF_CheckboxInput.php';
 163+$wgAutoloadClasses['SFCheckboxesInput'] = $sfgIP . '/includes/forminputs/SF_CheckboxesInput.php';
 164+$wgAutoloadClasses['SFRadioButtonInput'] = $sfgIP . '/includes/forminputs/SF_RadioButtonInput.php';
 165+$wgAutoloadClasses['SFDropdownInput'] = $sfgIP . '/includes/forminputs/SF_DropdownInput.php';
 166+$wgAutoloadClasses['SFListBoxInput'] = $sfgIP . '/includes/forminputs/SF_ListBoxInput.php';
 167+$wgAutoloadClasses['SFComboBoxInput'] = $sfgIP . '/includes/forminputs/SF_ComboBoxInput.php';
 168+$wgAutoloadClasses['SFDateInput'] = $sfgIP . '/includes/forminputs/SF_DateInput.php';
 169+$wgAutoloadClasses['SFDateTimeInput'] = $sfgIP . '/includes/forminputs/SF_DateTimeInput.php';
 170+$wgAutoloadClasses['SFYearInput'] = $sfgIP . '/includes/forminputs/SF_YearInput.php';
 171+$wgAutoloadClasses['SFCategoryInput'] = $sfgIP . '/includes/forminputs/SF_CategoryInput.php';
 172+$wgAutoloadClasses['SFCategoriesInput'] = $sfgIP . '/includes/forminputs/SF_CategoriesInput.php';
 173+
167174 $wgJobClasses['createPage'] = 'SFCreatePageJob';
168175 $wgAutoloadClasses['SFCreatePageJob'] = $sfgIP . '/includes/SF_CreatePageJob.php';
169176 require_once( $sfgIP . '/languages/SF_Language.php' );
@@ -319,5 +326,3 @@
320327 # ##
321328 $sfgShowOnSelect = array();
322329 $sfgAutocompleteValues = array();
323 -$sfgInitJSFunctions = array();
324 -$sfgValidationJSFunctions = array();
Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -1,1643 +0,0 @@
2 -<?php
3 -/**
4 - * Helper functions to display the various inputs of a user-generated form
5 - *
6 - * @author Yaron Koren
7 - * @author Jeffrey Stuckman
8 - * @author Matt Williamson
9 - * @author Patrick Nagel
10 - * @author Sanyam Goyal
11 - * @file
12 - * @ingroup SF
13 - */
14 -
15 -/**
16 - * Parent class for all form input classes.
17 - * @ingroup SFFormInput
18 - */
19 -class SFFormInput {
20 - /**
21 - * Returns the set of SMW property types for which this input is
22 - * meant to be the default one - ideally, no more than one input
23 - * should declare itself the default for any specific type.
24 - */
25 - public static function getDefaultPropTypes() {
26 - return array();
27 - }
28 -
29 - /**
30 - * Returns the set of SMW property types which this input can
31 - * handle, but for which it isn't the default input.
32 - */
33 - public static function getOtherPropTypesHandled() {
34 - return array();
35 - }
36 -
37 - /**
38 - * Like getDefaultPropTypes(), but for a field which holds a
39 - * list of values instead of just one.
40 - */
41 - public static function getDefaultPropTypeLists() {
42 - return array();
43 - }
44 -
45 - /**
46 - * Like getOtherPropTypesHandled(), but for a field which holds a
47 - * list of values instead of just one.
48 - */
49 - public static function getOtherPropTypeListsHandled() {
50 - return array();
51 - }
52 -
53 - /**
54 - * Returns the set of parameters for this form input.
55 - */
56 - public static function getParameters() {
57 - $params = array();
58 - $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) );
59 - $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) );
60 - $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) );
61 - $params[] = array( 'name' => 'property', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_property' ) );
62 - $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) );
63 - return $params;
64 - }
65 -
66 - /**
67 - * Returns the name and parameters for the initialization Javascript
68 - * function for this input type, if any.
69 - *
70 - * This function is not used yet.
71 - */
72 - public static function getInitJSFunction() {
73 - return null;
74 - }
75 -
76 - /**
77 - * Returns the name and parameters for the validation Javascript
78 - * functions for this input type, if any.
79 - *
80 - * This function is not used yet.
81 - */
82 - public static function getValidationJSFunctions() {
83 - return array();
84 - }
85 -}
86 -
87 -/**
88 - * The base class for every form input that holds a pre-set enumeration
89 - * of values.
90 - * @ingroup SFFormInput
91 - */
92 -class SFEnumInput extends SFFormInput {
93 - public static function getOtherPropTypesHandled() {
94 - return array( 'enumeration', '_boo' );
95 - }
96 -
97 - public static function getValuesParameters() {
98 - $params = array();
99 - $params[] = array( 'name' => 'values', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_values' ) );
100 - $params[] = array( 'name' => 'values from property', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromproperty' ) );
101 - $params[] = array( 'name' => 'values from category', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromcategory' ) );
102 - $params[] = array( 'name' => 'values from namespace', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromnamespace' ) );
103 - $params[] = array( 'name' => 'values from concept', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromconcept' ) );
104 - return $params;
105 - }
106 -
107 - public static function getParameters() {
108 - $params = parent::getParameters();
109 - $params = array_merge( $params, self::getValuesParameters() );
110 - $params[] = array( 'name' => 'show on select', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_showonselect' ) );
111 - return $params;
112 - }
113 -}
114 -
115 -/**
116 - * The base class for every form input that holds a list of elements, each
117 - * one from a pre-set enumeration of values.
118 - * @ingroup SFFormInput
119 - */
120 -class SFMultiEnumInput extends SFEnumInput {
121 - public static function getOtherPropTypesHandled() {
122 - return array();
123 - }
124 -
125 - public static function getOtherPropTypeListsHandled() {
126 - return array( 'enumeration' );
127 - }
128 -
129 - public static function getParameters() {
130 - $params = parent::getParameters();
131 - $params[] = array( 'name' => 'delimiter', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_delimiter' ) );
132 - return $params;
133 - }
134 -}
135 -
136 -/**
137 - * @ingroup SFFormInput
138 - */
139 -class SFTextInput extends SFFormInput {
140 - public static function getName() {
141 - return 'text';
142 - }
143 -
144 - public static function getDefaultPropTypes() {
145 - return array(
146 - '_str' => array( 'field_type' => 'string' ),
147 - '_num' => array( 'field_type' => 'number' ),
148 - '_uri' => array( 'field_type' => 'URL' ),
149 - '_ema' => array( 'field_type' => 'email' )
150 - );
151 - }
152 -
153 - public static function getOtherPropTypesHandled() {
154 - return array( '_wpg', '_geo' );
155 - }
156 -
157 - public static function getDefaultPropTypeLists() {
158 - return array(
159 - '_str' => array( 'field_type' => 'string', 'is_list' => 'true', 'size' => '100' ),
160 - '_num' => array( 'field_type' => 'number', 'is_list' => 'true', 'size' => '100' ),
161 - '_uri' => array( 'field_type' => 'URL', 'is_list' => 'true' ),
162 - '_ema' => array( 'field_type' => 'email', 'is_list' => 'true' )
163 - );
164 - }
165 -
166 - public static function getOtherPropTypeListsHandled() {
167 - return array( '_wpg' );
168 - }
169 -
170 - public static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) {
171 - $upload_window_page = SpecialPage::getPage( 'UploadWindow' );
172 - $query_string = "sfInputID=$input_id";
173 - if ( $delimiter != null )
174 - $query_string .= "&sfDelimiter=$delimiter";
175 - if ( $default_filename != null )
176 - $query_string .= "&wpDestFile=$default_filename";
177 - $upload_window_url = $upload_window_page->getTitle()->getFullURL( $query_string );
178 - $upload_label = wfMsg( 'upload' );
179 - // window needs to be bigger for MediaWiki version 1.16+
180 - if ( class_exists( 'HTMLForm' ) )
181 - $style = "width:650 height:500";
182 - else
183 - $style = '';
184 -
185 - $linkAttrs = array(
186 - 'href' => $upload_window_url,
187 - 'class' => 'sfFancyBox',
188 - 'title' => $upload_label,
189 - 'rev' => $style
190 - );
191 - $text = "\t" . Xml::element( 'a', $linkAttrs, $upload_label ) . "\n";
192 - return $text;
193 - }
194 -
195 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
196 - global $sfgTabIndex, $sfgFieldNum;
197 -
198 - // For backward compatibility with pre-SF-2.1 forms
199 - if ( array_key_exists( 'autocomplete field type', $other_args ) &&
200 - ! array_key_exists( 'no autocomplete', $other_args ) ) {
201 - return SFTextWithAutocompleteInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
202 - }
203 -
204 - $className = "createboxInput";
205 - if ( $is_mandatory ) {
206 - $className .= " mandatoryField";
207 - }
208 - if ( array_key_exists( 'class', $other_args ) ) {
209 - $className .= " " . $other_args['class'];
210 - }
211 - $input_id = "input_$sfgFieldNum";
212 - // Set size based on pre-set size, or field type - if field
213 - // type is set, possibly add validation too.
214 - $size = 35;
215 - $inputType = '';
216 - if ( array_key_exists( 'field_type', $other_args ) ) {
217 - if ( $other_args['field_type'] == 'number' ) {
218 - $size = 10;
219 - $inputType = 'number';
220 - } elseif ( $other_args['field_type'] == 'URL' ) {
221 - $size = 100;
222 - $inputType = 'URL';
223 - } elseif ( $other_args['field_type'] == 'email' ) {
224 - $size = 45;
225 - $inputType = 'email';
226 - }
227 - }
228 - if ( array_key_exists( 'size', $other_args ) ) {
229 - $size = $other_args['size'];
230 - }
231 -
232 - $inputAttrs = array(
233 - 'type' => 'text',
234 - 'id' => $input_id,
235 - 'tabindex' => $sfgTabIndex,
236 - 'class' => $className,
237 - 'name' => $input_name,
238 - 'value' => $cur_value,
239 - 'size' => $size
240 - );
241 - if ( $is_disabled ) {
242 - $inputAttrs['disabled'] = 'disabled';
243 - }
244 - if ( array_key_exists( 'maxlength', $other_args ) ) {
245 - $inputAttrs['maxlength'] = $other_args['maxlength'];
246 - }
247 - $text = Xml::element( 'input', $inputAttrs );
248 -
249 - if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
250 - if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) {
251 - if ( array_key_exists( 'delimiter', $other_args ) ) {
252 - $delimiter = $other_args['delimiter'];
253 - } else {
254 - $delimiter = ",";
255 - }
256 - } else {
257 - $delimiter = null;
258 - }
259 - if ( array_key_exists( 'default filename', $other_args ) ) {
260 - $default_filename = $other_args['default filename'];
261 - } else {
262 - $default_filename = "";
263 - }
264 - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
265 - }
266 - $spanClass = "inputSpan";
267 - if ( $inputType != '' ) {
268 - $spanClass .= " {$inputType}Input";
269 - }
270 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
271 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
272 - return $text;
273 - }
274 -
275 - public static function getParameters() {
276 - $params = parent::getParameters();
277 - $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
278 - $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
279 - $params[] = array( 'name' => 'uploadable', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_uploadable' ) );
280 - $params[] = array( 'name' => 'default filename', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_defaultfilename' ) );
281 - return $params;
282 - }
283 -}
284 -
285 -/**
286 - * @ingroup SFFormInput
287 - */
288 -class SFTextAreaInput extends SFFormInput {
289 - public static function getName() {
290 - return 'textarea';
291 - }
292 -
293 - public static function getDefaultPropTypes() {
294 - return array( '_txt' => array(), '_cod' => array() );
295 - }
296 -
297 - public static function getOtherPropTypesHandled() {
298 - return array( '_wpg', '_str' );
299 - }
300 -
301 - public static function getOtherPropTypeListsHandled() {
302 - return array( '_wpg', '_str' );
303 - }
304 -
305 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
306 - global $sfgTabIndex, $sfgFieldNum;
307 -
308 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
309 - if ( array_key_exists( 'class', $other_args ) ) {
310 - $className .= " " . $other_args['class'];
311 - }
312 - // Use a special ID for the free text field, for FCK's needs.
313 - $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
314 -
315 - if ( array_key_exists( 'rows', $other_args ) ) {
316 - $rows = $other_args['rows'];
317 - } else {
318 - $rows = 5;
319 - }
320 -
321 - if ( array_key_exists( 'autogrow', $other_args ) ) {
322 - $className .= ' autoGrow';
323 - }
324 -
325 - $textarea_attrs = array(
326 - 'tabindex' => $sfgTabIndex,
327 - 'id' => $input_id,
328 - 'name' => $input_name,
329 - 'rows' => $rows,
330 - 'class' => $className,
331 - );
332 -
333 - if ( array_key_exists( 'cols', $other_args ) ) {
334 - $textarea_attrs['cols'] = $other_args['cols'];
335 - } else {
336 - $textarea_attrs['style'] = "width: 100%";
337 - }
338 -
339 - if ( $is_disabled ) {
340 - $textarea_attrs['disabled'] = 'disabled';
341 - }
342 - if ( array_key_exists( 'maxlength', $other_args ) ) {
343 - $maxlength = $other_args['maxlength'];
344 - // For every actual character pressed (i.e., excluding
345 - // things like the Shift key), reduce the string to its
346 - // allowed length if it's exceeded that.
347 - // This JS code is complicated so that it'll work
348 - // correctly in IE - IE moves the cursor to the end
349 - // whenever this.value is reset, so we'll make sure to
350 - // do that only when we need to.
351 - $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
352 - $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
353 - $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
354 - }
355 - // Bug in Xml::element()? It doesn't close the textarea tag
356 - // properly if the text inside is null - set it to '' instead.
357 - if ( is_null( $cur_value ) ) {
358 - $cur_value = '';
359 - }
360 - $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
361 - $spanClass = "inputSpan";
362 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
363 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
364 - return $text;
365 - }
366 -
367 - public static function getParameters() {
368 - $params = parent::getParameters();
369 - $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
370 - $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
371 - $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
372 - $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
373 - $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
374 - return $params;
375 - }
376 -}
377 -
378 -/**
379 - * @ingroup SFFormInput
380 - */
381 -class SFCheckboxInput extends SFFormInput {
382 - public static function getName() {
383 - return 'checkbox';
384 - }
385 -
386 - public static function getDefaultPropTypes() {
387 - return array( '_boo' => array() );
388 - }
389 -
390 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
391 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
392 -
393 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
394 - if ( array_key_exists( 'class', $other_args ) )
395 - $className .= " " . $other_args['class'];
396 - $input_id = "input_$sfgFieldNum";
397 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
398 - if ( array_key_exists( 'show on select', $other_args ) ) {
399 - $className .= " sfShowIfCheckedCheckbox";
400 - $div_id = key( $other_args['show on select'] );
401 - $sfgShowOnSelect[$input_id] = $div_id;
402 - }
403 -
404 - // Can show up here either as an array or a string, depending on
405 - // whether it came from user input or a wiki page
406 - if ( is_array( $cur_value ) ) {
407 - $checked_str = ( array_key_exists( 'value', $cur_value ) && $cur_value['value'] == 'on' ) ? ' checked="checked"' : "";
408 - } else {
409 - // Default to false - no need to check if it matches
410 - // a 'false' word.
411 - $vlc = strtolower( trim( $cur_value ) );
412 - // Manually load SMW's message values, if they weren't
413 - // loaded before.
414 - global $wgVersion;
415 - if ( version_compare( $wgVersion, '1.16', '<' ) ) {
416 - wfLoadExtensionMessages( 'SemanticMediaWiki' );
417 - }
418 - if ( in_array( $vlc, explode( ',', wfMsgForContent( 'smw_true_words' ) ), TRUE ) ) {
419 - $checked_str = ' checked="checked"';
420 - } else {
421 - $checked_str = "";
422 - }
423 - }
424 - $text = <<<END
425 - <input name="{$input_name}[is_checkbox]" type="hidden" value="true" />
426 - <input id="$input_id" name="{$input_name}[value]" type="checkbox" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
427 -
428 -END;
429 - return $text;
430 - }
431 -
432 - public static function getParameters() {
433 - // Remove the 'mandatory' option - it doesn't make sense for
434 - // checkboxes.
435 - $params = array();
436 - foreach( parent::getParameters() as $param ) {
437 - if ( $param['name'] != 'mandatory' ) {
438 - $params[] = $param;
439 - }
440 - }
441 - return $params;
442 - }
443 -}
444 -
445 -/**
446 - * @ingroup SFFormInput
447 - */
448 -class SFDropdownInput extends SFEnumInput {
449 - public static function getName() {
450 - return 'dropdown';
451 - }
452 -
453 - public static function getDefaultPropTypes() {
454 - return array(
455 - 'enumeration' => array()
456 - );
457 - }
458 -
459 - public static function getOtherPropTypesHandled() {
460 - return array( '_boo' );
461 - }
462 -
463 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
464 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
465 -
466 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
467 - if ( array_key_exists( 'class', $other_args ) ) {
468 - $className .= " " . $other_args['class'];
469 - }
470 - $input_id = "input_$sfgFieldNum";
471 - if ( array_key_exists( 'show on select', $other_args ) ) {
472 - $className .= " sfShowIfSelected";
473 - foreach ( $other_args['show on select'] as $div_id => $options ) {
474 - if ( array_key_exists( $input_id, $sfgShowOnSelect ) ) {
475 - $sfgShowOnSelect[$input_id][] = array( $options, $div_id );
476 - } else {
477 - $sfgShowOnSelect[$input_id] = array( array( $options, $div_id ) );
478 - }
479 - }
480 - }
481 - $innerDropdown = "";
482 - // Add a blank value at the beginning, unless this is a
483 - // mandatory field and there's a current value in place
484 - // (either through a default value or because we're editing
485 - // an existing page).
486 - if ( ! $is_mandatory || $cur_value == '' ) {
487 - $innerDropdown .= " <option value=\"\"></option>\n";
488 - }
489 - if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
490 - // If it's a Boolean property, display 'Yes' and 'No'
491 - // as the values.
492 - if ( array_key_exists( 'property_type', $other_args ) && $other_args['property_type'] == '_boo' ) {
493 - $possible_values = array(
494 - SFUtils::getWordForYesOrNo( true ),
495 - SFUtils::getWordForYesOrNo( false ),
496 - );
497 - } else {
498 - $possible_values = array();
499 - }
500 - }
501 - foreach ( $possible_values as $possible_value ) {
502 - $optionAttrs = array( 'value' => $possible_value );
503 - if ( $possible_value == $cur_value ) {
504 - $optionAttrs['selected'] = "selected";
505 - }
506 - if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) {
507 - $label = $other_args['value_labels'][$possible_value];
508 - } else {
509 - $label = $possible_value;
510 - }
511 - $innerDropdown .= Xml::element( 'option', $optionAttrs, $label );
512 - }
513 - $selectAttrs = array(
514 - 'id' => $input_id,
515 - 'tabindex' => $sfgTabIndex,
516 - 'name' => $input_name,
517 - 'class' => $className
518 - );
519 - if ( $is_disabled ) {
520 - $selectAttrs['disabled'] = 'disabled';
521 - }
522 - $text = Xml::tags( 'select', $selectAttrs, $innerDropdown );
523 - $spanClass = "inputSpan";
524 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
525 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
526 - return $text;
527 - }
528 -}
529 -
530 -/**
531 - * @ingroup SFFormInput
532 - */
533 -class SFRadioButtonInput extends SFEnumInput {
534 - public static function getName() {
535 - return 'radiobutton';
536 - }
537 -
538 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
539 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
540 -
541 - if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
542 - // If it's a Boolean property, display 'Yes' and 'No'
543 - // as the values.
544 - if ( $other_args['property_type'] == '_boo' ) {
545 - $possible_values = array(
546 - SFUtils::getWordForYesOrNo( true ),
547 - SFUtils::getWordForYesOrNo( false ),
548 - );
549 - } else {
550 - $possible_values = array();
551 - }
552 - }
553 -
554 - // Add a "None" value at the beginning, unless this is a
555 - // mandatory field and there's a current value in place (either
556 - // through a default value or because we're editing an existing
557 - // page).
558 - if ( ! $is_mandatory || $cur_value == '' ) {
559 - array_unshift( $possible_values, '' );
560 - }
561 -
562 - // Set $cur_value to be one of the allowed options, if it isn't
563 - // already - that makes it easier to automatically have one of
564 - // the radiobuttons be checked at the beginning.
565 - if ( ! in_array( $cur_value, $possible_values ) ) {
566 - if ( in_array( '', $possible_values ) )
567 - $cur_value = '';
568 - else
569 - $cur_value = $possible_values[0];
570 - }
571 -
572 - $text = '';
573 - foreach ( $possible_values as $i => $possible_value ) {
574 - $sfgTabIndex++;
575 - $sfgFieldNum++;
576 - $input_id = "input_$sfgFieldNum";
577 -
578 - $radiobutton_attrs = array(
579 - 'type' => 'radio',
580 - 'id' => $input_id,
581 - 'tabindex' => $sfgTabIndex,
582 - 'name' => $input_name,
583 - 'value' => $possible_value,
584 - );
585 - if ( $cur_value == $possible_value ) {
586 - $radiobutton_attrs['checked'] = 'checked';
587 - }
588 - if ( $is_disabled ) {
589 - $radiobutton_attrs['disabled'] = 'disabled';
590 - }
591 - if ( $possible_value == '' ) // blank/"None" value
592 - $label = wfMsg( 'sf_formedit_none' );
593 - elseif ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
594 - $label = htmlspecialchars( $other_args['value_labels'][$possible_value] );
595 - else
596 - $label = $possible_value;
597 -
598 - $text .= "\t" . Xml::element ( 'input', $radiobutton_attrs ) . " $label\n";
599 - }
600 -
601 - $spanClass = "radioButtonSpan";
602 - if ( array_key_exists( 'class', $other_args ) ) {
603 - $spanClass .= " " . $other_args['class'];
604 - }
605 - if ( $is_mandatory ) {
606 - $spanClass .= " mandatoryFieldSpan";
607 - }
608 -
609 - $spanID = "span_$sfgFieldNum";
610 -
611 - // Do the 'show on select' handling.
612 - if ( array_key_exists( 'show on select', $other_args ) ) {
613 - $spanClass .= " sfShowIfChecked";
614 - foreach ( $other_args['show on select'] as $div_id => $options ) {
615 - if ( array_key_exists( $spanID, $sfgShowOnSelect ) ) {
616 - $sfgShowOnSelect[$spanID][] = array( $options, $div_id );
617 - } else {
618 - $sfgShowOnSelect[$spanID] = array( array( $options, $div_id ) );
619 - }
620 - }
621 - }
622 - $spanAttrs = array(
623 - 'id' => $spanID,
624 - 'class' => $spanClass
625 - );
626 - $text = Xml::tags( 'span', $spanAttrs, $text );
627 -
628 - return $text;
629 - }
630 -}
631 -
632 -/**
633 - * @ingroup SFFormInput
634 - */
635 -class SFListBoxInput extends SFMultiEnumInput {
636 - public static function getName() {
637 - return 'listbox';
638 - }
639 -
640 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
641 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
642 -
643 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
644 - if ( array_key_exists( 'class', $other_args ) ) {
645 - $className .= " " . $other_args['class'];
646 - }
647 - $input_id = "input_$sfgFieldNum";
648 - // get list delimiter - default is comma
649 - if ( array_key_exists( 'delimiter', $other_args ) ) {
650 - $delimiter = $other_args['delimiter'];
651 - } else {
652 - $delimiter = ",";
653 - }
654 - $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
655 - $className .= " sfShowIfSelected";
656 -
657 - if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
658 - $possible_values = array();
659 - }
660 - $optionsText = "";
661 - foreach ( $possible_values as $possible_value ) {
662 - if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) {
663 - $optionLabel = $other_args['value_labels'][$possible_value];
664 - } else {
665 - $optionLabel = $possible_value;
666 - }
667 - $optionAttrs = array( 'value' => $possible_value );
668 - if ( in_array( $possible_value, $cur_values ) ) {
669 - $optionAttrs['selected'] = 'selected';
670 - }
671 - $optionsText .= Xml::element( 'option', $optionAttrs, $optionLabel );
672 - }
673 - $selectAttrs = array(
674 - 'id' => $input_id,
675 - 'tabindex' => $sfgTabIndex,
676 - 'name' => $input_name . '[]',
677 - 'class' => $className,
678 - 'multiple' => 'multiple'
679 - );
680 - if ( array_key_exists( 'size', $other_args ) ) {
681 - $selectAttrs['size'] = $other_args['size'];
682 - }
683 - if ( $is_disabled ) {
684 - $selectAttrs['disabled'] = 'disabled';
685 - }
686 - $text = Xml::tags( 'select', $selectAttrs, $optionsText );
687 - $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
688 - if ( $is_mandatory ) {
689 - $text = Xml::tags( 'span', array( 'class' => 'inputSpan mandatoryFieldSpan' ), $text );
690 - }
691 -
692 - if ( array_key_exists( 'show on select', $other_args ) ) {
693 - foreach ( $other_args['show on select'] as $div_id => $options ) {
694 - if ( array_key_exists( $input_id, $sfgShowOnSelect ) ) {
695 - $sfgShowOnSelect[$input_id][] = array( $options, $div_id );
696 - } else {
697 - $sfgShowOnSelect[$input_id] = array( array( $options, $div_id ) );
698 - }
699 - }
700 - }
701 -
702 - return $text;
703 - }
704 -
705 - public static function getParameters() {
706 - $params = parent::getParameters();
707 - $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_listboxsize' ) );
708 - return $params;
709 - }
710 -}
711 -
712 -/**
713 - * @ingroup SFFormInput
714 - */
715 -class SFCheckboxesInput extends SFMultiEnumInput {
716 - public static function getName() {
717 - return 'checkboxes';
718 - }
719 -
720 - public static function getDefaultPropTypeLists() {
721 - return array(
722 - 'enumeration' => array()
723 - );
724 - }
725 -
726 - public static function getOtherPropTypeListsHandled() {
727 - return array();
728 - }
729 -
730 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
731 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
732 -
733 - $checkbox_class = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
734 - $span_class = "checkboxSpan";
735 - if ( array_key_exists( 'class', $other_args ) )
736 - $span_class .= " " . $other_args['class'];
737 - $input_id = "input_$sfgFieldNum";
738 - // get list delimiter - default is comma
739 - if ( array_key_exists( 'delimiter', $other_args ) ) {
740 - $delimiter = $other_args['delimiter'];
741 - } else {
742 - $delimiter = ",";
743 - }
744 - $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
745 -
746 - if ( ( $possible_values = $other_args['possible_values'] ) == null )
747 - $possible_values = array();
748 - $text = "";
749 - foreach ( $possible_values as $key => $possible_value ) {
750 - $cur_input_name = $input_name . "[" . $key . "]";
751 -
752 - if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
753 - $label = $other_args['value_labels'][$possible_value];
754 - else
755 - $label = $possible_value;
756 -
757 - $checkbox_attrs = array(
758 - 'type' => 'checkbox',
759 - 'id' => $input_id,
760 - 'tabindex' => $sfgTabIndex,
761 - 'name' => $cur_input_name,
762 - 'value' => $possible_value,
763 - 'class' => $checkbox_class,
764 - );
765 - if ( in_array( $possible_value, $cur_values ) ) {
766 - $checkbox_attrs['checked'] = 'checked';
767 - }
768 - if ( $is_disabled ) {
769 - $checkbox_attrs['disabled'] = 'disabled';
770 - }
771 - $checkbox_input = Xml::element( 'input', $checkbox_attrs );
772 -
773 - // Make a span around each checkbox, for CSS purposes.
774 - $text .= ' ' . Xml::tags( 'span',
775 - array( 'class' => $span_class ),
776 - $checkbox_input . ' ' . $label
777 - ) . "\n";
778 - $sfgTabIndex++;
779 - $sfgFieldNum++;
780 - }
781 -
782 - $outerSpanID = "span_$sfgFieldNum";
783 - $outerSpanClass = "checkboxesSpan";
784 - if ( $is_mandatory ) {
785 - $outerSpanClass .= " mandatoryFieldSpan";
786 - }
787 -
788 - if ( array_key_exists( 'show on select', $other_args ) ) {
789 - $outerSpanClass .= " sfShowIfChecked";
790 - foreach ( $other_args['show on select'] as $div_id => $options ) {
791 - if ( array_key_exists( $outerSpanID, $sfgShowOnSelect ) ) {
792 - $sfgShowOnSelect[$outerSpanID][] = array( $options, $div_id );
793 - } else {
794 - $sfgShowOnSelect[$outerSpanID] = array( array( $options, $div_id ) );
795 - }
796 - }
797 - }
798 -
799 - $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
800 - $outerSpanAttrs = array( 'id' => $outerSpanID, 'class' => $outerSpanClass );
801 - $text = "\t" . Xml::tags( 'span', $outerSpanAttrs, $text ) . "\n";
802 -
803 - return $text;
804 - }
805 -}
806 -
807 -/**
808 - * @ingroup SFFormInput
809 - */
810 -class SFTextWithAutocompleteInput extends SFTextInput {
811 - public static function getName() {
812 - return 'text with autocomplete';
813 - }
814 -
815 - public static function getDefaultPropTypes() {
816 - return array(
817 - '_wpg' => array()
818 - );
819 - }
820 -
821 - public static function getOtherPropTypesHandled() {
822 - return array( '_str' );
823 - }
824 -
825 - public static function getDefaultPropTypeLists() {
826 - return array(
827 - '_wpg' => array( 'is_list' => true, 'size' => 100 )
828 - );
829 - }
830 -
831 - public static function getOtherPropTypeListsHandled() {
832 - return array( '_str' );
833 - }
834 -
835 - public static function getAutocompletionTypeAndSource( &$field_args ) {
836 - if ( array_key_exists( 'values from property', $field_args ) ) {
837 - $autocompletionSource = $field_args['values from property'];
838 - $propValue = SMWPropertyValue::makeUserProperty( $autocompletionSource );
839 - if ( $propValue->getPropertyTypeID() == '_wpg' ) {
840 - $autocompleteFieldType = 'relation';
841 - } else {
842 - $autocompleteFieldType = 'attribute';
843 - }
844 - } elseif ( array_key_exists( 'values from category', $field_args ) ) {
845 - $autocompleteFieldType = 'category';
846 - $autocompletionSource = $field_args['values from category'];
847 - } elseif ( array_key_exists( 'values from concept', $field_args ) ) {
848 - $autocompleteFieldType = 'concept';
849 - $autocompletionSource = $field_args['values from concept'];
850 - } elseif ( array_key_exists( 'values from namespace', $field_args ) ) {
851 - $autocompleteFieldType = 'namespace';
852 - $autocompletionSource = $field_args['values from namespace'];
853 - } elseif ( array_key_exists( 'values from url', $field_args ) ) {
854 - $autocompleteFieldType = 'external_url';
855 - $autocompletionSource = $field_args['values from url'];
856 - // Autocompletion from URL is always done remotely.
857 - $field_args['remote autocompletion'] = true;
858 - } elseif ( array_key_exists( 'values', $field_args ) ) {
859 - global $sfgFieldNum;
860 - $autocompleteFieldType = 'values';
861 - $autocompletionSource = "values-$sfgFieldNum";
862 - } elseif ( array_key_exists( 'autocomplete field type', $field_args ) ) {
863 - $autocompleteFieldType = $field_args['autocomplete field type'];
864 - $autocompletionSource = $field_args['autocompletion source'];
865 - } elseif ( array_key_exists( 'semantic_property', $field_args ) ) {
866 - $autocompletionSource = $field_args['semantic_property'];
867 - $propValue = SMWPropertyValue::makeUserProperty( $autocompletionSource );
868 - if ( $propValue->getPropertyTypeID() == '_wpg' ) {
869 - $autocompleteFieldType = 'relation';
870 - } else {
871 - $autocompleteFieldType = 'attribute';
872 - }
873 - } else {
874 - $autocompleteFieldType = null;
875 - $autocompletionSource = null;
876 - }
877 -
878 - if ( $autocompleteFieldType != 'external_url' ) {
879 - global $wgContLang;
880 - $autocompletionSource = $wgContLang->ucfirst( $autocompletionSource );
881 - }
882 -
883 - return array( $autocompleteFieldType, $autocompletionSource );
884 - }
885 -
886 - public static function setAutocompleteValues( $field_args ) {
887 - global $sfgAutocompleteValues;
888 -
889 - // Get all autocomplete-related values, plus delimiter value
890 - // (it's needed also for the 'uploadable' link, if there is one).
891 - list( $autocompleteFieldType, $autocompletionSource ) =
892 - self::getAutocompletionTypeAndSource( $field_args );
893 - $autocompleteSettings = $autocompletionSource;
894 - $is_list = ( array_key_exists( 'is_list', $field_args ) && $field_args['is_list'] == true );
895 - if ( $is_list ) {
896 - $autocompleteSettings .= ",list";
897 - if ( array_key_exists( 'delimiter', $field_args ) ) {
898 - $delimiter = $field_args['delimiter'];
899 - $autocompleteSettings .= "," . $delimiter;
900 - } else {
901 - $delimiter = ",";
902 - }
903 - } else {
904 - $delimiter = null;
905 - }
906 -
907 - $remoteDataType = null;
908 - if ( array_key_exists( 'remote autocompletion', $field_args ) &&
909 - $field_args['remote autocompletion'] == true ) {
910 - $remoteDataType = $autocompleteFieldType;
911 - } elseif ( $autocompletionSource != '' ) {
912 - // @TODO - that count() check shouldn't be necessary
913 - if ( array_key_exists( 'possible_values', $field_args ) &&
914 - count( $field_args['possible_values'] ) > 0 ) {
915 - $autocompleteValues = $field_args['possible_values'];
916 - } elseif ( $autocompleteFieldType == 'values' ) {
917 - $autocompleteValues = explode( ',', $field_args['values'] );
918 - } else {
919 - $autocompleteValues = SFUtils::getAutocompleteValues( $autocompletionSource, $autocompleteFieldType );
920 - }
921 - $sfgAutocompleteValues[$autocompleteSettings] = $autocompleteValues;
922 - }
923 - return array( $autocompleteSettings, $remoteDataType, $delimiter );
924 - }
925 -
926 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
927 - // Backwards compatibility, for pre-SF-2.1 forms:
928 - // if 'no autocomplete' was specified, switch to SFTextInput.
929 - if ( array_key_exists( 'no autocomplete', $other_args ) &&
930 - $other_args['no autocomplete'] == true ) {
931 - unset( $other_args['autocompletion source'] );
932 - return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
933 - }
934 -
935 - global $sfgTabIndex, $sfgFieldNum;
936 -
937 - list( $autocompleteSettings, $remoteDataType, $delimiter ) = self::setAutocompleteValues( $other_args );
938 -
939 - $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
940 - if ( array_key_exists( 'class', $other_args ) )
941 - $className .= " " . $other_args['class'];
942 - $input_id = "input_" . $sfgFieldNum;
943 -
944 - if ( array_key_exists( 'size', $other_args ) ) {
945 - $size = $other_args['size'];
946 - } elseif ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] ) {
947 - $size = "100";
948 - } else {
949 - $size = "35";
950 - }
951 -
952 - $inputAttrs = array(
953 - 'type' => 'text',
954 - 'id' => $input_id,
955 - 'name' => $input_name,
956 - 'value' => $cur_value,
957 - 'size' => $size,
958 - 'class' => $className,
959 - 'tabindex' => $sfgTabIndex,
960 - 'autocompletesettings' => $autocompleteSettings,
961 - );
962 - if ( !is_null( $remoteDataType ) ) {
963 - $inputAttrs['autocompletedatatype'] = $remoteDataType;
964 - }
965 - if ( $is_disabled ) {
966 - $inputAttrs['disabled'] = 'disabled';
967 - }
968 - if ( array_key_exists( 'maxlength', $other_args ) ) {
969 - $inputAttrs['maxlength'] = $other_args['maxlength'];
970 - }
971 - $text = "\n\t" . Xml::element( 'input', $inputAttrs ) . "\n";
972 -
973 - if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
974 - if ( array_key_exists( 'default filename', $other_args ) ) {
975 - $default_filename = $other_args['default filename'];
976 - } else {
977 - $default_filename = "";
978 - }
979 - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
980 - }
981 -
982 - $spanClass = "inputSpan";
983 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
984 - $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
985 -
986 - return $text;
987 - }
988 -
989 - public static function getAutocompletionParameters() {
990 - $params = SFEnumInput::getValuesParameters();
991 - $params[] = array( 'name' => 'values from url', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromurl' ) );
992 - $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_remoteautocompletion' ) );
993 - $params[] = array( 'name' => 'list', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_list' ) );
994 - $params[] = array( 'name' => 'delimiter', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_delimiter' ) );
995 - return $params;
996 - }
997 -
998 - public static function getParameters() {
999 - $params = parent::getParameters();
1000 - $params = array_merge( $params, self::getAutocompletionParameters() );
1001 - return $params;
1002 - }
1003 -}
1004 -
1005 -/**
1006 - * @ingroup SFFormInput
1007 - */
1008 -class SFTextAreaWithAutocompleteInput extends SFTextAreaInput {
1009 - public static function getName() {
1010 - return 'textarea with autocomplete';
1011 - }
1012 -
1013 - public static function getDefaultPropTypes() {
1014 - return array();
1015 - }
1016 -
1017 - public static function getOtherPropTypesHandled() {
1018 - return array( '_wpg', '_str' );
1019 - }
1020 -
1021 - public static function getOtherPropTypeListsHandled() {
1022 - return array( '_wpg', '_str' );
1023 - }
1024 -
1025 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1026 - // If 'no autocomplete' was specified, print a regular
1027 - // textarea instead.
1028 - if ( array_key_exists( 'no autocomplete', $other_args ) &&
1029 - $other_args['no autocomplete'] == true ) {
1030 - unset( $other_args['autocompletion source'] );
1031 - return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
1032 - }
1033 -
1034 - global $sfgTabIndex, $sfgFieldNum;
1035 -
1036 - list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args );
1037 -
1038 - $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
1039 - if ( array_key_exists( 'class', $other_args ) )
1040 - $className .= " " . $other_args['class'];
1041 - $input_id = "input_" . $sfgFieldNum;
1042 -
1043 - if ( array_key_exists( 'rows', $other_args ) ) {
1044 - $rows = $other_args['rows'];
1045 - } else {
1046 - $rows = 5;
1047 - }
1048 - if ( array_key_exists( 'cols', $other_args ) ) {
1049 - $cols = $other_args['cols'];
1050 - } else {
1051 - $cols = 80;
1052 - }
1053 - $text = "";
1054 - if ( array_key_exists( 'autogrow', $other_args ) ) {
1055 - $className .= ' autoGrow';
1056 - }
1057 -
1058 - $textarea_attrs = array(
1059 - 'tabindex' => $sfgTabIndex,
1060 - 'id' => $input_id,
1061 - 'name' => $input_name,
1062 - 'rows' => $rows,
1063 - 'cols' => $cols,
1064 - 'class' => $className,
1065 - 'autocompletesettings' => $autocompleteSettings,
1066 - );
1067 - if ( !is_null( $remoteDataType ) ) {
1068 - $textarea_attrs['autocompletedatatype'] = $remoteDataType;
1069 - }
1070 - if ( $is_disabled ) {
1071 - $textarea_attrs['disabled'] = 'disabled';
1072 - }
1073 - if ( array_key_exists( 'maxlength', $other_args ) ) {
1074 - $maxlength = $other_args['maxlength'];
1075 - // For every actual character pressed (i.e., excluding
1076 - // things like the Shift key), reduce the string to
1077 - // its allowed length if it's exceeded that.
1078 - // This JS code is complicated so that it'll work
1079 - // correctly in IE - IE moves the cursor to the end
1080 - // whenever this.value is reset, so we'll make sure
1081 - // to do that only when we need to.
1082 - $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
1083 - $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
1084 - $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
1085 - }
1086 - $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false);
1087 - $text .= $textarea_input;
1088 -
1089 - if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
1090 - if ( array_key_exists( 'default filename', $other_args ) ) {
1091 - $default_filename = $other_args['default filename'];
1092 - } else {
1093 - $default_filename = "";
1094 - }
1095 - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
1096 - }
1097 -
1098 - $spanClass = "inputSpan";
1099 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
1100 - $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
1101 -
1102 - return $text;
1103 - }
1104 -
1105 - public static function getParameters() {
1106 - $params = parent::getParameters();
1107 - $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
1108 - return $params;
1109 - }
1110 -}
1111 -
1112 -/**
1113 - * @ingroup SFFormInput
1114 - */
1115 -class SFComboBoxInput extends SFFormInput {
1116 - public static function getName() {
1117 - return 'combobox';
1118 - }
1119 -
1120 - public static function getOtherPropTypesHandled() {
1121 - return array( '_wpg', '_str' );
1122 - }
1123 -
1124 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1125 - // For backward compatibility with pre-SF-2.1 forms
1126 - if ( array_key_exists( 'no autocomplete', $other_args ) &&
1127 - $other_args['no autocomplete'] == true ) {
1128 - unset( $other_args['autocompletion source'] );
1129 - return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
1130 - }
1131 -
1132 - global $sfgTabIndex, $sfgFieldNum;
1133 -
1134 - $className = "sfComboBox";
1135 - if ( $is_mandatory ) {
1136 - $className .= " mandatoryField";
1137 - }
1138 - if ( array_key_exists( 'class', $other_args ) ) {
1139 - $className .= " " . $other_args['class'];
1140 - }
1141 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
1142 -
1143 - if ( array_key_exists( 'size', $other_args ) ) {
1144 - $size = $other_args['size'];
1145 - } else {
1146 - $size = "35";
1147 - }
1148 - // There's no direct correspondence between the 'size='
1149 - // attribute for text inputs and the number of pixels, but
1150 - // multiplying by 6 seems to be about right for the major
1151 - // browsers.
1152 - $pixel_width = $size * 6 . "px";
1153 -
1154 - list( $autocompleteFieldType, $autocompletionSource ) =
1155 - SFTextWithAutocompleteInput::getAutocompletionTypeAndSource( $other_args );
1156 - $values = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType );
1157 - $autocompletionSource = str_replace( "'", "\'", $autocompletionSource );
1158 -
1159 - $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
1160 - foreach ( $values as $value ) {
1161 - $optionsText .= Xml::element( 'option', array( 'value' => $value ), $value ) . "\n";
1162 - }
1163 -
1164 - $selectAttrs = array(
1165 - 'id' => "input_$sfgFieldNum",
1166 - 'name' => $input_name,
1167 - 'class' => $className,
1168 - 'tabindex' => $sfgTabIndex,
1169 - 'autocompletesettings' => $autocompletionSource,
1170 - 'comboboxwidth' => $pixel_width,
1171 - );
1172 - if ( array_key_exists( 'existing values only', $other_args ) ) {
1173 - $selectAttrs['existingvaluesonly'] = 'true';
1174 - }
1175 - $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
1176 -
1177 - $divClass = "ui-widget";
1178 - if ( $is_mandatory ) { $divClass .= " mandatory"; }
1179 - $text = Xml::tags( 'div', array( 'class' => $divClass ), $selectText );
1180 - return $text;
1181 - }
1182 -
1183 - public static function getParameters() {
1184 - $params = parent::getParameters();
1185 - $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
1186 - $params = array_merge( $params, SFEnumInput::getValuesParameters() );
1187 - $params[] = array( 'name' => 'existing values only', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
1188 - return $params;
1189 - }
1190 -}
1191 -
1192 -/**
1193 - * @ingroup SFFormInput
1194 - */
1195 -class SFDateInput extends SFFormInput {
1196 - public static function getName() {
1197 - return 'date';
1198 - }
1199 -
1200 - public static function getDefaultPropTypes() {
1201 - return array( '_dat' => array() );
1202 - }
1203 -
1204 - public static function monthDropdownHTML( $cur_month, $input_name, $is_disabled ) {
1205 - global $sfgTabIndex, $wgAmericanDates;
1206 -
1207 - $optionsText = "";
1208 - $month_names = SFFormUtils::getMonthNames();
1209 - foreach ( $month_names as $i => $name ) {
1210 - // pad out month to always be two digits
1211 - $month_value = ( $wgAmericanDates == true ) ? $name : str_pad( $i + 1, 2, "0", STR_PAD_LEFT );
1212 - $optionAttrs = array ( 'value' => $month_value );
1213 - if ( $name == $cur_month || ( $i + 1 ) == $cur_month ) {
1214 - $optionAttrs['selected'] = 'selected';
1215 - }
1216 - $optionsText .= Xml::element( 'option', $optionAttrs, $name );
1217 - }
1218 - $selectAttrs = array(
1219 - 'class' => 'monthInput',
1220 - 'name' => $input_name . '[month]',
1221 - 'tabindex' => $sfgTabIndex
1222 - );
1223 - if ( $is_disabled ) {
1224 - $selectAttrs['disabled'] = 'disabled';
1225 - }
1226 - $text = Xml::tags( 'select', $selectAttrs, $optionsText );
1227 - return $text;
1228 - }
1229 -
1230 - public static function getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1231 - global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
1232 -
1233 - $input_id = "input_$sfgFieldNum";
1234 -
1235 - if ( $date ) {
1236 - // Can show up here either as an array or a string,
1237 - // depending on whether it came from user input or a
1238 - // wiki page.
1239 - if ( is_array( $date ) ) {
1240 - $year = $date['year'];
1241 - $month = $date['month'];
1242 - $day = $date['day'];
1243 - } else {
1244 - // handle 'default=now'
1245 - if ( $date == 'now' ) {
1246 - global $wgLocaltimezone;
1247 - if ( isset( $wgLocaltimezone ) ) {
1248 - $serverTimezone = date_default_timezone_get();
1249 - date_default_timezone_set( $wgLocaltimezone );
1250 - }
1251 - $date = date( 'Y/m/d' );
1252 - if ( isset( $wgLocaltimezone ) ) {
1253 - date_default_timezone_set( $serverTimezone );
1254 - }
1255 - }
1256 - $actual_date = new SMWTimeValue( '_dat' );
1257 - $actual_date->setUserValue( $date );
1258 - $year = $actual_date->getYear();
1259 - // TODO - the code to convert from negative to
1260 - // BC notation should be in SMW itself.
1261 - if ( $year < 0 ) { $year = ( $year * - 1 + 1 ) . " BC"; }
1262 - $month = $actual_date->getMonth();
1263 - $day = $actual_date->getDay();
1264 - }
1265 - } else {
1266 - $cur_date = getdate();
1267 - $year = $cur_date['year'];
1268 - $month = $cur_date['month'];
1269 - $day = null; // no need for day
1270 - }
1271 - $text = "";
1272 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
1273 - $monthInput = self::monthDropdownHTML( $month, $input_name, $is_disabled );
1274 - $dayInput = ' <input tabindex="' . $sfgTabIndex . '" class="dayInput" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>';
1275 - if ( $wgAmericanDates ) {
1276 - $text .= "$monthInput\n$dayInput\n";
1277 - } else {
1278 - $text .= "$dayInput\n$monthInput\n";
1279 - }
1280 - $text .= ' <input tabindex="' . $sfgTabIndex . '" class="yearInput" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
1281 - return $text;
1282 - }
1283 -
1284 - public static function getHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1285 - $text = self::getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args );
1286 - $spanClass = "dateInput";
1287 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
1288 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
1289 - return $text;
1290 - }
1291 -}
1292 -
1293 -/**
1294 - * @ingroup SFFormInput
1295 - */
1296 -class SFDateTimeInput extends SFDateInput {
1297 - public static function getName() {
1298 - return 'datetime';
1299 - }
1300 -
1301 - public static function getDefaultPropTypes() {
1302 - return array();
1303 - }
1304 -
1305 - public static function getOtherPropTypesHandled() {
1306 - return array( '_dat' );
1307 - }
1308 -
1309 - public static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1310 - global $sfgTabIndex, $sfg24HourTime;
1311 -
1312 - $include_timezone = array_key_exists( 'include timezone', $other_args );
1313 -
1314 - if ( $datetime ) {
1315 - // Can show up here either as an array or a string,
1316 - // depending on whether it came from user input or a
1317 - // wiki page.
1318 - if ( is_array( $datetime ) ) {
1319 - if ( isset( $datetime['hour'] ) ) $hour = $datetime['hour'];
1320 - if ( isset( $datetime['minute'] ) ) $minute = $datetime['minute'];
1321 - if ( isset( $datetime['second'] ) ) $second = $datetime['second'];
1322 - if ( ! $sfg24HourTime ) {
1323 - if ( isset( $datetime['ampm24h'] ) ) $ampm24h = $datetime['ampm24h'];
1324 - }
1325 - if ( isset( $datetime['timezone'] ) ) $timezone = $datetime['timezone'];
1326 - } else {
1327 - // TODO - this should change to use SMW's own
1328 - // date-handling class, just like
1329 - // dateEntryHTML() does.
1330 -
1331 - // Handle 'default=now'.
1332 - if ( $datetime == 'now' ) {
1333 - global $wgLocaltimezone;
1334 - if ( isset( $wgLocaltimezone ) ) {
1335 - $serverTimezone = date_default_timezone_get();
1336 - date_default_timezone_set( $wgLocaltimezone );
1337 - }
1338 - $actual_date = time();
1339 - } else {
1340 - $actual_date = strtotime( $datetime );
1341 - }
1342 - if ( $sfg24HourTime ) {
1343 - $hour = date( "G", $actual_date );
1344 - } else {
1345 - $hour = date( "g", $actual_date );
1346 - }
1347 - $minute = date( "i", $actual_date );
1348 - $second = date( "s", $actual_date );
1349 - if ( ! $sfg24HourTime ) {
1350 - $ampm24h = date( "A", $actual_date );
1351 - }
1352 - $timezone = date( "T", $actual_date );
1353 - // Restore back to the server's timezone.
1354 - if ( $datetime == 'now' ) {
1355 - if ( isset( $wgLocaltimezone ) ) {
1356 - date_default_timezone_set( $serverTimezone );
1357 - }
1358 - }
1359 - }
1360 - } else {
1361 - $cur_date = getdate();
1362 - $hour = null;
1363 - $minute = null;
1364 - $second = "00"; // default at least this value
1365 - $ampm24h = "";
1366 - $timezone = "";
1367 - }
1368 -
1369 - $text = parent::getMainHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args );
1370 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
1371 - $text .= ' &#160;<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $disabled_text . '>';
1372 - $sfgTabIndex++;
1373 - $text .= ' :<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $disabled_text . '>';
1374 - $sfgTabIndex++;
1375 - $text .= ':<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $disabled_text . '>' . "\n";
1376 -
1377 - if ( ! $sfg24HourTime ) {
1378 - $sfgTabIndex++;
1379 - $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
1380 - $ampm24h_options = array( '', 'AM', 'PM' );
1381 - foreach ( $ampm24h_options as $value ) {
1382 - $text .= " <option value=\"$value\"";
1383 - if ( $value == $ampm24h ) { $text .= " selected=\"selected\""; }
1384 - $text .= ">$value</option>\n";
1385 - }
1386 - $text .= " </select>\n";
1387 - }
1388 -
1389 - if ( $include_timezone ) {
1390 - $sfgTabIndex++;
1391 - $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="3"/ ' . $disabled_text . '>' . "\n";
1392 - }
1393 -
1394 - return $text;
1395 - }
1396 -
1397 - public static function getParameters() {
1398 - $params = parent::getParameters();
1399 - $params[] = array( 'name' => 'include timezone', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_includetimezone' ) );
1400 - return $params;
1401 - }
1402 -}
1403 -
1404 -/**
1405 - * @ingroup SFFormInput
1406 - */
1407 -class SFYearInput extends SFTextInput {
1408 - public static function getName() {
1409 - return 'year';
1410 - }
1411 -
1412 - public static function getDefaultPropTypes() {
1413 - return array();
1414 - }
1415 -
1416 - public static function getOtherPropTypesHandled() {
1417 - return array( '_dat' );
1418 - }
1419 -
1420 - public static function getDefaultPropTypeLists() {
1421 - return array();
1422 - }
1423 -
1424 - public static function getOtherPropTypeListsHandled() {
1425 - return array();
1426 - }
1427 -
1428 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1429 - $other_args['size'] = 4;
1430 - return parent::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
1431 - }
1432 -
1433 - public static function getParameters() {
1434 - $params = array();
1435 - $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) );
1436 - $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) );
1437 - $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) );
1438 - $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) );
1439 - $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
1440 - return $params;
1441 - }
1442 -}
1443 -
1444 -/**
1445 - * @ingroup SFFormInput
1446 - */
1447 -class SFCategoryInput extends SFFormInput {
1448 - public static function getName() {
1449 - return 'category';
1450 - }
1451 -
1452 - public static function getOtherPropTypesHandled() {
1453 - return array( '_wpg' );
1454 - }
1455 -
1456 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1457 - // escape if CategoryTree extension isn't included
1458 - if ( ! function_exists( 'efCategoryTreeParserHook' ) )
1459 - return null;
1460 -
1461 - global $sfgTabIndex, $sfgFieldNum;
1462 -
1463 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
1464 - if ( array_key_exists( 'class', $other_args ) )
1465 - $className .= " " . $other_args['class'];
1466 - if ( array_key_exists( 'top category', $other_args ) ) {
1467 - $top_category = $other_args['top category'];
1468 - } else {
1469 - // escape - we can't do anything
1470 - return null;
1471 - }
1472 - $hideroot = array_key_exists( 'hideroot', $other_args );
1473 - if ( array_key_exists( 'height', $other_args ) ) {
1474 - $height = $other_args['height'];
1475 - } else {
1476 - $height = "100";
1477 - }
1478 - if ( array_key_exists( 'width', $other_args ) ) {
1479 - $width = $other_args['width'];
1480 - } else {
1481 - $width = "500";
1482 - }
1483 -
1484 - $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">';
1485 -
1486 - // Start with an initial "None" value, unless this is a
1487 - // mandatory field and there's a current value in place
1488 - // (either through a default value or because we're editing
1489 - // an existing page)
1490 - if ( ! $is_mandatory || $cur_value == '' ) {
1491 - $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""';
1492 - if ( ! $cur_value ) {
1493 - $text .= ' checked="checked"';
1494 - }
1495 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
1496 - $text .= " $disabled_text/> <em>" . wfMsg( 'sf_formedit_none' ) . "</em>\n";
1497 - }
1498 -
1499 - global $wgCategoryTreeMaxDepth;
1500 - $wgCategoryTreeMaxDepth = 10;
1501 - $tree = efCategoryTreeParserHook( $top_category,
1502 - array(
1503 - 'mode' => 'categories',
1504 - 'namespaces' => array( NS_CATEGORY ),
1505 - 'depth' => 10,
1506 - 'hideroot' => $hideroot,
1507 - )
1508 - );
1509 -
1510 - // Capitalize the first letter, if first letters always get
1511 - // capitalized.
1512 - global $wgCapitalLinks;
1513 - if ( $wgCapitalLinks ) {
1514 - global $wgContLang;
1515 - $cur_value = $wgContLang->ucfirst( $cur_value );
1516 - }
1517 -
1518 - $tree = preg_replace( '/(<a class="CategoryTreeLabel.*>)(.*)(<\/a>)/', '<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="$2" type="radio"> $1$2$3', $tree );
1519 - $tree = str_replace( "value=\"$cur_value\"", "value=\"$cur_value\" checked=\"checked\"", $tree );
1520 - // if it's disabled, set all to disabled
1521 - if ( $is_disabled ) {
1522 - $tree = str_replace( 'type="radio"', 'type="radio" disabled', $tree );
1523 - }
1524 -
1525 - // Get rid of all the 'no subcategories' messages.
1526 - $tree = str_replace( '<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg( 'categorytree-no-subcategories' ) . '</i></div>', '', $tree );
1527 -
1528 - $text .= $tree . '</div>';
1529 -
1530 - $spanClass = "radioButtonSpan";
1531 - if ( $is_mandatory) { $spanClass .= " mandatoryFieldSpan"; }
1532 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
1533 -
1534 - return $text;
1535 - }
1536 -
1537 - public static function getParameters() {
1538 - $params = parent::getParameters();
1539 - $params[] = array( 'name' => 'top category', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_topcategory' ) );
1540 - $params[] = array( 'name' => 'hideroot', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_hideroot' ) );
1541 - $params[] = array( 'name' => 'height', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_height' ) );
1542 - $params[] = array( 'name' => 'width', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_width' ) );
1543 - return $params;
1544 - }
1545 -}
1546 -
1547 -/**
1548 - * @ingroup SFFormInput
1549 - */
1550 -class SFCategoriesInput extends SFCategoryInput {
1551 - public static function getName() {
1552 - return 'categories';
1553 - }
1554 -
1555 - public static function getOtherPropTypeListsHandled() {
1556 - return array( '_wpg' );
1557 - }
1558 -
1559 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1560 - // escape if CategoryTree extension isn't included
1561 - if ( ! function_exists( 'efCategoryTreeParserHook' ) )
1562 - return null;
1563 -
1564 - global $sfgTabIndex, $sfgFieldNum, $wgCapitalLinks;
1565 -
1566 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
1567 - if ( array_key_exists( 'class', $other_args ) )
1568 - $className .= " " . $other_args['class'];
1569 - $input_id = "input_$sfgFieldNum";
1570 - $info_id = "info_$sfgFieldNum";
1571 - // get list delimiter - default is comma
1572 - if ( array_key_exists( 'delimiter', $other_args ) ) {
1573 - $delimiter = $other_args['delimiter'];
1574 - } else {
1575 - $delimiter = ",";
1576 - }
1577 - $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
1578 - if ( array_key_exists( 'top category', $other_args ) ) {
1579 - $top_category = $other_args['top category'];
1580 - } else {
1581 - // escape - we can't do anything
1582 - return null;
1583 - }
1584 - $hideroot = array_key_exists( 'hideroot', $other_args );
1585 - if ( array_key_exists( 'height', $other_args ) ) {
1586 - $height = $other_args['height'];
1587 - } else {
1588 - $height = "100";
1589 - }
1590 - if ( array_key_exists( 'width', $other_args ) ) {
1591 - $width = $other_args['width'];
1592 - } else {
1593 - $width = "500";
1594 - }
1595 -
1596 - global $wgCategoryTreeMaxDepth;
1597 - $wgCategoryTreeMaxDepth = 10;
1598 - $tree = efCategoryTreeParserHook(
1599 - $top_category, array(
1600 - 'mode' => 'categories',
1601 - 'namespaces' => array( NS_CATEGORY ),
1602 - 'depth' => 10,
1603 - 'hideroot' => $hideroot,
1604 - )
1605 - );
1606 - // Some string that will hopefully never show up in a category,
1607 - // template or field name.
1608 - $dummy_str = 'REPLACE THIS STRING!';
1609 - $tree = preg_replace( '/(<a class="CategoryTreeLabel.*>)(.*)(<\/a>)/', '<input id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[' . $dummy_str . ']" value="$2" type="checkbox"> $1$2$3', $tree );
1610 - // replace values one at a time, by an incrementing index -
1611 - // inspired by http://bugs.php.net/bug.php?id=11457
1612 - $i = 0;
1613 - while ( ( $a = strpos( $tree, $dummy_str ) ) > 0 ) {
1614 - $tree = substr( $tree, 0, $a ) . $i++ . substr( $tree, $a + strlen( $dummy_str ) );
1615 - }
1616 - // set all checkboxes matching $cur_values to checked
1617 - foreach ( $cur_values as $value ) {
1618 - // Capitalize the first letter, if first letters
1619 - // always get capitalized.
1620 - if ( $wgCapitalLinks ) {
1621 - global $wgContLang;
1622 - $value = $wgContLang->ucfirst( $value );
1623 - }
1624 -
1625 - $tree = str_replace( "value=\"$value\"", "value=\"$value\" checked=\"checked\"", $tree );
1626 - }
1627 - // if it's disabled, set all to disabled
1628 - if ( $is_disabled ) {
1629 - $tree = str_replace( 'type="checkbox"', 'type="checkbox" disabled', $tree );
1630 - }
1631 -
1632 - // Get rid of all the 'no subcategories' messages.
1633 - $tree = str_replace( '<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg( 'categorytree-no-subcategories' ) . '</i></div>', '', $tree );
1634 -
1635 - $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">' . $tree . '</div>';
1636 -
1637 - $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
1638 - $spanClass = "checkboxesSpan";
1639 - if ( $is_mandatory) { $spanClass .= " mandatoryFieldSpan"; }
1640 - $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text ) . "\n";
1641 -
1642 - return $text;
1643 - }
1644 -}
Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php
@@ -13,7 +13,7 @@
1414 class SFFormUtils {
1515 static function setGlobalJSVariables( &$vars ) {
1616 global $sfgAutocompleteValues, $sfgAutocompleteOnAllChars;
17 - global $sfgInitJSFunctions, $sfgValidationJSFunctions;
 17+// global $sfgInitJSFunctions, $sfgValidationJSFunctions;
1818 global $sfgShowOnSelect;
1919
2020 $vars['sfgRemoveText'] = wfMsg( 'sf_formedit_remove' );
@@ -22,8 +22,8 @@
2323 // objects, to work with MW 1.15 and earlier
2424 $vars['sfgAutocompleteValues'] = (object)$sfgAutocompleteValues;
2525 $vars['sfgShowOnSelect'] = (object)$sfgShowOnSelect;
26 - $vars['sfgInitJSFunctions'] = (object)$sfgInitJSFunctions;
27 - $vars['sfgValidationJSFunctions'] = (object)$sfgValidationJSFunctions;
 26+// $vars['sfgInitJSFunctions'] = (object)$sfgInitJSFunctions;
 27+// $vars['sfgValidationJSFunctions'] = (object)$sfgValidationJSFunctions;
2828 $vars['sfgFormErrorsHeader'] = wfMsg( 'sf_formerrors_header' );
2929 $vars['sfgBlankErrorStr'] = wfMsg( 'sf_blank_error' );
3030 $vars['sfgBadURLErrorStr'] = wfMsg( 'sf_bad_url_error' );
Index: trunk/extensions/SemanticForms/includes/SF_AutoeditAPI.php
@@ -21,6 +21,14 @@
2222 private $mOptions;
2323 private $mIsApiQuery = true;
2424
 25+ /**
 26+ * Handles autoedit Ajax call from #autoedit parser function and from save
 27+ * and continue button.
 28+ *
 29+ * @param String $optionsString the options/data string
 30+ * @param String $prefillFromExisting String set to 'true' to retain existing form values (unset by save and continue)
 31+ * @return String
 32+ */
2533 static function handleAutoEdit( $optionsString = null, $prefillFromExisting = 'true' ) {
2634
2735 global $wgParser;
@@ -90,10 +98,20 @@
9199 return $ret;
92100 }
93101
 102+ /**
 103+ * Converts an options string into an options array and stores it
 104+ *
 105+ * @param string $options
 106+ * @return the options array
 107+ */
94108 function setOptionsString( $options ) {
95109 return $this->parseDataFromQueryString( $this->mOptions, $options );
96110 }
97111
 112+ /**
 113+ * Returns the options array
 114+ * @return array
 115+ */
98116 function getOptions() {
99117 return $this->mOptions;
100118 }
@@ -196,6 +214,8 @@
197215 * It will return true on success or an error message on failure.
198216 * The used form and target page will be available in mOptions after
199217 * execution of the method.
 218+ *
 219+ * This method also sets HTTP response headers according to the result.
200220 *
201221 * @param bool $prefillFromExisting If this is set, existing values in the page will be used to prefill the form.
202222 * @return true or an error message
@@ -426,13 +446,7 @@
427447 *
428448 * @param Array $data
429449 * @param String $queryString
430 - * @param Boolean $expand If this is set to true, field values will get
431 - * urldecoded and expanded. This allows us to have parser functions
432 - * skip handling by the MW parser on page creation (since they will be
433 - * URL-encoded), and to instead have them handled by #autoedit.
434 - * This can prevent cache issues, such as when dealing with the
435 - * {{#time:}} parser function.
436 - * @return <type>
 450+ * @return Array
437451 */
438452 private function parseDataFromQueryString( &$data, $queryString ) {
439453 $params = explode( '&', $queryString );
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_ListBoxInput.php
@@ -0,0 +1,101 @@
 2+<?php
 3+/**
 4+ * File holding the SFListBoxInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFListBoxInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFListBoxInput extends SFMultiEnumInput {
 20+
 21+ public static function getName() {
 22+ return 'listbox';
 23+ }
 24+
 25+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 26+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 27+
 28+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 29+ if ( array_key_exists( 'class', $other_args ) ) {
 30+ $className .= " " . $other_args['class'];
 31+ }
 32+ $input_id = "input_$sfgFieldNum";
 33+ // get list delimiter - default is comma
 34+ if ( array_key_exists( 'delimiter', $other_args ) ) {
 35+ $delimiter = $other_args['delimiter'];
 36+ } else {
 37+ $delimiter = ",";
 38+ }
 39+ $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
 40+ $className .= " sfShowIfSelected";
 41+
 42+ if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
 43+ $possible_values = array();
 44+ }
 45+ $optionsText = "";
 46+ foreach ( $possible_values as $possible_value ) {
 47+ if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) {
 48+ $optionLabel = $other_args['value_labels'][$possible_value];
 49+ } else {
 50+ $optionLabel = $possible_value;
 51+ }
 52+ $optionAttrs = array( 'value' => $possible_value );
 53+ if ( in_array( $possible_value, $cur_values ) ) {
 54+ $optionAttrs['selected'] = 'selected';
 55+ }
 56+ $optionsText .= Xml::element( 'option', $optionAttrs, $optionLabel );
 57+ }
 58+ $selectAttrs = array(
 59+ 'id' => $input_id,
 60+ 'tabindex' => $sfgTabIndex,
 61+ 'name' => $input_name . '[]',
 62+ 'class' => $className,
 63+ 'multiple' => 'multiple'
 64+ );
 65+ if ( array_key_exists( 'size', $other_args ) ) {
 66+ $selectAttrs['size'] = $other_args['size'];
 67+ }
 68+ if ( $is_disabled ) {
 69+ $selectAttrs['disabled'] = 'disabled';
 70+ }
 71+ $text = Xml::tags( 'select', $selectAttrs, $optionsText );
 72+ $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
 73+ if ( $is_mandatory ) {
 74+ $text = Xml::tags( 'span', array( 'class' => 'inputSpan mandatoryFieldSpan' ), $text );
 75+ }
 76+
 77+ if ( array_key_exists( 'show on select', $other_args ) ) {
 78+ foreach ( $other_args['show on select'] as $div_id => $options ) {
 79+ if ( array_key_exists( $input_id, $sfgShowOnSelect ) ) {
 80+ $sfgShowOnSelect[$input_id][] = array( $options, $div_id );
 81+ } else {
 82+ $sfgShowOnSelect[$input_id] = array( array( $options, $div_id ) );
 83+ }
 84+ }
 85+ }
 86+
 87+ return $text;
 88+ }
 89+
 90+ public static function getParameters() {
 91+ $params = parent::getParameters();
 92+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_listboxsize' ) );
 93+ return $params;
 94+ }
 95+
 96+ /**
 97+ * Returns the HTML code to be included in the output page for this input.
 98+ */
 99+ public function getHtmlText() {
 100+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 101+ }
 102+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_ListBoxInput.php
___________________________________________________________________
Added: svn:eol-style
1103 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextInput.php
@@ -0,0 +1,169 @@
 2+<?php
 3+/**
 4+ * File holding the SFTextInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFTextInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFTextInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'text';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array(
 26+ '_str' => array( 'field_type' => 'string' ),
 27+ '_num' => array( 'field_type' => 'number' ),
 28+ '_uri' => array( 'field_type' => 'URL' ),
 29+ '_ema' => array( 'field_type' => 'email' )
 30+ );
 31+ }
 32+
 33+ public static function getOtherPropTypesHandled() {
 34+ return array( '_wpg', '_geo' );
 35+ }
 36+
 37+ public static function getDefaultPropTypeLists() {
 38+ return array(
 39+ '_str' => array( 'field_type' => 'string', 'is_list' => 'true', 'size' => '100' ),
 40+ '_num' => array( 'field_type' => 'number', 'is_list' => 'true', 'size' => '100' ),
 41+ '_uri' => array( 'field_type' => 'URL', 'is_list' => 'true' ),
 42+ '_ema' => array( 'field_type' => 'email', 'is_list' => 'true' )
 43+ );
 44+ }
 45+
 46+ public static function getOtherPropTypeListsHandled() {
 47+ return array( '_wpg' );
 48+ }
 49+
 50+ public static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) {
 51+ $upload_window_page = SpecialPage::getPage( 'UploadWindow' );
 52+ $query_string = "sfInputID=$input_id";
 53+ if ( $delimiter != null )
 54+ $query_string .= "&sfDelimiter=$delimiter";
 55+ if ( $default_filename != null )
 56+ $query_string .= "&wpDestFile=$default_filename";
 57+ $upload_window_url = $upload_window_page->getTitle()->getFullURL( $query_string );
 58+ $upload_label = wfMsg( 'upload' );
 59+ // window needs to be bigger for MediaWiki version 1.16+
 60+ if ( class_exists( 'HTMLForm' ) )
 61+ $style = "width:650 height:500";
 62+ else
 63+ $style = '';
 64+
 65+ $linkAttrs = array(
 66+ 'href' => $upload_window_url,
 67+ 'class' => 'sfFancyBox',
 68+ 'title' => $upload_label,
 69+ 'rev' => $style
 70+ );
 71+ $text = "\t" . Xml::element( 'a', $linkAttrs, $upload_label ) . "\n";
 72+ return $text;
 73+ }
 74+
 75+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 76+ global $sfgTabIndex, $sfgFieldNum;
 77+
 78+ // For backward compatibility with pre-SF-2.1 forms
 79+ if ( array_key_exists( 'autocomplete field type', $other_args ) &&
 80+ ! array_key_exists( 'no autocomplete', $other_args ) ) {
 81+ return SFTextWithAutocompleteInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 82+ }
 83+
 84+ $className = "createboxInput";
 85+ if ( $is_mandatory ) {
 86+ $className .= " mandatoryField";
 87+ }
 88+ if ( array_key_exists( 'class', $other_args ) ) {
 89+ $className .= " " . $other_args['class'];
 90+ }
 91+ $input_id = "input_$sfgFieldNum";
 92+ // Set size based on pre-set size, or field type - if field
 93+ // type is set, possibly add validation too.
 94+ $size = 35;
 95+ $inputType = '';
 96+ if ( array_key_exists( 'field_type', $other_args ) ) {
 97+ if ( $other_args['field_type'] == 'number' ) {
 98+ $size = 10;
 99+ $inputType = 'number';
 100+ } elseif ( $other_args['field_type'] == 'URL' ) {
 101+ $size = 100;
 102+ $inputType = 'URL';
 103+ } elseif ( $other_args['field_type'] == 'email' ) {
 104+ $size = 45;
 105+ $inputType = 'email';
 106+ }
 107+ }
 108+ if ( array_key_exists( 'size', $other_args ) ) {
 109+ $size = $other_args['size'];
 110+ }
 111+
 112+ $inputAttrs = array(
 113+ 'type' => 'text',
 114+ 'id' => $input_id,
 115+ 'tabindex' => $sfgTabIndex,
 116+ 'class' => $className,
 117+ 'name' => $input_name,
 118+ 'value' => $cur_value,
 119+ 'size' => $size
 120+ );
 121+ if ( $is_disabled ) {
 122+ $inputAttrs['disabled'] = 'disabled';
 123+ }
 124+ if ( array_key_exists( 'maxlength', $other_args ) ) {
 125+ $inputAttrs['maxlength'] = $other_args['maxlength'];
 126+ }
 127+ $text = Xml::element( 'input', $inputAttrs );
 128+
 129+ if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
 130+ if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) {
 131+ if ( array_key_exists( 'delimiter', $other_args ) ) {
 132+ $delimiter = $other_args['delimiter'];
 133+ } else {
 134+ $delimiter = ",";
 135+ }
 136+ } else {
 137+ $delimiter = null;
 138+ }
 139+ if ( array_key_exists( 'default filename', $other_args ) ) {
 140+ $default_filename = $other_args['default filename'];
 141+ } else {
 142+ $default_filename = "";
 143+ }
 144+ $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
 145+ }
 146+ $spanClass = "inputSpan";
 147+ if ( $inputType != '' ) {
 148+ $spanClass .= " {$inputType}Input";
 149+ }
 150+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 151+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 152+ return $text;
 153+ }
 154+
 155+ public static function getParameters() {
 156+ $params = parent::getParameters();
 157+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 158+ $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
 159+ $params[] = array( 'name' => 'uploadable', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_uploadable' ) );
 160+ $params[] = array( 'name' => 'default filename', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_defaultfilename' ) );
 161+ return $params;
 162+ }
 163+
 164+ /**
 165+ * Returns the HTML code to be included in the output page for this input.
 166+ */
 167+ public function getHtmlText() {
 168+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 169+ }
 170+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_TextInput.php
___________________________________________________________________
Added: svn:eol-style
1171 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_CategoriesInput.php
@@ -0,0 +1,119 @@
 2+<?php
 3+/**
 4+ * File holding the SFCategoriesInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFCategoriesInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFCategoriesInput extends SFCategoryInput {
 20+ public static function getName() {
 21+ return 'categories';
 22+ }
 23+
 24+ public static function getOtherPropTypeListsHandled() {
 25+ return array( '_wpg' );
 26+ }
 27+
 28+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 29+ // escape if CategoryTree extension isn't included
 30+ if ( ! function_exists( 'efCategoryTreeParserHook' ) )
 31+ return null;
 32+
 33+ global $sfgTabIndex, $sfgFieldNum, $wgCapitalLinks;
 34+
 35+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 36+ if ( array_key_exists( 'class', $other_args ) )
 37+ $className .= " " . $other_args['class'];
 38+ $input_id = "input_$sfgFieldNum";
 39+ $info_id = "info_$sfgFieldNum";
 40+ // get list delimiter - default is comma
 41+ if ( array_key_exists( 'delimiter', $other_args ) ) {
 42+ $delimiter = $other_args['delimiter'];
 43+ } else {
 44+ $delimiter = ",";
 45+ }
 46+ $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
 47+ if ( array_key_exists( 'top category', $other_args ) ) {
 48+ $top_category = $other_args['top category'];
 49+ } else {
 50+ // escape - we can't do anything
 51+ return null;
 52+ }
 53+ $hideroot = array_key_exists( 'hideroot', $other_args );
 54+ if ( array_key_exists( 'height', $other_args ) ) {
 55+ $height = $other_args['height'];
 56+ } else {
 57+ $height = "100";
 58+ }
 59+ if ( array_key_exists( 'width', $other_args ) ) {
 60+ $width = $other_args['width'];
 61+ } else {
 62+ $width = "500";
 63+ }
 64+
 65+ global $wgCategoryTreeMaxDepth;
 66+ $wgCategoryTreeMaxDepth = 10;
 67+ $tree = efCategoryTreeParserHook(
 68+ $top_category, array(
 69+ 'mode' => 'categories',
 70+ 'namespaces' => array( NS_CATEGORY ),
 71+ 'depth' => 10,
 72+ 'hideroot' => $hideroot,
 73+ )
 74+ );
 75+ // Some string that will hopefully never show up in a category,
 76+ // template or field name.
 77+ $dummy_str = 'REPLACE THIS STRING!';
 78+ $tree = preg_replace( '/(<a class="CategoryTreeLabel.*>)(.*)(<\/a>)/', '<input id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[' . $dummy_str . ']" value="$2" type="checkbox"> $1$2$3', $tree );
 79+ // replace values one at a time, by an incrementing index -
 80+ // inspired by http://bugs.php.net/bug.php?id=11457
 81+ $i = 0;
 82+ while ( ( $a = strpos( $tree, $dummy_str ) ) > 0 ) {
 83+ $tree = substr( $tree, 0, $a ) . $i++ . substr( $tree, $a + strlen( $dummy_str ) );
 84+ }
 85+ // set all checkboxes matching $cur_values to checked
 86+ foreach ( $cur_values as $value ) {
 87+ // Capitalize the first letter, if first letters
 88+ // always get capitalized.
 89+ if ( $wgCapitalLinks ) {
 90+ global $wgContLang;
 91+ $value = $wgContLang->ucfirst( $value );
 92+ }
 93+
 94+ $tree = str_replace( "value=\"$value\"", "value=\"$value\" checked=\"checked\"", $tree );
 95+ }
 96+ // if it's disabled, set all to disabled
 97+ if ( $is_disabled ) {
 98+ $tree = str_replace( 'type="checkbox"', 'type="checkbox" disabled', $tree );
 99+ }
 100+
 101+ // Get rid of all the 'no subcategories' messages.
 102+ $tree = str_replace( '<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg( 'categorytree-no-subcategories' ) . '</i></div>', '', $tree );
 103+
 104+ $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">' . $tree . '</div>';
 105+
 106+ $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
 107+ $spanClass = "checkboxesSpan";
 108+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 109+ $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text ) . "\n";
 110+
 111+ return $text;
 112+ }
 113+
 114+ /**
 115+ * Returns the HTML code to be included in the output page for this input.
 116+ */
 117+ public function getHtmlText() {
 118+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 119+ }
 120+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_CategoriesInput.php
___________________________________________________________________
Added: svn:eol-style
1121 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxInput.php
@@ -0,0 +1,87 @@
 2+<?php
 3+/**
 4+ * File holding the SFCheckboxInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFCheckboxInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFCheckboxInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'checkbox';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array( '_boo' => array() );
 26+ }
 27+
 28+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 29+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 30+
 31+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 32+ if ( array_key_exists( 'class', $other_args ) )
 33+ $className .= " " . $other_args['class'];
 34+ $input_id = "input_$sfgFieldNum";
 35+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 36+ if ( array_key_exists( 'show on select', $other_args ) ) {
 37+ $className .= " sfShowIfCheckedCheckbox";
 38+ $div_id = key( $other_args['show on select'] );
 39+ $sfgShowOnSelect[$input_id] = $div_id;
 40+ }
 41+
 42+ // Can show up here either as an array or a string, depending on
 43+ // whether it came from user input or a wiki page
 44+ if ( is_array( $cur_value ) ) {
 45+ $checked_str = ( array_key_exists( 'value', $cur_value ) && $cur_value['value'] == 'on' ) ? ' checked="checked"' : "";
 46+ } else {
 47+ // Default to false - no need to check if it matches
 48+ // a 'false' word.
 49+ $vlc = strtolower( trim( $cur_value ) );
 50+ // Manually load SMW's message values, if they weren't
 51+ // loaded before.
 52+ global $wgVersion;
 53+ if ( version_compare( $wgVersion, '1.16', '<' ) ) {
 54+ wfLoadExtensionMessages( 'SemanticMediaWiki' );
 55+ }
 56+ if ( in_array( $vlc, explode( ',', wfMsgForContent( 'smw_true_words' ) ), TRUE ) ) {
 57+ $checked_str = ' checked="checked"';
 58+ } else {
 59+ $checked_str = "";
 60+ }
 61+ }
 62+ $text = <<<END
 63+ <input name="{$input_name}[is_checkbox]" type="hidden" value="true" />
 64+ <input id="$input_id" name="{$input_name}[value]" type="checkbox" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
 65+
 66+END;
 67+ return $text;
 68+ }
 69+
 70+ public static function getParameters() {
 71+ // Remove the 'mandatory' option - it doesn't make sense for
 72+ // checkboxes.
 73+ $params = array();
 74+ foreach ( parent::getParameters() as $param ) {
 75+ if ( $param['name'] != 'mandatory' ) {
 76+ $params[] = $param;
 77+ }
 78+ }
 79+ return $params;
 80+ }
 81+
 82+ /**
 83+ * Returns the HTML code to be included in the output page for this input.
 84+ */
 85+ public function getHtmlText() {
 86+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 87+ }
 88+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxInput.php
___________________________________________________________________
Added: svn:eol-style
189 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_RadioButtonInput.php
@@ -0,0 +1,128 @@
 2+<?php
 3+/**
 4+ * File holding the SFRadioButtonInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFRadioButtonInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFRadioButtonInput extends SFEnumInput {
 20+ public static function getName() {
 21+ return 'radiobutton';
 22+ }
 23+
 24+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 25+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 26+
 27+ if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
 28+ // If it's a Boolean property, display 'Yes' and 'No'
 29+ // as the values.
 30+ if ( $other_args['property_type'] == '_boo' ) {
 31+ $possible_values = array(
 32+ SFUtils::getWordForYesOrNo( true ),
 33+ SFUtils::getWordForYesOrNo( false ),
 34+ );
 35+ } else {
 36+ $possible_values = array();
 37+ }
 38+ }
 39+
 40+ // Add a "None" value at the beginning, unless this is a
 41+ // mandatory field and there's a current value in place (either
 42+ // through a default value or because we're editing an existing
 43+ // page).
 44+ if ( ! $is_mandatory || $cur_value == '' ) {
 45+ array_unshift( $possible_values, '' );
 46+ }
 47+
 48+ // Set $cur_value to be one of the allowed options, if it isn't
 49+ // already - that makes it easier to automatically have one of
 50+ // the radiobuttons be checked at the beginning.
 51+ if ( ! in_array( $cur_value, $possible_values ) ) {
 52+ if ( in_array( '', $possible_values ) )
 53+ $cur_value = '';
 54+ else
 55+ $cur_value = $possible_values[0];
 56+ }
 57+
 58+ $text = '';
 59+ $itemClass = "radioButtonItem";
 60+ if ( array_key_exists( 'class', $other_args ) ) {
 61+ $itemClass .= " " . $other_args['class'];
 62+ }
 63+ $itemAttrs = array ( 'class' => $itemClass );
 64+
 65+ foreach ( $possible_values as $i => $possible_value ) {
 66+ $sfgTabIndex++;
 67+ $sfgFieldNum++;
 68+ $input_id = "input_$sfgFieldNum";
 69+
 70+ $radiobutton_attrs = array(
 71+ 'type' => 'radio',
 72+ 'id' => $input_id,
 73+ 'tabindex' => $sfgTabIndex,
 74+ 'name' => $input_name,
 75+ 'value' => $possible_value,
 76+ );
 77+ if ( $cur_value == $possible_value ) {
 78+ $radiobutton_attrs['checked'] = 'checked';
 79+ }
 80+ if ( $is_disabled ) {
 81+ $radiobutton_attrs['disabled'] = 'disabled';
 82+ }
 83+ if ( $possible_value == '' ) // blank/"None" value
 84+ $label = wfMsg( 'sf_formedit_none' );
 85+ elseif ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
 86+ $label = htmlspecialchars( $other_args['value_labels'][$possible_value] );
 87+ else
 88+ $label = $possible_value;
 89+
 90+ $text .= "\t" . Xml::openElement( 'span', $itemAttrs ) . Xml::element ( 'input', $radiobutton_attrs ) . " $label\n" . Xml::closeElement( 'span' );
 91+ }
 92+
 93+ $spanClass = "radioButtonSpan";
 94+ if ( array_key_exists( 'class', $other_args ) ) {
 95+ $spanClass .= " " . $other_args['class'];
 96+ }
 97+ if ( $is_mandatory ) {
 98+ $spanClass .= " mandatoryFieldSpan";
 99+ }
 100+
 101+ $spanID = "span_$sfgFieldNum";
 102+
 103+ // Do the 'show on select' handling.
 104+ if ( array_key_exists( 'show on select', $other_args ) ) {
 105+ $spanClass .= " sfShowIfChecked";
 106+ foreach ( $other_args['show on select'] as $div_id => $options ) {
 107+ if ( array_key_exists( $spanID, $sfgShowOnSelect ) ) {
 108+ $sfgShowOnSelect[$spanID][] = array( $options, $div_id );
 109+ } else {
 110+ $sfgShowOnSelect[$spanID] = array( array( $options, $div_id ) );
 111+ }
 112+ }
 113+ }
 114+ $spanAttrs = array(
 115+ 'id' => $spanID,
 116+ 'class' => $spanClass
 117+ );
 118+ $text = Xml::tags( 'span', $spanAttrs, $text );
 119+
 120+ return $text;
 121+ }
 122+
 123+ /**
 124+ * Returns the HTML code to be included in the output page for this input.
 125+ */
 126+ public function getHtmlText() {
 127+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 128+ }
 129+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_RadioButtonInput.php
___________________________________________________________________
Added: svn:eol-style
1130 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
@@ -0,0 +1,127 @@
 2+<?php
 3+/**
 4+ * File holding the SFTextAreaWithAutocompleteInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFTextAreaWithAutocompleteInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFTextAreaWithAutocompleteInput extends SFTextAreaInput {
 20+ public static function getName() {
 21+ return 'textarea with autocomplete';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array();
 26+ }
 27+
 28+ public static function getOtherPropTypesHandled() {
 29+ return array( '_wpg', '_str' );
 30+ }
 31+
 32+ public static function getOtherPropTypeListsHandled() {
 33+ return array( '_wpg', '_str' );
 34+ }
 35+
 36+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 37+ // If 'no autocomplete' was specified, print a regular
 38+ // textarea instead.
 39+ if ( array_key_exists( 'no autocomplete', $other_args ) &&
 40+ $other_args['no autocomplete'] == true ) {
 41+ unset( $other_args['autocompletion source'] );
 42+ return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 43+ }
 44+
 45+ global $sfgTabIndex, $sfgFieldNum;
 46+
 47+ list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args );
 48+
 49+ $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
 50+ if ( array_key_exists( 'class', $other_args ) )
 51+ $className .= " " . $other_args['class'];
 52+ $input_id = "input_" . $sfgFieldNum;
 53+
 54+ if ( array_key_exists( 'rows', $other_args ) ) {
 55+ $rows = $other_args['rows'];
 56+ } else {
 57+ $rows = 5;
 58+ }
 59+ if ( array_key_exists( 'cols', $other_args ) ) {
 60+ $cols = $other_args['cols'];
 61+ } else {
 62+ $cols = 80;
 63+ }
 64+ $text = "";
 65+ if ( array_key_exists( 'autogrow', $other_args ) ) {
 66+ $className .= ' autoGrow';
 67+ }
 68+
 69+ $textarea_attrs = array(
 70+ 'tabindex' => $sfgTabIndex,
 71+ 'id' => $input_id,
 72+ 'name' => $input_name,
 73+ 'rows' => $rows,
 74+ 'cols' => $cols,
 75+ 'class' => $className,
 76+ 'autocompletesettings' => $autocompleteSettings,
 77+ );
 78+ if ( !is_null( $remoteDataType ) ) {
 79+ $textarea_attrs['autocompletedatatype'] = $remoteDataType;
 80+ }
 81+ if ( $is_disabled ) {
 82+ $textarea_attrs['disabled'] = 'disabled';
 83+ }
 84+ if ( array_key_exists( 'maxlength', $other_args ) ) {
 85+ $maxlength = $other_args['maxlength'];
 86+ // For every actual character pressed (i.e., excluding
 87+ // things like the Shift key), reduce the string to
 88+ // its allowed length if it's exceeded that.
 89+ // This JS code is complicated so that it'll work
 90+ // correctly in IE - IE moves the cursor to the end
 91+ // whenever this.value is reset, so we'll make sure
 92+ // to do that only when we need to.
 93+ $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
 94+ $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
 95+ $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
 96+ }
 97+ $textarea_input = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
 98+ $text .= $textarea_input;
 99+
 100+ if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
 101+ if ( array_key_exists( 'default filename', $other_args ) ) {
 102+ $default_filename = $other_args['default filename'];
 103+ } else {
 104+ $default_filename = "";
 105+ }
 106+ $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
 107+ }
 108+
 109+ $spanClass = "inputSpan";
 110+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 111+ $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 112+
 113+ return $text;
 114+ }
 115+
 116+ public static function getParameters() {
 117+ $params = parent::getParameters();
 118+ $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
 119+ return $params;
 120+ }
 121+
 122+ /**
 123+ * Returns the HTML code to be included in the output page for this input.
 124+ */
 125+ public function getHtmlText() {
 126+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 127+ }
 128+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
___________________________________________________________________
Added: svn:eol-style
1129 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_DateTimeInput.php
@@ -0,0 +1,131 @@
 2+<?php
 3+/**
 4+ * File holding the SFDateTimeInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFDateTimeInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFDateTimeInput extends SFDateInput {
 20+ public static function getName() {
 21+ return 'datetime';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array();
 26+ }
 27+
 28+ public static function getOtherPropTypesHandled() {
 29+ return array( '_dat' );
 30+ }
 31+
 32+ public static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 33+ global $sfgTabIndex, $sfg24HourTime;
 34+
 35+ $include_timezone = array_key_exists( 'include timezone', $other_args );
 36+
 37+ if ( $datetime ) {
 38+ // Can show up here either as an array or a string,
 39+ // depending on whether it came from user input or a
 40+ // wiki page.
 41+ if ( is_array( $datetime ) ) {
 42+ if ( isset( $datetime['hour'] ) ) $hour = $datetime['hour'];
 43+ if ( isset( $datetime['minute'] ) ) $minute = $datetime['minute'];
 44+ if ( isset( $datetime['second'] ) ) $second = $datetime['second'];
 45+ if ( ! $sfg24HourTime ) {
 46+ if ( isset( $datetime['ampm24h'] ) ) $ampm24h = $datetime['ampm24h'];
 47+ }
 48+ if ( isset( $datetime['timezone'] ) ) $timezone = $datetime['timezone'];
 49+ } else {
 50+ // TODO - this should change to use SMW's own
 51+ // date-handling class, just like
 52+ // dateEntryHTML() does.
 53+
 54+ // Handle 'default=now'.
 55+ if ( $datetime == 'now' ) {
 56+ global $wgLocaltimezone;
 57+ if ( isset( $wgLocaltimezone ) ) {
 58+ $serverTimezone = date_default_timezone_get();
 59+ date_default_timezone_set( $wgLocaltimezone );
 60+ }
 61+ $actual_date = time();
 62+ } else {
 63+ $actual_date = strtotime( $datetime );
 64+ }
 65+ if ( $sfg24HourTime ) {
 66+ $hour = date( "G", $actual_date );
 67+ } else {
 68+ $hour = date( "g", $actual_date );
 69+ }
 70+ $minute = date( "i", $actual_date );
 71+ $second = date( "s", $actual_date );
 72+ if ( ! $sfg24HourTime ) {
 73+ $ampm24h = date( "A", $actual_date );
 74+ }
 75+ $timezone = date( "T", $actual_date );
 76+ // Restore back to the server's timezone.
 77+ if ( $datetime == 'now' ) {
 78+ if ( isset( $wgLocaltimezone ) ) {
 79+ date_default_timezone_set( $serverTimezone );
 80+ }
 81+ }
 82+ }
 83+ } else {
 84+ $cur_date = getdate();
 85+ $hour = null;
 86+ $minute = null;
 87+ $second = "00"; // default at least this value
 88+ $ampm24h = "";
 89+ $timezone = "";
 90+ }
 91+
 92+ $text = parent::getMainHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args );
 93+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 94+ $text .= ' &#160;<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $disabled_text . '>';
 95+ $sfgTabIndex++;
 96+ $text .= ' :<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $disabled_text . '>';
 97+ $sfgTabIndex++;
 98+ $text .= ':<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $disabled_text . '>' . "\n";
 99+
 100+ if ( ! $sfg24HourTime ) {
 101+ $sfgTabIndex++;
 102+ $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
 103+ $ampm24h_options = array( '', 'AM', 'PM' );
 104+ foreach ( $ampm24h_options as $value ) {
 105+ $text .= " <option value=\"$value\"";
 106+ if ( $value == $ampm24h ) { $text .= " selected=\"selected\""; }
 107+ $text .= ">$value</option>\n";
 108+ }
 109+ $text .= " </select>\n";
 110+ }
 111+
 112+ if ( $include_timezone ) {
 113+ $sfgTabIndex++;
 114+ $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="3"/ ' . $disabled_text . '>' . "\n";
 115+ }
 116+
 117+ return $text;
 118+ }
 119+
 120+ public static function getParameters() {
 121+ $params = parent::getParameters();
 122+ $params[] = array( 'name' => 'include timezone', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_includetimezone' ) );
 123+ return $params;
 124+ }
 125+
 126+ /**
 127+ * Returns the HTML code to be included in the output page for this input.
 128+ */
 129+ public function getHtmlText() {
 130+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 131+ }
 132+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_DateTimeInput.php
___________________________________________________________________
Added: svn:eol-style
1133 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_DropdownInput.php
@@ -0,0 +1,105 @@
 2+<?php
 3+/**
 4+ * File holding the SFDropdownInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFDropdownInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFDropdownInput extends SFEnumInput {
 20+ public static function getName() {
 21+ return 'dropdown';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array(
 26+ 'enumeration' => array()
 27+ );
 28+ }
 29+
 30+ public static function getOtherPropTypesHandled() {
 31+ return array( '_boo' );
 32+ }
 33+
 34+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 35+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 36+
 37+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 38+ if ( array_key_exists( 'class', $other_args ) ) {
 39+ $className .= " " . $other_args['class'];
 40+ }
 41+ $input_id = "input_$sfgFieldNum";
 42+ if ( array_key_exists( 'show on select', $other_args ) ) {
 43+ $className .= " sfShowIfSelected";
 44+ foreach ( $other_args['show on select'] as $div_id => $options ) {
 45+ if ( array_key_exists( $input_id, $sfgShowOnSelect ) ) {
 46+ $sfgShowOnSelect[$input_id][] = array( $options, $div_id );
 47+ } else {
 48+ $sfgShowOnSelect[$input_id] = array( array( $options, $div_id ) );
 49+ }
 50+ }
 51+ }
 52+ $innerDropdown = "";
 53+ // Add a blank value at the beginning, unless this is a
 54+ // mandatory field and there's a current value in place
 55+ // (either through a default value or because we're editing
 56+ // an existing page).
 57+ if ( ! $is_mandatory || $cur_value == '' ) {
 58+ $innerDropdown .= " <option value=\"\"></option>\n";
 59+ }
 60+ if ( ( $possible_values = $other_args['possible_values'] ) == null ) {
 61+ // If it's a Boolean property, display 'Yes' and 'No'
 62+ // as the values.
 63+ if ( array_key_exists( 'property_type', $other_args ) && $other_args['property_type'] == '_boo' ) {
 64+ $possible_values = array(
 65+ SFUtils::getWordForYesOrNo( true ),
 66+ SFUtils::getWordForYesOrNo( false ),
 67+ );
 68+ } else {
 69+ $possible_values = array();
 70+ }
 71+ }
 72+ foreach ( $possible_values as $possible_value ) {
 73+ $optionAttrs = array( 'value' => $possible_value );
 74+ if ( $possible_value == $cur_value ) {
 75+ $optionAttrs['selected'] = "selected";
 76+ }
 77+ if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) {
 78+ $label = $other_args['value_labels'][$possible_value];
 79+ } else {
 80+ $label = $possible_value;
 81+ }
 82+ $innerDropdown .= Xml::element( 'option', $optionAttrs, $label );
 83+ }
 84+ $selectAttrs = array(
 85+ 'id' => $input_id,
 86+ 'tabindex' => $sfgTabIndex,
 87+ 'name' => $input_name,
 88+ 'class' => $className
 89+ );
 90+ if ( $is_disabled ) {
 91+ $selectAttrs['disabled'] = 'disabled';
 92+ }
 93+ $text = Xml::tags( 'select', $selectAttrs, $innerDropdown );
 94+ $spanClass = "inputSpan";
 95+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 96+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 97+ return $text;
 98+ }
 99+
 100+ /**
 101+ * Returns the HTML code to be included in the output page for this input.
 102+ */
 103+ public function getHtmlText() {
 104+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 105+ }
 106+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_DropdownInput.php
___________________________________________________________________
Added: svn:eol-style
1107 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_YearInput.php
@@ -0,0 +1,60 @@
 2+<?php
 3+/**
 4+ * File holding the SFYearInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFYearInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFYearInput extends SFTextInput {
 20+ public static function getName() {
 21+ return 'year';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array();
 26+ }
 27+
 28+ public static function getOtherPropTypesHandled() {
 29+ return array( '_dat' );
 30+ }
 31+
 32+ public static function getDefaultPropTypeLists() {
 33+ return array();
 34+ }
 35+
 36+ public static function getOtherPropTypeListsHandled() {
 37+ return array();
 38+ }
 39+
 40+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 41+ $other_args['size'] = 4;
 42+ return parent::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 43+ }
 44+
 45+ public static function getParameters() {
 46+ $params = array();
 47+ $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) );
 48+ $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) );
 49+ $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) );
 50+ $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) );
 51+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 52+ return $params;
 53+ }
 54+
 55+ /**
 56+ * Returns the HTML code to be included in the output page for this input.
 57+ */
 58+ public function getHtmlText() {
 59+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 60+ }
 61+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_YearInput.php
___________________________________________________________________
Added: svn:eol-style
162 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
@@ -0,0 +1,218 @@
 2+<?php
 3+/**
 4+ * File holding the SFTextWithAutocompleteInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFTextWithAutocompleteInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFTextWithAutocompleteInput extends SFTextInput {
 20+ public static function getName() {
 21+ return 'text with autocomplete';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array(
 26+ '_wpg' => array()
 27+ );
 28+ }
 29+
 30+ public static function getOtherPropTypesHandled() {
 31+ return array( '_str' );
 32+ }
 33+
 34+ public static function getDefaultPropTypeLists() {
 35+ return array(
 36+ '_wpg' => array( 'is_list' => true, 'size' => 100 )
 37+ );
 38+ }
 39+
 40+ public static function getOtherPropTypeListsHandled() {
 41+ return array( '_str' );
 42+ }
 43+
 44+ public static function getAutocompletionTypeAndSource( &$field_args ) {
 45+ if ( array_key_exists( 'values from property', $field_args ) ) {
 46+ $autocompletionSource = $field_args['values from property'];
 47+ $propValue = SMWPropertyValue::makeUserProperty( $autocompletionSource );
 48+ if ( $propValue->getPropertyTypeID() == '_wpg' ) {
 49+ $autocompleteFieldType = 'relation';
 50+ } else {
 51+ $autocompleteFieldType = 'attribute';
 52+ }
 53+ } elseif ( array_key_exists( 'values from category', $field_args ) ) {
 54+ $autocompleteFieldType = 'category';
 55+ $autocompletionSource = $field_args['values from category'];
 56+ } elseif ( array_key_exists( 'values from concept', $field_args ) ) {
 57+ $autocompleteFieldType = 'concept';
 58+ $autocompletionSource = $field_args['values from concept'];
 59+ } elseif ( array_key_exists( 'values from namespace', $field_args ) ) {
 60+ $autocompleteFieldType = 'namespace';
 61+ $autocompletionSource = $field_args['values from namespace'];
 62+ } elseif ( array_key_exists( 'values from url', $field_args ) ) {
 63+ $autocompleteFieldType = 'external_url';
 64+ $autocompletionSource = $field_args['values from url'];
 65+ // Autocompletion from URL is always done remotely.
 66+ $field_args['remote autocompletion'] = true;
 67+ } elseif ( array_key_exists( 'values', $field_args ) ) {
 68+ global $sfgFieldNum;
 69+ $autocompleteFieldType = 'values';
 70+ $autocompletionSource = "values-$sfgFieldNum";
 71+ } elseif ( array_key_exists( 'autocomplete field type', $field_args ) ) {
 72+ $autocompleteFieldType = $field_args['autocomplete field type'];
 73+ $autocompletionSource = $field_args['autocompletion source'];
 74+ } elseif ( array_key_exists( 'semantic_property', $field_args ) ) {
 75+ $autocompletionSource = $field_args['semantic_property'];
 76+ $propValue = SMWPropertyValue::makeUserProperty( $autocompletionSource );
 77+ if ( $propValue->getPropertyTypeID() == '_wpg' ) {
 78+ $autocompleteFieldType = 'relation';
 79+ } else {
 80+ $autocompleteFieldType = 'attribute';
 81+ }
 82+ } else {
 83+ $autocompleteFieldType = null;
 84+ $autocompletionSource = null;
 85+ }
 86+
 87+ if ( $autocompleteFieldType != 'external_url' ) {
 88+ global $wgContLang;
 89+ $autocompletionSource = $wgContLang->ucfirst( $autocompletionSource );
 90+ }
 91+
 92+ return array( $autocompleteFieldType, $autocompletionSource );
 93+ }
 94+
 95+ public static function setAutocompleteValues( $field_args ) {
 96+ global $sfgAutocompleteValues;
 97+
 98+ // Get all autocomplete-related values, plus delimiter value
 99+ // (it's needed also for the 'uploadable' link, if there is one).
 100+ list( $autocompleteFieldType, $autocompletionSource ) =
 101+ self::getAutocompletionTypeAndSource( $field_args );
 102+ $autocompleteSettings = $autocompletionSource;
 103+ $is_list = ( array_key_exists( 'is_list', $field_args ) && $field_args['is_list'] == true );
 104+ if ( $is_list ) {
 105+ $autocompleteSettings .= ",list";
 106+ if ( array_key_exists( 'delimiter', $field_args ) ) {
 107+ $delimiter = $field_args['delimiter'];
 108+ $autocompleteSettings .= "," . $delimiter;
 109+ } else {
 110+ $delimiter = ",";
 111+ }
 112+ } else {
 113+ $delimiter = null;
 114+ }
 115+
 116+ $remoteDataType = null;
 117+ if ( array_key_exists( 'remote autocompletion', $field_args ) &&
 118+ $field_args['remote autocompletion'] == true ) {
 119+ $remoteDataType = $autocompleteFieldType;
 120+ } elseif ( $autocompletionSource != '' ) {
 121+ // @TODO - that count() check shouldn't be necessary
 122+ if ( array_key_exists( 'possible_values', $field_args ) &&
 123+ count( $field_args['possible_values'] ) > 0 ) {
 124+ $autocompleteValues = $field_args['possible_values'];
 125+ } elseif ( $autocompleteFieldType == 'values' ) {
 126+ $autocompleteValues = explode( ',', $field_args['values'] );
 127+ } else {
 128+ $autocompleteValues = SFUtils::getAutocompleteValues( $autocompletionSource, $autocompleteFieldType );
 129+ }
 130+ $sfgAutocompleteValues[$autocompleteSettings] = $autocompleteValues;
 131+ }
 132+ return array( $autocompleteSettings, $remoteDataType, $delimiter );
 133+ }
 134+
 135+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 136+ // Backwards compatibility, for pre-SF-2.1 forms:
 137+ // if 'no autocomplete' was specified, switch to SFTextInput.
 138+ if ( array_key_exists( 'no autocomplete', $other_args ) &&
 139+ $other_args['no autocomplete'] == true ) {
 140+ unset( $other_args['autocompletion source'] );
 141+ return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 142+ }
 143+
 144+ global $sfgTabIndex, $sfgFieldNum;
 145+
 146+ list( $autocompleteSettings, $remoteDataType, $delimiter ) = self::setAutocompleteValues( $other_args );
 147+
 148+ $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
 149+ if ( array_key_exists( 'class', $other_args ) )
 150+ $className .= " " . $other_args['class'];
 151+ $input_id = "input_" . $sfgFieldNum;
 152+
 153+ if ( array_key_exists( 'size', $other_args ) ) {
 154+ $size = $other_args['size'];
 155+ } elseif ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] ) {
 156+ $size = "100";
 157+ } else {
 158+ $size = "35";
 159+ }
 160+
 161+ $inputAttrs = array(
 162+ 'type' => 'text',
 163+ 'id' => $input_id,
 164+ 'name' => $input_name,
 165+ 'value' => $cur_value,
 166+ 'size' => $size,
 167+ 'class' => $className,
 168+ 'tabindex' => $sfgTabIndex,
 169+ 'autocompletesettings' => $autocompleteSettings,
 170+ );
 171+ if ( !is_null( $remoteDataType ) ) {
 172+ $inputAttrs['autocompletedatatype'] = $remoteDataType;
 173+ }
 174+ if ( $is_disabled ) {
 175+ $inputAttrs['disabled'] = 'disabled';
 176+ }
 177+ if ( array_key_exists( 'maxlength', $other_args ) ) {
 178+ $inputAttrs['maxlength'] = $other_args['maxlength'];
 179+ }
 180+ $text = "\n\t" . Xml::element( 'input', $inputAttrs ) . "\n";
 181+
 182+ if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
 183+ if ( array_key_exists( 'default filename', $other_args ) ) {
 184+ $default_filename = $other_args['default filename'];
 185+ } else {
 186+ $default_filename = "";
 187+ }
 188+ $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
 189+ }
 190+
 191+ $spanClass = "inputSpan";
 192+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 193+ $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 194+
 195+ return $text;
 196+ }
 197+
 198+ public static function getAutocompletionParameters() {
 199+ $params = SFEnumInput::getValuesParameters();
 200+ $params[] = array( 'name' => 'values from url', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromurl' ) );
 201+ $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_remoteautocompletion' ) );
 202+ $params[] = array( 'name' => 'list', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_list' ) );
 203+ $params[] = array( 'name' => 'delimiter', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_delimiter' ) );
 204+ return $params;
 205+ }
 206+
 207+ public static function getParameters() {
 208+ $params = parent::getParameters();
 209+ $params = array_merge( $params, self::getAutocompletionParameters() );
 210+ return $params;
 211+ }
 212+
 213+ /**
 214+ * Returns the HTML code to be included in the output page for this input.
 215+ */
 216+ public function getHtmlText() {
 217+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 218+ }
 219+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php
___________________________________________________________________
Added: svn:eol-style
1220 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
@@ -0,0 +1,310 @@
 2+<?php
 3+/**
 4+ * File holding the SFFormInput class.
 5+ *
 6+ * The predecessor of this file held several subclasses of SFFormInput. The
 7+ * authors can not be sorted out with certainty anymore, thus are all listed
 8+ * here.
 9+ *
 10+ * @author Yaron Koren
 11+ * @author Jeffrey Stuckman
 12+ * @author Matt Williamson
 13+ * @author Patrick Nagel
 14+ * @author Sanyam Goyal
 15+ * @author Stephan Gambke
 16+ * @file
 17+ * @ingroup SF
 18+ */
 19+
 20+if ( !defined( 'SF_VERSION' ) ) {
 21+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 22+}
 23+
 24+/**
 25+ * Parent class for all form input classes.
 26+ * @ingroup SFFormInput
 27+ */
 28+abstract class SFFormInput {
 29+
 30+ protected $mInputNumber;
 31+ protected $mCurrentValue;
 32+ protected $mInputName;
 33+ protected $mIsMandatory;
 34+ protected $mIsDisabled;
 35+ protected $mOtherArgs;
 36+
 37+ private $mJsInitFunctionData = array();
 38+ private $mJsValidationFunctionData = array();
 39+
 40+
 41+ /**
 42+ * Constructor for the SFFormInput class.
 43+ *
 44+ * @param String $input_number
 45+ * The number of the input in the form. For a simple HTML input element
 46+ * this should end up in the id attribute in the format 'input_<number>'.
 47+ * @param String $cur_value
 48+ * The current value of the input field. For a simple HTML input
 49+ * element this should end up in the value attribute.
 50+ * @param String $input_name
 51+ * The name of the input. For a simple HTML input element this should
 52+ * end up in the name attribute.
 53+ * @param Array $other_args
 54+ * An associative array of other parameters that were present in the
 55+ * input definition.
 56+ */
 57+ public function __construct ( $input_number, $cur_value, $input_name, $other_args ) {
 58+
 59+ $this->mInputNumber = $input_number;
 60+ $this->mCurrentValue = $cur_value;
 61+ $this->mInputName = $input_name;
 62+ $this->mOtherArgs = $other_args;
 63+
 64+ }
 65+
 66+ /**
 67+ * Returns the name of the input type this class handles.
 68+ *
 69+ * This is the name to be used in the field definition for the "input type"
 70+ * parameter.
 71+ *
 72+ * @return String The name of the input type this class handles.
 73+ * @fixme Should be declared abstract. Static functions cannot be abstract.
 74+ * Do we need this method at all? The name should be set outside this class
 75+ * when the input type is registered.
 76+ */
 77+ public static function getName() {
 78+ return null;
 79+ }
 80+
 81+ /**
 82+ * Returns the set of SMW property types which this input can
 83+ * handle.
 84+ *
 85+ * @return Array of Strings
 86+ */
 87+ public static function getHandledPropertyTypes() {
 88+ return null;
 89+ }
 90+
 91+ /**
 92+ * Returns the set of parameters for this form input.
 93+ */
 94+ public static function getAllowedParameters() {
 95+ $params = array();
 96+ $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) );
 97+ $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) );
 98+ $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) );
 99+ $params[] = array( 'name' => 'property', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_property' ) );
 100+ $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) );
 101+ return $params;
 102+ }
 103+
 104+ /**
 105+ * Return an array of the default parameters for this input where the
 106+ * parameter name is the key while the parameter value is the value.
 107+ *
 108+ * @return Array of Strings
 109+ */
 110+ public function getDefaultParameters() {
 111+ return null;
 112+ }
 113+
 114+ /**
 115+ * Returns the HTML code to be included in the output page for this input.
 116+ *
 117+ * Ideally this HTML code should provide a basic functionality even if the
 118+ * browser is not Javascript capable. I.e. even without Javascript the user
 119+ * should be able to input values.
 120+ *
 121+ * This function is not used yet.
 122+ */
 123+ public function getHtmlText() {
 124+ return null;
 125+ }
 126+
 127+ /**
 128+ *
 129+ * @return Boolean True, if this input type can handle lists
 130+ */
 131+ public static function canHandleLists() {
 132+ return false;
 133+ }
 134+
 135+ /**
 136+ * Returns the name and parameters for the initialization Javascript
 137+ * function for this input type, if any.
 138+ *
 139+ * This function is not used yet.
 140+ */
 141+ final public function getJsInitFunctionData() {
 142+ return $this->mJsInitFunctionData;
 143+ }
 144+
 145+ /**
 146+ * Returns the name and parameters for the validation Javascript
 147+ * functions for this input type, if any.
 148+ *
 149+ * This function is not used yet.
 150+ */
 151+ final public function getJsValidationFunctionData() {
 152+ return $this->mJsValidationFunctionData;
 153+ }
 154+
 155+ /**
 156+ * For each input type one or more JavaScript initialization functions may
 157+ * be specified.
 158+ *
 159+ * <b>This function is not used yet.</b>
 160+ *
 161+ * They are called to initialize the input after the page html has loaded
 162+ * (or for "multiple" templates after the page fragment has loaded).
 163+ *
 164+ * The JavaScript function specified here must be in the top level scope of
 165+ * the document. When it is called it will get the input's id attribute as
 166+ * the first parameter and the specified param as the second.
 167+ *
 168+ *
 169+ * Examples:
 170+ *
 171+ * Adding initFoo like this: <code>addJsInitFunctionData( "initFoo", "'bar'" );</code> will result in this JavaScript call: <code>initFoo( inputID, 'bar' );</code>.
 172+ *
 173+ * Adding initFoo like this: <code>addJsInitFunctionData( "initFoo", "array('bar', 'baz'" );</code> will result in this JavaScript call: <code>initFoo( inputID, array('bar', 'baz') );</code>.
 174+ *
 175+ *
 176+ * @param String $name The name of the initialization function.
 177+ * @param String $param The parameter passed to the initialization function.
 178+ */
 179+ final public function addJsInitFunctionData( $name, $param ) {
 180+ $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param );
 181+ }
 182+
 183+ /**
 184+ * For each input type one or more JavaScript validation functions may
 185+ * be specified.
 186+ *
 187+ * <b>Not used yet.</b>
 188+ *
 189+ * They are called to validate the input before the form is submitted for
 190+ * saving or preview.
 191+ *
 192+ * The JavaScript function specified here must be in the top level scope of
 193+ * the document. When it is called it will get the input's id attribute as
 194+ * the first parameter and the specified param as the second.
 195+ *
 196+ *
 197+ * Examples:
 198+ *
 199+ * Adding validateFoo like this: <code>addJsValidationFunctionData( "initFoo", "'bar'" );</code> will result in this JavaScript call: <code>validateFoo( inputID, 'bar' );</code>.
 200+ *
 201+ * Adding validateFoo like this: <code>addJsValidationFunctionData( "initFoo", "array('bar', 'baz'" );</code> will result in this JavaScript call: <code>validateFoo( inputID, array('bar', 'baz') );</code>.
 202+ *
 203+ *
 204+ * @param String $name The name of the initialization function.
 205+ * @param String $param The parameter passed to the initialization function.
 206+ */
 207+ final public function addJsValidationFunctionData( $name, $param ) {
 208+ $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param );
 209+ }
 210+
 211+
 212+
 213+
 214+
 215+
 216+
 217+
 218+
 219+ /**
 220+ * Returns the set of SMW property types for which this input is
 221+ * meant to be the default one - ideally, no more than one input
 222+ * should declare itself the default for any specific type.
 223+ *
 224+ * @deprecated
 225+ * @return Array of arrays (key is the property type, value is an array of
 226+ * default args to be used for this input)
 227+ */
 228+ public static function getDefaultPropTypes() {
 229+ return array();
 230+ }
 231+
 232+ /**
 233+ * Returns the set of SMW property types for which this input is
 234+ * meant to be the default one - ideally, no more than one input
 235+ * should declare itself the default for any specific type.
 236+ *
 237+ * @deprecated
 238+ * @return Array of arrays (key is the property type, value is an array of
 239+ * default args to be used for this input)
 240+ */
 241+ public static function getDefaultPropTypeLists() {
 242+ return array();
 243+ }
 244+
 245+ /**
 246+ * Returns the set of SMW property types which this input can
 247+ * handle, but for which it isn't the default input.
 248+ *
 249+ * @deprecated
 250+ * @return Array of strings
 251+ */
 252+ public static function getOtherPropTypesHandled() {
 253+ return array();
 254+ }
 255+
 256+ /**
 257+ * Returns the set of SMW property types which this input can
 258+ * handle, but for which it isn't the default input.
 259+ *
 260+ * @deprecated
 261+ * @return Array of strings
 262+ */
 263+ public static function getOtherPropTypeListsHandled() {
 264+ return array();
 265+ }
 266+
 267+
 268+// /**
 269+// * SFFormPrinter depends on a statically callable function.
 270+// *
 271+// * @deprecated
 272+// * @param <type> $cur_value
 273+// * @param <type> $input_name
 274+// * @param <type> $is_mandatory
 275+// * @param <type> $is_disabled
 276+// * @param <type> $other_args
 277+// */
 278+// public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 279+// global $sfgFieldNum;
 280+//
 281+// $input = new self( $sfgFieldNum, $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 282+//
 283+// $initFunctionData = $input->getJsInitFunctionData();
 284+//
 285+// if ( $initFunctionData ) {
 286+// $jstext = <<<JAVASCRIPT
 287+// jQuery(function(){ jQuery('#input_{$sfgFieldNum}').SemanticForms_registerInputInit( {$initFunctionData['name']}, {$initFunctionData['param']} ); });
 288+// JAVASCRIPT;
 289+//
 290+// // insert the code of the JS init function into the pages code
 291+// $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
 292+// }
 293+//
 294+// $validationFunctionData = $input->getJsValidationFunctionData();
 295+//
 296+// if ( $validationFunctionData ) {
 297+// $validationFunctionName = $validationFunctionData['name'];
 298+// $validationFunctionParam = $validationFunctionData['param'];
 299+//
 300+// $jstext = <<<JAVASCRIPT
 301+// jQuery(function(){ jQuery('#input_{$sfgFieldNum}').SemanticForms_registerInputValidation( {$validationFunctionData['name']}, {$validationFunctionData['param']} ); });
 302+// JAVASCRIPT;
 303+//
 304+// // insert the code of the JS init function into the pages code
 305+// $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
 306+// }
 307+//
 308+// return $input->getHtmlText();
 309+// }
 310+
 311+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
___________________________________________________________________
Added: svn:eol-style
1312 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_EnumInput.php
@@ -0,0 +1,42 @@
 2+<?php
 3+/**
 4+ * File holding the SFEnumInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFEnumInput class.
 16+ * The base class for every form input that holds a pre-set enumeration
 17+ * of values.
 18+ *
 19+ * @ingroup SFFormInput
 20+ */
 21+abstract class SFEnumInput extends SFFormInput {
 22+
 23+ public static function getOtherPropTypesHandled() {
 24+ return array( 'enumeration', '_boo' );
 25+ }
 26+
 27+ public static function getValuesParameters() {
 28+ $params = array();
 29+ $params[] = array( 'name' => 'values', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_values' ) );
 30+ $params[] = array( 'name' => 'values from property', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromproperty' ) );
 31+ $params[] = array( 'name' => 'values from category', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromcategory' ) );
 32+ $params[] = array( 'name' => 'values from namespace', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromnamespace' ) );
 33+ $params[] = array( 'name' => 'values from concept', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_valuesfromconcept' ) );
 34+ return $params;
 35+ }
 36+
 37+ public static function getParameters() {
 38+ $params = parent::getParameters();
 39+ $params = array_merge( $params, self::getValuesParameters() );
 40+ $params[] = array( 'name' => 'show on select', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_showonselect' ) );
 41+ return $params;
 42+ }
 43+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_EnumInput.php
___________________________________________________________________
Added: svn:eol-style
144 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php
@@ -0,0 +1,100 @@
 2+<?php
 3+/**
 4+ * File holding the SFComboBoxInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFComboBoxInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFComboBoxInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'combobox';
 22+ }
 23+
 24+ public static function getOtherPropTypesHandled() {
 25+ return array( '_wpg', '_str' );
 26+ }
 27+
 28+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 29+ // For backward compatibility with pre-SF-2.1 forms
 30+ if ( array_key_exists( 'no autocomplete', $other_args ) &&
 31+ $other_args['no autocomplete'] == true ) {
 32+ unset( $other_args['autocompletion source'] );
 33+ return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 34+ }
 35+
 36+ global $sfgTabIndex, $sfgFieldNum;
 37+
 38+ $className = "sfComboBox";
 39+ if ( $is_mandatory ) {
 40+ $className .= " mandatoryField";
 41+ }
 42+ if ( array_key_exists( 'class', $other_args ) ) {
 43+ $className .= " " . $other_args['class'];
 44+ }
 45+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 46+
 47+ if ( array_key_exists( 'size', $other_args ) ) {
 48+ $size = $other_args['size'];
 49+ } else {
 50+ $size = "35";
 51+ }
 52+ // There's no direct correspondence between the 'size='
 53+ // attribute for text inputs and the number of pixels, but
 54+ // multiplying by 6 seems to be about right for the major
 55+ // browsers.
 56+ $pixel_width = $size * 6 . "px";
 57+
 58+ list( $autocompleteFieldType, $autocompletionSource ) =
 59+ SFTextWithAutocompleteInput::getAutocompletionTypeAndSource( $other_args );
 60+ $values = SFUtils::getAutocompleteValues( $autocompletionSource, $autocompleteFieldType );
 61+ $autocompletionSource = str_replace( "'", "\'", $autocompletionSource );
 62+
 63+ $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
 64+ foreach ( $values as $value ) {
 65+ $optionsText .= Xml::element( 'option', array( 'value' => $value ), $value ) . "\n";
 66+ }
 67+
 68+ $selectAttrs = array(
 69+ 'id' => "input_$sfgFieldNum",
 70+ 'name' => $input_name,
 71+ 'class' => $className,
 72+ 'tabindex' => $sfgTabIndex,
 73+ 'autocompletesettings' => $autocompletionSource,
 74+ 'comboboxwidth' => $pixel_width,
 75+ );
 76+ if ( array_key_exists( 'existing values only', $other_args ) ) {
 77+ $selectAttrs['existingvaluesonly'] = 'true';
 78+ }
 79+ $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
 80+
 81+ $divClass = "ui-widget";
 82+ if ( $is_mandatory ) { $divClass .= " mandatory"; }
 83+ $text = Xml::tags( 'div', array( 'class' => $divClass ), $selectText );
 84+ return $text;
 85+ }
 86+
 87+ public static function getParameters() {
 88+ $params = parent::getParameters();
 89+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 90+ $params = array_merge( $params, SFEnumInput::getValuesParameters() );
 91+ $params[] = array( 'name' => 'existing values only', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
 92+ return $params;
 93+ }
 94+
 95+ /**
 96+ * Returns the HTML code to be included in the output page for this input.
 97+ */
 98+ public function getHtmlText() {
 99+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 100+ }
 101+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_ComboBoxInput.php
___________________________________________________________________
Added: svn:eol-style
1102 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_CategoryInput.php
@@ -0,0 +1,123 @@
 2+<?php
 3+/**
 4+ * File holding the SFCategoryInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFCategoryInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFCategoryInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'category';
 22+ }
 23+
 24+ public static function getOtherPropTypesHandled() {
 25+ return array( '_wpg' );
 26+ }
 27+
 28+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 29+ // escape if CategoryTree extension isn't included
 30+ if ( ! function_exists( 'efCategoryTreeParserHook' ) )
 31+ return null;
 32+
 33+ global $sfgTabIndex, $sfgFieldNum;
 34+
 35+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 36+ if ( array_key_exists( 'class', $other_args ) )
 37+ $className .= " " . $other_args['class'];
 38+ if ( array_key_exists( 'top category', $other_args ) ) {
 39+ $top_category = $other_args['top category'];
 40+ } else {
 41+ // escape - we can't do anything
 42+ return null;
 43+ }
 44+ $hideroot = array_key_exists( 'hideroot', $other_args );
 45+ if ( array_key_exists( 'height', $other_args ) ) {
 46+ $height = $other_args['height'];
 47+ } else {
 48+ $height = "100";
 49+ }
 50+ if ( array_key_exists( 'width', $other_args ) ) {
 51+ $width = $other_args['width'];
 52+ } else {
 53+ $width = "500";
 54+ }
 55+
 56+ $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">';
 57+
 58+ // Start with an initial "None" value, unless this is a
 59+ // mandatory field and there's a current value in place
 60+ // (either through a default value or because we're editing
 61+ // an existing page)
 62+ if ( ! $is_mandatory || $cur_value == '' ) {
 63+ $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""';
 64+ if ( ! $cur_value ) {
 65+ $text .= ' checked="checked"';
 66+ }
 67+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 68+ $text .= " $disabled_text/> <em>" . wfMsg( 'sf_formedit_none' ) . "</em>\n";
 69+ }
 70+
 71+ global $wgCategoryTreeMaxDepth;
 72+ $wgCategoryTreeMaxDepth = 10;
 73+ $tree = efCategoryTreeParserHook( $top_category,
 74+ array(
 75+ 'mode' => 'categories',
 76+ 'namespaces' => array( NS_CATEGORY ),
 77+ 'depth' => 10,
 78+ 'hideroot' => $hideroot,
 79+ )
 80+ );
 81+
 82+ // Capitalize the first letter, if first letters always get
 83+ // capitalized.
 84+ global $wgCapitalLinks;
 85+ if ( $wgCapitalLinks ) {
 86+ global $wgContLang;
 87+ $cur_value = $wgContLang->ucfirst( $cur_value );
 88+ }
 89+
 90+ $tree = preg_replace( '/(<a class="CategoryTreeLabel.*>)(.*)(<\/a>)/', '<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="$2" type="radio"> $1$2$3', $tree );
 91+ $tree = str_replace( "value=\"$cur_value\"", "value=\"$cur_value\" checked=\"checked\"", $tree );
 92+ // if it's disabled, set all to disabled
 93+ if ( $is_disabled ) {
 94+ $tree = str_replace( 'type="radio"', 'type="radio" disabled', $tree );
 95+ }
 96+
 97+ // Get rid of all the 'no subcategories' messages.
 98+ $tree = str_replace( '<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg( 'categorytree-no-subcategories' ) . '</i></div>', '', $tree );
 99+
 100+ $text .= $tree . '</div>';
 101+
 102+ $spanClass = "radioButtonSpan";
 103+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 104+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 105+
 106+ return $text;
 107+ }
 108+
 109+ public static function getParameters() {
 110+ $params = parent::getParameters();
 111+ $params[] = array( 'name' => 'top category', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_topcategory' ) );
 112+ $params[] = array( 'name' => 'hideroot', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_hideroot' ) );
 113+ $params[] = array( 'name' => 'height', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_height' ) );
 114+ $params[] = array( 'name' => 'width', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_width' ) );
 115+ return $params;
 116+ }
 117+
 118+ /**
 119+ * Returns the HTML code to be included in the output page for this input.
 120+ */
 121+ public function getHtmlText() {
 122+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 123+ }
 124+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_CategoryInput.php
___________________________________________________________________
Added: svn:eol-style
1125 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_DateInput.php
@@ -0,0 +1,121 @@
 2+<?php
 3+/**
 4+ * File holding the SFDateInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFDateInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFDateInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'date';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array( '_dat' => array() );
 26+ }
 27+
 28+ public static function monthDropdownHTML( $cur_month, $input_name, $is_disabled ) {
 29+ global $sfgTabIndex, $wgAmericanDates;
 30+
 31+ $optionsText = "";
 32+ $month_names = SFFormUtils::getMonthNames();
 33+ foreach ( $month_names as $i => $name ) {
 34+ // pad out month to always be two digits
 35+ $month_value = ( $wgAmericanDates == true ) ? $name : str_pad( $i + 1, 2, "0", STR_PAD_LEFT );
 36+ $optionAttrs = array ( 'value' => $month_value );
 37+ if ( $name == $cur_month || ( $i + 1 ) == $cur_month ) {
 38+ $optionAttrs['selected'] = 'selected';
 39+ }
 40+ $optionsText .= Xml::element( 'option', $optionAttrs, $name );
 41+ }
 42+ $selectAttrs = array(
 43+ 'class' => 'monthInput',
 44+ 'name' => $input_name . '[month]',
 45+ 'tabindex' => $sfgTabIndex
 46+ );
 47+ if ( $is_disabled ) {
 48+ $selectAttrs['disabled'] = 'disabled';
 49+ }
 50+ $text = Xml::tags( 'select', $selectAttrs, $optionsText );
 51+ return $text;
 52+ }
 53+
 54+ public static function getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 55+ global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
 56+
 57+ $input_id = "input_$sfgFieldNum";
 58+
 59+ if ( $date ) {
 60+ // Can show up here either as an array or a string,
 61+ // depending on whether it came from user input or a
 62+ // wiki page.
 63+ if ( is_array( $date ) ) {
 64+ $year = $date['year'];
 65+ $month = $date['month'];
 66+ $day = $date['day'];
 67+ } else {
 68+ // handle 'default=now'
 69+ if ( $date == 'now' ) {
 70+ global $wgLocaltimezone;
 71+ if ( isset( $wgLocaltimezone ) ) {
 72+ $serverTimezone = date_default_timezone_get();
 73+ date_default_timezone_set( $wgLocaltimezone );
 74+ }
 75+ $date = date( 'Y/m/d' );
 76+ if ( isset( $wgLocaltimezone ) ) {
 77+ date_default_timezone_set( $serverTimezone );
 78+ }
 79+ }
 80+ $actual_date = new SMWTimeValue( '_dat' );
 81+ $actual_date->setUserValue( $date );
 82+ $year = $actual_date->getYear();
 83+ // TODO - the code to convert from negative to
 84+ // BC notation should be in SMW itself.
 85+ if ( $year < 0 ) { $year = ( $year * - 1 + 1 ) . " BC"; }
 86+ $month = $actual_date->getMonth();
 87+ $day = $actual_date->getDay();
 88+ }
 89+ } else {
 90+ $cur_date = getdate();
 91+ $year = $cur_date['year'];
 92+ $month = $cur_date['month'];
 93+ $day = null; // no need for day
 94+ }
 95+ $text = "";
 96+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 97+ $monthInput = self::monthDropdownHTML( $month, $input_name, $is_disabled );
 98+ $dayInput = ' <input tabindex="' . $sfgTabIndex . '" class="dayInput" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>';
 99+ if ( $wgAmericanDates ) {
 100+ $text .= "$monthInput\n$dayInput\n";
 101+ } else {
 102+ $text .= "$dayInput\n$monthInput\n";
 103+ }
 104+ $text .= ' <input tabindex="' . $sfgTabIndex . '" class="yearInput" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
 105+ return $text;
 106+ }
 107+
 108+ public static function getHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 109+ $text = self::getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args );
 110+ $spanClass = "dateInput";
 111+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 112+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 113+ return $text;
 114+ }
 115+
 116+ /**
 117+ * Returns the HTML code to be included in the output page for this input.
 118+ */
 119+ public function getHtmlText() {
 120+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 121+ }
 122+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_DateInput.php
___________________________________________________________________
Added: svn:eol-style
1123 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php
@@ -0,0 +1,113 @@
 2+<?php
 3+/**
 4+ * File holding the SFTextAreaInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFTextAreaInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFTextAreaInput extends SFFormInput {
 20+ public static function getName() {
 21+ return 'textarea';
 22+ }
 23+
 24+ public static function getDefaultPropTypes() {
 25+ return array( '_txt' => array(), '_cod' => array() );
 26+ }
 27+
 28+ public static function getOtherPropTypesHandled() {
 29+ return array( '_wpg', '_str' );
 30+ }
 31+
 32+ public static function getOtherPropTypeListsHandled() {
 33+ return array( '_wpg', '_str' );
 34+ }
 35+
 36+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 37+ global $sfgTabIndex, $sfgFieldNum;
 38+
 39+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 40+ if ( array_key_exists( 'class', $other_args ) ) {
 41+ $className .= " " . $other_args['class'];
 42+ }
 43+ // Use a special ID for the free text field, for FCK's needs.
 44+ $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
 45+
 46+ if ( array_key_exists( 'rows', $other_args ) ) {
 47+ $rows = $other_args['rows'];
 48+ } else {
 49+ $rows = 5;
 50+ }
 51+
 52+ if ( array_key_exists( 'autogrow', $other_args ) ) {
 53+ $className .= ' autoGrow';
 54+ }
 55+
 56+ $textarea_attrs = array(
 57+ 'tabindex' => $sfgTabIndex,
 58+ 'id' => $input_id,
 59+ 'name' => $input_name,
 60+ 'rows' => $rows,
 61+ 'class' => $className,
 62+ );
 63+
 64+ if ( array_key_exists( 'cols', $other_args ) ) {
 65+ $textarea_attrs['cols'] = $other_args['cols'];
 66+ } else {
 67+ $textarea_attrs['style'] = "width: 100%";
 68+ }
 69+
 70+ if ( $is_disabled ) {
 71+ $textarea_attrs['disabled'] = 'disabled';
 72+ }
 73+ if ( array_key_exists( 'maxlength', $other_args ) ) {
 74+ $maxlength = $other_args['maxlength'];
 75+ // For every actual character pressed (i.e., excluding
 76+ // things like the Shift key), reduce the string to its
 77+ // allowed length if it's exceeded that.
 78+ // This JS code is complicated so that it'll work
 79+ // correctly in IE - IE moves the cursor to the end
 80+ // whenever this.value is reset, so we'll make sure to
 81+ // do that only when we need to.
 82+ $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
 83+ $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
 84+ $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
 85+ }
 86+ // Bug in Xml::element()? It doesn't close the textarea tag
 87+ // properly if the text inside is null - set it to '' instead.
 88+ if ( is_null( $cur_value ) ) {
 89+ $cur_value = '';
 90+ }
 91+ $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
 92+ $spanClass = "inputSpan";
 93+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 94+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 95+ return $text;
 96+ }
 97+
 98+ public static function getParameters() {
 99+ $params = parent::getParameters();
 100+ $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
 101+ $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
 102+ $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
 103+ $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
 104+ $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
 105+ return $params;
 106+ }
 107+
 108+ /**
 109+ * Returns the HTML code to be included in the output page for this input.
 110+ */
 111+ public function getHtmlText() {
 112+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 113+ }
 114+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php
___________________________________________________________________
Added: svn:eol-style
1115 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxesInput.php
@@ -0,0 +1,116 @@
 2+<?php
 3+/**
 4+ * File holding the SFCheckboxesInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFCheckboxesInput class.
 16+ *
 17+ * @ingroup SFFormInput
 18+ */
 19+class SFCheckboxesInput extends SFMultiEnumInput {
 20+
 21+ public static function getName() {
 22+ return 'checkboxes';
 23+ }
 24+
 25+ public static function getDefaultPropTypeLists() {
 26+ return array(
 27+ 'enumeration' => array()
 28+ );
 29+ }
 30+
 31+ public static function getOtherPropTypeListsHandled() {
 32+ return array();
 33+ }
 34+
 35+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 36+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 37+
 38+ $checkbox_class = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 39+ $span_class = "checkboxSpan";
 40+ if ( array_key_exists( 'class', $other_args ) )
 41+ $span_class .= " " . $other_args['class'];
 42+ $input_id = "input_$sfgFieldNum";
 43+ // get list delimiter - default is comma
 44+ if ( array_key_exists( 'delimiter', $other_args ) ) {
 45+ $delimiter = $other_args['delimiter'];
 46+ } else {
 47+ $delimiter = ",";
 48+ }
 49+ $cur_values = SFUtils::getValuesArray( $cur_value, $delimiter );
 50+
 51+ if ( ( $possible_values = $other_args['possible_values'] ) == null )
 52+ $possible_values = array();
 53+ $text = "";
 54+ foreach ( $possible_values as $key => $possible_value ) {
 55+ $cur_input_name = $input_name . "[" . $key . "]";
 56+
 57+ if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
 58+ $label = $other_args['value_labels'][$possible_value];
 59+ else
 60+ $label = $possible_value;
 61+
 62+ $checkbox_attrs = array(
 63+ 'type' => 'checkbox',
 64+ 'id' => $input_id,
 65+ 'tabindex' => $sfgTabIndex,
 66+ 'name' => $cur_input_name,
 67+ 'value' => $possible_value,
 68+ 'class' => $checkbox_class,
 69+ );
 70+ if ( in_array( $possible_value, $cur_values ) ) {
 71+ $checkbox_attrs['checked'] = 'checked';
 72+ }
 73+ if ( $is_disabled ) {
 74+ $checkbox_attrs['disabled'] = 'disabled';
 75+ }
 76+ $checkbox_input = Xml::element( 'input', $checkbox_attrs );
 77+
 78+ // Make a span around each checkbox, for CSS purposes.
 79+ $text .= ' ' . Xml::tags( 'span',
 80+ array( 'class' => $span_class ),
 81+ $checkbox_input . ' ' . $label
 82+ ) . "\n";
 83+ $sfgTabIndex++;
 84+ $sfgFieldNum++;
 85+ }
 86+
 87+ $outerSpanID = "span_$sfgFieldNum";
 88+ $outerSpanClass = "checkboxesSpan";
 89+ if ( $is_mandatory ) {
 90+ $outerSpanClass .= " mandatoryFieldSpan";
 91+ }
 92+
 93+ if ( array_key_exists( 'show on select', $other_args ) ) {
 94+ $outerSpanClass .= " sfShowIfChecked";
 95+ foreach ( $other_args['show on select'] as $div_id => $options ) {
 96+ if ( array_key_exists( $outerSpanID, $sfgShowOnSelect ) ) {
 97+ $sfgShowOnSelect[$outerSpanID][] = array( $options, $div_id );
 98+ } else {
 99+ $sfgShowOnSelect[$outerSpanID] = array( array( $options, $div_id ) );
 100+ }
 101+ }
 102+ }
 103+
 104+ $text .= SFFormUtils::hiddenFieldHTML( $input_name . '[is_list]', 1 );
 105+ $outerSpanAttrs = array( 'id' => $outerSpanID, 'class' => $outerSpanClass );
 106+ $text = "\t" . Xml::tags( 'span', $outerSpanAttrs, $text ) . "\n";
 107+
 108+ return $text;
 109+ }
 110+
 111+ /**
 112+ * Returns the HTML code to be included in the output page for this input.
 113+ */
 114+ public function getHtmlText() {
 115+ return self::getHTML( $this -> mCurrentValue, $this -> mInputName, $this -> mIsMandatory, $this -> mIsDisabled, $mOtherArgs );
 116+ }
 117+}
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_CheckboxesInput.php
___________________________________________________________________
Added: svn:eol-style
1118 + native
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_MultiEnumInput.php
@@ -0,0 +1,36 @@
 2+<?php
 3+/**
 4+ * File holding the SFMultiEnumInput class
 5+ *
 6+ * @file
 7+ * @ingroup SF
 8+ */
 9+
 10+if ( !defined( 'SF_VERSION' ) ) {
 11+ die( 'This file is part of the SemanticForms extension, it is not a valid entry point.' );
 12+}
 13+
 14+/**
 15+ * The SFMultiEnumInput class.
 16+ * The base class for every form input that holds a list of elements, each
 17+ * one from a pre-set enumeration of values.
 18+ *
 19+ * @ingroup SFFormInput
 20+ */
 21+abstract class SFMultiEnumInput extends SFEnumInput {
 22+
 23+ public static function getOtherPropTypesHandled() {
 24+ return array();
 25+ }
 26+
 27+ public static function getOtherPropTypeListsHandled() {
 28+ return array( 'enumeration' );
 29+ }
 30+
 31+ public static function getParameters() {
 32+ $params = parent::getParameters();
 33+ $params[] = array( 'name' => 'delimiter', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_delimiter' ) );
 34+ return $params;
 35+ }
 36+}
 37+
Property changes on: trunk/extensions/SemanticForms/includes/forminputs/SF_MultiEnumInput.php
___________________________________________________________________
Added: svn:eol-style
138 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r101819Followup r101538, r93112: fix the fail everywherenikerabbit15:13, 3 November 2011