I can't get the examples working with Semantic MediaWiki Version 1.8.0.1.
$propertyValue = SMWPropertyValue::makeProperty('Test'); $property = new SMWSomeProperty($propertyValue, new SMWThingDescription);
This produces the following error:
PHP Catchable fatal error: Argument 1 passed to SMWSomeProperty::__construct() must be an instance of SMWDIProperty, instance of SMWPropertyValue given, called in /srv/httpd/mediawiki/extensions/SidebarLanguagelink/SidebarLanguagelink.php on line 38 and defined in /srv/httpd/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php on line 786
I did manage to do some queries based on the examples, but I think they won't work with the current version of SMW. Here's an example which looks up the value for a property "Master_page" on the current page, and returns the value of that property:
function getCanonical() { global $wgTitle; $masterPageProperty = new SMWDIProperty('Master_page'); $title = Title::newFromText( $wgTitle->mTextform ); $currentArticle = SMWDIWikiPage::newFromTitle( $title ); $semanticData = smwfGetStore()->getSemanticData( $currentArticle ); $masterPagePropVals = $semanticData->getPropertyValues( $masterPageProperty ); $masterPageProp = array_pop( $masterPagePropVals ); if ( is_null( $masterPageProp ) ) return NULL; $masterPage = $masterPageProp->getDBkey(); $canonicalTitle = Title::newFromText( $masterPage ); return SMWDIWikiPage::newFromTitle( $canonicalTitle ); }
Here's an example that finds all pages which have the same value for a particular property "Master_page", sorted by a "Language_code" property:
function getTranslations(&$canonicalTranslation) { $masterPageProperty = new SMWDIProperty('Master_page'); $description = new SMWValueDescription( $canonicalTranslation ); $property = new SMWSomeProperty( $masterPageProperty, $description ); $query = new SMWQuery( $property ); $query->sort = true; $query->sortkeys = array('Language_code' => 'ASC'); $queryResult = smwfGetStore()->getQueryResult( $query ); return $queryResult->getResults(); }
Perhaps such examples are best written in actual PHP files, put in SemanticMediaWiki/docs/technical/examples/. Then they could have simple tests executed by the CI, ensuring they stay up to date with the SMW version they are bundled with.