/**
  * Returns a DataTypeRegistry instance
  *
  * @since 1.9
  *
  * @return DataTypeRegistry
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self($GLOBALS['smwgContLang']->getDatatypeLabels(), $GLOBALS['smwgContLang']->getDatatypeAliases(), $GLOBALS['smwgContLang']->getCanonicalDatatypeLabels());
         self::$instance->initDatatypes();
     }
     return self::$instance;
 }
 /**
  * Returns a DataTypeRegistry instance
  *
  * @since 1.9
  *
  * @return DataTypeRegistry
  */
 public static function getInstance()
 {
     if (self::$instance !== null) {
         return self::$instance;
     }
     $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage();
     self::$instance = new self($extraneousLanguage);
     self::$instance->initDatatypes();
     self::$instance->setOption('smwgDVFeatures', ApplicationFactory::getInstance()->getSettings()->get('smwgDVFeatures'));
     return self::$instance;
 }
Ejemplo n.º 3
0
 protected function getTypesList()
 {
     $html = '<p>' . wfMessage('smw_types_docu')->escaped() . "</p><br />\n";
     $typeLabels = DataTypeRegistry::getInstance()->getKnownTypeLabels();
     asort($typeLabels, SORT_STRING);
     $html .= "<ul>\n";
     foreach ($typeLabels as $typeId => $label) {
         $typeValue = SMWTypesValue::newFromTypeId($typeId);
         $html .= '<li>' . $typeValue->getLongHTMLText(smwfGetLinker()) . "</li>\n";
     }
     $html .= "</ul>\n";
     return $html;
 }
 /**
  * @since 1.9
  *
  * @return true
  */
 protected function copyStatistics()
 {
     $statistics = ApplicationFactory::getInstance()->getStore()->getStatistics();
     $this->extraStats['smw-statistics'] = array();
     foreach ($this->messageMapper as $key => $message) {
         if (isset($statistics[$key])) {
             $this->extraStats['smw-statistics'][$message] = $statistics[$key];
         }
     }
     $count = count(DataTypeRegistry::getInstance()->getKnownTypeLabels());
     $this->extraStats['smw-statistics']['smw-statistics-datatype-count'] = $count;
     return true;
 }
 private function addTypeFromImportVocabulary($dataItem)
 {
     $importValue = DataValueFactory::getInstance()->newDataItemValue($dataItem, new DIProperty('_IMPO'));
     if (strpos($importValue->getTermType(), ':') === false) {
         return;
     }
     $property = new DIProperty('_TYPE');
     list($ns, $type) = explode(':', $importValue->getTermType(), 2);
     $typeId = DataTypeRegistry::getInstance()->findTypeId($type);
     if ($typeId === '') {
         return;
     }
     $dataValue = DataValueFactory::getInstance()->newPropertyObjectValue($property, $typeId);
     $this->replaceAnyTypeByImportType($property, $dataValue);
 }
 protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     $this->getOutput()->prependHTML($this->getTypesLink());
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $escapedTypeLabel = htmlspecialchars($typeValue->getWikiValue());
     $canonicalLabel = DataTypeRegistry::getInstance()->findCanonicalLabelById($typeValue->getDataItem()->getFragment());
     $typeKey = 'smw-sp-types' . strtolower($typeValue->getDataItem()->getFragment());
     $messageKey = wfMessage($typeKey)->exists() ? $typeKey : 'smw-sp-types-default';
     $result = \Html::rawElement('div', array('class' => 'smw-sp-types-intro' . $typeKey), wfMessage($messageKey, str_replace('_', ' ', $escapedTypeLabel))->parse() . ' ' . wfMessage('smw-sp-types-help', str_replace(' ', '_', $canonicalLabel))->parse());
     $result .= $this->displayExtraInformationAbout($typeValue);
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }
 /**
  * Determine what kind of OWL property some SMW property should be exported as.
  * The input is an SMWTypesValue object, a typeid string, or empty (use default)
  * @todo An improved mechanism for selecting property types here is needed.
  */
 public static function getOWLPropertyType($type = '')
 {
     if ($type instanceof SMWDIWikiPage) {
         $type = DataTypeRegistry::getInstance()->findTypeId(str_replace('_', ' ', $type->getDBkey()));
     } elseif ($type == false) {
         $type = '';
     }
     switch ($type) {
         case '_anu':
             return 'AnnotationProperty';
         case '':
         case '_wpg':
         case '_wpp':
         case '_wpc':
         case '_wpf':
         case '_uri':
         case '_ema':
         case '_tel':
         case '_rec':
         case '__typ':
         case '__red':
         case '__spf':
         case '__spu':
             return 'ObjectProperty';
         default:
             return 'DatatypeProperty';
     }
 }
 /**
  * @see SMWStore::getPropertyValues
  *
  * @todo Retrieving all sortkeys (values for _SKEY with $subject null)
  * is not supported. An empty array will be given.
  *
  * @since 1.8
  *
  * @param $subject mixed DIWikiPage or null
  * @param $property SMWDIProperty
  * @param $requestOptions SMWRequestOptions
  *
  * @return SMWDataItem[]
  */
 public function getPropertyValues($subject, SMWDIProperty $property, $requestOptions = null)
 {
     if ($property->isInverse()) {
         // inverses are working differently
         $noninverse = new SMWDIProperty($property->getKey(), false);
         $result = $this->getPropertySubjects($noninverse, $subject, $requestOptions);
     } elseif (!is_null($subject)) {
         // subject given, use semantic data cache
         $sid = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), true);
         if ($sid == 0) {
             $result = array();
         } elseif ($property->getKey() == '_SKEY') {
             $this->store->smwIds->getSMWPageIDandSort($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortKey, true);
             $sortKeyDi = new SMWDIBlob($sortKey);
             $result = $this->store->applyRequestOptions(array($sortKeyDi), $requestOptions);
         } else {
             $propTableId = $this->store->findPropertyTableID($property);
             $proptables = $this->store->getPropertyTables();
             $sd = $this->getSemanticDataFromTable($sid, $subject, $proptables[$propTableId]);
             $result = $this->store->applyRequestOptions($sd->getPropertyValues($property), $requestOptions);
         }
     } else {
         // no subject given, get all values for the given property
         $pid = $this->store->smwIds->getSMWPropertyID($property);
         $tableid = $this->store->findPropertyTableID($property);
         if ($pid == 0 || $tableid === '') {
             return array();
         }
         $proptables = $this->store->getPropertyTables();
         $data = $this->fetchSemanticData($pid, $property, $proptables[$tableid], false, $requestOptions);
         $result = array();
         $propertyTypeId = $property->findPropertyTypeID();
         $propertyDiId = DataTypeRegistry::getInstance()->getDataItemId($propertyTypeId);
         foreach ($data as $dbkeys) {
             try {
                 $diHandler = $this->store->getDataItemHandlerForDIType($propertyDiId);
                 $result[] = $diHandler->dataItemFromDBKeys($dbkeys);
             } catch (SMWDataItemException $e) {
                 // maybe type assignment changed since data was stored;
                 // don't worry, but we can only drop the data here
             }
         }
     }
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Modify the given query object to account for some property condition for
  * the given property. If it is not possible to generate a query for the
  * given data, the query type is changed to SMWSQLStore3Query::Q_NOQUERY. Callers need
  * to check for this and discard the query in this case.
  *
  * @note This method does not support sortkey (_SKEY) property queries,
  * since they do not have a normal property table. This should not be a
  * problem since comparators on sortkeys are supported indirectly when
  * using comparators on wikipages. There is no reason to create any
  * query with _SKEY ad users cannot do so either (no user label).
  *
  * @since 1.8
  */
 protected function compileSomePropertyDescription(SMWSQLStore3Query $query, SMWSomeProperty $description)
 {
     $db = $this->m_store->getConnection();
     $property = $description->getProperty();
     $tableid = $this->m_store->findPropertyTableID($property);
     if ($tableid === '') {
         // Give up
         $query->type = SMWSQLStore3Query::Q_NOQUERY;
         return;
     }
     $proptables = $this->m_store->getPropertyTables();
     $proptable = $proptables[$tableid];
     if (!$proptable->usesIdSubject()) {
         // no queries with such tables
         // (only redirects are affected in practice)
         $query->type = SMWSQLStore3Query::Q_NOQUERY;
         return;
     }
     $typeid = $property->findPropertyTypeID();
     $diType = DataTypeRegistry::getInstance()->getDataItemId($typeid);
     if ($property->isInverse() && $diType != SMWDataItem::TYPE_WIKIPAGE) {
         // can only invert properties that point to pages
         $query->type = SMWSQLStore3Query::Q_NOQUERY;
         return;
     }
     $diHandler = $this->m_store->getDataItemHandlerForDIType($diType);
     $indexField = $diHandler->getIndexField();
     $sortkey = $property->getKey();
     // TODO: strictly speaking, the DB key is not what we want here, since sortkey is based on a "wiki value"
     // *** Now construct the query ... ***//
     $query->jointable = $proptable->getName();
     // *** Add conditions for selecting rows for this property ***//
     if (!$proptable->isFixedPropertyTable()) {
         $pid = $this->m_store->smwIds->getSMWPropertyID($property);
         // Construct property hierarchy:
         $pqid = SMWSQLStore3Query::$qnum;
         $pquery = new SMWSQLStore3Query();
         $pquery->type = SMWSQLStore3Query::Q_PROP_HIERARCHY;
         $pquery->joinfield = array($pid);
         $query->components[$pqid] = "{$query->alias}.p_id";
         $this->m_queries[$pqid] = $pquery;
         // Alternative code without property hierarchies:
         // $query->where = "{$query->alias}.p_id=" . $this->m_dbs->addQuotes( $pid );
     }
     // else: no property column, no hierarchy queries
     // *** Add conditions on the value of the property ***//
     if ($diType == SMWDataItem::TYPE_WIKIPAGE) {
         $o_id = $indexField;
         if ($property->isInverse()) {
             $s_id = $o_id;
             $o_id = 's_id';
         } else {
             $s_id = 's_id';
         }
         $query->joinfield = "{$query->alias}.{$s_id}";
         // process page description like main query
         $sub = $this->compileQueries($description->getDescription());
         if ($sub >= 0) {
             $query->components[$sub] = "{$query->alias}.{$o_id}";
         }
         if (array_key_exists($sortkey, $this->m_sortkeys)) {
             // TODO: This SMW IDs table is possibly duplicated in the query.
             // Example: [[has capital::!Berlin]] with sort=has capital
             // Can we prevent that? (PERFORMANCE)
             $query->from = ' INNER JOIN ' . $db->tableName(SMWSql3SmwIds::tableName) . " AS ids{$query->alias} ON ids{$query->alias}.smw_id={$query->alias}.{$o_id}";
             $query->sortfields[$sortkey] = "ids{$query->alias}.smw_sortkey";
         }
     } else {
         // non-page value description
         $query->joinfield = "{$query->alias}.s_id";
         $this->compilePropertyValueDescription($query, $description->getDescription(), $proptable, $diHandler, 'AND');
         if (array_key_exists($sortkey, $this->m_sortkeys)) {
             $query->sortfields[$sortkey] = "{$query->alias}.{$indexField}";
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Find the id of a property table that is suitable for storing values of
  * the given type. The type is specified by an SMW type id such as '_wpg'.
  * An empty string is returned if no matching table could be found.
  *
  * @since 1.8
  * @param string $typeid
  * @return string
  */
 public function findTypeTableId($typeid)
 {
     $dataItemId = DataTypeRegistry::getInstance()->getDataItemId($typeid);
     return $this->findDiTypeTableId($dataItemId);
 }
 /**
  * Extend the given SPARQL condition by a suitable order by variable,
  * if an order by property is set.
  *
  * @param Condition $sparqlCondition condition to modify
  * @param string $mainVariable the variable that represents the value to be ordered
  * @param mixed $orderByProperty DIProperty or null
  * @param integer $diType DataItem type id if known, or DataItem::TYPE_NOTYPE to determine it from the property
  */
 public function addOrderByDataForProperty(Condition &$sparqlCondition, $mainVariable, $orderByProperty, $diType = DataItem::TYPE_NOTYPE)
 {
     if (is_null($orderByProperty)) {
         return;
     }
     if ($diType == DataItem::TYPE_NOTYPE) {
         $diType = DataTypeRegistry::getInstance()->getDataItemId($orderByProperty->findPropertyTypeID());
     }
     $this->addOrderByData($sparqlCondition, $mainVariable, $diType);
 }
Ejemplo n.º 12
0
 /**
  * @deprecated since 1.9, use DataTypeRegistry::getDataItemId
  */
 public static function getDataItemId($typeId)
 {
     return DataTypeRegistry::getInstance()->getDataItemId($typeId);
 }
 /**
  * @since  2.0
  *
  * @return self
  * @throws RuntimeException
  * @throws InvalidArgumentException
  */
 public function setPropertyTypeId($propertyTypeId)
 {
     if (!DataTypeRegistry::getInstance()->isKnownTypeId($propertyTypeId)) {
         throw new RuntimeException("{$propertyTypeId} is an unknown type id");
     }
     if ($this->isUserDefined() && $this->m_proptypeid === null) {
         $this->m_proptypeid = $propertyTypeId;
         return $this;
     }
     if (!$this->isUserDefined() && $propertyTypeId === self::getPredefinedPropertyTypeId($this->m_key)) {
         $this->m_proptypeid = $propertyTypeId;
         return $this;
     }
     throw new InvalidArgumentException('Property type can not be altered for a predefined object');
 }
 /**
  * @see SemanticData::getSubSemanticData
  *
  * @note SubSemanticData are added only on request to avoid unnecessary DB
  * transactions
  *
  * @since 2.0
  */
 public function getSubSemanticData()
 {
     if ($this->subSemanticDataInitialized) {
         return parent::getSubSemanticData();
     }
     $this->subSemanticDataInitialized = true;
     foreach ($this->getProperties() as $property) {
         // #619 Do not resolve subobjects for redirects
         if (!DataTypeRegistry::getInstance()->isSubDataType($property->findPropertyTypeID()) || $this->isRedirect()) {
             continue;
         }
         $this->addSubSemanticDataToInternalCache($property);
     }
     return parent::getSubSemanticData();
 }
 /**
  * @see SMWStore::getPropertySubjects
  *
  * @todo This method cannot retrieve subjects for sortkeys, i.e., for
  * property _SKEY. Only empty arrays will be returned there.
  *
  * @param SMWDIProperty $property
  * @param SMWDataItem|null $value
  * @param SMWRequestOptions|null $requestOptions
  *
  * @return array of DIWikiPage
  */
 public function getPropertySubjects(SMWDIProperty $property, SMWDataItem $value = null, SMWRequestOptions $requestOptions = null)
 {
     /// TODO: should we share code with #ask query computation here? Just use queries?
     if ($property->isInverse()) {
         // inverses are working differently
         $noninverse = new SMW\DIProperty($property->getKey(), false);
         $result = $this->getPropertyValues($value, $noninverse, $requestOptions);
         return $result;
     }
     // #1222, Filter those where types don't match (e.g property = _txt
     // and value = _wpg)
     if ($value !== null && DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()) !== $value->getDIType()) {
         return array();
     }
     // First build $select, $from, and $where for the DB query
     $where = $from = '';
     $pid = $this->store->smwIds->getSMWPropertyID($property);
     $tableid = $this->store->findPropertyTableID($property);
     if ($pid == 0 || $tableid === '') {
         return array();
     }
     $proptables = $this->store->getPropertyTables();
     $proptable = $proptables[$tableid];
     $db = $this->store->getConnection();
     if ($proptable->usesIdSubject()) {
         // join with ID table to get title data
         $from = $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " INNER JOIN " . $db->tableName($proptable->getName()) . " AS t1 ON t1.s_id=smw_id";
         $select = 'smw_title, smw_namespace, smw_iw, smw_sortkey, smw_subobject';
     } else {
         // no join needed, title+namespace as given in proptable
         $from = $db->tableName($proptable->getName()) . " AS t1";
         $select = 's_title AS smw_title, s_namespace AS smw_namespace, \'\' AS smw_iw, s_title AS smw_sortkey, \'\' AS smw_subobject';
     }
     if (!$proptable->isFixedPropertyTable()) {
         $where .= ($where ? ' AND ' : '') . "t1.p_id=" . $db->addQuotes($pid);
     }
     $this->prepareValueQuery($from, $where, $proptable, $value, 1);
     // ***  Now execute the query and read the results  ***//
     $result = array();
     if (!$proptable->isFixedPropertyTable()) {
         if ($where !== '' && strpos(SMW_SQL3_SMWIW_OUTDATED, $where) === false) {
             $where .= " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         } else {
             $where .= " smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         }
     }
     $res = $db->select($from, 'DISTINCT ' . $select, $where . $this->store->getSQLConditions($requestOptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), __METHOD__, $this->store->getSQLOptions($requestOptions, 'smw_sortkey'));
     $diHandler = $this->store->getDataItemHandlerForDIType(SMWDataItem::TYPE_WIKIPAGE);
     foreach ($res as $row) {
         try {
             if ($row->smw_iw === '' || $row->smw_iw[0] != ':') {
                 // filter special objects
                 $result[] = $diHandler->dataItemFromDBKeys(array_values((array) $row));
             }
         } catch (DataItemHandlerException $e) {
             // silently drop data, should be extremely rare and will usually fix itself at next edit
         }
     }
     $db->freeResult($res);
     return $result;
 }
Ejemplo n.º 16
0
 /**
  * Adds support for the geographical coordinates and shapes data type to Semantic MediaWiki.
  *
  * @since 2.0
  *
  * @return boolean
  */
 public static function initGeoDataTypes()
 {
     DataTypeRegistry::getInstance()->registerDatatype('_geo', 'SMGeoCoordsValue', SMWDataItem::TYPE_GEO);
     DataTypeRegistry::getInstance()->registerDatatype('_gpo', 'SMGeoPolygonsValue', SMWDataItem::TYPE_BLOB);
     return true;
 }
 /**
  * @param array $properties
  */
 private function addTableDefinitionForFixedProperties(array $properties)
 {
     foreach ($properties as $propertyKey => $propetyTableSuffix) {
         // Either as plain index array containing the property key or as associated
         // array with property key => tableSuffix
         $propertyKey = is_int($propertyKey) ? $propetyTableSuffix : $propertyKey;
         $this->addPropertyTable(DataTypeRegistry::getInstance()->getDataItemId(DIProperty::getPredefinedPropertyTypeId($propertyKey)), $this->fixedPropertyTablePrefix . strtolower($propetyTableSuffix), $propertyKey);
     }
 }
 /**
  * @since 2.2
  *
  * @return DataItem[]
  */
 public function getExpectedDataItems()
 {
     $dataItems = array();
     if (!isset($this->contents['queryresult']['dataitems'])) {
         return $dataItems;
     }
     foreach ($this->contents['queryresult']['dataitems'] as $dataitem) {
         $dataItems[] = DataItem::newFromSerialization(DataTypeRegistry::getInstance()->getDataItemId($dataitem['type']), $dataitem['value']);
     }
     return $dataItems;
 }
 protected function getPropertyDataItemTypeId($id)
 {
     $type = $this->getPropertyType($id);
     if ($type) {
         return DataTypeRegistry::getInstance()->getDefaultDataItemTypeId($type);
     }
     return null;
 }
 protected function tearDown()
 {
     PropertyRegistry::clear();
     DataTypeRegistry::clear();
     parent::tearDown();
 }
 /**
  * Find the id of a property table that is suitable for storing values of
  * the given type. The type is specified by an SMW type id such as '_wpg'.
  * An empty string is returned if no matching table could be found.
  *
  * @since 2.2
  *
  * @param string $dataTypeTypeId
  *
  * @return string
  */
 public function findTableIdForDataTypeTypeId($dataTypeTypeId)
 {
     return $this->findTableIdForDataItemTypeId(DataTypeRegistry::getInstance()->getDataItemId($dataTypeTypeId));
 }
 /**
  * Get the array of all stored values for some property.
  *
  * @since 1.8
  *
  * @param DIProperty $property
  *
  * @return array of SMWDataItem
  */
 public function getPropertyValues(DIProperty $property)
 {
     if ($property->isInverse()) {
         // we never have any data for inverses
         return array();
     }
     if (array_key_exists($property->getKey(), $this->mStubPropVals)) {
         // Not catching exception here; the
         $this->unstubProperty($property->getKey(), $property);
         $propertyTypeId = $property->findPropertyTypeID();
         $propertyDiId = DataTypeRegistry::getInstance()->getDataItemId($propertyTypeId);
         foreach ($this->mStubPropVals[$property->getKey()] as $dbkeys) {
             try {
                 $diHandler = $this->store->getDataItemHandlerForDIType($propertyDiId);
                 $di = $diHandler->dataItemFromDBKeys($dbkeys);
                 if ($this->mNoDuplicates) {
                     $this->mPropVals[$property->getKey()][$di->getHash()] = $di;
                 } else {
                     $this->mPropVals[$property->getKey()][] = $di;
                 }
             } catch (SMWDataItemException $e) {
                 // ignore data
             }
         }
         unset($this->mStubPropVals[$property->getKey()]);
     }
     return parent::getPropertyValues($property);
 }
Ejemplo n.º 23
0
 protected function assertRegistryFindsIdForAliases($inputLabel, array $equivalentLabels)
 {
     $id = '_wpg';
     $registry = new DataTypeRegistry(array($id => $inputLabel), array());
     foreach ($equivalentLabels as $caseVariant) {
         $this->assertEquals($id, $registry->findTypeId($caseVariant));
     }
 }
Ejemplo n.º 24
0
 /**
  * Returns DataItemId for a property
  *
  * @note findPropertyTypeID is calling the Store to find the
  * typeId reference this is costly but at the moment there is no other
  * way to determine the typeId
  *
  * This check is to ensure that during unserialization the correct item
  * in terms of its definition is being sought otherwise inconsistencies
  * can occur due to type changes of a property between the time of
  * the serialization and the deserialization (e.g for when the
  * serialization object is stored in cache, DB etc.)
  *
  * @return integer
  */
 protected function getDataItemId(DIProperty $property)
 {
     if (!isset($this->dataItemTypeIdCache[$property->getKey()])) {
         $this->dataItemTypeIdCache[$property->getKey()] = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID());
     }
     return $this->dataItemTypeIdCache[$property->getKey()];
 }
 /**
  * @param array $specialProperties
  */
 private function buildPropertyTablesForSpecialProperties(array $specialProperties)
 {
     foreach ($specialProperties as $propertyKey) {
         $this->addPropertyTable(DataTypeRegistry::getInstance()->getDataItemId(DIProperty::getPredefinedPropertyTypeId($propertyKey)), $this->getTablePrefix() . strtolower($propertyKey), $propertyKey);
     }
     // Redirect table uses another subject scheme for historic reasons
     // TODO This should be changed if possible
     $redirectTableName = $this->getTablePrefix() . '_redi';
     if (isset($this->propertyTables[$redirectTableName])) {
         $this->propertyTables[$redirectTableName]->setUsesIdSubject(false);
     }
 }
Ejemplo n.º 26
0
 /**
  * @since 2.5
  *
  * @param DIProperty $property
  *
  * @return boolean
  */
 public function isExemptedProperty(DIProperty $property)
 {
     $dataItemTypeId = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID());
     // Is neither therefore is exempted
     if ($dataItemTypeId !== DataItem::TYPE_BLOB && $dataItemTypeId !== DataItem::TYPE_URI) {
         return true;
     }
     return isset($this->propertyExemptionList[$property->getKey()]);
 }
Ejemplo n.º 27
0
 private function canShowSearchByPropertyLink(DataValue $dataValue)
 {
     $dataTypeClass = DataTypeRegistry::getInstance()->getDataTypeClassById($dataValue->getTypeID());
     return $this->pageRequestOptions->value instanceof $dataTypeClass && $this->pageRequestOptions->valueString === '';
 }
 protected function assertRegistryFindsIdForAliases($inputLabel, array $equivalentLabels)
 {
     $id = '_wpg';
     $extraneousLanguage = $this->getMockBuilder('\\SMW\\ExtraneousLanguage\\ExtraneousLanguage')->disableOriginalConstructor()->getMock();
     $extraneousLanguage->expects($this->once())->method('getDatatypeLabels')->will($this->returnValue(array($id => $inputLabel)));
     $extraneousLanguage->expects($this->once())->method('getDatatypeAliases')->will($this->returnValue(array()));
     $extraneousLanguage->expects($this->once())->method('getCanonicalDatatypeLabels')->will($this->returnValue(array()));
     $instance = new DataTypeRegistry($extraneousLanguage);
     foreach ($equivalentLabels as $caseVariant) {
         $this->assertEquals($id, $instance->findTypeId($caseVariant));
     }
 }
Ejemplo n.º 29
0
 /**
  * Convenience method to get a dataitem handler for a datatype id.
  *
  * @since 1.8
  * @param string $typeid
  * @throws MWException if there is no handler for this type
  * @return SMWDataItemHandler
  */
 public function getDataItemHandlerForDatatype($typeid)
 {
     $dataItemId = DataTypeRegistry::getInstance()->getDataItemId($typeid);
     return $this->getDataItemHandlerForDIType($dataItemId);
 }
Ejemplo n.º 30
0
 private function isPagePropertyType($typeid)
 {
     return $typeid == '_wpg' || DataTypeRegistry::getInstance()->isSubDataType($typeid);
 }