public function equals(SMWDataItem $di) { if (!$di instanceof SMWDIBlob) { return false; } return $di->getString() === $this->m_string; }
public function equals(SMWDataItem $di) { if ($di->getDIType() !== SMWDataItem::TYPE_NUMBER) { return false; } return $di->getNumber() === $this->m_number; }
/** * Get the serialization for the provided data item. * * @since 1.7 * * @param SMWDataItem $dataItem * * @return mixed */ public static function getSerialization(DataItem $dataItem, $printRequest = null) { $result = array(); switch ($dataItem->getDIType()) { case DataItem::TYPE_WIKIPAGE: $title = $dataItem->getTitle(); $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl(), 'namespace' => $title->getNamespace(), 'exists' => $title->isKnown()); break; case DataItem::TYPE_NUMBER: // dataitems and datavalues // Quantity is a datavalue type that belongs to dataitem // type number which means in order to identify the correct // unit, we have re-factor the corresponding datavalue otherwise // we will not be able to determine the unit // (unit is part of the datavalue object) if ($printRequest !== null && $printRequest->getTypeID() === '_qty') { $diProperty = $printRequest->getData()->getDataItem(); $dataValue = DataValueFactory::getInstance()->newDataItemValue($dataItem, $diProperty); $result = array('value' => $dataValue->getNumber(), 'unit' => $dataValue->getUnit()); } else { $result = $dataItem->getNumber(); } break; case DataItem::TYPE_GEO: $result = $dataItem->getCoordinateSet(); break; case DataItem::TYPE_TIME: $result = $dataItem->getMwTimestamp(); break; default: $result = $dataItem->getSerialization(); break; } return $result; }
public function equals(SMWDataItem $di) { if ($di->getDIType() !== SMWDataItem::TYPE_ERROR) { return false; } return $di->getSerialization() === $this->getSerialization(); }
public function equals(SMWDataItem $di) { if ($di->getDIType() !== SMWDataItem::TYPE_BOOLEAN) { return false; } return $di->getBoolean() === $this->m_boolean; }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem( SMWDataItem $dataItem ) { if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) { $this->m_dataitem = $dataItem; $this->m_caption = $dataItem->getConceptQuery(); // probably useless return true; } else { return false; } }
/** * @see DataValue::loadDataItem * * @param DataItem $dataItem * * @return boolean */ protected function loadDataItem(DataItem $dataItem) { if ($dataItem->getDIType() !== DataItem::TYPE_BOOLEAN) { return false; } $this->m_dataitem = $dataItem; $this->m_caption = $this->getStandardCaption(true); return true; }
/** * @since 1.8 * * {@inheritDoc} */ public function getInsertValues(DataItem $dataItem) { $serialization = rawurldecode($dataItem->getSerialization()); $text = mb_strlen($serialization) <= self::MAX_LENGTH ? null : $serialization; // bytea type handling if ($text !== null && $GLOBALS['wgDBtype'] === 'postgres') { $text = pg_escape_bytea($text); } return array('o_blob' => $text, 'o_serialized' => $serialization); }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_ERROR) { $this->addError($dataItem->getErrors()); $this->m_caption = $this->getErrorText(); return true; } else { return false; } }
/** * @see SMWDataValue::setDataItem() * * @since 1.0 * * @param $dataitem SMWDataItem * * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_GEO) { $this->m_dataitem = $dataItem; global $smgQPCoodFormat, $smgQPCoodDirectional; $this->wikiValue = MapsCoordinateParser::formatCoordinates($dataItem->getCoordinateSet(), $smgQPCoodFormat, $smgQPCoodDirectional); return true; } else { return false; } }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN) { $this->m_dataitem = $dataItem; $this->m_caption = $this->getStandardCaption(true); // use default for this language return true; } else { return false; } }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem instanceof SMWDIUri && $dataItem->getScheme() == 'http' && $dataItem->getHierpart() == 'semantic-mediawiki.org/swivt/1.0' && $dataItem->getQuery() === '') { $this->m_isAlias = false; $this->m_typeId = $dataItem->getFragment(); $this->m_realLabel = SMWDataValueFactory::findTypeLabel($this->m_typeId); $this->m_caption = $this->m_givenLabel = $this->m_realLabel; $this->m_dataitem = $dataItem; return true; } else { return false; } }
/** * Get the serialization for the provided data item. * * @since 1.7 * * @param SMWDataItem $dataItem * * @return mixed */ public static function getSerialization(DataItem $dataItem, $printRequest = null) { switch ($dataItem->getDIType()) { case DataItem::TYPE_WIKIPAGE: // Support for a deserializable _rec type with 0.6 if ($printRequest !== null && strpos($printRequest->getTypeID(), '_rec') !== false) { $recordValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $printRequest->getData()->getDataItem()); $recordDiValues = array(); foreach ($recordValue->getPropertyDataItems() as $property) { $label = $property->getLabel(); $recordDiValues[$label] = array('label' => $label, 'key' => $property->getKey(), 'typeid' => $property->findPropertyTypeID(), 'item' => array()); foreach ($recordValue->getDataItem()->getSemanticData()->getPropertyValues($property) as $value) { $recordDiValues[$label]['item'][] = self::getSerialization($value); } } $result = $recordDiValues; } else { $title = $dataItem->getTitle(); $wikiPageValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem); $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl(), 'namespace' => $title->getNamespace(), 'exists' => strval($title->isKnown()), 'displaytitle' => $wikiPageValue->getDisplayTitle()); } break; case DataItem::TYPE_NUMBER: // dataitems and datavalues // Quantity is a datavalue type that belongs to dataitem // type number which means in order to identify the correct // unit, we have re-factor the corresponding datavalue otherwise // we will not be able to determine the unit // (unit is part of the datavalue object) if ($printRequest !== null && $printRequest->getTypeID() === '_qty') { $diProperty = $printRequest->getData()->getDataItem(); $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $diProperty); $result = array('value' => $dataValue->getNumber(), 'unit' => $dataValue->getUnit()); } else { $result = $dataItem->getNumber(); } break; case DataItem::TYPE_GEO: $result = $dataItem->getCoordinateSet(); break; case DataItem::TYPE_TIME: $result = array('timestamp' => $dataItem->getMwTimestamp(), 'raw' => $dataItem->getSerialization()); break; default: $result = $dataItem->getSerialization(); break; } return $result; }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { $diType = $this->m_typeid == '_txt' || $this->m_typeid == '_cod' ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING; if ($dataItem->getDIType() == $diType) { $this->m_dataitem = $dataItem; if ($this->m_typeid == '_cod') { $this->m_caption = $this->getCodeDisplay($this->m_dataitem->getString()); } else { $this->m_caption = $this->m_dataitem->getString(); } return true; } else { return false; } }
/** * Check if property is range restricted and, if so, whether the current value is allowed. * Creates an error if the value is illegal. */ protected function checkAllowedValues() { if (!is_null($this->m_property)) { $propertyDiWikiPage = $this->m_property->getDiWikiPage(); } if (is_null($this->m_property) || is_null($propertyDiWikiPage) || !isset($this->m_dataitem)) { return; // no property known, or no data to check } $allowedvalues = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, new SMWDIProperty('_PVAL')); if (count($allowedvalues) == 0) { return; } $hash = $this->m_dataitem->getHash(); $testdv = DataValueFactory::getInstance()->newTypeIDValue($this->getTypeID()); $accept = false; $valuestring = ''; foreach ($allowedvalues as $di) { if ($di instanceof SMWDIBlob) { $testdv->setUserValue($di->getString()); if ($hash === $testdv->getDataItem()->getHash()) { $accept = true; break; } else { if ($valuestring !== '') { $valuestring .= ', '; } $valuestring .= $di->getString(); } } } if (!$accept) { $this->addError(wfMessage('smw_notinenum', $this->getWikiValue(), $valuestring)->inContentLanguage()->text()); } }
/** * Creates and returns a new SWLPropertyChange instance from a serialization. * * @param string|null $oldValue * @param string|null $newValue * * @return SWLPropertyChange */ public static function newFromSerialization(SMWDIProperty $property, $oldValue, $newValue) { $diType = SMWDataValueFactory::getDataItemId($property->findPropertyTypeID()); //var_dump($property); //if($diType!=7) {throw new Exception();exit;} return new self(is_null($oldValue) ? null : SMWDataItem::newFromSerialization($diType, $oldValue), is_null($newValue) ? null : SMWDataItem::newFromSerialization($diType, $newValue)); }
/** * Convenience method that checks if the value that is used to sort * data of this type is numeric. This only works if the value is set. * * @return boolean */ public function isNumeric() { if (isset($this->m_dataitem)) { return is_numeric($this->m_dataitem->getSortKey()); } else { return false; } }
/** * Creates and returns a new SWLPropertyChange instance from a serialization. * * @param string|null $oldValue * @param string|null $newValue * * @return SWLPropertyChange */ public static function newFromSerialization( SMWDIProperty $property, $oldValue, $newValue ) { $diType = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeID() ); return new self( is_null( $oldValue ) ? null : SMWDataItem::newFromSerialization( $diType, $oldValue ), is_null( $newValue ) ? null : SMWDataItem::newFromSerialization( $diType, $newValue ) ); }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem DataItem * @return boolean */ protected function loadDataItem(DataItem $dataItem) { if (!$dataItem instanceof DIBlob) { return false; } $this->m_dataitem = $dataItem; $parts = explode(' ', $dataItem->getString(), 4); if (count($parts) != 4) { $this->addErrorMsg(array('smw-datavalue-import-invalid-format', $dataItem->getString())); } else { $this->m_namespace = $parts[0]; $this->m_section = $parts[1]; $this->m_uri = $parts[2]; $this->termType = $parts[3]; $this->m_qname = $this->m_namespace . ':' . $this->m_section; $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] " . " | " . wfMessage('smw-datavalue-import-link', $this->m_namespace)->escaped(); } return true; }
/** * @see SMWDataValue::loadDataItem() * * @param $dataitem SMWDataItem * * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem instanceof SMWDIBlob) { $this->m_dataitem = $dataItem; $this->m_diProperties = array(); foreach (explode(';', $dataItem->getString()) as $propertyKey) { try { $this->m_diProperties[] = new SMWDIProperty($propertyKey); } catch (SMWDataItemException $e) { $this->m_diProperties[] = new SMWDIProperty('Error'); $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text()); } } $this->m_caption = false; return true; } else { return false; } }
/** * @see SMWDataValue::loadDataItem() * * @param $dataitem SMWDataItem * * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_STRING) { $this->m_dataitem = $dataItem; $this->m_diProperties = array(); foreach (explode(';', $dataItem->getString()) as $propertyKey) { try { $this->m_diProperties[] = new SMWDIProperty($propertyKey); } catch (SMWDataItemException $e) { $this->m_diProperties[] = new SMWDIProperty('Error'); $this->addError(wfMsgForContent('smw_parseerror')); } } $this->m_caption = false; return true; } else { return false; } }
/** * @see ExpElement::newFromSerialization */ protected static function deserialize($serialization) { $dataItem = null; if (!array_key_exists('dataitem', $serialization)) { throw new RuntimeException("The serialization format is missing a dataitem element"); } // If it is null, isset will ignore it if (isset($serialization['dataitem'])) { $dataItem = DataItem::newFromSerialization($serialization['dataitem']['type'], $serialization['dataitem']['item']); } return $dataItem; }
/** * @see SMWDataValue::loadDataItem() * * @param $dataitem SMWDataItem * * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if (!$dataItem instanceof SMWDIBlob) { return false; } $this->m_dataitem = $dataItem; $this->m_diProperties = array(); foreach (explode(';', $dataItem->getString()) as $propertyKey) { $property = null; try { $property = new SMWDIProperty($propertyKey); } catch (SMWDataItemException $e) { $property = new SMWDIProperty('Error'); $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text()); } if ($property instanceof SMWDIProperty) { // Find a possible redirect $this->m_diProperties[] = StoreFactory::getStore()->getRedirectTarget($property); } } $this->m_caption = false; return true; }
/** * Get the serialization for the provided data item. * * @since 1.7 * * @param SMWDataItem $dataItem * * @return mixed */ public static function getSerialization(SMWDataItem $dataItem) { switch ($dataItem->getDIType()) { case SMWDataItem::TYPE_WIKIPAGE: $title = $dataItem->getTitle(); $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl()); break; case SMWDataItem::TYPE_NUMBER: $result = $dataItem->getNumber(); break; case SMWDataItem::TYPE_GEO: $result = $dataItem->getCoordinateSet(); break; case SMWDataItem::TYPE_TIME: $result = $dataItem->getMwTimestamp(); break; default: $result = $dataItem->getSerialization(); break; } return $result; }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() !== SMWDataItem::TYPE_URI) { return false; } $this->m_dataitem = $dataItem; if ($this->m_mode == SMW_URI_MODE_EMAIL) { $this->m_wikitext = substr($dataItem->getURI(), 7); } elseif ($this->m_mode == SMW_URI_MODE_TEL) { $this->m_wikitext = substr($dataItem->getURI(), 4); } else { $this->m_wikitext = $dataItem->getURI(); } $this->m_caption = $this->m_wikitext; $this->showUrlContextInRawFormat = false; return true; }
/** * Implementation of SMWStore::getInProperties(). This function is meant to * be used for finding properties that link to wiki pages. * * @see SMWStore::getInProperties * * 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. * * @param SMWDataItem $value * @param SMWRequestOptions $requestoptions * * @return array of SMWWikiPageValue */ public function getInProperties(SMWDataItem $value, $requestoptions = null) { wfProfileIn("SMWSQLStore2::getInProperties (SMW)"); $db = wfGetDB(DB_SLAVE); $result = array(); // Potentially need to get more results, since options apply to union. if ($requestoptions !== null) { $suboptions = clone $requestoptions; $suboptions->limit = $requestoptions->limit + $requestoptions->offset; $suboptions->offset = 0; } else { $suboptions = null; } $tableIds = self::findAllDiTypeTableIds($value->getDIType()); $proptables = self::getPropertyTables(); foreach ($tableIds as $tid) { $proptable = $proptables[$tid]; $where = $from = ''; if ($proptable->fixedproperty == false) { // join smw_ids to get property titles $from = $db->tableName('smw_ids') . " INNER JOIN " . $db->tableName($proptable->name) . " AS t1 ON t1.p_id=smw_id"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), 'SMW::getInProperties', $this->getSQLOptions($suboptions, 'smw_sortkey')); foreach ($res as $row) { try { $result[] = new SMWDIProperty($row->smw_title); } catch (SMWDataItemException $e) { // has been observed to happen (empty property title); cause unclear; ignore this data } } } else { $from = $db->tableName($proptable->name) . " AS t1"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $res = $db->select($from, '*', $where, 'SMW::getInProperties', array('LIMIT' => 1)); if ($db->numRows($res) > 0) { $result[] = new SMWDIProperty($proptable->fixedproperty); } } $db->freeResult($res); } $result = $this->applyRequestOptions($result, $requestoptions); // apply options to overall result wfProfileOut("SMWSQLStore2::getInProperties (SMW)"); return $result; }
/** * @see SMWDataValue::loadDataItem() * * @param $dataitem SMWDataItem * * @return boolean */ protected function loadDataItem(DataItem $dataItem) { if (!$dataItem instanceof DIBlob) { return false; } $this->m_caption = false; $this->m_dataitem = $dataItem; $this->initPropertyChain($dataItem->getString()); return true; }
/** * @since 1.8 * * {@inheritDoc} */ public function getInsertValues(DataItem $dataItem) { $oid = $this->store->getObjectIds()->makeSMWPageID($dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSubobjectName()); return array('o_id' => $oid); }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER) { $this->m_dataitem = $dataItem; return true; } elseif ($dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE) { $semanticData = new SMWContainerSemanticData($dataItem); $semanticData->copyDataFrom(\SMW\StoreFactory::getStore()->getSemanticData($dataItem)); $this->m_dataitem = new SMWDIContainer($semanticData); return true; } else { return false; } }
/** * @see SMWDataValue::loadDataItem() * @param $dataitem SMWDataItem * @return boolean */ protected function loadDataItem(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER) { // might throw an exception, we just pass it through $dataItem = $dataItem->getSemanticData()->getSubject(); } if ($dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE) { $this->m_dataitem = $dataItem; $this->m_id = -1; $this->m_title = null; $this->m_fragment = $dataItem->getSubobjectName(); $this->m_prefixedtext = ''; $this->m_caption = false; // this class can handle this if ($this->m_fixNamespace != NS_MAIN && $this->m_fixNamespace != $dataItem->getNamespace()) { global $wgContLang; $this->addError(wfMessage('smw_wrong_namespace', $wgContLang->getNsText($this->m_fixNamespace))->inContentLanguage()->text()); } return true; } else { return false; } }