r88214 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88213‎ | r88214 | r88215 >
Date:03:35, 16 May 2011
Author:yaron
Status:deferred
Tags:
Comment:
Additions for further SMW 1.6 compatibility
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_Filter.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
@@ -31,7 +31,11 @@
3232 $proptitle = Title::newFromText( $f->property, SMW_NS_PROPERTY );
3333 if ( $proptitle != null ) {
3434 $store = smwfGetStore();
35 - if ( class_exists( 'SMWPropertyValue' ) ) {
 35+ if ( class_exists( 'SMWDIProperty' ) ) {
 36+ // SMW 1.6
 37+ $propPage = new SMWDIWikiPage( $f->escaped_property, SMW_NS_PROPERTY, null );
 38+ $types = $store->getPropertyValues( $propPage, new SMWDIProperty( '_TYPE' ) );
 39+ } elseif ( class_exists( 'SMWPropertyValue' ) ) {
3640 $types = $store->getPropertyValues( $proptitle, SMWPropertyValue::makeUserProperty( 'Has type' ) );
3741 } else {
3842 $types = $store->getSpecialValues( $proptitle, SMW_SP_HAS_TYPE );
@@ -39,13 +43,19 @@
4044 global $smwgContLang;
4145 $datatypeLabels = $smwgContLang->getDatatypeLabels();
4246 if ( count( $types ) > 0 ) {
43 - if ( $types[0]->getWikiValue() != $datatypeLabels['_wpg'] ) {
 47+ if ( $types[0] instanceof SMWDIWikiPage ) {
 48+ // SMW 1.6
 49+ $typeValue = $types[0]->getDBkey();
 50+ } else {
 51+ $typeValue = $types[0]->getWikiValue();
 52+ }
 53+ if ( $typeValue != $datatypeLabels['_wpg'] ) {
4454 $f->is_relation = false;
4555 }
46 - if ( $types[0]->getWikiValue() == $datatypeLabels['_boo'] ) {
 56+ if ( $typeValue == $datatypeLabels['_boo'] ) {
4757 $f->is_boolean = true;
4858 }
49 - if ( $types[0]->getWikiValue() == $datatypeLabels['_dat'] ) {
 59+ if ( $typeValue == $datatypeLabels['_dat'] ) {
5060 $f->is_date = true;
5161 }
5262 }
Index: trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
@@ -72,8 +72,8 @@
7373 $sdgNamespaceIndex = 170;
7474 }
7575
76 - define( 'SD_NS_FILTER', $sdgNamespaceIndex );
77 - define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
 76+ define( 'SD_NS_FILTER', $sdgNamespaceIndex );
 77+ define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
7878
7979 sdfInitContentLanguage( $wgLanguageCode );
8080
@@ -139,11 +139,11 @@
140140 include_once( $sdgIP . '/languages/' . $sdLangClass . '.php' );
141141 }
142142
143 - // fallback if language not supported
144 - if ( !class_exists( $sdLangClass ) ) {
145 - include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
146 - $sdLangClass = 'SD_LanguageEn';
147 - }
 143+ // fallback if language not supported
 144+ if ( !class_exists( $sdLangClass ) ) {
 145+ include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
 146+ $sdLangClass = 'SD_LanguageEn';
 147+ }
148148
149149 $sdgLang = new $sdLangClass();
150150 }
@@ -166,30 +166,38 @@
167167 $sd_prop_labels = $sdgContLang->getPropertyLabels();
168168 foreach ( $sd_prop_labels as $prop_id => $prop_alias ) {
169169 $prop_vals = $sd_property_vals[$prop_id];
170 - SMWPropertyValue::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
 170+ if ( class_exists( 'SMWDIProperty' ) ) {
 171+ SMWDIProperty::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
 172+ } else {
 173+ SMWPropertyValue::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
 174+ }
171175 }
172176 // if it's not English, add the English-language aliases as well
173177 if ( $wgLanguageCode != 'en' ) {
174178 $sd_prop_aliases = $sdgContLang->getPropertyAliases();
175179 foreach ( $sd_prop_aliases as $prop_alias => $prop_id ) {
176180 $prop_vals = $sd_property_vals[$prop_id];
177 - SMWPropertyValue::registerPropertyAlias( $prop_vals[0], $prop_alias );
 181+ if ( class_exists( 'SMWDIProperty' ) ) {
 182+ SMWDIProperty::registerPropertyAlias( $prop_vals[0], $prop_alias );
 183+ } else {
 184+ SMWPropertyValue::registerPropertyAlias( $prop_vals[0], $prop_alias );
 185+ }
178186 }
179187 }
180 - return true;
 188+ return true;
181189 }
182190
183191 function sdfAddToAdminLinks( &$admin_links_tree ) {
184 - $browse_search_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_browsesearch' ) );
185 - $sd_row = new ALRow( 'sd' );
186 - $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
187 - $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
188 - $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
189 - $sd_name = wfMsg( 'specialpages-group-sd_group' );
190 - $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
191 - $sd_row->addItem( AlItem::newFromExternalLink( "http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label ) );
 192+ $browse_search_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_browsesearch' ) );
 193+ $sd_row = new ALRow( 'sd' );
 194+ $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
 195+ $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
 196+ $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
 197+ $sd_name = wfMsg( 'specialpages-group-sd_group' );
 198+ $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
 199+ $sd_row->addItem( AlItem::newFromExternalLink( "http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label ) );
192200
193 - $browse_search_section->addRow( $sd_row );
 201+ $browse_search_section->addRow( $sd_row );
194202
195 - return true;
 203+ return true;
196204 }
Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php
@@ -16,6 +16,7 @@
1717 public static function getSMWPropertyValues( $store, $pageName, $pageNamespace, $propID, $requestOptions = null ) {
1818 // SMWDIProperty was added in SMW 1.6
1919 if ( class_exists( 'SMWDIProperty' ) ) {
 20+ $pageName = str_replace( ' ', '_', $pageName );
2021 $page = new SMWDIWikiPage( $pageName, $pageNamespace, null );
2122 $property = new SMWDIProperty( $propID );
2223 return $store->getPropertyValues( $page, $property, $requestOptions );
@@ -127,8 +128,6 @@
128129 /**
129130 * Generic static function - gets all the values that a specific page
130131 * points to with a specific property
131 - * ($special_prop and $prop represent the same value, depending on
132 - * whether we're using SMW 1.4 or an earlier version)
133132 */
134133 static function getValuesForProperty( $subject, $subject_namespace, $special_prop ) {
135134 $store = smwfGetStore();
@@ -136,7 +135,11 @@
137136 $values = array();
138137 foreach ( $res as $prop_val ) {
139138 // depends on version of SMW
140 - if ( method_exists( $prop_val, 'getValueKey' ) ) {
 139+ if ( $prop_val instanceof SMWDIWikiPage ) {
 140+ $actual_val = $prop_val->getDBkey();
 141+ } elseif ( $prop_val instanceof SMWDIString ) {
 142+ $actual_val = $prop_val->getString();
 143+ } elseif ( method_exists( $prop_val, 'getValueKey' ) ) {
141144 $actual_val = $prop_val->getValueKey();
142145 } else {
143146 $actual_val = $prop_val->getXSDValue();

Status & tagging log