Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php |
— | — | @@ -47,15 +47,19 @@ |
48 | 48 | return true; |
49 | 49 | } |
50 | 50 | |
| 51 | + /** |
| 52 | + * Constructs XML for the SMW property, based on what was submitted |
| 53 | + * in the 'edit schema' form. |
| 54 | + */ |
51 | 55 | function getFieldXML( $request, &$xmlArray ) { |
52 | | - $templateNum = -1; |
| 56 | + $fieldNum = -1; |
53 | 57 | $xmlPerField = array(); |
54 | 58 | foreach ( $request->getValues() as $var => $val ) { |
55 | 59 | if ( substr( $var, 0, 18 ) == 'smw_property_name_' ) { |
56 | | - $templateNum = substr($var,18,1); |
57 | | - $xml = '<semanticmediawiki_Property name="'.$val.'" >'; |
| 60 | + $fieldNum = substr( $var, 18 ); |
| 61 | + $xml = '<semanticmediawiki_Property name="' . $val . '" >'; |
58 | 62 | } elseif ( substr( $var, 0, 18 ) == 'smw_property_type_'){ |
59 | | - $xml .= '<Type>'.$val.'</Type>'; |
| 63 | + $xml .= '<Type>' . $val . '</Type>'; |
60 | 64 | } elseif ( substr( $var, 0, 11 ) == 'smw_values_') { |
61 | 65 | if ( $val != '' ) { |
62 | 66 | // replace the comma substitution character that has no chance of |
— | — | @@ -66,11 +70,11 @@ |
67 | 71 | foreach ( $allowed_values_array as $i => $value ) { |
68 | 72 | // replace beep back with comma, trim |
69 | 73 | $value = str_replace( "\a", $listSeparator, trim( $value ) ); |
70 | | - $xml .= '<AllowedValue>'.$value.'</AllowedValue>'; |
| 74 | + $xml .= '<AllowedValue>' . $value . '</AllowedValue>'; |
71 | 75 | } |
72 | 76 | } |
73 | 77 | $xml .= '</semanticmediawiki_Property>'; |
74 | | - $xmlPerField[] = $xml; |
| 78 | + $xmlPerField[$fieldNum] = $xml; |
75 | 79 | } |
76 | 80 | } |
77 | 81 | $xmlArray['smw'] = $xmlPerField; |
— | — | @@ -80,11 +84,15 @@ |
81 | 85 | function getFieldHTML( $field, &$text_extensions ) { |
82 | 86 | global $smwgContLang; |
83 | 87 | $datatype_labels = $smwgContLang->getDatatypeLabels(); |
| 88 | + $prop_array = array(); |
84 | 89 | if ( !is_null( $field ) ) { |
85 | 90 | $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
86 | | - $prop_array = $smw_array['smw']; |
87 | | - } else { |
88 | | - $prop_array = array(); |
| 91 | + if ( array_key_exists( 'smw', $smw_array ) ) { |
| 92 | + $prop_array = $smw_array['smw']; |
| 93 | + $hasExistingValues = true; |
| 94 | + } else { |
| 95 | + $hasExistingValues = false; |
| 96 | + } |
89 | 97 | } |
90 | 98 | $html_text = '<p>Property name: '; |
91 | 99 | if ( array_key_exists( 'name', $prop_array ) ) { |
— | — | @@ -123,7 +131,7 @@ |
124 | 132 | } |
125 | 133 | $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n"; |
126 | 134 | |
127 | | - $text_extensions['smw'] = array( 'Property', '#DEF', $html_text ); |
| 135 | + $text_extensions['smw'] = array( 'Semantic property', '#DEF', $html_text, $hasExistingValues ); |
128 | 136 | |
129 | 137 | return true; |
130 | 138 | } |
— | — | @@ -207,9 +215,10 @@ |
208 | 216 | } |
209 | 217 | } |
210 | 218 | $smw_array['allowed_value_array'] = $allowed_value_array; |
| 219 | + $object['smw'] = $smw_array; |
| 220 | + return true; |
211 | 221 | } |
212 | 222 | } |
213 | | - $object['smw'] = $smw_array; |
214 | 223 | } |
215 | 224 | return true; |
216 | 225 | } |