Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend support for interwiki and querysource, refs #1271 #1278

Merged
merged 1 commit into from Nov 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions includes/dataitems/SMW_DI_Property.php
Expand Up @@ -62,6 +62,13 @@ class DIProperty extends SMWDataItem {
*/
private $m_proptypeid;

/**
* Interwiki prefix for when a property represents a non-local entity
*
* @var string
*/
private $interwiki = '';

/**
* Initialise a property. This constructor checks that keys of
* predefined properties do really exist (in the current configuration
Expand Down Expand Up @@ -188,6 +195,15 @@ public function getLabel() {
return $prefix . PropertyRegistry::getInstance()->findPropertyLabelById( $this->m_key );
}

/**
* @since 2.4
*
* @param string $interwiki
*/
public function setInterwiki( $interwiki ) {
$this->interwiki = $interwiki;
}

/**
* Get an object of type SMWDIWikiPage that represents the page which
* relates to this property, or null if no such page exists. The latter
Expand All @@ -212,7 +228,7 @@ public function getDiWikiPage( $subobjectName = '' ) {
}

try {
return new SMWDIWikiPage( $dbkey, SMW_NS_PROPERTY, '', $subobjectName );
return new SMWDIWikiPage( $dbkey, SMW_NS_PROPERTY, $this->interwiki, $subobjectName );
} catch ( DataItemException $e ) {
return null;
}
Expand Down Expand Up @@ -257,7 +273,7 @@ public function findPropertyTypeID() {

if ( !isset( $this->m_proptypeid ) ) {
if ( $this->isUserDefined() ) { // normal property
$diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' );
$diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, $this->interwiki );
$typearray = StoreFactory::getStore()->getPropertyValues( $diWikiPage, new self( '_TYPE' ) );

if ( count( $typearray ) >= 1 ) { // some types given, pick one (hopefully unique)
Expand Down
4 changes: 2 additions & 2 deletions includes/datavalues/SMW_DV_WikiPage.php
Expand Up @@ -195,7 +195,7 @@ public function getShortWikiText( $linked = null ) {
return $this->m_caption !== false ? $this->m_caption : $this->getWikiValue();
}

if ( $this->m_dataitem->getNamespace() == NS_FILE ) {
if ( $this->m_dataitem->getNamespace() == NS_FILE && $this->m_dataitem->getInterwiki() === '' ) {
$linkEscape = '';
$defaultCaption = '|' . $this->getShortCaptionText() . '|frameless|border|text-top';
} else {
Expand Down Expand Up @@ -277,7 +277,7 @@ public function getLongWikiText( $linked = null ) {

if ( is_null( $linked ) || $linked === false || $this->m_outformat == '-' ) {
return $this->getWikiValue();
} elseif ( $this->m_dataitem->getNamespace() == NS_FILE ) {
} elseif ( $this->m_dataitem->getNamespace() == NS_FILE && $this->m_dataitem->getInterwiki() === '' ) {
// Embed images and other files
// Note that the embedded file links to the image, hence needs no additional link text.
// There should not be a linebreak after an impage, just like there is no linebreak after
Expand Down
36 changes: 34 additions & 2 deletions includes/query/SMW_Query.php
Expand Up @@ -59,6 +59,13 @@ class SMWQuery {
*/
private $subject;

/**
* Describes a non-local (remote) query source
*
* @var string|null
*/
private $querySource = null;

/**
* Constructor.
* @param $description SMWDescription object describing the query conditions
Expand Down Expand Up @@ -94,6 +101,24 @@ public function getSubject() {
return $this->subject;
}

/**
* @since 2.4
*
* @param string
*/
public function setQuerySource( $querySource ) {
$this->querySource = $querySource;
}

/**
* @since 2.4
*
* @return string
*/
public function getQuerySource() {
return $this->querySource;
}

/**
* Sets the mainlabel.
*
Expand Down Expand Up @@ -226,7 +251,7 @@ public function setUnboundLimit( $limit ) {
* @param array $sortKeys
*/
public function setSortKeys( array $sortKeys ) {
$this->sortKeys = $sortKeys;
$this->sortkeys = $sortKeys;
}

/**
Expand All @@ -235,7 +260,7 @@ public function setSortKeys( array $sortKeys ) {
* @return array
*/
public function getSortKeys() {
return $this->sortKeys;
return $this->sortkeys;
}

/**
Expand Down Expand Up @@ -294,6 +319,13 @@ public function toArray() {
'querymode' => $this->querymode
);

// @2.4 Keep the queryID stable with previous versions unless
// a query source is selected. The "same" query executed on different
// remote systems requires a different queryID
if ( $this->querySource !== '' ) {
$serialized['parameters']['source'] = $this->querySource;
}

foreach ( $this->getExtraPrintouts() as $printout ) {
$serialization = $printout->getSerialisation();
if ( $serialization !== '?#' ) {
Expand Down
1 change: 1 addition & 0 deletions includes/query/SMW_QueryProcessor.php
Expand Up @@ -125,6 +125,7 @@ static public function createQuery( $queryString, array $params, $context = self
$query->setExtraPrintouts( $extraPrintouts );
$query->setMainLabel( $params['mainlabel']->getValue() );
$query->addErrors( $qp->getErrors() ); // keep parsing errors for later output
$query->setQuerySource( $params['source']->getValue() );

// set mode, limit, and offset:
$query->querymode = $querymode;
Expand Down
5 changes: 3 additions & 2 deletions includes/storage/SMW_QueryResult.php
Expand Up @@ -354,9 +354,10 @@ public function toArray() {

return array_merge( $serializeArray, array(
'meta'=> array(
'hash' => md5( FormatJson::encode( $serializeArray ) ),
'hash' => HashBuilder::createHashIdForContent( $serializeArray ),
'count' => $this->getCount(),
'offset' => $this->mQuery->getOffset()
'offset' => $this->mQuery->getOffset(),
'source' => $this->mQuery->getQuerySource()
)
)
);
Expand Down
4 changes: 4 additions & 0 deletions src/SPARQLStore/QueryEngine/CompoundConditionBuilder.php
Expand Up @@ -477,6 +477,10 @@ protected function addMissingOrderByConditions( Condition &$condition ) {
throw new RuntimeException( "Expected a string value as sortkey" );
}

if ( strpos( $propertyKey, " " ) !== false ) {
throw new RuntimeException( "Expected the canonical form of {$propertyKey} (without any whitespace)" );
}

if ( !array_key_exists( $propertyKey, $condition->orderVariables ) ) { // Find missing property to sort by.
$this->addOrderForUnknownPropertyKey( $condition, $propertyKey );
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
"printouts" : [ "Member of" ],
"parameters" : {
"limit" : "10",
"sort": { "Member of": "DESC" }
"sort": { "Member_of": "DESC" }
},
"queryresult": {
"count": "3",
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/includes/dataitems/DIPropertyTest.php
Expand Up @@ -91,4 +91,15 @@ public function testCorrectInversePrefixForPredefinedProperty() {
);
}

public function testUseInterwikiPrefix() {

$property = new DIProperty( 'Foo' );
$property->setInterwiki( 'bar' );

$this->assertEquals(
new \SMW\DiWikiPage( 'Foo', SMW_NS_PROPERTY, 'bar' ),
$property->getDiWikiPage()
);
}

}