r99752 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99751‎ | r99752 | r99753 >
Date:02:40, 14 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fix for r99748, plus some small improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php
@@ -32,15 +32,15 @@
3333 }
3434
3535 /**
36 - * Returns the list of property pages defined by the passed-in
37 - * Page Schemas XML object.
 36+ * Returns the set of SMW property data from the entire page schema.
3837 */
39 - function getPageList( $psSchemaObj , &$genPageList ) {
40 - $template_all = $psSchemaObj->getTemplates();
41 - foreach ( $template_all as $template ) {
42 - $field_all = $template->getFields();
43 - foreach( $field_all as $field ) {
44 - $smw_array = $field->getObject('semanticmediawiki_Property');
 38+ static function getAllPropertyData( $psSchemaObj ) {
 39+ $propertyDataArray = array();
 40+ $psTemplates = $psSchemaObj->getTemplates();
 41+ foreach ( $psTemplates as $psTemplate ) {
 42+ $psTemplateFields = $psTemplate->getFields();
 43+ foreach ( $psTemplateFields as $psTemplateField ) {
 44+ $smw_array = $psTemplateField->getObject('semanticmediawiki_Property');
4545 if ( !array_key_exists( 'smw', $smw_array ) ) {
4646 continue;
4747 }
@@ -51,10 +51,22 @@
5252 if ( empty( $prop_array['name'] ) ) {
5353 continue;
5454 }
55 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
56 - $genPageList[] = $title;
 55+ $propertyDataArray[] = $prop_array;
5756 }
5857 }
 58+ return $propertyDataArray;
 59+ }
 60+
 61+ /**
 62+ * Sets the list of property pages defined by the passed-in
 63+ * Page Schemas XML object.
 64+ */
 65+ function getPageList( $psSchemaObj , &$genPageList ) {
 66+ $propertyDataArray = self::getAllPropertyData( $psSchemaObj );
 67+ foreach ( $propertyDataArray as $propertyData ) {
 68+ $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $propertyData['name'] );
 69+ $genPageList[] = $title;
 70+ }
5971 return true;
6072 }
6173
@@ -96,7 +108,7 @@
97109 * Returns the HTML necessary for getting information about the
98110 * semantic property within the Page Schemas 'editschema' page.
99111 */
100 - function getFieldHTML( $field, &$text_extensions ) {
 112+ function getFieldHTML( $field, &$fieldHTMLFromExtensions ) {
101113 global $smwgContLang;
102114
103115 $prop_array = array();
@@ -146,7 +158,7 @@
147159 }
148160 $html_text .= '<p>' . Html::input( 'smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs ) . "</p>\n";
149161
150 - $text_extensions['smw'] = array( 'Semantic property', '#DEF', $html_text, $hasExistingValues );
 162+ $fieldHTMLFromExtensions['smw'] = array( 'Semantic property', '#DEF', $html_text, $hasExistingValues );
151163
152164 return true;
153165 }
@@ -156,17 +168,20 @@
157169 * passed-in Page Schemas XML object.
158170 */
159171 function generatePages( $psSchemaObj, $selectedPageList ) {
160 - $genPageList = array();
161 - self::getPageList( $psSchemaObj , &$genPageList );
162 - foreach ( $genPageList as $generatedPage ) {
163 - if ( !in_array( $generatedPage, $selectedPageList ) ) {
 172+ $propertyDataArray = self::getAllPropertyData( $psSchemaObj );
 173+ foreach ( $propertyDataArray as $propertyData ) {
 174+ $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $propertyData['name'] );
 175+ if ( !in_array( $title, $selectedPageList ) ) {
164176 continue;
165177 }
166 - self::createProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_values'] ) ;
 178+ self::createProperty( $propertyData['name'], $propertyData['Type'], $propertyData['allowed_values'] );
167179 }
168180 return true;
169181 }
170182
 183+ /**
 184+ * Creates the text for a property page.
 185+ */
171186 function createPropertyText( $property_type, $allowed_values ) {
172187 global $smwgContLang;
173188 $prop_labels = $smwgContLang->getPropertyLabels();
@@ -194,6 +209,7 @@
195210
196211 function createProperty( $prop_name, $prop_type, $allowed_values ) {
197212 global $wgUser;
 213+
198214 $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_name );
199215 $params = array();
200216 $params['user_id'] = $wgUser->getId();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99748Simplified generatePages() by eliminating some duplicate codeyaron00:11, 14 October 2011