r97699 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97698‎ | r97699 | r97700 >
Date:06:11, 21 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Some improvements to code and comments, including internationalizing more messages
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php
@@ -15,9 +15,8 @@
1616 function parseFieldElements( $field_xml, &$text_object ) {
1717 foreach ( $field_xml->children() as $tag => $child ) {
1818 if ( $tag == "semanticmediawiki_Property" ) {
19 - $text = "";
20 - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticMediaWiki", (string)$tag );
21 - $propName = $child->attributes()->name;
 19+ $text = PageSchemas::tableMessageRowHTML( "paramAttr", wfMsg( 'specialpages-group-smw_group' ), wfMsg( 'smw_pp_type' ) );
 20+ $propName = $child->attributes()->name;
2221 // this means object has already been initialized by some other extension.
2322 $text .= PageSchemas::tableMessageRowHTML( "paramAttrMsg", "name", (string)$propName );
2423 foreach ( $child->children() as $prop => $value ) {
@@ -29,14 +28,16 @@
3029 return true;
3130 }
3231
 32+ /**
 33+ * Returns the list of property pages defined by the passed-in
 34+ * Page Schemas XML object.
 35+ */
3336 function getPageList( $psSchemaObj , &$genPageList ) {
3437 $template_all = $psSchemaObj->getTemplates();
3538 foreach ( $template_all as $template ) {
3639 $field_all = $template->getFields();
37 - $field_count = 0; //counts the number of fields
38 - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
39 - $field_count++;
40 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
 40+ foreach( $field_all as $field ) {
 41+ $smw_array = $field->getObject('semanticmediawiki_Property');
4142 if ( array_key_exists( 'smw', $smw_array ) ) {
4243 $prop_array = $smw_array['smw'];
4344 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
@@ -81,6 +82,10 @@
8283 return true;
8384 }
8485
 86+ /**
 87+ * Returns the HTML necessary for getting information about the
 88+ * semantic property within the Page Schemas 'editschema' page.
 89+ */
8590 function getFieldHTML( $field, &$text_extensions ) {
8691 global $smwgContLang;
8792
@@ -88,7 +93,7 @@
8994 $prop_array = array();
9095 $hasExistingValues = false;
9196 if ( !is_null( $field ) ) {
92 - $smw_array = $field->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
 97+ $smw_array = $field->getObject('semanticmediawiki_Property');
9398 if ( array_key_exists( 'smw', $smw_array ) ) {
9499 $prop_array = $smw_array['smw'];
95100 $hasExistingValues = true;
@@ -136,17 +141,19 @@
137142 return true;
138143 }
139144
 145+ /**
 146+ * Creates the property page for each property specified in the
 147+ * passed-in Page Schemas XML object.
 148+ */
140149 function generatePages( $psSchemaObj, $toGenPageList ) {
141150 // Get the SMW info from every field in every template
142151 $template_all = $psSchemaObj->getTemplates();
143152 foreach ( $template_all as $template ) {
144153 $field_all = $template->getFields();
145 - $field_count = 0;
146154 foreach( $field_all as $field ) {
147 - $field_count++;
148155 $smw_array = $field->getObject('semanticmediawiki_Property');
149 - $prop_array = $smw_array['smw'];
150 - if($prop_array != null){
 156+ if ( array_key_exists( 'smw', $smw_array ) ) {
 157+ $prop_array = $smw_array['smw'];
151158 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
152159 $key_title = PageSchemas::titleString( $title );
153160 if(in_array( $key_title, $toGenPageList )){
@@ -185,25 +192,25 @@
186193 function createProperty( $prop_name, $prop_type, $allowed_values ) {
187194 global $wgUser;
188195 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name );
189 - $text = self::createPropertyText( $prop_type, $allowed_values );
190 - $jobs = array();
191196 $params = array();
192197 $params['user_id'] = $wgUser->getId();
193 - $params['page_text'] = $text;
 198+ $params['page_text'] = self::createPropertyText( $prop_type, $allowed_values );
 199+ $jobs = array();
194200 $jobs[] = new PSCreatePageJob( $title, $params );
195201 Job::batchInsert( $jobs );
196202 return true;
197203 }
198204
199205 /**
200 - * Returns the property based on the XML passed from the Page Schemas extension
 206+ * Returns the property based on the XML passed from the Page Schemas
 207+ * extension.
201208 */
202209 function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
203210 $smw_array = array();
204211 if ( $objectName == "semanticmediawiki_Property" ) {
205212 foreach ( $xmlForField->children() as $tag => $child ) {
206213 if ( $tag == $objectName ) {
207 - $propName = $child->attributes()->name;
 214+ $propName = $child->attributes()->name;
208215 $smw_array['name'] = (string)$propName;
209216 $allowed_values = array();
210217 $count = 0;