r97425 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97424‎ | r97425 | r97426 >
Date:15:57, 18 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Some improvements to code and comments
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php
@@ -83,18 +83,18 @@
8484
8585 function getFieldHTML( $field, &$text_extensions ) {
8686 global $smwgContLang;
 87+
8788 $datatype_labels = $smwgContLang->getDatatypeLabels();
8889 $prop_array = array();
 90+ $hasExistingValues = false;
8991 if ( !is_null( $field ) ) {
9092 $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
9193 if ( array_key_exists( 'smw', $smw_array ) ) {
9294 $prop_array = $smw_array['smw'];
9395 $hasExistingValues = true;
94 - } else {
95 - $hasExistingValues = false;
9696 }
9797 }
98 - $html_text = '<p>Property name: ';
 98+ $html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' ';
9999 if ( array_key_exists( 'name', $prop_array ) ) {
100100 $propName = $prop_array['name'];
101101 } else {
@@ -124,8 +124,8 @@
125125 $allowedValsInputAttrs = array(
126126 'size' => 80
127127 );
128 - if ( array_key_exists( 'allowed_value_array', $prop_array ) ) {
129 - $allowed_val_string = implode( ', ', $prop_array['allowed_value_array'] );
 128+ if ( array_key_exists( 'allowed_values', $prop_array ) ) {
 129+ $allowed_val_string = implode( ', ', $prop_array['allowed_values'] );
130130 } else {
131131 $allowed_val_string = '';
132132 }
@@ -137,19 +137,20 @@
138138 }
139139
140140 function generatePages( $psSchemaObj, $toGenPageList ) {
 141+ // Get the SMW info from every field in every template
141142 $template_all = $psSchemaObj->getTemplates();
142143 foreach ( $template_all as $template ) {
143144 $field_all = $template->getFields();
144 - $field_count = 0; //counts the number of fields
145 - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
 145+ $field_count = 0;
 146+ foreach( $field_all as $field ) {
146147 $field_count++;
147 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
 148+ $smw_array = $field->getObject('semanticmediawiki_Property');
148149 $prop_array = $smw_array['smw'];
149150 if($prop_array != null){
150151 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
151152 $key_title = PageSchemas::titleString( $title );
152153 if(in_array( $key_title, $toGenPageList )){
153 - self::createProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_value_array'] ) ;
 154+ self::createProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_values'] ) ;
154155 }
155156 }
156157 }
@@ -157,16 +158,16 @@
158159 return true;
159160 }
160161
161 - function createPropertyText( $property_type, $allowed_value_array ) {
 162+ function createPropertyText( $property_type, $allowed_values ) {
162163 global $smwgContLang;
163164 $prop_labels = $smwgContLang->getPropertyLabels();
164165 $type_tag = "[[{$prop_labels['_TYPE']}::$property_type]]";
165166 $text = wfMsgForContent( 'ps-property-isproperty', $type_tag );
166 - if ( $allowed_value_array != null) {
 167+ if ( $allowed_values != null) {
167168 // replace the comma substitution character that has no chance of
168169 // being included in the values list - namely, the ASCII beep
169 - $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_value_array ) );
170 - foreach ( $allowed_value_array as $i => $value ) {
 170+ $text .= "\n\n" . wfMsgExt( 'ps-property-allowedvals', array( 'parsemag', 'content' ), count( $allowed_values ) );
 171+ foreach ( $allowed_values as $i => $value ) {
171172 // replace beep back with comma, trim
172173 $value = str_replace( "\a",',' , trim( $value ) );
173174 if ( method_exists( $smwgContLang, 'getPropertyLabels' ) ) {
@@ -181,10 +182,10 @@
182183 return $text;
183184 }
184185
185 - function createProperty( $prop_name, $prop_type, $allowed_value_array ) {
 186+ function createProperty( $prop_name, $prop_type, $allowed_values ) {
186187 global $wgUser;
187188 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name );
188 - $text = self::createPropertyText( $prop_type, $allowed_value_array );
 189+ $text = self::createPropertyText( $prop_type, $allowed_values );
189190 $jobs = array();
190191 $params = array();
191192 $params['user_id'] = $wgUser->getId();
@@ -203,18 +204,17 @@
204205 foreach ( $xmlForField->children() as $tag => $child ) {
205206 if ( $tag == $objectName ) {
206207 $propName = $child->attributes()->name;
207 - //this means object has already been initialized by some other extension.
208 - $smw_array['name']=(string)$propName;
209 - $allowed_value_array = array();
 208+ $smw_array['name'] = (string)$propName;
 209+ $allowed_values = array();
210210 $count = 0;
211211 foreach ( $child->children() as $prop => $value ) {
212212 if ( $prop == "AllowedValue" ) {
213 - $allowed_value_array[$count++] = $value;
 213+ $allowed_values[$count++] = $value;
214214 } else {
215215 $smw_array[$prop] = (string)$value;
216216 }
217217 }
218 - $smw_array['allowed_value_array'] = $allowed_value_array;
 218+ $smw_array['allowed_values'] = $allowed_values;
219219 $object['smw'] = $smw_array;
220220 return true;
221221 }
@@ -223,4 +223,3 @@
224224 return true;
225225 }
226226 }
227 -