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

ValueDescription::getQueryString to set DV output option #2111

Merged
merged 1 commit into from
Dec 17, 2016
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
13 changes: 9 additions & 4 deletions includes/datavalues/SMW_DV_Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/
class SMWNumberValue extends SMWDataValue {

/**
* Internal state to ensure no precision limitation is applied to an output
*/
const NO_DISP_PRECISION_LIMIT = 'num.no.displayprecision.limit';

/**
* Array with entries unit=>value, mapping a normalized unit to the
* converted value. Used for conversion tooltips.
Expand Down Expand Up @@ -299,10 +304,10 @@ public function getInfolinks() {

// When generating an infoLink, use the normalized value without any
// precision limitation
$this->setOption( 'no.displayprecision', true );
$this->setOption( self::NO_DISP_PRECISION_LIMIT, true );
$this->setOption( 'content.language', Message::CONTENT_LANGUAGE );
$infoLinks = parent::getInfolinks();
$this->setOption( 'no.displayprecision', false );
$this->setOption( self::NO_DISP_PRECISION_LIMIT, false );

return $infoLinks;
}
Expand Down Expand Up @@ -453,8 +458,8 @@ public function getUnitList() {

protected function getPreferredDisplayPrecision() {

// In case of a value description, don't restrict the value with a display precision
if ( $this->getProperty() === null || $this->getOptionBy( 'value.description' ) || $this->getOptionBy( 'no.displayprecision' ) ) {
// Don't restrict the value with a display precision
if ( $this->getProperty() === null || $this->getOptionBy( self::NO_DISP_PRECISION_LIMIT ) ) {
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions includes/datavalues/SMW_DV_URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
class SMWURIValue extends SMWDataValue {

/**
* Raw value without encoding
*/
const VALUE_RAW = 'uri.value.raw';

/**
* The value as returned by getWikitext() and getLongText().
* @var string
Expand Down Expand Up @@ -271,6 +276,11 @@ public function getLongHTMLText( $linker = null ) {
}

public function getWikiValue() {

if ( $this->getOptionBy( self::VALUE_RAW ) ) {
return rawurldecode( $this->m_wikitext );
}

return $this->m_wikitext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function unescape( $value, $escaped ) {
$value = $escaped ? str_replace( array( '-20', '-2D' ), array( ' ', '-' ), $value ) : $value;
// Do not try to decode things like 1.2e-13
// Signals that we don't want any precision limitation
$this->value->setOption( 'no.displayprecision', true );
$this->value->setOption( NumberValue::NO_DISP_PRECISION_LIMIT, true );
} elseif ( $this->value instanceof TelephoneUriValue ) {
$value = $escaped ? str_replace( array( '-20', '-2D' ), array( ' ', '-' ), $value ) : $value;
// No encoding to avoid turning +1-201-555-0123
Expand Down
19 changes: 15 additions & 4 deletions src/Query/Language/ValueDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use SMw\DIProperty;
use SMW\Query\QueryComparator;
use SMWDataItem as DataItem;
use SMWURIValue as UriValue;
use SMWNumberValue as NumberValue;

/**
* Description of one data value, or of a range of data values.
Expand Down Expand Up @@ -100,11 +102,20 @@ public function getComparator() {
* @return string
*/
public function getQueryString( $asValue = false ) {
$comparator = QueryComparator::getInstance()->getStringForComparator( $this->comparator );
$dataValue = DataValueFactory::getInstance()->newDataValueByItem( $this->dataItem, $this->property );

// Signals that we don't want any precision limitation
$dataValue->setOption( 'value.description', true );
$comparator = QueryComparator::getInstance()->getStringForComparator(
$this->comparator
);

$dataValue = DataValueFactory::getInstance()->newDataValueByItem(
$this->dataItem,
$this->property
);

// Set option to ensure that the output doesn't alter the display
// characteristics of a value
$dataValue->setOption( UriValue::VALUE_RAW, true );
$dataValue->setOption( NumberValue::NO_DISP_PRECISION_LIMIT, true );

if ( $asValue ) {
return $comparator . $dataValue->getWikiValue();
Expand Down