Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc |
— | — | @@ -23,14 +23,16 @@ |
24 | 24 | // in the form definition |
25 | 25 | $this->mSemanticTypeHooks = array(); |
26 | 26 | if ($smwgContLang != null) { |
27 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_string'), array('SFFormPrinter', 'textEntryHTML'), array('size' => 35)); |
28 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_url'), array('SFFormPrinter', 'textEntryHTML'), array('size' => 100)); |
29 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_float'), array('SFFormPrinter', 'textEntryHTML'), array('size' => 10)); |
30 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_int'), array('SFFormPrinter', 'textEntryHTML'), array('size' => 10)); |
31 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_bool'), array('SFFormPrinter', 'checkboxHTML'), array()); |
32 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_datetime'), array('SFFormPrinter', 'dateEntryHTML'), array()); |
33 | | - $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_enum'), array('SFFormPrinter', 'dropdownHTML'), array()); |
34 | | - $this->setSemanticTypeHook('relation', array('SFFormPrinter', 'textEntryWithAutocompleteHTML'), array('size' => 35)); |
| 27 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_string'), false, array('SFFormPrinter', 'textEntryHTML'), array('size' => 35)); |
| 28 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_string'), true, array('SFFormPrinter', 'textEntryHTML'), array('size' => 35)); |
| 29 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_url'), false, array('SFFormPrinter', 'textEntryHTML'), array('size' => 100)); |
| 30 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_float'), false, array('SFFormPrinter', 'textEntryHTML'), array('size' => 10)); |
| 31 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_int'), false, array('SFFormPrinter', 'textEntryHTML'), array('size' => 10)); |
| 32 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_bool'), false, array('SFFormPrinter', 'checkboxHTML'), array()); |
| 33 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_datetime'), false, array('SFFormPrinter', 'dateEntryHTML'), array()); |
| 34 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_enum'), false, array('SFFormPrinter', 'dropdownHTML'), array()); |
| 35 | + $this->setSemanticTypeHook($smwgContLang->getDatatypeLabel('smw_enum'), true, array('SFFormPrinter', 'checkboxesHTML'), array()); |
| 36 | + $this->setSemanticTypeHook('relation', false, array('SFFormPrinter', 'textEntryWithAutocompleteHTML'), array('size' => 35)); |
35 | 37 | } |
36 | 38 | $this->mInputTypeHooks = array(); |
37 | 39 | $this->setInputTypeHook('text', array('SFFormPrinter', 'textEntryHTML'), array('size' => 35)); |
— | — | @@ -40,15 +42,15 @@ |
41 | 43 | $this->setInputTypeHook('datetime with timezone', array('SFFormPrinter', 'dateTimeEntryHTML'), array('include_timezone' => true)); |
42 | 44 | $this->setInputTypeHook('checkbox', array('SFFormPrinter', 'checkboxHTML'), array()); |
43 | 45 | $this->setInputTypeHook('radiobutton', array('SFFormPrinter', 'radioButtonHTML'), array()); |
| 46 | + $this->setInputTypeHook('checkboxes', array('SFFormPrinter', 'checkboxesHTML'), array()); |
44 | 47 | $this->setInputTypeHook('listbox', array('SFFormPrinter', 'listboxHTML'), array()); |
45 | | - $this->setInputTypeHook('checkboxes', array('SFFormPrinter', 'checkboxesHTML'), array()); |
46 | 48 | |
47 | 49 | // initialize other variables |
48 | 50 | $this->standardInputsIncluded = false; |
49 | 51 | } |
50 | 52 | |
51 | | - function setSemanticTypeHook($type, $function_name, $default_args) { |
52 | | - $this->mSemanticTypeHooks[$type] = array($function_name, $default_args); |
| 53 | + function setSemanticTypeHook($type, $is_list, $function_name, $default_args) { |
| 54 | + $this->mSemanticTypeHooks[$type][$is_list] = array($function_name, $default_args); |
53 | 55 | } |
54 | 56 | |
55 | 57 | function setInputTypeHook($input_type, $function_name, $default_args) { |
— | — | @@ -933,8 +935,11 @@ |
934 | 936 | list($text, $javascript_text) = $this->textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $field_args); |
935 | 937 | } else { // input type not defined in form, and not a relation |
936 | 938 | $field_type = $template_field->field_type; |
937 | | - if ($field_type != '' && array_key_exists($field_type, $this->mSemanticTypeHooks)) { |
938 | | - $hook_values = $this->mSemanticTypeHooks[$field_type]; |
| 939 | + $is_list = $template_field->is_list; |
| 940 | + if ($field_type != '' && |
| 941 | + array_key_exists($field_type, $this->mSemanticTypeHooks) && |
| 942 | + isset($this->mSemanticTypeHooks[$field_type][$is_list])) { |
| 943 | + $hook_values = $this->mSemanticTypeHooks[$field_type][$is_list]; |
939 | 944 | $funcArgs = array(); |
940 | 945 | $funcArgs[] = $cur_value; |
941 | 946 | $funcArgs[] = $form_field->input_name; |
— | — | @@ -960,15 +965,37 @@ |
961 | 966 | return array($text, $javascript_text); |
962 | 967 | } |
963 | 968 | |
| 969 | + function getAllPagesForRelation_0_7($relation_name) { |
| 970 | + global $sfgMaxAutocompleteValues; |
| 971 | + |
| 972 | + $fname = "SFFormPrinter::getAllPagesForRelation_0_7"; |
| 973 | + $pages = array(); |
| 974 | + $db = wfGetDB( DB_SLAVE ); |
| 975 | + $sql_options = array(); |
| 976 | + $sql_options['LIMIT'] = $sfgMaxAutocompleteValues; |
| 977 | + $conditions = "relation_title = '$relation_name'"; |
| 978 | + $sql_options['ORDER BY'] = 'object_title'; |
| 979 | + $res = $db->select( $db->tableName('smw_relations'), |
| 980 | + 'DISTINCT object_title', |
| 981 | + $conditions, $fname, $sql_options); |
| 982 | + while ($row = $db->fetchRow($res)) { |
| 983 | + $cur_value = str_replace("'", "\'", $row[0]); |
| 984 | + $pages[] = str_replace('_', ' ', $cur_value); |
| 985 | + } |
| 986 | + $db->freeResult($res); |
| 987 | + return $pages; |
| 988 | + } |
| 989 | + |
964 | 990 | /* |
965 | 991 | * Get all the pages that belong to a category and all its subcategories, |
966 | 992 | * down a certain number of levels - heavily based on SMW's |
967 | 993 | * SMWInlineQuery::includeSubcategories() |
968 | 994 | */ |
969 | | - private function getAllPagesForCategory($dbr, $top_category, $num_levels) { |
| 995 | + function getAllPagesForCategory($top_category, $num_levels) { |
970 | 996 | if (0 == $num_levels) return $top_category; |
971 | 997 | global $sfgMaxAutocompleteValues; |
972 | 998 | |
| 999 | + $db = wfGetDB( DB_SLAVE ); |
973 | 1000 | $fname = "SFFormPrinter::getAllPagesForCategory"; |
974 | 1001 | $categories = array($top_category); |
975 | 1002 | $checkcategories = array($top_category); |
— | — | @@ -976,14 +1003,14 @@ |
977 | 1004 | for ($level = $num_levels; $level > 0; $level--) { |
978 | 1005 | $newcategories = array(); |
979 | 1006 | foreach ($checkcategories as $category) { |
980 | | - $res = $dbr->select( // make the query |
| 1007 | + $res = $db->select( // make the query |
981 | 1008 | array('categorylinks', 'page'), |
982 | 1009 | array('page_title', 'page_namespace'), |
983 | 1010 | array('cl_from = page_id', |
984 | | - 'cl_to = '. $dbr->addQuotes($category)), |
| 1011 | + 'cl_to = '. $db->addQuotes($category)), |
985 | 1012 | $fname); |
986 | 1013 | if ($res) { |
987 | | - while ($res && $row = $dbr->fetchRow($res)) { |
| 1014 | + while ($res && $row = $db->fetchRow($res)) { |
988 | 1015 | if (array_key_exists('page_title', $row)) { |
989 | 1016 | $page_namespace = $row['page_namespace']; |
990 | 1017 | if ($page_namespace == NS_CATEGORY) { |
— | — | @@ -1000,7 +1027,7 @@ |
1001 | 1028 | } |
1002 | 1029 | } |
1003 | 1030 | } |
1004 | | - $dbr->freeResult( $res ); |
| 1031 | + $db->freeResult( $res ); |
1005 | 1032 | } |
1006 | 1033 | } |
1007 | 1034 | if (count($newcategories) == 0) { |
— | — | @@ -1014,34 +1041,25 @@ |
1015 | 1042 | } |
1016 | 1043 | |
1017 | 1044 | function createAutocompleteValuesString($field_name, $autocomplete_field_type) { |
1018 | | - global $sfgMaxAutocompleteValues; |
1019 | | - $fname = 'SFFormPrinter::createAutocompleteValuesString'; |
1020 | | - |
1021 | 1045 | $names_array = array(); |
1022 | | - $db = wfGetDB( DB_SLAVE ); |
1023 | | - $sql_options = array(); |
1024 | | - $sql_options['LIMIT'] = $sfgMaxAutocompleteValues; |
1025 | 1046 | // the query depends on whether this field is a relation, category or |
1026 | 1047 | // namespace |
1027 | 1048 | if ($autocomplete_field_type == 'relation') { |
1028 | | - $conditions = "relation_title = '$field_name'"; |
1029 | | - $sql_options['ORDER BY'] = 'object_title'; |
1030 | | - $res = $db->select( $db->tableName('smw_relations'), |
1031 | | - 'DISTINCT object_title', |
1032 | | - $conditions, $fname, $sql_options); |
1033 | | - while ($row = $db->fetchRow($res)) { |
1034 | | - $cur_value = str_replace("'", "\'", $row[0]); |
1035 | | - $names_array[] = str_replace('_', ' ', $cur_value); |
| 1049 | + $smw_version = SMW_VERSION; |
| 1050 | + if ($smw_version{0} == '0') { |
| 1051 | + $names_array = $this->getAllPagesForRelation_0_7($field_name); |
| 1052 | + } else { |
| 1053 | + // no handling yet |
1036 | 1054 | } |
1037 | | - $db->freeResult($res); |
1038 | 1055 | } elseif ($autocomplete_field_type == 'category') { |
1039 | | - $names_array = $this->getAllPagesForCategory($db, $field_name, 10); |
| 1056 | + $names_array = $this->getAllPagesForCategory($field_name, 10); |
1040 | 1057 | } else { // i.e., $autocomplete_field_type == 'namespace' |
1041 | 1058 | // cycle through all the namespace names for this language, and if |
1042 | 1059 | // one matches the namespace specified in the form, add the names |
1043 | 1060 | // of all the pages in that namespace to $names_array |
1044 | 1061 | global $wgContLang; |
1045 | 1062 | $namespaces = $wgContLang->getNamespaces(); |
| 1063 | + $db = wfGetDB( DB_SLAVE ); |
1046 | 1064 | foreach ($namespaces as $ns_code => $ns_name) { |
1047 | 1065 | if ($ns_name == $field_name) { |
1048 | 1066 | $conditions = "page_namespace = $ns_code"; |
— | — | @@ -1062,8 +1080,9 @@ |
1063 | 1081 | } |
1064 | 1082 | |
1065 | 1083 | function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
1066 | | - // if it's an autocomplete, call the with-autocomplete function insted |
1067 | | - if (array_key_exists('autocomplete on', $other_args) || array_key_exists('autocomplete on namespace', $other_args)) { |
| 1084 | + // if it's an autocomplete, call the with-autocomplete function instead |
| 1085 | + if ((array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] != "") || |
| 1086 | + array_key_exists('autocomplete on namespace', $other_args)) { |
1068 | 1087 | return SFFormPrinter::textEntryWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args); |
1069 | 1088 | } |
1070 | 1089 | |
— | — | @@ -1194,7 +1213,8 @@ |
1195 | 1214 | |
1196 | 1215 | function textEntryWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
1197 | 1216 | // if 'no autocomplete' was specified, call the regular text entry instead |
1198 | | - if ($other_args['no_autocomplete'] == true) |
| 1217 | + if (array_key_exists('no_autocomplete', $other_args) && |
| 1218 | + $other_args['no_autocomplete'] == true) |
1199 | 1219 | return SFFormPrinter::textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args); |
1200 | 1220 | |
1201 | 1221 | global $sfgTabIndex, $sfgFieldNum; |
— | — | @@ -1226,7 +1246,7 @@ |
1227 | 1247 | $autocomplete_values = array(); |
1228 | 1248 | $autocomplete_values['mappings'] = array(); |
1229 | 1249 | $options_str_key = $semantic_field_name . ',' . $autocomplete_field_type; |
1230 | | - if (!$autocomplete_values[$options_str_key]) |
| 1250 | + if (! array_key_exists($options_str_key, $autocomplete_values)) |
1231 | 1251 | $autocomplete_values[$options_str_key] = $this->createAutocompleteValuesString(str_replace(' ', '_', $semantic_field_name), $autocomplete_field_type); |
1232 | 1252 | $autocomplete_values['mappings'][$sfgFieldNum] = $options_str_key; |
1233 | 1253 | foreach ($autocomplete_values as $autocomplete_key => $autocomplete_string) { |
— | — | @@ -1267,7 +1287,6 @@ |
1268 | 1288 | function monthDropdownHTML($cur_month, $input_name, $is_disabled) { |
1269 | 1289 | global $sfgTabIndex, $sfgFieldNum; |
1270 | 1290 | |
1271 | | - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput"; |
1272 | 1291 | $disabled_text = ($is_disabled) ? "disabled" : ""; |
1273 | 1292 | $text = ' <select tabindex="' . $sfgTabIndex . '" id="input_' . $sfgFieldNum . '_1" name="' . $input_name . "[month]\" $disabled_text>\n"; |
1274 | 1293 | $month_names = array( |