Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -53,7 +53,9 @@ |
54 | 54 | * Register all information about the passed-in form input class. |
55 | 55 | */ |
56 | 56 | function registerInputType( $inputTypeClass ) { |
57 | | - global $smwgContLang; |
| 57 | + global $smwgContLang, $sfgDefaultInputForPropType, $sfgDefaultInputForPropTypeList; |
| 58 | + global $sfgPossibleInputsForPropType, $sfgPossibleInputsForPropTypeList; |
| 59 | + global $sfgInitJSFunctions, $sfgValidationJSFunctions; |
58 | 60 | |
59 | 61 | $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) ); |
60 | 62 | $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass; |
— | — | @@ -70,6 +72,7 @@ |
71 | 73 | $propertyType = $datatypeLabels[$propertyTypeID]; |
72 | 74 | $this->setSemanticTypeHook( $propertyType, false, array( $inputTypeClass, 'getHTML' ), $additionalValues ); |
73 | 75 | } |
| 76 | + $sfgDefaultInputForPropType[$propertyTypeID] = $inputTypeName; |
74 | 77 | } |
75 | 78 | $defaultPropertyLists = call_user_func( array( $inputTypeClass, 'getDefaultPropTypeLists' ) ); |
76 | 79 | foreach ( $defaultPropertyLists as $propertyTypeID => $additionalValues ) { |
— | — | @@ -79,7 +82,34 @@ |
80 | 83 | $propertyType = $datatypeLabels[$propertyTypeID]; |
81 | 84 | $this->setSemanticTypeHook( $propertyType, true, array( $inputTypeClass, 'getHTML' ), $additionalValues ); |
82 | 85 | } |
| 86 | + $sfgDefaultInputForPropTypeList[$propertyTypeID] = $inputTypeName; |
83 | 87 | } |
| 88 | + |
| 89 | + $otherProperties = call_user_func( array( $inputTypeClass, 'getOtherPropTypesHandled' ) ); |
| 90 | + foreach ( $otherProperties as $propertyTypeID ) { |
| 91 | + if ( array_key_exists( $propertyTypeID, $sfgPossibleInputsForPropType ) ) { |
| 92 | + $sfgPossibleInputsForPropType[$propertyTypeID][] = $inputTypeName; |
| 93 | + } else { |
| 94 | + $sfgPossibleInputsForPropType[$propertyTypeID] = array( $inputTypeName ); |
| 95 | + } |
| 96 | + } |
| 97 | + $otherPropertyLists = call_user_func( array( $inputTypeClass, 'getOtherPropTypeListsHandled' ) ); |
| 98 | + foreach ( $otherPropertyLists as $propertyTypeID ) { |
| 99 | + if ( array_key_exists( $propertyTypeID, $sfgPossibleInputsForPropTypeList ) ) { |
| 100 | + $sfgPossibleInputsForPropTypeList[$propertyTypeID][] = $inputTypeName; |
| 101 | + } else { |
| 102 | + $sfgPossibleInputsForPropTypeList[$propertyTypeID] = array( $inputTypeName ); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + $initJSFunction = call_user_func( array( $inputTypeClass, 'getInitJSFunction' ) ); |
| 107 | + if ( !is_null( $initJSFunction ) ) { |
| 108 | + $sfgInitJSFunctions[] = $initJSFunction; |
| 109 | + } |
| 110 | + $validationJSFunctions = call_user_func( array( $inputTypeClass, 'getValidationJSFunctions' ) ); |
| 111 | + if ( count( $validationJSFunctions ) > 0 ) { |
| 112 | + $sfgValidationJSFunctions = array_merge( $sfgValidationJSFunctions, $initJSFunction ); |
| 113 | + } |
84 | 114 | } |
85 | 115 | |
86 | 116 | function getInputType( $inputTypeName ) { |
— | — | @@ -90,42 +120,32 @@ |
91 | 121 | } |
92 | 122 | } |
93 | 123 | |
94 | | - // TODO - this is very inefficient; the information should be stored in a |
95 | | - // separate array, populated within registerInputType(). |
96 | 124 | public function getDefaultInputType( $isList, $propertyType ) { |
97 | | - foreach ( $this->mInputTypeClasses as $inputTypeName => $className ) { |
98 | | - if ( $isList ) { |
99 | | - $defaultPropTypes = call_user_func( array( $className, 'getDefaultPropTypeLists' ) ); |
100 | | - if ( array_key_exists( $propertyType, $defaultPropTypes ) ) { |
101 | | - return $inputTypeName; |
102 | | - } |
103 | | - } else { |
104 | | - $defaultPropTypes = call_user_func( array( $className, 'getDefaultPropTypes' ) ); |
105 | | - if ( array_key_exists( $propertyType, $defaultPropTypes ) ) { |
106 | | - return $inputTypeName; |
107 | | - } |
108 | | - } |
| 125 | + if ( $isList ) { |
| 126 | + global $sfgDefaultInputForPropTypeList; |
| 127 | + return $sfgDefaultInputForPropTypeList[$propertyType]; |
| 128 | + } else { |
| 129 | + global $sfgDefaultInputForPropType; |
| 130 | + return $sfgDefaultInputForPropType[$propertyType]; |
109 | 131 | } |
110 | 132 | } |
111 | 133 | |
112 | | - // TODO - this is very inefficient; the information should be stored in a |
113 | | - // separate array, populated within registerInputType(). |
114 | 134 | public function getPossibleInputTypes( $isList, $propertyType ) { |
115 | | - $possibleInputTypes = array(); |
116 | | - foreach ( $this->mInputTypeClasses as $inputTypeName => $className ) { |
117 | | - if ( $isList ) { |
118 | | - $handledPropTypes = call_user_func( array( $className, 'getOtherPropTypeListsHandled' ) ); |
119 | | - if ( in_array( $propertyType, $handledPropTypes ) ) { |
120 | | - $possibleInputTypes[] = $inputTypeName; |
121 | | - } |
| 135 | + if ( $isList ) { |
| 136 | + global $sfgPossibleInputsForPropTypeList; |
| 137 | + if ( array_key_exists( $propertyType, $sfgPossibleInputsForPropTypeList ) ) { |
| 138 | + return $sfgPossibleInputsForPropTypeList[$propertyType]; |
122 | 139 | } else { |
123 | | - $handledPropTypes = call_user_func( array( $className, 'getOtherPropTypesHandled' ) ); |
124 | | - if ( in_array( $propertyType, $handledPropTypes ) ) { |
125 | | - $possibleInputTypes[] = $inputTypeName; |
126 | | - } |
| 140 | + return array(); |
127 | 141 | } |
| 142 | + } else { |
| 143 | + global $sfgPossibleInputsForPropType; |
| 144 | + if ( array_key_exists( $propertyType, $sfgPossibleInputsForPropType ) ) { |
| 145 | + return $sfgPossibleInputsForPropType[$propertyType]; |
| 146 | + } else { |
| 147 | + return array(); |
| 148 | + } |
128 | 149 | } |
129 | | - return $possibleInputTypes; |
130 | 150 | } |
131 | 151 | |
132 | 152 | public function getAllInputTypes() { |
— | — | @@ -1363,7 +1383,7 @@ |
1364 | 1384 | global $wgParser; |
1365 | 1385 | $new_text = ""; |
1366 | 1386 | if ( !$embedded ) { |
1367 | | - $new_text = $wgParser->recursiveTagParse (str_replace( "{{!}}", "|", $form_page_title ) ); |
| 1387 | + $new_text = $wgParser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) ); |
1368 | 1388 | } |
1369 | 1389 | |
1370 | 1390 | // If the form has already been submitted, i.e. this is just the redirect |