http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88214
Revision: 88214
Author: yaron
Date: 2011-05-16 03:35:18 +0000 (Mon, 16 May 2011)
Log Message:
-----------
Additions for further SMW 1.6 compatibility
Modified Paths:
--------------
trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
trunk/extensions/SemanticDrilldown/includes/SD_Utils.php
Modified: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
===================================================================
--- trunk/extensions/SemanticDrilldown/includes/SD_Filter.php 2011-05-16
03:28:16 UTC (rev 88213)
+++ trunk/extensions/SemanticDrilldown/includes/SD_Filter.php 2011-05-16
03:35:18 UTC (rev 88214)
@@ -31,7 +31,11 @@
$proptitle = Title::newFromText( $f->property, SMW_NS_PROPERTY
);
if ( $proptitle != null ) {
$store = smwfGetStore();
- if ( class_exists( 'SMWPropertyValue' ) ) {
+ if ( class_exists( 'SMWDIProperty' ) ) {
+ // SMW 1.6
+ $propPage = new SMWDIWikiPage(
$f->escaped_property, SMW_NS_PROPERTY, null );
+ $types = $store->getPropertyValues( $propPage,
new SMWDIProperty( '_TYPE' ) );
+ } elseif ( class_exists( 'SMWPropertyValue' ) ) {
$types = $store->getPropertyValues( $proptitle,
SMWPropertyValue::makeUserProperty( 'Has type' ) );
} else {
$types = $store->getSpecialValues( $proptitle,
SMW_SP_HAS_TYPE );
@@ -39,13 +43,19 @@
global $smwgContLang;
$datatypeLabels = $smwgContLang->getDatatypeLabels();
if ( count( $types ) > 0 ) {
- if ( $types[0]->getWikiValue() !=
$datatypeLabels['_wpg'] ) {
+ if ( $types[0] instanceof SMWDIWikiPage ) {
+ // SMW 1.6
+ $typeValue = $types[0]->getDBkey();
+ } else {
+ $typeValue = $types[0]->getWikiValue();
+ }
+ if ( $typeValue != $datatypeLabels['_wpg'] ) {
$f->is_relation = false;
}
- if ( $types[0]->getWikiValue() ==
$datatypeLabels['_boo'] ) {
+ if ( $typeValue == $datatypeLabels['_boo'] ) {
$f->is_boolean = true;
}
- if ( $types[0]->getWikiValue() ==
$datatypeLabels['_dat'] ) {
+ if ( $typeValue == $datatypeLabels['_dat'] ) {
$f->is_date = true;
}
}
Modified: trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
===================================================================
--- trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
2011-05-16 03:28:16 UTC (rev 88213)
+++ trunk/extensions/SemanticDrilldown/includes/SD_GlobalFunctions.php
2011-05-16 03:35:18 UTC (rev 88214)
@@ -72,8 +72,8 @@
$sdgNamespaceIndex = 170;
}
- define( 'SD_NS_FILTER', $sdgNamespaceIndex );
- define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
+ define( 'SD_NS_FILTER', $sdgNamespaceIndex );
+ define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
sdfInitContentLanguage( $wgLanguageCode );
@@ -139,11 +139,11 @@
include_once( $sdgIP . '/languages/' . $sdLangClass . '.php' );
}
- // fallback if language not supported
- if ( !class_exists( $sdLangClass ) ) {
- include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
- $sdLangClass = 'SD_LanguageEn';
- }
+ // fallback if language not supported
+ if ( !class_exists( $sdLangClass ) ) {
+ include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
+ $sdLangClass = 'SD_LanguageEn';
+ }
$sdgLang = new $sdLangClass();
}
@@ -166,30 +166,38 @@
$sd_prop_labels = $sdgContLang->getPropertyLabels();
foreach ( $sd_prop_labels as $prop_id => $prop_alias ) {
$prop_vals = $sd_property_vals[$prop_id];
- SMWPropertyValue::registerProperty( $prop_vals[0],
$prop_vals[1], $prop_alias, true );
+ if ( class_exists( 'SMWDIProperty' ) ) {
+ SMWDIProperty::registerProperty( $prop_vals[0],
$prop_vals[1], $prop_alias, true );
+ } else {
+ SMWPropertyValue::registerProperty( $prop_vals[0],
$prop_vals[1], $prop_alias, true );
+ }
}
// if it's not English, add the English-language aliases as well
if ( $wgLanguageCode != 'en' ) {
$sd_prop_aliases = $sdgContLang->getPropertyAliases();
foreach ( $sd_prop_aliases as $prop_alias => $prop_id ) {
$prop_vals = $sd_property_vals[$prop_id];
- SMWPropertyValue::registerPropertyAlias( $prop_vals[0],
$prop_alias );
+ if ( class_exists( 'SMWDIProperty' ) ) {
+ SMWDIProperty::registerPropertyAlias(
$prop_vals[0], $prop_alias );
+ } else {
+ SMWPropertyValue::registerPropertyAlias(
$prop_vals[0], $prop_alias );
+ }
}
}
- return true;
+ return true;
}
function sdfAddToAdminLinks( &$admin_links_tree ) {
- $browse_search_section = $admin_links_tree->getSection( wfMsg(
'adminlinks_browsesearch' ) );
- $sd_row = new ALRow( 'sd' );
- $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
- $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
- $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
- $sd_name = wfMsg( 'specialpages-group-sd_group' );
- $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
- $sd_row->addItem( AlItem::newFromExternalLink(
"http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label )
);
+ $browse_search_section = $admin_links_tree->getSection( wfMsg(
'adminlinks_browsesearch' ) );
+ $sd_row = new ALRow( 'sd' );
+ $sd_row->addItem( ALItem::newFromSpecialPage( 'BrowseData' ) );
+ $sd_row->addItem( ALItem::newFromSpecialPage( 'Filters' ) );
+ $sd_row->addItem( ALItem::newFromSpecialPage( 'CreateFilter' ) );
+ $sd_name = wfMsg( 'specialpages-group-sd_group' );
+ $sd_docu_label = wfMsg( 'adminlinks_documentation', $sd_name );
+ $sd_row->addItem( AlItem::newFromExternalLink(
"http://www.mediawiki.org/wiki/Extension:Semantic_Drilldown", $sd_docu_label )
);
- $browse_search_section->addRow( $sd_row );
+ $browse_search_section->addRow( $sd_row );
- return true;
+ return true;
}
Modified: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php
===================================================================
--- trunk/extensions/SemanticDrilldown/includes/SD_Utils.php 2011-05-16
03:28:16 UTC (rev 88213)
+++ trunk/extensions/SemanticDrilldown/includes/SD_Utils.php 2011-05-16
03:35:18 UTC (rev 88214)
@@ -16,6 +16,7 @@
public static function getSMWPropertyValues( $store, $pageName,
$pageNamespace, $propID, $requestOptions = null ) {
// SMWDIProperty was added in SMW 1.6
if ( class_exists( 'SMWDIProperty' ) ) {
+ $pageName = str_replace( ' ', '_', $pageName );
$page = new SMWDIWikiPage( $pageName, $pageNamespace,
null );
$property = new SMWDIProperty( $propID );
return $store->getPropertyValues( $page, $property,
$requestOptions );
@@ -127,8 +128,6 @@
/**
* Generic static function - gets all the values that a specific page
* points to with a specific property
- * ($special_prop and $prop represent the same value, depending on
- * whether we're using SMW 1.4 or an earlier version)
*/
static function getValuesForProperty( $subject, $subject_namespace,
$special_prop ) {
$store = smwfGetStore();
@@ -136,7 +135,11 @@
$values = array();
foreach ( $res as $prop_val ) {
// depends on version of SMW
- if ( method_exists( $prop_val, 'getValueKey' ) ) {
+ if ( $prop_val instanceof SMWDIWikiPage ) {
+ $actual_val = $prop_val->getDBkey();
+ } elseif ( $prop_val instanceof SMWDIString ) {
+ $actual_val = $prop_val->getString();
+ } elseif ( method_exists( $prop_val, 'getValueKey' ) ) {
$actual_val = $prop_val->getValueKey();
} else {
$actual_val = $prop_val->getXSDValue();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs