r99748 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99747‎ | r99748 | r99749 >
Date:00:11, 14 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Simplified generatePages() by eliminating some duplicate code
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PageSchemas.php
@@ -41,11 +41,18 @@
4242 $field_all = $template->getFields();
4343 foreach( $field_all as $field ) {
4444 $smw_array = $field->getObject('semanticmediawiki_Property');
45 - if ( array_key_exists( 'smw', $smw_array ) ) {
46 - $prop_array = $smw_array['smw'];
47 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
48 - $genPageList[] = $title;
 45+ if ( !array_key_exists( 'smw', $smw_array ) ) {
 46+ continue;
4947 }
 48+ $prop_array = $smw_array['smw'];
 49+ if ( !array_key_exists( 'name', $prop_array ) ) {
 50+ continue;
 51+ }
 52+ if ( empty( $prop_array['name'] ) ) {
 53+ continue;
 54+ }
 55+ $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
 56+ $genPageList[] = $title;
5057 }
5158 }
5259 return true;
@@ -148,30 +155,14 @@
149156 * Creates the property page for each property specified in the
150157 * passed-in Page Schemas XML object.
151158 */
152 - function generatePages( $psSchemaObj, $toGenPageList ) {
153 - // Get the SMW info from every field in every template
154 - $template_all = $psSchemaObj->getTemplates();
155 - foreach ( $template_all as $template ) {
156 - $field_all = $template->getFields();
157 - foreach ( $field_all as $field ) {
158 - $smw_array = $field->getObject('semanticmediawiki_Property');
159 - if ( !array_key_exists( 'smw', $smw_array ) ) {
160 - continue;
161 - }
162 - $prop_array = $smw_array['smw'];
163 - if ( !array_key_exists( 'name', $prop_array ) ) {
164 - continue;
165 - }
166 - if ( empty( $prop_array['name'] ) ) {
167 - continue;
168 - }
169 - $title = Title::makeTitleSafe( SMW_NS_PROPERTY, $prop_array['name'] );
170 - $key_title = PageSchemas::titleString( $title );
171 - if ( !in_array( $key_title, $toGenPageList ) ) {
172 - continue;
173 - }
174 - self::createProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_values'] ) ;
 159+ function generatePages( $psSchemaObj, $selectedPageList ) {
 160+ $genPageList = array();
 161+ self::getPageList( $psSchemaObj , &$genPageList );
 162+ foreach ( $genPageList as $generatedPage ) {
 163+ if ( !in_array( $generatedPage, $selectedPageList ) ) {
 164+ continue;
175165 }
 166+ self::createProperty( $prop_array['name'], $prop_array['Type'], $prop_array['allowed_values'] ) ;
176167 }
177168 return true;
178169 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r99752Fix for r99748, plus some small improvementsyaron02:40, 14 October 2011