r97282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97281‎ | r97282 | r97283 >
Date:14:55, 16 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added support for new collapsed-sections feature in Page Schemas extension's 'edit schema' page
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php
@@ -47,15 +47,19 @@
4848 return true;
4949 }
5050
 51+ /**
 52+ * Constructs XML for the SMW property, based on what was submitted
 53+ * in the 'edit schema' form.
 54+ */
5155 function getFieldXML( $request, &$xmlArray ) {
52 - $templateNum = -1;
 56+ $fieldNum = -1;
5357 $xmlPerField = array();
5458 foreach ( $request->getValues() as $var => $val ) {
5559 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 . '" >';
5862 } elseif ( substr( $var, 0, 18 ) == 'smw_property_type_'){
59 - $xml .= '<Type>'.$val.'</Type>';
 63+ $xml .= '<Type>' . $val . '</Type>';
6064 } elseif ( substr( $var, 0, 11 ) == 'smw_values_') {
6165 if ( $val != '' ) {
6266 // replace the comma substitution character that has no chance of
@@ -66,11 +70,11 @@
6771 foreach ( $allowed_values_array as $i => $value ) {
6872 // replace beep back with comma, trim
6973 $value = str_replace( "\a", $listSeparator, trim( $value ) );
70 - $xml .= '<AllowedValue>'.$value.'</AllowedValue>';
 74+ $xml .= '<AllowedValue>' . $value . '</AllowedValue>';
7175 }
7276 }
7377 $xml .= '</semanticmediawiki_Property>';
74 - $xmlPerField[] = $xml;
 78+ $xmlPerField[$fieldNum] = $xml;
7579 }
7680 }
7781 $xmlArray['smw'] = $xmlPerField;
@@ -80,11 +84,15 @@
8185 function getFieldHTML( $field, &$text_extensions ) {
8286 global $smwgContLang;
8387 $datatype_labels = $smwgContLang->getDatatypeLabels();
 88+ $prop_array = array();
8489 if ( !is_null( $field ) ) {
8590 $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+ }
8997 }
9098 $html_text = '<p>Property name: ';
9199 if ( array_key_exists( 'name', $prop_array ) ) {
@@ -123,7 +131,7 @@
124132 }
125133 $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n";
126134
127 - $text_extensions['smw'] = array( 'Property', '#DEF', $html_text );
 135+ $text_extensions['smw'] = array( 'Semantic property', '#DEF', $html_text, $hasExistingValues );
128136
129137 return true;
130138 }
@@ -207,9 +215,10 @@
208216 }
209217 }
210218 $smw_array['allowed_value_array'] = $allowed_value_array;
 219+ $object['smw'] = $smw_array;
 220+ return true;
211221 }
212222 }
213 - $object['smw'] = $smw_array;
214223 }
215224 return true;
216225 }