r86822 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86821‎ | r86822 | r86823 >
Date:17:23, 24 April 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added new function, SFUtils::getSMWPropertyValues() - wrapper around old and new versions of SMW's getPropertyValues()
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormLinker.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormLinker.php
@@ -33,12 +33,22 @@
3434 die( "ERROR: <a href=\"http://semantic-mediawiki.org\">Semantic MediaWiki</a> must be installed for Semantic Forms to run!" );
3535 }
3636 $store = smwfGetStore();
37 - $title_text = SFUtils::titleString( $title );
38 - $value = SMWDataValueFactory::newTypeIDValue( '_wpg', $title_text );
 37+ // SMW 1.6+
 38+ if ( class_exists( 'SMWDataItem' ) ) {
 39+ $value = new SMWDIWikiPage( $title->getText(), $title->getNamespace(), null );
 40+ } else {
 41+ $title_text = SFUtils::titleString( $title );
 42+ $value = SMWDataValueFactory::newTypeIDValue( '_wpg', $title_text );
 43+ }
3944 $properties = $store->getInProperties( $value );
4045 $propertyNames = array();
4146 foreach( $properties as $property ) {
42 - $property_name = $property->getWikiValue();
 47+ // SMW 1.6+
 48+ if ( $property instanceof SMWDIProperty ) {
 49+ $property_name = $property->getKey();
 50+ } else {
 51+ $property_name = $property->getWikiValue();
 52+ }
4353 if ( !empty( $property_name ) ) {
4454 $propertyNames[] = $property_name;
4555 }
@@ -123,13 +133,8 @@
124134 }
125135
126136 $store = smwfGetStore();
127 - $title = Title::makeTitleSafe( $page_namespace, $page_name );
128 - $property = SMWPropertyValue::makeProperty( $prop_smw_id );
 137+ $res = SFUtils::getSMWPropertyValues( $store, $page_name, $page_namespace, $prop_smw_id );
129138
130 - $res = $store->getPropertyValues( $title, $property );
131 - // FIXME: should probably change into something like this for SMW 1.6:
132 - //$res = $store->getPropertyValues( $title, new SMWDIProperty( $title->getDBkey() ) );
133 -
134139 $form_names = array();
135140 foreach ( $res as $wiki_page_value ) {
136141 $form_title = $wiki_page_value->getTitle();
@@ -139,8 +144,7 @@
140145 }
141146 // if we're using a non-English language, check for the English string as well
142147 if ( ! class_exists( 'SF_LanguageEn' ) || ! $sfgContLang instanceof SF_LanguageEn ) {
143 - $backup_property = SMWPropertyValue::makeProperty( $backup_prop_smw_id );
144 - $res = $store->getPropertyValues( $title, $backup_property );
 148+ $res = SFUtils::getSMWPropertyValues( $store, $page_name, $page_namespace, $backup_prop_smw_id );
145149 foreach ( $res as $wiki_page_value )
146150 $form_names[] = $wiki_page_value->getTitle()->getText();
147151 }
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -72,6 +72,24 @@
7373 }
7474
7575 /**
 76+ * Helper function to handle getPropertyValues() in both SMW 1.6
 77+ * and earlier versions.
 78+ */
 79+ public static function getSMWPropertyValues( $store, $pageName, $pageNamespace, $propID, $requestOptions = null ) {
 80+ // SMWDIProperty was added in SMW 1.6
 81+ if ( class_exists( 'SMWDIProperty' ) ) {
 82+
 83+ $page = new SMWDIWikiPage( $pageName, $pageNamespace, null );
 84+ $property = new SMWDIProperty( $propID );
 85+ return $store->getPropertyValues( $page, $property, $requestOptions );
 86+ } else {
 87+ $title = Title::makeTitleSafe( $pageNamespace, $pageName );
 88+ $property = SMWPropertyValue::makeProperty( $propID );
 89+ return $store->getPropertyValues( $title, $property, $requestOptions );
 90+ }
 91+ }
 92+
 93+ /**
7694 * Helper function - gets names of categories for a page;
7795 * based on Title::getParentCategories(), but simpler
7896 * - this function doubles as a function to get all categories on
@@ -348,7 +366,8 @@
349367 $requestoptions = new SMWRequestOptions();
350368 $requestoptions->limit = $sfgMaxAutocompleteValues;
351369 $property = SMWPropertyValue::makeProperty( $property_name );
352 - $data_values = $store->getPropertyValues( null, $property, $requestoptions );
 370+ //$data_values = $store->getPropertyValues( null, $property, $requestoptions );
 371+ $data_values = self::getSMWPropertyValues( $store, null, null, $property, $requestoptions );
353372 $values = array();
354373 foreach ( $data_values as $dv ) {
355374 // getPropertyValues() gets many repeat values - we want

Follow-up revisions

RevisionCommit summaryAuthorDate
r86836Follow-up to r86822 - fix for erroryaron05:04, 25 April 2011