Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc |
— | — | @@ -135,6 +135,7 @@ |
136 | 136 | // section |
137 | 137 | $existing_template_text = null; |
138 | 138 | if ($source_is_page) { |
| 139 | + $matches = array(); |
139 | 140 | if ($allow_multiple) { |
140 | 141 | // find the number of instances of this template in the page - |
141 | 142 | // if it's more than one, re-parse this section of the |
— | — | @@ -285,7 +286,10 @@ |
286 | 287 | } |
287 | 288 | } |
288 | 289 | // get the value from the request, if it's there |
289 | | - $cur_value = $template_instance_query_values[$field_name]; |
| 290 | + if (isset ($template_instance_query_values[$field_name])) |
| 291 | + $cur_value = $template_instance_query_values[$field_name]; |
| 292 | + else |
| 293 | + $cur_value = ''; |
290 | 294 | if ($cur_value && ! is_array($cur_value)) { |
291 | 295 | $cur_value = Sanitizer::safeEncodeAttribute($cur_value); |
292 | 296 | } |
— | — | @@ -297,8 +301,11 @@ |
298 | 302 | // if the user is starting to edit a page, and that page contains |
299 | 303 | // the current template being processed, get the current template |
300 | 304 | // field's value in the existing page |
301 | | - if ($source_is_page && ($existing_template_text != null)) { |
302 | | - $cur_value = $template_contents[$field_name]; |
| 305 | + if ($source_is_page && (! empty($existing_template_text))) { |
| 306 | + if (isset($template_contents[$field_name])) |
| 307 | + $cur_value = $template_contents[$field_name]; |
| 308 | + else |
| 309 | + $cur_value = ''; |
303 | 310 | if ($cur_value) { |
304 | 311 | $cur_value = Sanitizer::safeEncodeAttribute($cur_value); |
305 | 312 | } |
— | — | @@ -420,7 +427,13 @@ |
421 | 428 | if ($is_mandatory) { |
422 | 429 | $input_id = "input_" . $gTabIndex; |
423 | 430 | $info_id = "info_" . $gTabIndex; |
424 | | - $js_validation_calls[] = "validate_mandatory_field ('$input_id', '$info_id')"; |
| 431 | + if ($input_type == 'date') { |
| 432 | + $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_1', '$info_id')"; |
| 433 | + $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_2', '$info_id')"; |
| 434 | + $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_3', '$info_id')"; |
| 435 | + } else { |
| 436 | + $js_validation_calls[] = "validate_mandatory_field ('$input_id', '$info_id')"; |
| 437 | + } |
425 | 438 | } |
426 | 439 | } else { |
427 | 440 | $start_position = $brackets_end_loc; |
— | — | @@ -820,6 +833,9 @@ |
821 | 834 | $text = SFFormPrinter::dateEntryHTML($template_field->input_name, $cur_value); |
822 | 835 | } elseif ($template_field->input_type == 'checkbox') { |
823 | 836 | $text = SFFormPrinter::checkboxHTML($template_field->input_name, $cur_value); |
| 837 | + } elseif ($template_field->input_type == 'radiobutton') { |
| 838 | + $include_none = ! $template_field->is_mandatory; |
| 839 | + $text = SFFormPrinter::radioButtonHTML($template_field->input_name, $cur_value, $include_none, $template_field->possible_values); |
824 | 840 | } elseif ($template_field->attr_or_rel == "relation") { |
825 | 841 | $size = $template_field->size; |
826 | 842 | if ($size == null) $size = 35; |
— | — | @@ -828,6 +844,10 @@ |
829 | 845 | } else { |
830 | 846 | $text = SFFormPrinter::textEntryWithAutocompleteHTML($size, $template_field->input_name, $template_field->part_of_multiple, $template_field->semantic_field, true, $cur_value, $out_autocomplete_values); |
831 | 847 | } |
| 848 | + // escape out here if user doesn't have SMW installed |
| 849 | + } elseif ($smwgContLang == null) { |
| 850 | + if ($size == null) $size = 35; |
| 851 | + $text = SFFormPrinter::textEntryHTML($size, $template_field->input_name, $cur_value); |
832 | 852 | } else { // input type not defined in form, and not a relation |
833 | 853 | $attr_type = $template_field->attribute_type; |
834 | 854 | $size = $template_field->size; |
— | — | @@ -856,7 +876,7 @@ |
857 | 877 | function createAutocompleteValuesString($field_name, $is_relation) { |
858 | 878 | global $sfgMaxAutocompleteValues; |
859 | 879 | $fname = 'SFFormPrinter::createAutocompleteValuesString'; |
860 | | - $db = & wfGetDB( DB_SLAVE ); |
| 880 | + $db = wfGetDB( DB_SLAVE ); |
861 | 881 | $sql_options = array(); |
862 | 882 | $sql_options['LIMIT'] = $sfgMaxAutocompleteValues; |
863 | 883 | // the query depends on whether this field is a relation or a category |
— | — | @@ -907,7 +927,7 @@ |
908 | 928 | |
909 | 929 | $text = ' <select tabindex="' . $gTabIndex . '" name="' . $input_name . '" ' . $gDisabledText . '>'; |
910 | 930 | if ($include_none) |
911 | | - $text .= " <option value=\"\">[None]</option>\n"; |
| 931 | + $text .= " <option value=\"\">" . wfMsg('sf_editdata_none') . "</option>\n"; |
912 | 932 | foreach ($possible_values as $possible_value) { |
913 | 933 | $text .= " <option value=\"$possible_value\""; |
914 | 934 | if ($possible_value == $cur_value) {$text .= " selected=\"selected\""; } |
— | — | @@ -953,7 +973,7 @@ |
954 | 974 | $info_id = "info_$gTabIndex"; |
955 | 975 | |
956 | 976 | $text =<<<END |
957 | | - <textarea tabindex="$gTabIndex" id="$input_id" name="$input_name" rows=$rows cols=$cols $gDisabledText/>$cur_value</textarea> |
| 977 | + <textarea tabindex="$gTabIndex" id="$input_id" name="$input_name" rows=$rows cols=$cols $gDisabledText>$cur_value</textarea> |
958 | 978 | <span id="$info_id" class="error_message"></span> |
959 | 979 | |
960 | 980 | END; |
— | — | @@ -963,7 +983,7 @@ |
964 | 984 | function monthDropdownHTML($cur_month, $input_name) { |
965 | 985 | global $gTabIndex, $gDisabledText; |
966 | 986 | |
967 | | - $text = ' <select tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '" name="' . $input_name . "[month]\" $gDisabledText>\n"; |
| 987 | + $text = ' <select tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '_1" name="' . $input_name . "[month]\" $gDisabledText>\n"; |
968 | 988 | $month_names = array( |
969 | 989 | wfMsgForContent('sf_january'), |
970 | 990 | wfMsgForContent('sf_february'), |
— | — | @@ -1005,27 +1025,36 @@ |
1006 | 1026 | } |
1007 | 1027 | } else { |
1008 | 1028 | $cur_date = getdate(); |
1009 | | - $year = $cur_date[year]; |
1010 | | - $month = $cur_date[month]; |
| 1029 | + $year = $cur_date['year']; |
| 1030 | + $month = $cur_date['month']; |
1011 | 1031 | $day = null; // no need for day |
1012 | 1032 | } |
1013 | | - $text .= SFFormPrinter::monthDropdownHTML($month, $input_name); |
1014 | | - $text .= ' <input tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2"/ ' . $gDisabledText . '>' . "\n"; |
1015 | | - $text .= ' <input tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4"/ ' . $gDisabledText . '>' . "\n"; |
| 1033 | + $text = SFFormPrinter::monthDropdownHTML($month, $input_name); |
| 1034 | + $text .= ' <input tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '_2" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2"/ ' . $gDisabledText . '>' . "\n"; |
| 1035 | + $text .= ' <input tabindex="' . $gTabIndex . '" id="input_' . $gTabIndex . '_3" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4"/ ' . $gDisabledText . '>' . "\n"; |
1016 | 1036 | $info_id = "info_$gTabIndex"; |
1017 | 1037 | $text .= " <span id=\"$info_id\" class=\"error_message\"></span>"; |
1018 | 1038 | return $text; |
1019 | 1039 | } |
1020 | 1040 | |
1021 | | - function radioButtonHTML($input_name, $cur_value, $options_array) { |
| 1041 | + function radioButtonHTML($input_name, $cur_value, $include_none, $options_array) { |
1022 | 1042 | global $gTabIndex, $gDisabledText; |
1023 | 1043 | |
1024 | | - if ($title) |
1025 | | - $text .= " <strong>$title:</strong>\n"; |
| 1044 | + $check_set = false; |
| 1045 | + if ($include_none) { |
| 1046 | + $text .= ' <input type="radio" tabindex="' . $gTabIndex . '" name="' . $input_name . '" value=""'; |
| 1047 | + if (! $cur_value) { |
| 1048 | + $text .= " checked"; |
| 1049 | + $check_set = true; |
| 1050 | + } |
| 1051 | + $text .= " $gDisabledText/> " . wfMsg('sf_editdata_none') . "\n"; |
| 1052 | + } |
1026 | 1053 | foreach ($options_array as $i => $option) { |
1027 | 1054 | $text .= ' <input type="radio" tabindex="' . $gTabIndex . '" name="' . $input_name . '" value="' . $option . '"'; |
1028 | | - if ($cur_value == $option || (! $cur_value && $i == 0)) |
| 1055 | + if ($cur_value == $option || (! $cur_value && ! $check_set)) { |
1029 | 1056 | $text .= " checked"; |
| 1057 | + $check_set = true; |
| 1058 | + } |
1030 | 1059 | $text .= " $gDisabledText/> $option\n"; |
1031 | 1060 | } |
1032 | 1061 | return $text; |
— | — | @@ -1229,22 +1258,22 @@ |
1230 | 1259 | |
1231 | 1260 | // based on MediaWiki's EditPage::getPreloadedText() |
1232 | 1261 | function getPreloadedText($preload) { |
1233 | | - if ( $preload === '' ) |
1234 | | - return ''; |
1235 | | - else { |
| 1262 | + if ( $preload === '' ) { |
| 1263 | + return ''; |
| 1264 | + } else { |
1236 | 1265 | $preloadTitle = Title::newFromText( $preload ); |
1237 | | - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { |
1238 | | - $rev=Revision::newFromTitle($preloadTitle); |
| 1266 | + if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { |
| 1267 | + $rev = Revision::newFromTitle($preloadTitle); |
1239 | 1268 | if ( is_object( $rev ) ) { |
1240 | 1269 | $text = $rev->getText(); |
1241 | 1270 | // Remove <noinclude> sections and <includeonly> tags from text |
1242 | 1271 | $text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $text); |
1243 | 1272 | $text = strtr($text, array('<includeonly>' => '', '</includeonly>' => '')); |
1244 | 1273 | return $text; |
1245 | | - } else |
1246 | | - return ''; |
1247 | 1274 | } |
1248 | | - } |
| 1275 | + } |
| 1276 | + return ''; |
| 1277 | + } |
1249 | 1278 | } |
1250 | 1279 | |
1251 | 1280 | } |