public function __construct($typeid) { parent::__construct($typeid); switch ($typeid) { case '__typ': $this->m_fixNamespace = SMW_NS_TYPE; break; case '_wpp': case '__sup': $this->m_fixNamespace = SMW_NS_PROPERTY; break; case '_wpc': case '__suc': case '__sin': $this->m_fixNamespace = NS_CATEGORY; break; case '_wpf': case '__spf': $this->m_fixNamespace = SF_NS_FORM; break; default: // case '_wpg': $this->m_fixNamespace = NS_MAIN; } }
public function getInfolinks() { if ($this->m_typeid != '_txt' && $this->m_typeid != '_cod') { return parent::getInfolinks(); } else { return $this->m_infolinks; } }
public function __construct($typeid, $errormsg = '', $uservalue = '', $caption = false) { parent::__construct($typeid); $this->m_caption = $caption !== false ? $caption : $uservalue; if ($errormsg !== '') { $this->addError($errormsg); } }
/** * Parses the value into the coordinates and any meta data provided, such as distance. * * @since 0.6 * * @param $value String * @param $asQuery Boolean * * @return SMWDescription */ protected function parseUserValueOrQuery( $value, $asQuery = false ) { $this->wikiValue = $value; $comparator = SMW_CMP_EQ; if ( $value === '' ) { $this->addError( wfMsg( 'smw_novalues' ) ); } else { SMWDataValue::prepareValue( $value, $comparator ); $parts = explode( '(', $value ); $coordinates = trim( array_shift( $parts ) ); $distance = count( $parts ) > 0 ? trim( array_shift( $parts ) ) : false; if ( $distance !== false ) { $distance = substr( trim( $distance ), 0, -1 ); if ( !MapsDistanceParser::isDistance( $distance ) ) { $this->addError( wfMsgExt( 'semanticmaps-unrecognizeddistance', array( 'parsemag' ), $distance ) ); $distance = false; } } $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates ); if ( $parsedCoords ) { $this->m_dataitem = new SMWDIGeoCoord( $parsedCoords ); } else { $this->addError( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $coordinates, 1 ) ); // Make sure this is always set // TODO: Why is this needed?! $this->m_dataitem = new SMWDIGeoCoord( array( 'lat' => 0, 'lon' => 0 ) ); } } if ( $asQuery ) { $this->setUserValue( $value ); switch ( true ) { case !$this->isValid() : return new SMWThingDescription(); case $distance !== false : return new SMAreaValueDescription( $this->getDataItem(), $comparator, $distance ); default : return new SMGeoCoordsValueDescription( $this->getDataItem(), $comparator ); } } }
public function __construct( $typeid ) { parent::__construct( $typeid ); switch ( $typeid ) { case '_ema': $this->m_mode = SMW_URI_MODE_EMAIL; break; case '_anu': $this->m_mode = SMW_URI_MODE_ANNOURI; break; case '_tel': $this->m_mode = SMW_URI_MODE_TEL; break; case '_uri': case '_url': case '__spu': default: $this->m_mode = SMW_URI_MODE_URI; break; } }
/** * @param string $typeid */ public function __construct($typeid = '') { parent::__construct($typeid); }
public function SMWChemicalFormulaTypeHandler($typeid) { SMWDataValue::__construct($typeid); }
/** * @since 2.4 * * {@inheritDoc} */ public function isFormatterFor(DataValue $dataValue) { return $dataValue->getTypeID() === '_cod'; }
/** * @see DataValue::__construct */ public function __construct($typeId = '') { parent::__construct('__errt'); }
/** * @param string $typeid */ public function __construct($typeid) { parent::__construct($typeid); $this->importValueParser = ValueParserFactory::getInstance()->newImportValueParser(); }
/** * @since 2.5 * * @param DataValue $dataValue * * @return DIContainer|null */ public function getErrorContainerFromDataValue(DataValue $dataValue) { if ($dataValue->getErrors() === array()) { return null; } $property = $dataValue->getProperty(); $hash = ''; if ($property !== null) { $hash = $property->getKey(); } $containerSemanticData = $this->newContainerSemanticData($hash); foreach ($dataValue->getErrors() as $error) { $this->addToContainerSemanticData($containerSemanticData, $property, Message::encode($error)); } return new DIContainer($containerSemanticData); }
/** * @see SMWDataValue::parseUserValue * * @since 0.6 */ protected function parseUserValue($value) { if (!is_string($value)) { throw new InvalidArgumentException('$value needs to be a string'); } $this->wikiValue = $value; $comparator = SMW_CMP_EQ; $distance = false; if ($value === '') { $this->addError(wfMessage('smw_novalues')->text()); } else { SMWDataValue::prepareValue($value, $comparator); list($coordinates, $distance) = $this->findValueParts($value); $this->tryParseAndSetDataItem($coordinates); } return array($distance, $comparator); }
/** * Make sure that the content is reset in this case. * @todo This is not a full reset yet (the case that property is changed after a value * was set does not occur in the normal flow of things, hence this has low priority). */ public function setProperty(SMWDIProperty $property) { parent::setProperty($property); $this->m_diProperties = null; }
/** * Returns the GV for a single SMWDataValue. * * @since 1.5.4 * * @param SMWDataValue $object * @param $outputmode * @param boolean $isName Is this the name that should be used for the node? * @param string $name * @param string $labelName * * @return string */ protected function getGVForDataValue(SMWDataValue $object, $outputmode, $isName, $name, $labelName) { $graphInput = ''; $text = $object->getShortText($outputmode); if ($this->m_graphLink) { $nodeLinkURL = "[[" . $text . "]]"; } $text = $this->getWordWrappedText($text, $this->m_wordWrapLimit); if ($this->m_graphLink) { $graphInput .= " \"{$text}\" [URL = \"{$nodeLinkURL}\"]; "; } if (!$isName) { $graphInput .= $this->m_parentRelation ? " \"{$text}\" -> \"{$name}\" " : " \"{$name}\" -> \"{$text}\" "; if ($this->m_graphLabel || $this->m_graphColor) { $graphInput .= ' ['; if (array_search($labelName, $this->m_labelArray, true) === false) { $this->m_labelArray[] = $labelName; } $color = $this->m_graphColors[array_search($labelName, $this->m_labelArray, true)]; if ($this->m_graphLabel) { $graphInput .= "label=\"{$labelName}\""; if ($this->m_graphColor) { $graphInput .= ",fontcolor={$color},"; } } if ($this->m_graphColor) { $graphInput .= "color={$color}"; } $graphInput .= ']'; } $graphInput .= ';'; } return $graphInput; }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value SMWDataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) { $linker = smwfGetLinker(); $html = $dataValue->getLongHTMLText( $linker ); if ( $dataValue->getTypeID() == '_wpg' ) { $html .= " " . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker ); } elseif ( $incoming && $property->isVisible() ) { $html .= " " . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch' )->getHTML( $linker ); } else { $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $linker ); } return $html; }
/** * Hanldes a single property value. Returns an array with data for a single event or false. * * FIXME: 13 arguments, of which a whole bunch are byref... not a good design :) * * @since 1.5.3 * * @param SMWDataValue $object * @param $outputmode * @param SMWPrintRequest $pr * @param boolean $first_col * @param boolean &$hastitle * @param boolean &$hastime * @param boolean $first_value * @param boolean $isEventline * @param string &$curmeta * @param string &$curdata * @param &$date_value * @param boolean &$output * @param array &$positions * * @return false or array */ protected function handlePropertyValue( SMWDataValue $object, $outputmode, SMWPrintRequest $pr, $first_col, &$hastitle, &$hastime, $first_value, $isEventline, &$curmeta, &$curdata, $date_value, &$output, array &$positions ) { global $curarticle, $cururl; $event = false; $l = $this->getLinker( $first_col ); if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this $l = null; } if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage $objectlabel = $object->getLongText( $outputmode, $l ); } else { $objectlabel = $object->getShortText( $outputmode, $l ); } $urlobject = ( $l !== null ); $header = ''; if ( $first_value ) { // find header for current value: if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) { $header = $pr->getText( $outputmode, $this->mLinker ) . ': '; } // is this a start date? if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $date_value == $this->m_tlstart ) ) { // FIXME: Timeline scripts should support XSD format explicitly. They // currently seem to implement iso8601 which deviates from XSD in cases. // NOTE: We can assume $object to be an SMWDataValue in this case. $curmeta .= Html::element( 'span', array( 'class' => 'smwtlstart' ), $object->getXMLSchemaDate() ); $positions[$object->getHash()] = $object->getXMLSchemaDate(); $hastime = true; } // is this the end date? if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $date_value == $this->m_tlend ) ) { // NOTE: We can assume $object to be an SMWDataValue in this case. $curmeta .= Html::element( 'span', array( 'class' => 'smwtlend' ), $object->getXMLSchemaDate( false ) ); } // find title for displaying event if ( !$hastitle ) { $curmeta .= Html::element( 'span', array( 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle' ), $objectlabel ); if ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) { $curarticle = $object->getShortText( $outputmode, false ); $cururl = $object->getTitle()->getFullUrl(); } // NOTE: type Title of $object implied $hastitle = true; } } elseif ( $output ) { // it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row $curdata .= ', '; } if ( !$first_col || !$first_value || $isEventline ) { $curdata .= $header . $objectlabel; $output = true; } if ( $isEventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) { $event = array( $object->getXMLSchemaDate(), $pr->getLabel(), $object->getDataItem()->getSortKey(), ); } return $event; }
/** * Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue). * * @since 1.0 * * @param SMWDataValue $object * @param SMWPrintRequest $printRequest * * @return string */ protected function handleResultProperty(SMWDataValue $object, SMWPrintRequest $printRequest) { if ($this->template) { if ($object instanceof SMWWikiPageValue) { return $object->getTitle()->getPrefixedText(); } else { return $object->getLongText(SMW_OUTPUT_WIKI, NULL); } } if ($this->linkAbsolute) { $t = Title::newFromText($printRequest->getHTMLText(NULL), SMW_NS_PROPERTY); if ($t instanceof Title && $t->exists()) { $propertyName = $propertyName = Html::element('a', array('href' => $t->getFullUrl()), $printRequest->getHTMLText(NULL)); } else { $propertyName = $printRequest->getHTMLText(NULL); } } else { $propertyName = $printRequest->getHTMLText(smwfGetLinker()); } if ($this->linkAbsolute) { $hasPage = $object->getTypeID() == '_wpg'; if ($hasPage) { $t = Title::newFromText($object->getLongText($this->outputmode, NULL), NS_MAIN); $hasPage = $t->exists(); } if ($hasPage) { $propertyValue = Html::element('a', array('href' => $t->getFullUrl()), $object->getLongText($this->outputmode, NULL)); } else { $propertyValue = $object->getLongText($this->outputmode, NULL); } } else { $propertyValue = $object->getLongText($this->outputmode, smwfGetLinker()); } return $propertyName . ($propertyName === '' ? '' : ': ') . $propertyValue; }
/** * @see DataVelue::getInfolinks * * @return array */ public function getInfolinks() { // When generating an infoLink, use the normalized value without any // precision limitation $this->setOption('no.displayprecision', true); $this->setOption('content.language', Message::CONTENT_LANGUAGE); $infoLinks = parent::getInfolinks(); $this->setOption('no.displayprecision', false); return $infoLinks; }
/** * DataValue::getPreferredCaption * * @since 2.4 * * @return string */ public function getPreferredCaption() { if (($preferredCaption = parent::getPreferredCaption()) !== '' && $preferredCaption !== false) { return $preferredCaption; } $preferredCaption = $this->getDisplayTitle(); if ($preferredCaption === '') { $preferredCaption = $this->getText(); } return $preferredCaption; }
public function getInfolinks() { if ($this->m_typeid != '_cod') { return parent::getInfolinks(); } return array(); }
public function setCaption($caption) { parent::setCaption($caption); if ($this->getWikiPageValue() instanceof SMWDataValue) { // pass caption to embedded datavalue (used for printout) $this->m_wikipage->setCaption($caption); } }
/** * @since 2.4 * * @return array */ public function getErrors() { return $this->dataValue->getErrors(); }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value DataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue(\SMWPropertyValue $property, DataValue $dataValue, $incoming) { $linker = smwfGetLinker(); // Allow the DV formatter to access a specific language code $dataValue->setOption(DataValue::OPT_CONTENT_LANGUAGE, Localizer::getInstance()->getPreferredContentLanguage($this->subject->getDataItem())->getCode()); $dataValue->setOption(DataValue::OPT_USER_LANGUAGE, Localizer::getInstance()->getUserLanguage()->getCode()); $dataValue->setContextPage($this->subject->getDataItem()); // Use LOCL formatting where appropriate (date) $dataValue->setOutputFormat('LOCL'); $html = $dataValue->getLongHTMLText($linker); if ($dataValue->getTypeID() === '_wpg' || $dataValue->getTypeID() === '__sob') { $html .= " " . \SMWInfolink::newBrowsingLink('+', $dataValue->getLongWikiText())->getHTML($linker); } elseif ($incoming && $property->isVisible()) { $html .= " " . \SMWInfolink::newInversePropertySearchLink('+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch')->getHTML($linker); } elseif ($dataValue->getProperty() instanceof DIProperty && $dataValue->getProperty()->getKey() !== '_INST') { $html .= $dataValue->getInfolinkText(SMW_OUTPUT_HTML, $linker); } return $html; }
/** * Constructor */ public function SMWSIUnitTypeHandler($typeid) { SMWDataValue::__construct($typeid); wfLoadExtensionMessages('SemanticMediaWiki'); }
public function SMWMathematicalEquationTypeHandler($typeid) { SMWDataValue::__construct($typeid); }
/** * Implementation of SMWStore::getInProperties(). This function is meant to * be used for finding properties that link to wiki pages. * @todo When used for other datatypes, the function may return too many * properties since it selects results by comparing the stored information * (DB keys) only, while not currently comparing the type of the returned * property to the type of the queried data. So values with the same DB keys * can be confused. This is a minor issue now since no code is known to use * this function in cases where this occurs. */ public function getInProperties(SMWDataValue $value, $requestoptions = null) { wfProfileIn("SMWSQLStoreLight::getInProperties (SMW)"); $db = wfGetDB(DB_SLAVE); $result = array(); $typeid = $value->getTypeID(); if ($requestoptions !== null) { // potentially need to get more results, since options apply to union $suboptions = clone $requestoptions; $suboptions->limit = $requestoptions->limit + $requestoptions->offset; $suboptions->offset = 0; } else { $suboptions = null; } foreach (array('smwsimple_data', 'smwsimple_special') as $tablename) { if (SMWSQLStoreLight::findTypeTableName($typeid) != $tablename) { continue; } $valuestring = $tablename == 'smwsimple_special' ? reset($value->getDBkeys()) : serialize($value->getDBkeys()); $where = 'value=' . $db->addQuotes($valuestring); $res = $db->select($tablename, 'DISTINCT propname', $where . $this->getSQLConditions($suboptions, 'propname', 'propname'), 'SMW::getInProperties', $this->getSQLOptions($suboptions, 'propname')); foreach ($res as $row) { $result[] = new SMWDIProperty($row->propname); } $db->freeResult($res); } $result = $this->applyRequestOptions($result, $requestoptions); // apply options to overall result wfProfileOut("SMWSQLStoreLight::getInProperties (SMW)"); return $result; }
/** * Get a single data value item * * @since 1.8 * * @param integer $type * @param SMWDataValue $dataValue * * @return mixed */ private function getDataValueItem($type, SMWDataValue $dataValue) { if ($type == SMWDataItem::TYPE_NUMBER) { // Set unit if available $dataValue->setOutputFormat($this->params['unit']); // Check if unit is available and return the converted value otherwise // just return a plain number return $dataValue->getUnit() !== '' ? $dataValue->getShortWikiText() : $dataValue->getNumber(); } else { // For all other data types return the wikivalue return $dataValue->getWikiValue(); } }
private function canShowSearchByPropertyLink(DataValue $dataValue) { $dataTypeClass = DataTypeRegistry::getInstance()->getDataTypeClassById($dataValue->getTypeID()); return $this->pageRequestOptions->value instanceof $dataTypeClass && $this->pageRequestOptions->valueString === ''; }
/** * @since 2.4 * * @param DataValue $dataValue * * @return Description */ public function newFromDataValue(DataValue $dataValue) { if (!$dataValue->isValid()) { return $this->newThingDescription(); } // Avoid circular reference when called from outside of the DV context $dataValue->setOption(DataValue::OPT_QUERY_CONTEXT, true); $description = $dataValue->getQueryDescription($dataValue->getWikiValue()); if ($dataValue->getProperty() === null) { return $description; } return $this->newSomeProperty($dataValue->getProperty(), $description); }
/** * Removes $value from $values * @param array of SMWDataValue $values The haystack * @param SMWDataValue $value The needle * @return array of SMWDataValue The new haystack */ private function remove_value( /* array of SMWDataValue */ $values, SMWDataValue $value ) { if ( $value->getTypeID() == "_wpg" ) $value = SMWWriterData::resolveRedirect( $value ); $count = count( $values ); for ( $i = 0; $i < $count; $i++ ) if ( $values[$i] != '' && $values[$i]->getHash() === $value->getHash() ) { unset( $values[$i] ); $values = array_values( $values ); return $values; } }