private function findPropertyIdByLabel($label) { $property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label)); $canonicalLabel = $property->getCanonicalLabel(); // #1966 and #1968 // In case something goes wrong, a recursive loop will kill PHP // and we know we messed up if ($canonicalLabel !== '' && $label !== $canonicalLabel) { $this->findPropertyIdByLabel($property->getCanonicalDiWikiPage()->getTitle()->getText()); } return array($label, $property); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null) { return; } if ($property->getKey() === $property->findPropertyTypeID()) { // Ensures that Boolean remains Boolean and not localized canonical // representation such as "Booléen" when the content languageis not // English $expNsResource = $this->getResourceElementForProperty(new DIProperty($property->getCanonicalDiWikiPage()->getDBKey())); } else { $expNsResource = $this->getResourceElementHelperForProperty($property); } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expResourceElement = $this->exporter->getResourceElementForWikiPage($property->getCanonicalDiWikiPage(), true); // Avoid that an imported vocabulary is pointing to an internal resource. // // For example: <Has_alternative_label> imported from <skos:altLabel> // with "Monolingual text" type is expected to produce: // // - <property:Has_alternative_label rdf:resource="http://example.org/id/Foo_MLa9c103f4379a94bfab97819dacd3c182"/> // - <skos:altLabel xml:lang="en">Foo</skos:altLabel> if ($expResourceElement->isImported()) { $seekImportVocabulary = false; $expData->addPropertyObjectValue($this->exporter->getResourceElementForProperty($property, false, $seekImportVocabulary), $this->exporter->getDataItemExpElement($dataItem)); } else { parent::addResourceValue($expData, $property, $dataItem); } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); $list = $dataValue->toArray(); if (!isset($list['_TEXT']) || !isset($list['_LCODE'])) { return; } $expData->addPropertyObjectValue($expResourceElement, new ExpLiteral((string) $list['_TEXT'], 'http://www.w3.org/2001/XMLSchema#string', (string) $list['_LCODE'], $dataItem)); }
/** * @since 1.8 * * {@inheritDoc} */ public function dataItemFromDBKeys($dbkeys) { if (is_array($dbkeys) && count($dbkeys) == 5) { $namespace = intval($dbkeys[1]); if ($namespace == SMW_NS_PROPERTY && $dbkeys[0] != '' && $dbkeys[0][0] == '_' && $dbkeys[2] == '') { // Correctly interpret internal property keys $property = new DIProperty($dbkeys[0]); $wikipage = $property->getCanonicalDiWikiPage($dbkeys[4]); if (!is_null($wikipage)) { return $wikipage; } } else { return $this->newDiWikiPage($dbkeys); } } throw new DataItemHandlerException('Failed to create data item from DB keys.'); }
private function doMatchProperty(&$subjects, DIProperty $property) { if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } $subject = $property->getCanonicalDiWikiPage(); if ($this->propertyHierarchyLookup->hasSubpropertyFor($property)) { $this->doMatchSubproperty($subjects, $subject, $property); } // Use the key here do match against pre-defined properties (e.g. _MDAT) $key = str_replace(' ', '_', $property->getKey()); if (!isset($this->propertyDependencyExemptionlist[$key])) { $subjects[$subject->getHash()] = $subject; } }
public function testCanonicalRepresentation() { $property = new DIProperty('_MDAT'); $this->assertEquals('Modification date', $property->getCanonicalLabel()); $this->assertEquals(new DIWikiPage('Modification_date', SMW_NS_PROPERTY), $property->getCanonicalDiWikiPage()); }
/** * @since 2.5 * * @param DIProperty $property * * @return integer */ public function getPropertyIdBy(DIProperty $property) { return $this->store->getObjectIds()->getIDFor($property->getCanonicalDiWikiPage()); }
/** * We try to cache anything to avoid unnecessary store connections or DB * lookups. For cases where a property was changed, the EventDipatcher will * receive a 'property.specification.change' event (emitted as soon as the content of * a property page was altered) with PropertySpecificationLookup::resetCacheBy * being invoked to remove the cache entry for that specific property. * * @since 2.4 * * @param DIProperty $property * @param mixed|null $linker * @param string $languageCode * * @return string */ public function getPropertyDescriptionBy(DIProperty $property, $linker = null, $languageCode = '') { // Take the linker into account (Special vs. in page rendering etc.) $languageCode = $languageCode === '' ? $this->languageCode : $languageCode; $key = '--pdesc:' . $languageCode . ':' . ($linker === null ? '0' : '1'); $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore(); $container = $blobStore->read($this->cachedPropertyValuesPrefetcher->getRootHashFrom($property->getCanonicalDiWikiPage())); if ($container->has($key)) { return $container->get($key); } $localPropertyDescription = $this->tryToFindLocalPropertyDescription($property, $linker, $languageCode); // If a local property description wasn't available for a predefined property // the try to find a system translation if (trim($localPropertyDescription) === '' && !$property->isUserDefined()) { $localPropertyDescription = $this->getPredefinedPropertyDescription($property, $linker, $languageCode); } $container->set($key, $localPropertyDescription); $blobStore->save($container); return $localPropertyDescription; }
private function findBasePropertyToRedirectFor($label) { $property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label)); // Ensure to redirect to `Property:Modification date` and not using // a possible user contextualized version such as `Property:Date de modification` $canonicalLabel = $property->getCanonicalLabel(); if ($canonicalLabel !== '' && $label !== $canonicalLabel) { $outputPage = $this->getContext()->getOutput(); $outputPage->redirect($property->getCanonicalDiWikiPage()->getTitle()->getFullURL()); } }
/** * Create an ExpElement for some internal resource, given by an * DIProperty object. * * This code is only applied to user-defined properties, since the * code for special properties in * Exporter::getSpecialPropertyResource may require information * about the namespace in which some special property is used. * * @note $useAuxiliaryModifier is to determine whether an auxiliary * property resource is to store a helper value * (see Exporter::getDataItemHelperExpElement) should be generated * * @param DIProperty $property * @param boolean $useAuxiliaryModifier * @param boolean $seekImportVocabulary * * @return ExpResource * @throws RuntimeException */ public function mapPropertyToResourceElement(DIProperty $property, $useAuxiliaryModifier = false, $seekImportVocabulary = true) { // We want the a canonical representation to ensure that resources // are language independent $this->seekImportVocabulary = $seekImportVocabulary; $diWikiPage = $property->getCanonicalDiWikiPage(); if ($diWikiPage === null) { throw new RuntimeException('Only non-inverse, user-defined properties are permitted.'); } // No need for any aux properties besides those listed here if (!$this->bcAuxiliaryUse && $property->findPropertyTypeID() !== '_dat' && $property->findPropertyTypeID() !== '_geo') { $useAuxiliaryModifier = false; } $expResource = $this->mapWikiPageToResourceElement($diWikiPage, $useAuxiliaryModifier); $this->seekImportVocabulary = true; return $expResource; }
/** * Fetch all subobjects for a given subject using a lazy-mapping iterator * in order to only resolve one subobject per iteration step. * * @since 2.5 * * @param DIWikiPage $subject * * @return MappingIterator */ private function newMappingIterator(DIWikiPage $subject) { $callback = function ($row) use($subject) { // #1955 if ($subject->getNamespace() === SMW_NS_PROPERTY) { $property = new DIProperty($subject->getDBkey()); $subobject = $property->getCanonicalDiWikiPage($row->smw_subobject); } else { $subobject = new DIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $row->smw_subobject); } $subobject->setSortKey($row->smw_sortkey); $subobject->setId($row->smw_id); return $subobject; }; return $this->iteratorFactory->newMappingIterator($this->newResultIterator($subject), $callback); }