Skip to content

Commit

Permalink
Extend support for interwiki and querysource, refs 1271
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Nov 17, 2015
1 parent 9ba8553 commit ab34739
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
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

0 comments on commit ab34739

Please sign in to comment.