public function testPredefinedProperty() { $instance = new HashBuilder(); $property = new DIProperty('_MDAT'); $dataItem = $property->getDiWikiPage(); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->getHashIdForDiWikiPage($dataItem))); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->createHashIdFromSegments($property->getKey(), SMW_NS_PROPERTY))); }
private function findBasePropertyToRedirectFor($label) { $property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label)); if ($property->getLabel() !== '' && $label !== $property->getLabel()) { $outputPage = $this->getContext()->getOutput(); $outputPage->redirect($property->getDiWikiPage()->getTitle()->getFullURL()); } }
/** * @since 2.4 * * @param DIProperty $property * * @return DataItem|false */ public function tryToFindAtLeastOneReferenceForProperty(DIProperty $property) { $dataItem = $property->getDiWikiPage(); $sid = $this->store->getObjectIds()->getSMWPageID($dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), ''); // Lets see if we have some lower/upper case matching for // when wgCapitalLinks setting was involved if (!$this->usesCapitalLinks && $sid == 0) { $sid = $this->store->getObjectIds()->getSMWPageID(lcfirst($dataItem->getDBkey()), $dataItem->getNamespace(), $dataItem->getInterwiki(), ''); } return $this->tryToFindAtLeastOneReferenceForId($sid); }
public function testFindSubpropertyList() { $property = new DIProperty('Foo'); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $store->expects($this->once())->method('getPropertySubjects')->with($this->equalTo(new DIProperty('_SUBP')), $this->equalTo($property->getDiWikiPage()), $this->anything())->will($this->returnValue(array(DIWikiPage::newFromText('Bar', SMW_NS_PROPERTY)))); $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock(); $cache->expects($this->once())->method('contains')->will($this->returnValue(false)); $cache->expects($this->once())->method('save')->with($this->equalTo('_SUBP#Foo#-1#0##1##1#'), $this->anything()); $instance = new PropertyHierarchyLookup($store, $cache); $expected = array(DIWikiPage::newFromText('Bar', SMW_NS_PROPERTY)); $this->assertEquals($expected, $instance->findSubpropertListFor($property)); }
public function testUseInterwikiPrefix() { $property = new DIProperty('Foo'); $property->setInterwiki('bar'); $this->assertEquals(new \SMW\DiWikiPage('Foo', SMW_NS_PROPERTY, 'bar'), $property->getDiWikiPage()); }
private function findMostSuitablePropertyRepresentation(DIProperty $property, DIProperty $nonInverseProperty, &$namespaces) { $redirectByVariable = $this->compoundConditionBuilder->tryToFindRedirectVariableForDataItem($nonInverseProperty->getDiWikiPage()); // If the property is represented by a redirect then use the variable instead if ($redirectByVariable !== null) { return $redirectByVariable; } // Use helper properties in encoding values, refer to this helper property: if ($this->exporter->hasHelperExpElement($property)) { $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty, true); } elseif (!$property->isUserDefined()) { $propertyExpElement = $this->exporter->getSpecialPropertyResource($nonInverseProperty->getKey(), SMW_NS_PROPERTY); } else { $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty); } if ($propertyExpElement instanceof ExpNsResource) { $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace(); } return TurtleSerializer::getTurtleNameForExpElement($propertyExpElement); }
private function addPropertyHierarchy(DIProperty $property, $targetHierarchy) { $semanticData = $this->semanticDataFactory->setSubject($property->getDiWikiPage())->newEmptySemanticData(); $semanticData->addDataValue($this->dataValueFactory->newPropertyObjectValue(new DIProperty('_SUBP'), $targetHierarchy)); $this->getStore()->updateData($semanticData); }
/** * @note There are different ways to find out whether a property * has a subproperty or not. * * In SPARQL one could try using FILTER NOT EXISTS { ?s my:property ?o } * * @since 2.3 * * @param DIProperty $property * * @return boolean */ public function hasSubpropertyFor(DIProperty $property) { return $this->hasMatchFor('_SUBP', $property->getKey(), $property->getDiWikiPage()); }
/** * @since 2.4 * * @param DIProperty|null $property */ public function fetchCachedConversionData(DIProperty $property = null) { if ($property === null || ($propertyDiWikiPage = $property->getDiWikiPage()) === null) { return; } $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore(); // Ensure that when the property page is altered the cache gets // evicted $hash = $this->cachedPropertyValuesPrefetcher->getRootHashFrom($propertyDiWikiPage); $container = $blobStore->read($hash); $key = '--conv'; if ($container->has($key)) { $data = $container->get($key); $this->unitIds = $data['ids']; $this->unitFactors = $data['factors']; $this->mainUnit = $data['main']; $this->prefixalUnitPreference = $data['prefix']; return; } $this->fetchConversionData($property); if ($this->errors !== array()) { return; } $data = array('ids' => $this->unitIds, 'factors' => $this->unitFactors, 'main' => $this->mainUnit, 'prefix' => $this->prefixalUnitPreference); $container->set($key, $data); $blobStore->save($container); }
/** * Returns information related to user-defined properties * * @since 1.9 * * @param Title $title * @param DIProperty $property * @param integer $useCount * * @return array */ private function getUserDefinedPropertyInfo($title, $property, $useCount) { if ($useCount <= $this->settings->get('smwgPropertyLowUsageThreshold')) { $this->getMessageFormatter()->addFromKey('smw_propertyhardlyused'); } // User defined types default to Page $typestring = SMWTypesValue::newFromTypeId($this->settings->get('smwgPDefaultType'))->getLongHTMLText($this->getLinker()); $label = htmlspecialchars($property->getLabel()); if ($title->exists()) { $typeProperty = new DIProperty('_TYPE'); $types = $this->store->getPropertyValues($property->getDiWikiPage(), $typeProperty); if (count($types) >= 1) { $typeDataValue = DataValueFactory::getInstance()->newDataItemValue(current($types), $typeProperty); $typestring = $typeDataValue->getLongHTMLText($this->getLinker()); } else { $this->getMessageFormatter()->addFromKey('smw_propertylackstype', $typestring); } $proplink = $this->getLinker()->link($title, $label); } else { $this->getMessageFormatter()->addFromKey('smw_propertylackspage'); $proplink = $this->getLinker()->link($title, $label, array(), array('action' => 'view')); } return array($typestring, $proplink); }
/** * @since 2.1 * * @return SemanticData */ public function getDependencies() { $semanticData = new SemanticData($this->property->getDiWikiPage()); $semanticData->addDataValue(DataValueFactory::getInstance()->newPropertyObjectValue(new DIProperty('_TYPE'), $this->property->findPropertyTypeID())); return $semanticData; }
/** * 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 * * @return ExpResource * @throws RuntimeException */ public function mapPropertyToResourceElement(DIProperty $property, $useAuxiliaryModifier = false) { $diWikiPage = $property->getDiWikiPage(); 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; } return $this->mapWikiPageToResourceElement($diWikiPage, $useAuxiliaryModifier); }
/** * Produce a formatted string representation for showing a property and * its usage count in the list of used properties. * * @since 1.8 * * @param DIProperty $property * @param integer $useCount * @return string */ protected function formatPropertyItem(DIProperty $property, $useCount) { // Clear formatter before invoking messages $this->getMessageFormatter()->clear(); $diWikiPage = $property->getDiWikiPage(); $title = $diWikiPage !== null ? $diWikiPage->getTitle() : null; if ($useCount == 0 && !$this->settings->get('smwgPropertyZeroCountDisplay')) { return ''; } if ($property->isUserDefined()) { if ($title === null) { // Show even messed up property names. $typestring = ''; $proplink = $property->getLabel(); $this->getMessageFormatter()->addFromArray(array('ID: ' . (isset($property->id) ? $property->id : 'N/A')))->addFromKey('smw_notitle', $proplink); } else { list($typestring, $proplink) = $this->getUserDefinedPropertyInfo($title, $property, $useCount); } $infoLink = ''; // Add a link to SearchByProperty to hopefully identify the // "hidden" reference if ($useCount < 1) { $infoLink = ' ' . \SMWInfolink::newPropertySearchLink('+', $property->getLabel(), '')->getHTML($this->getLinker()); } $proplink .= $infoLink; } else { list($typestring, $proplink) = $this->getPredefinedPropertyInfo($property); } if ($typestring === '') { // Built-ins have no type // @todo Should use numParams for $useCount? return $this->msg('smw_property_template_notype')->rawParams($proplink)->numParams($useCount)->text() . ' ' . $this->getMessageFormatter()->setType('warning')->escape(false)->getHtml(); } else { // @todo Should use numParams for $useCount? return $this->msg('smw_property_template')->rawParams($proplink, $typestring)->numParams($useCount)->escaped() . ' ' . $this->getMessageFormatter()->setType('warning')->escape(false)->getHtml(); } }
/** * 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 $markForAuxiliaryUsage 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 $markForAuxiliaryUsage * * @return ExpResource * @throws RuntimeException */ public function mapPropertyToResourceElement(DIProperty $property, $markForAuxiliaryUsage = false) { $diWikiPage = $property->getDiWikiPage(); if ($diWikiPage !== null) { return $this->mapWikiPageToResourceElement($diWikiPage, $markForAuxiliaryUsage); } throw new RuntimeException('Only non-inverse, user-defined properties are permitted.'); }
private function findPropertyDataItems(DIProperty $property = null) { if ($property === null) { return array(); } $propertyDiWikiPage = $property->getDiWikiPage(); if ($propertyDiWikiPage === null) { return array(); } $listDiProperty = new DIProperty('_LIST'); $dataItems = ApplicationFactory::getInstance()->getStore()->getPropertyValues($propertyDiWikiPage, $listDiProperty); if (count($dataItems) == 1) { $propertyListValue = new PropertyListValue('__pls'); $propertyListValue->setDataItem(reset($dataItems)); if ($propertyListValue->isValid()) { return $propertyListValue->getPropertyDataItems(); } } return array(); }
/** * Produce a formatted string representation for showing a property in * the list of unused properties. * * @since 1.8 * * @param DIProperty $property * * @return string */ protected function formatPropertyItem(DIProperty $property) { // Clear formatter before invoking messages and // avoid having previous data to be present $this->getMessageFormatter()->clear(); if ($property->isUserDefined()) { $title = $property->getDiWikiPage()->getTitle(); if (!$title instanceof \Title) { return ''; } $propertyLink = $this->getLinker()->link($title, $property->getLabel()); $types = $this->store->getPropertyValues($property->getDiWikiPage(), new DIProperty('_TYPE')); if (count($types) >= 1) { $typeDataValue = DataValueFactory::getInstance()->newDataItemValue(current($types), new DIProperty('_TYPE')); } else { $typeDataValue = SMWTypesValue::newFromTypeId('_wpg'); $this->getMessageFormatter()->addFromKey('smw_propertylackstype', $typeDataValue->getLongHTMLText()); } } else { $typeDataValue = SMWTypesValue::newFromTypeId($property->findPropertyTypeID()); $propertyLink = DataValueFactory::getInstance()->newDataItemValue($property, null)->getShortHtmlText($this->getLinker()); } return $this->msg('smw_unusedproperty_template', $propertyLink, $typeDataValue->getLongHTMLText($this->getLinker()))->text() . ' ' . $this->getMessageFormatter()->getHtml(); }
/** * @since 2.3 * * @param DIProperty $property * * @return DIWikiPage[]|[] */ public function findSubpropertListFor(DIProperty $property) { return $this->findMatchesFor('_SUBP', $property->getKey(), $property->getDiWikiPage()); }
private function doResolveDependenciesFromPrintRequest(&$subjects, array $printRequests) { foreach ($printRequests as $printRequest) { $data = $printRequest->getData(); if ($data instanceof \SMWPropertyValue) { $property = $data->getDataItem(); if ($property->isInverse()) { $property = new DIProperty($property->getKey()); } $subjects[] = $property->getDiWikiPage(); } // Category if ($data instanceof \Title) { $subjects[] = DIWikiPage::newFromTitle($data); } } }
/** * @since 2.3 * * @param DIProperty $property * * @return DIWikiPage[]|[] */ public function findSubpropertListFor(DIProperty $property) { return $this->findMatchesWith('_SUBP', $property->getKey(), $property->getDiWikiPage(), new RequestOptions()); }