r82899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82898‎ | r82899 | r82900 >
Date:16:36, 27 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved handling of default and possible input types for each property type; other small changes
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -53,7 +53,9 @@
5454 * Register all information about the passed-in form input class.
5555 */
5656 function registerInputType( $inputTypeClass ) {
57 - global $smwgContLang;
 57+ global $smwgContLang, $sfgDefaultInputForPropType, $sfgDefaultInputForPropTypeList;
 58+ global $sfgPossibleInputsForPropType, $sfgPossibleInputsForPropTypeList;
 59+ global $sfgInitJSFunctions, $sfgValidationJSFunctions;
5860
5961 $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) );
6062 $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass;
@@ -70,6 +72,7 @@
7173 $propertyType = $datatypeLabels[$propertyTypeID];
7274 $this->setSemanticTypeHook( $propertyType, false, array( $inputTypeClass, 'getHTML' ), $additionalValues );
7375 }
 76+ $sfgDefaultInputForPropType[$propertyTypeID] = $inputTypeName;
7477 }
7578 $defaultPropertyLists = call_user_func( array( $inputTypeClass, 'getDefaultPropTypeLists' ) );
7679 foreach ( $defaultPropertyLists as $propertyTypeID => $additionalValues ) {
@@ -79,7 +82,34 @@
8083 $propertyType = $datatypeLabels[$propertyTypeID];
8184 $this->setSemanticTypeHook( $propertyType, true, array( $inputTypeClass, 'getHTML' ), $additionalValues );
8285 }
 86+ $sfgDefaultInputForPropTypeList[$propertyTypeID] = $inputTypeName;
8387 }
 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+ }
84114 }
85115
86116 function getInputType( $inputTypeName ) {
@@ -90,42 +120,32 @@
91121 }
92122 }
93123
94 - // TODO - this is very inefficient; the information should be stored in a
95 - // separate array, populated within registerInputType().
96124 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];
109131 }
110132 }
111133
112 - // TODO - this is very inefficient; the information should be stored in a
113 - // separate array, populated within registerInputType().
114134 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];
122139 } else {
123 - $handledPropTypes = call_user_func( array( $className, 'getOtherPropTypesHandled' ) );
124 - if ( in_array( $propertyType, $handledPropTypes ) ) {
125 - $possibleInputTypes[] = $inputTypeName;
126 - }
 140+ return array();
127141 }
 142+ } else {
 143+ global $sfgPossibleInputsForPropType;
 144+ if ( array_key_exists( $propertyType, $sfgPossibleInputsForPropType ) ) {
 145+ return $sfgPossibleInputsForPropType[$propertyType];
 146+ } else {
 147+ return array();
 148+ }
128149 }
129 - return $possibleInputTypes;
130150 }
131151
132152 public function getAllInputTypes() {
@@ -1363,7 +1383,7 @@
13641384 global $wgParser;
13651385 $new_text = "";
13661386 if ( !$embedded ) {
1367 - $new_text = $wgParser->recursiveTagParse (str_replace( "{{!}}", "|", $form_page_title ) );
 1387+ $new_text = $wgParser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) );
13681388 }
13691389
13701390 // If the form has already been submitted, i.e. this is just the redirect