Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -19,57 +19,26 @@ |
20 | 20 | function __construct() { |
21 | 21 | global $smwgContLang; |
22 | 22 | |
23 | | - // initialize the set of hooks for the entry-field functions to call for |
24 | | - // fields of both a specific semantic "type" and a defined "input type" |
25 | | - // in the form definition |
| 23 | + // Initialize variables. |
26 | 24 | $this->mSemanticTypeHooks = array(); |
27 | | - if ( $smwgContLang != null ) { |
28 | | - $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
29 | | - $string_type = $datatypeLabels['_str']; |
30 | | - $text_type = $datatypeLabels['_txt']; |
31 | | - // type introduced in SMW 1.2 |
32 | | - if ( array_key_exists( '_cod', $datatypeLabels ) ) |
33 | | - $code_type = $datatypeLabels['_cod']; |
34 | | - else |
35 | | - $code_type = 'code'; |
36 | | - $url_type = $datatypeLabels['_uri']; |
37 | | - $email_type = $datatypeLabels['_ema']; |
38 | | - $number_type = $datatypeLabels['_num']; |
39 | | - $bool_type = $datatypeLabels['_boo']; |
40 | | - $date_type = $datatypeLabels['_dat']; |
41 | | - $enum_type = 'enumeration'; // not a real type |
42 | | - $page_type = $datatypeLabels['_wpg']; |
43 | | - $this->setSemanticTypeHook( $string_type, false, array( 'SFTextInput', 'getText' ), array( 'field_type' => 'string' ) ); |
44 | | - $this->setSemanticTypeHook( $string_type, true, array( 'SFTextInput', 'getText' ), array( 'field_type' => 'string', 'is_list' => 'true', 'size' => '100' ) ); |
45 | | - $this->setSemanticTypeHook( $text_type, false, array( 'SFTextAreaInput', 'getText' ), array() ); |
46 | | - $this->setSemanticTypeHook( $code_type, false, array( 'SFTextAreaInput', 'getText' ), array() ); |
47 | | - $this->setSemanticTypeHook( $url_type, false, array( 'SFTextInput', 'getText' ), array( 'field_type' => 'URL' ) ); |
48 | | - $this->setSemanticTypeHook( $email_type, false, array( 'SFTextInput', 'getText' ), array( 'field_type' => 'email' ) ); |
49 | | - $this->setSemanticTypeHook( $number_type, false, array( 'SFTextInput', 'getText' ), array( 'field_type' => 'number' ) ); |
50 | | - $this->setSemanticTypeHook( $bool_type, false, array( 'SFCheckboxInput', 'getText' ), array() ); |
51 | | - $this->setSemanticTypeHook( $date_type, false, array( 'SFDateInput', 'getText' ), array() ); |
52 | | - $this->setSemanticTypeHook( $enum_type, false, array( 'SFDropdownInput', 'getText' ), array() ); |
53 | | - $this->setSemanticTypeHook( $enum_type, true, array( 'SFCheckboxesInput', 'getText' ), array() ); |
54 | | - $this->setSemanticTypeHook( $page_type, false, array( 'SFTextWithAutocompleteInput', 'getText' ), array( 'field_type' => 'page' ) ); |
55 | | - $this->setSemanticTypeHook( $page_type, true, array( 'SFTextWithAutocompleteInput', 'getText' ), array( 'field_type' => 'page', 'size' => '100', 'is_list' => 'true' ) ); |
56 | | - } |
57 | 25 | $this->mInputTypeHooks = array(); |
58 | | - $this->setInputTypeHook( 'text', array( 'SFTextInput', 'getText' ), array() ); |
59 | | - $this->setInputTypeHook( 'textarea', array( 'SFTextAreaInput', 'getText' ), array() ); |
60 | | - $this->setInputTypeHook( 'date', array( 'SFDateInput', 'getText' ), array() ); |
61 | | - $this->setInputTypeHook( 'datetime', array( 'SFDateTimeInput', 'getText' ), array( 'include_timezone' => false ) ); |
62 | | - $this->setInputTypeHook( 'datetime with timezone', array( 'SFDateTimeInput', 'getText' ), array( 'include_timezone' => true ) ); |
63 | | - $this->setInputTypeHook( 'year', array( 'SFTextInput', 'getText' ), array( 'size' => 4 ) ); |
64 | | - $this->setInputTypeHook( 'checkbox', array( 'SFCheckboxInput', 'getText' ), array() ); |
65 | | - $this->setInputTypeHook( 'radiobutton', array( 'SFRadioButtonInput', 'getText' ), array() ); |
66 | | - $this->setInputTypeHook( 'checkboxes', array( 'SFCheckboxesInput', 'getText' ), array() ); |
67 | | - $this->setInputTypeHook( 'listbox', array( 'SFListBoxInput', 'getText' ), array() ); |
68 | | - $this->setInputTypeHook( 'combobox', array( 'SFComboBoxInput', 'getText' ), array() ); |
69 | | - $this->setInputTypeHook( 'category', array( 'SFCategoryInput', 'getText' ), array() ); |
70 | | - $this->setInputTypeHook( 'categories', array( 'SFCategoriesInput', 'getText' ), array() ); |
| 26 | + $this->mInputTypeClasses = array(); |
| 27 | + $this->standardInputsIncluded = false; |
71 | 28 | |
72 | | - // initialize other variables |
73 | | - $this->standardInputsIncluded = false; |
| 29 | + $this->registerInputType( 'SFTextInput' ); |
| 30 | + $this->registerInputType( 'SFTextWithAutocompleteInput' ); |
| 31 | + $this->registerInputType( 'SFTextAreaInput' ); |
| 32 | + $this->registerInputType( 'SFTextAreaWithAutocompleteInput' ); |
| 33 | + $this->registerInputType( 'SFDateInput' ); |
| 34 | + $this->registerInputType( 'SFDateTimeInput' ); |
| 35 | + $this->registerInputType( 'SFCheckboxInput' ); |
| 36 | + $this->registerInputType( 'SFDropdownInput' ); |
| 37 | + $this->registerInputType( 'SFRadioButtonInput' ); |
| 38 | + $this->registerInputType( 'SFCheckboxesInput' ); |
| 39 | + $this->registerInputType( 'SFListBoxInput' ); |
| 40 | + $this->registerInputType( 'SFComboBoxInput' ); |
| 41 | + $this->registerInputType( 'SFCategoryInput' ); |
| 42 | + $this->registerInputType( 'SFCategoriesInput' ); |
74 | 43 | } |
75 | 44 | |
76 | 45 | function setSemanticTypeHook( $type, $is_list, $function_name, $default_args ) { |
— | — | @@ -80,7 +49,87 @@ |
81 | 50 | $this->mInputTypeHooks[$input_type] = array( $function_name, $default_args ); |
82 | 51 | } |
83 | 52 | |
| 53 | + /** |
| 54 | + * Register all information about the passed-in form input class. |
| 55 | + */ |
| 56 | + function registerInputType( $inputTypeClass ) { |
| 57 | + global $smwgContLang; |
| 58 | + |
| 59 | + $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) ); |
| 60 | + $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass; |
| 61 | + $this->setInputTypeHook( $inputTypeName, array( $inputTypeClass, 'getHTML' ), array() ); |
| 62 | + $alternateInputTypes = call_user_func( array( $inputTypeClass, 'getAlternateInputTypes' ) ); |
| 63 | + foreach ( $alternateInputTypes as $altInputTypeName => $additionalValues ) { |
| 64 | + $this->setInputTypeHook( $altInputTypeName, array( $inputTypeClass, 'getHTML' ), $additionalValues ); |
| 65 | + } |
| 66 | + $defaultProperties = call_user_func( array( $inputTypeClass, 'getDefaultPropTypes' ) ); |
| 67 | + foreach ( $defaultProperties as $propertyTypeID => $additionalValues ) { |
| 68 | + if ( $smwgContLang != null ) { |
| 69 | + $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
| 70 | + $propertyType = $datatypeLabels[$propertyTypeID]; |
| 71 | + $this->setSemanticTypeHook( $propertyType, false, array( $inputTypeClass, 'getHTML' ), $additionalValues ); |
| 72 | + } |
| 73 | + } |
| 74 | + $defaultPropertyLists = call_user_func( array( $inputTypeClass, 'getDefaultPropTypeLists' ) ); |
| 75 | + foreach ( $defaultPropertyLists as $propertyTypeID => $additionalValues ) { |
| 76 | + if ( $smwgContLang != null ) { |
| 77 | + $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
| 78 | + $propertyType = $datatypeLabels[$propertyTypeID]; |
| 79 | + $this->setSemanticTypeHook( $propertyType, true, array( $inputTypeClass, 'getHTML' ), $additionalValues ); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
84 | 83 | |
| 84 | + function getInputType( $inputTypeName ) { |
| 85 | + if ( array_key_exists( $inputTypeName, $this->mInputTypeClasses ) ) { |
| 86 | + return $this->mInputTypeClasses[$inputTypeName]; |
| 87 | + } else { |
| 88 | + return null; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + // TODO - this is very inefficient; the information should be stored in a |
| 93 | + // separate array, populated within registerInputType(). |
| 94 | + public function getDefaultInputType( $isList, $propertyType ) { |
| 95 | + foreach ( $this->mInputTypeClasses as $inputTypeName => $className ) { |
| 96 | + if ( $isList ) { |
| 97 | + $defaultPropTypes = call_user_func( array( $className, 'getDefaultPropTypeLists' ) ); |
| 98 | + if ( array_key_exists( $propertyType, $defaultPropTypes ) ) { |
| 99 | + return $inputTypeName; |
| 100 | + } |
| 101 | + } else { |
| 102 | + $defaultPropTypes = call_user_func( array( $className, 'getDefaultPropTypes' ) ); |
| 103 | + if ( array_key_exists( $propertyType, $defaultPropTypes ) ) { |
| 104 | + return $inputTypeName; |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + // TODO - this is very inefficient; the information should be stored in a |
| 111 | + // separate array, populated within registerInputType(). |
| 112 | + public function getPossibleInputTypes( $isList, $propertyType ) { |
| 113 | + $possibleInputTypes = array(); |
| 114 | + foreach ( $this->mInputTypeClasses as $inputTypeName => $className ) { |
| 115 | + if ( $isList ) { |
| 116 | + $handledPropTypes = call_user_func( array( $className, 'getOtherPropTypeListsHandled' ) ); |
| 117 | + if ( in_array( $propertyType, $handledPropTypes ) ) { |
| 118 | + $possibleInputTypes[] = $inputTypeName; |
| 119 | + } |
| 120 | + } else { |
| 121 | + $handledPropTypes = call_user_func( array( $className, 'getOtherPropTypesHandled' ) ); |
| 122 | + if ( in_array( $propertyType, $handledPropTypes ) ) { |
| 123 | + $possibleInputTypes[] = $inputTypeName; |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | + return $possibleInputTypes; |
| 128 | + } |
| 129 | + |
| 130 | + public function getAllInputTypes() { |
| 131 | + return array_keys( $this->mInputTypeClasses ); |
| 132 | + } |
| 133 | + |
85 | 134 | /** |
86 | 135 | * Show the set of previous deletions for the page being added. |
87 | 136 | * This function is copied almost exactly from EditPage::showDeletionLog() - |
— | — | @@ -204,9 +253,9 @@ |
205 | 254 | // flag for placing "<onlyinclude>" tags in form output |
206 | 255 | $onlyinclude_free_text = false; |
207 | 256 | |
208 | | - // if we have existing content and we're not in an active replacement |
| 257 | + // If we have existing content and we're not in an active replacement |
209 | 258 | // situation, preserve the original content. We do this because we want |
210 | | - // to pass the original content on IF this is a partial form |
| 259 | + // to pass the original content on IF this is a partial form. |
211 | 260 | // TODO: A better approach here would be to pass the revision id of the |
212 | 261 | // existing page content through the replace value, which would |
213 | 262 | // minimize the html traffic and would allow us to do a concurrent |
— | — | @@ -439,11 +488,11 @@ |
440 | 489 | $start_char = $matches[0][1]; |
441 | 490 | $fields_start_char = $start_char + 2 + strlen( $search_template_str ); |
442 | 491 | // Skip ahead to the first real character. |
443 | | - while ( in_array( $existing_page_content[$fields_start_char], array( ' ', '\n' ) ) ) { |
| 492 | + while ( in_array( $existing_page_content[$fields_start_char], array( ' ', '\n' ) ) ) { |
444 | 493 | $fields_start_char++; |
445 | 494 | } |
446 | | - // If the next character is a pipe, skip that too. |
447 | | - if( $existing_page_content[$fields_start_char] == '|' ) { |
| 495 | + // If the next character is a pipe, skip that too. |
| 496 | + if( $existing_page_content[$fields_start_char] == '|' ) { |
448 | 497 | $fields_start_char++; |
449 | 498 | } |
450 | 499 | $template_contents = array( '0' => '' ); |
— | — | @@ -634,14 +683,9 @@ |
635 | 684 | } |
636 | 685 | } |
637 | 686 | } elseif ( $sub_components[0] == 'autocomplete on property' ) { |
638 | | - // HACK - we need to figure out if this property is a |
639 | | - // relation or attribute, i.e. whether it points to wiki |
640 | | - // pages or not; so construct an SFTemplateField object |
641 | | - // with this property, and determine it that way |
642 | 687 | $property_name = $sub_components[1]; |
643 | | - $dummy_field = new SFTemplateField(); |
644 | | - $dummy_field->setSemanticProperty( $property_name ); |
645 | | - if ( $dummy_field->propertyIsOfType( '_wpg' ) ) { |
| 688 | + $propValue = SMWPropertyValue::makeUserProperty( $this->semantic_property ); |
| 689 | + if ( $propValue->getPropertyID() == '_wpg' ) { |
646 | 690 | $field_args['autocomplete field type'] = 'relation'; |
647 | 691 | } else { |
648 | 692 | $field_args['autocomplete field type'] = 'attribute'; |
— | — | @@ -757,7 +801,7 @@ |
758 | 802 | } else { |
759 | 803 | $default_value = $cur_value; |
760 | 804 | } |
761 | | - $new_text = SFTextAreaInput::getText( $default_value, 'free_text', false, ( $form_is_disabled || $is_restricted ), $field_args ); |
| 805 | + $new_text = SFTextAreaInput::getHTML( $default_value, 'free_text', false, ( $form_is_disabled || $is_restricted ), $field_args ); |
762 | 806 | if ( in_array( 'edittools', $free_text_components ) ) { |
763 | 807 | // borrowed from EditPage::showEditTools() |
764 | 808 | $options[] = 'parse'; |
— | — | @@ -948,7 +992,7 @@ |
949 | 993 | ( $cur_value == '' || $cur_value == 'now' ) ) { |
950 | 994 | if ( $input_type == 'date' || $input_type == 'datetime' || |
951 | 995 | $input_type == 'datetime with timezone' || $input_type == 'year' || |
952 | | - ( $input_type == '' && $form_field->template_field->propertyIsOfType( '_dat' ) ) ) { |
| 996 | + ( $input_type == '' && $form_field->template_field->field_type_id == '_dat' ) ) { |
953 | 997 | // Get current time, for the time zone specified in the wiki. |
954 | 998 | global $wgLocaltimezone; |
955 | 999 | if ( isset( $wgLocaltimezone ) ) { |
— | — | @@ -1316,7 +1360,7 @@ |
1317 | 1361 | global $wgParser; |
1318 | 1362 | $new_text = ""; |
1319 | 1363 | if ( !$embedded ) { |
1320 | | - $new_text = $wgParser->recursiveTagParse (str_replace( "{{!}}", "|", $form_page_title ) ); |
| 1364 | + $new_text = $wgParser->recursiveTagParse (str_replace( "{{!}}", "|", $form_page_title ) ); |
1321 | 1365 | } |
1322 | 1366 | |
1323 | 1367 | // If the form has already been submitted, i.e. this is just the redirect |
— | — | @@ -1377,7 +1421,7 @@ |
1378 | 1422 | if ( ! array_key_exists( 'size', $other_args ) ) |
1379 | 1423 | $other_args['size'] = 100; |
1380 | 1424 | } |
1381 | | - $text = SFTextInput::getText( $cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args ); |
| 1425 | + $text = SFTextInput::getHTML( $cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args ); |
1382 | 1426 | } |
1383 | 1427 | } |
1384 | 1428 | return $text; |