private function doFormatFinalOutputFor($type, $linker) { $text = ''; $languagecode = ''; foreach ($this->dataValue->getPropertyDataItems() as $property) { // If we wanted to omit the language code display for some outputs then // this is the point to make it happen if (($type == self::HTML_LONG || $type == self::WIKI_SHORT) && $property->getKey() === '_LCODE') { //continue; } $dataItems = $this->dataValue->getDataItem()->getSemanticData()->getPropertyValues($property); // Should not happen but just in case if (!$dataItems === array()) { $this->dataValue->addErrorMsg('smw-datavalue-monolingual-dataitem-missing'); continue; } $dataItem = reset($dataItems); if ($dataItem === false) { continue; } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); $result = $this->findValueOutputFor($type, $dataValue, $linker); if ($property->getKey() === '_LCODE' && $type !== self::VALUE) { $languagecode = ' ' . Message::get(array('smw-datavalue-monolingual-lcode-parenthesis', $result)); } elseif ($property->getKey() === '_LCODE' && $type === self::VALUE) { $languagecode = '@' . $result; } else { $text = $result; } } return $text . $languagecode; }
/** * @since 1.9 * * @param ParserData $parserData * @param Subobject $subobject * @param MessageFormatter $messageFormatter */ public function __construct(ParserData $parserData, Subobject $subobject, MessageFormatter $messageFormatter) { $this->parserData = $parserData; $this->subobject = $subobject; $this->messageFormatter = $messageFormatter; $this->dataValueFactory = DataValueFactory::getInstance(); }
/** * @since 1.9 * * @param ParserParameterProcessor $parameters * * @return string|null */ public function parse(ParserParameterProcessor $parameters) { $count = 0; $template = ''; $subject = $this->parserData->getSemanticData()->getSubject(); $parametersToArray = $parameters->toArray(); if (isset($parametersToArray['template'])) { $template = $parametersToArray['template'][0]; unset($parametersToArray['template']); } foreach ($parametersToArray as $property => $values) { $last = count($values) - 1; // -1 because the key starts with 0 foreach ($values as $key => $value) { $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject); if ($this->parserData->canModifySemanticData()) { $this->parserData->addDataValue($dataValue); } $this->messageFormatter->addFromArray($dataValue->getErrors()); $this->addFieldsToTemplate($template, $dataValue, $property, $value, $last == $key, $count); } } $this->parserData->pushSemanticDataToParserOutput(); $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml(); return array($html, 'noparse' => $template === '', 'isHTML' => false); }
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); 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); } $result = ''; 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; }
protected function setUp() { parent::setUp(); $this->testEnvironment = new TestEnvironment(); $this->semanticDataValidator = $this->testEnvironment->getUtilityFactory()->newValidatorFactory()->newSemanticDataValidator(); $this->dataValueFactory = DataValueFactory::getInstance(); }
protected function setUp() { parent::setUp(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator(); $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); }
/** * @since 2.4 * * @param string $value * * @return Description * @throws InvalidArgumentException */ public function deserialize($value) { if (!is_string($value)) { throw new InvalidArgumentException('Value needs to be a string'); } if ($value === '') { $this->addError(wfMessage('smw_novalues')->text()); return new ThingDescription(); } $subdescriptions = array(); list($text, $languageCode) = $this->dataValue->getValuesFromString($value); foreach ($this->dataValue->getPropertyDataItems() as $property) { // If the DVFeature doesn't require a language code to be present then // allow to skip it as conjunctive condition when it is empty if ($languageCode === '' && $property->getKey() === '_LCODE' && !$this->dataValue->isEnabledFeature(SMW_DV_MLTV_LCODE)) { continue; } $value = $property->getKey() === '_LCODE' ? $languageCode : $text; $comparator = SMW_CMP_EQ; $this->prepareValue($value, $comparator); // Directly use the DI instead of going through the DVFactory to // avoid having ~zh-* being validated when building a DV // If one of the values is empty use, ? so queries can be arbitrary // in respect of the query condition $dataValue = DataValueFactory::getInstance()->newDataValueByItem(new DIBlob($value === '' ? '?' : $value), $property, false, $this->dataValue->getContextPage()); if (!$dataValue->isValid()) { $this->addError($dataValue->getErrors()); continue; } $subdescriptions[] = $this->newSubdescription($dataValue, $comparator); } return $this->getFinalDescriptionFor($subdescriptions); }
public function semanticDataProvider() { // Is a dataprovider therefore can't use the setUp $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $title = Title::newFromText('Foo'); #0 Empty container $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $provider[] = array($foo); #1 Single entry $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $provider[] = array($foo); // #2 Single + single subobject entry $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo); #3 Multiple entries $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData(); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar')); $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has queez', 'Xeey')); $subobject = new Subobject($title); $subobject->setSemanticData('Foo'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam')); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz')); $subobject->setSemanticData('Bar'); $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz')); $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $provider[] = array($foo); return $provider; }
protected function setUp() { parent::setUp(); $validatorFactory = $this->testEnvironment->getUtilityFactory()->newValidatorFactory(); $stringValidator = $validatorFactory->newStringValidator(); $semanticDataValidator = $validatorFactory->newSemanticDataValidator(); $queryResultValidator = $validatorFactory->newQueryResultValidator(); $this->queryTestCaseProcessor = new QueryTestCaseProcessor($this->getStore(), $queryResultValidator, $stringValidator); $this->rdfTestCaseProcessor = new RdfTestCaseProcessor($this->getStore(), $stringValidator); $this->parserTestCaseProcessor = new ParserTestCaseProcessor($this->getStore(), $semanticDataValidator, $stringValidator); $this->specialPageTestCaseProcessor = new SpecialPageTestCaseProcessor($this->getStore(), $stringValidator); $this->eventDispatcher = EventHandler::getInstance()->getEventDispatcher(); // This ensures that if content is created in the NS_MEDIAWIKI namespace // and an object relies on the MediaWikiNsContentReader then it uses the DB ApplicationFactory::getInstance()->getMediaWikiNsContentReader()->skipMessageCache(); DataValueFactory::getInstance()->clear(); // Reset the Title/TitleParser otherwise a singleton instance holds an outdated // content language reference $this->testEnvironment->resetMediaWikiService('_MediaWikiTitleCodec'); $this->testEnvironment->resetMediaWikiService('TitleParser'); $this->testEnvironment->resetPoolCacheFor(PropertySpecificationLookup::POOLCACHE_ID); // Make sure LocalSettings don't interfere with the default settings $GLOBALS['smwgDVFeatures'] = $GLOBALS['smwgDVFeatures'] & ~SMW_DV_NUMV_USPACE; $this->testEnvironment->addConfiguration('smwgQueryResultCacheType', 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) { $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; }
protected function setUp() { parent::setUp(); $this->dataItemFactory = new DataItemFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->testEnvironment = new TestEnvironment(); $this->testEnvironment->resetPoolCacheFor(\SMWExporter::POOLCACHE_ID); }
protected function setUp() { parent::setUp(); $this->apiFactory = new MwApiFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->serializerFactory = new SerializerFactory(); $this->semanticDataFactory = new SemanticDataFactory(); }
protected function setUp() { parent::setUp(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->semanticDataFactory = new SemanticDataFactory(); $this->exportDataValidator = new ExportDataValidator(); $this->fixturesProvider = new FixturesProvider(); }
/** * @since 1.9 * * @param Store $store * @param ParserData $parserData * @param MessageBuilder $messageBuilder */ public function __construct(Store $store, ParserData $parserData, MessageBuilder $messageBuilder) { $this->store = $store; $this->parserData = $parserData; $this->messageBuilder = $messageBuilder; $this->applicationFactory = ApplicationFactory::getInstance(); $this->dataValueFactory = DataValueFactory::getInstance(); }
/** * @since 2.1 * * @param DIWikiPage|null $targetSubject */ public function __construct(DIWikiPage $targetSubject = null) { $this->targetSubject = $targetSubject; if ($this->targetSubject === null) { $this->targetSubject = $this->asSubject(); } $this->dataValueFactory = DataValueFactory::getInstance(); }
protected function setUp() { parent::setUp(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator(); $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); $this->testEnvironment->addConfiguration('smwgQueryResultCacheType', false); }
protected function setUp() { $this->testEnvironment = new TestEnvironment(); $this->dataItemFactory = new DataItemFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->cachedPropertyValuesPrefetcher = $this->getMockBuilder('\\SMW\\CachedPropertyValuesPrefetcher')->disableOriginalConstructor()->getMock(); $this->testEnvironment->registerObject('CachedPropertyValuesPrefetcher', $this->cachedPropertyValuesPrefetcher); }
/** * @since 1.9 * * @param ParserData $parserData * @param MagicWordsFinder $magicWordsFinder * @param RedirectTargetFinder $redirectTargetFinder */ public function __construct(ParserData $parserData, MagicWordsFinder $magicWordsFinder, RedirectTargetFinder $redirectTargetFinder) { $this->parserData = $parserData; $this->magicWordsFinder = $magicWordsFinder; $this->redirectTargetFinder = $redirectTargetFinder; $this->dataValueFactory = DataValueFactory::getInstance(); $this->applicationFactory = ApplicationFactory::getInstance(); }
/** * @since 2.2 * * @param Store $store * @param Cache|null $cache */ public function __construct(Store $store, Cache $cache = null) { $this->store = $store; $this->cache = $cache; if ($this->cache === null) { $this->cache = ApplicationFactory::getInstance()->newCacheFactory()->newNullCache(); } $this->dataValueFactory = DataValueFactory::getInstance(); }
protected function setUp() { parent::setUp(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator(); $this->fixturesProvider = UtilityFactory::getInstance()->newFixturesFactory()->newFixturesProvider(); $this->fixturesProvider->setupDependencies($this->getStore()); }
public function getQueryString($asValue = false) { $pageValue = DataValueFactory::getInstance()->newDataValueByItem($this->concept, null); $result = '[[' . $pageValue->getPrefixedText() . ']]'; if ($asValue) { return ' <q>' . $result . '</q> '; } return $result; }
/** * Instead of representing an external identifier as "owl:sameAs", the weaker * declarative axiom "skos:exactMatch" has been choosen to avoid potential * issues with undesirable entailments. * * "skos:exactMatch" has been defined as "... indicating a high degree of * confidence that the concepts can be used interchangeably across a wide * range of information retrieval applications ..." * * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { parent::addResourceValue($expData, $property, $dataItem); $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); $formattedUriDataItem = $dataValue->getWithFormattedUri(); if ($formattedUriDataItem instanceof DIUri) { $expData->addPropertyObjectValue($this->exporter->getSpecialNsResource('skos', 'exactMatch'), $this->exporter->getDataItemExpElement($formattedUriDataItem)); } }
/** * @since 2.1 * * @return SemanticData */ public function getDependencies() { $semanticData = parent::getDependencies(); $dataValueFactory = DataValueFactory::getInstance(); foreach ($this->conversionValues as $conversionValue) { $semanticData->addDataValue($dataValueFactory->newDataValueByProperty(new DIProperty('_CONV'), $conversionValue)); } return $semanticData; }
protected function setUp() { parent::setUp(); $this->mwHooksHandler = UtilityFactory::getInstance()->newMwHooksHandler(); $this->mwHooksHandler->deregisterListedHooks()->invokeHooksFromRegistry(); $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); $this->pageCreator = UtilityFactory::getInstance()->newPageCreator(); $this->applicationFactory = ApplicationFactory::getInstance(); $this->dataValueFactory = DataValueFactory::getInstance(); }
/** * @since 1.9 * * @param ArrayFormatter $parameters * * @return string|null */ public function parse(ArrayFormatter $parameters) { $subject = $this->parserData->getSemanticData()->getSubject(); foreach ($parameters->toArray() as $property => $values) { foreach ($values as $value) { $dataValue = DataValueFactory::getInstance()->newPropertyValue($property, $value, false, $subject); $this->parserData->addDataValue($dataValue); } } $this->parserData->pushSemanticDataToParserOutput(); return $this->messageFormatter->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml(); }
public function testRedirectTragetLookupForExistingEntry() { $property = new DIProperty('RedirectLookupForExistingEntry'); $semanticData = new SemanticData(new DIWikiPage(__METHOD__, NS_MAIN, '')); $semanticData->addDataValue(DataValueFactory::getInstance()->newPropertyObjectValue($property, 'Bar')); $this->store->doSparqlDataUpdate($semanticData); $expNsResource = new ExpNsResource('RedirectLookupForExistingEntry', Exporter::getNamespaceUri('property'), 'property'); $instance = new RedirectLookup($this->sparqlDatabase); $instance->clear(); $exists = null; $this->assertSame($expNsResource, $instance->findRedirectTargetResource($expNsResource, $exists)); $this->assertTrue($exists); }
public function testRoundtripOfSerializedSemanticDataAfterStoreUpdate() { $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__)); $semanticDataBeforeUpdate = new SemanticData($subject); $subobject = new Subobject($subject->getTitle()); $subobject->setEmptyContainerForId('SomeSubobjectToSerialize'); $subobject->getSemanticData()->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Foo', 'Bar')); $semanticDataBeforeUpdate->addSubobject($subobject); $this->getStore()->updateData($semanticDataBeforeUpdate); $semanticDataAfterUpdate = $this->getStore()->getSemanticData($subject); $serializerFactory = new SerializerFactory(); $this->assertEquals($semanticDataAfterUpdate->getHash(), $serializerFactory->deserialize($serializerFactory->serialize($semanticDataAfterUpdate))->getHash()); }
public function printRequestProvider() { $provider['print-cats-wiki'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), null, Formatter::FORMAT_WIKI, 'Foo'); $provider['print-cats-html'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), null, Formatter::FORMAT_HTML, 'Foo'); $provider['print-ccat-html'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), null, Formatter::FORMAT_HTML, 'Foo'); $provider['print-ccat-wiki'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), null, Formatter::FORMAT_WIKI, 'Foo'); $provider['print-this-wiki'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), null, Formatter::FORMAT_WIKI, 'Foo'); $provider['print-this-html'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), null, Formatter::FORMAT_HTML, 'Foo'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop-wiki-no-linker'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), null, Formatter::FORMAT_WIKI, 'Foo'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop-html-no-linker'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), null, Formatter::FORMAT_HTML, 'Foo'); return $provider; }
protected function setUp() { $this->store = StoreFactory::getStore(); if (!$this->store instanceof SPARQLStore) { $this->markTestSkipped("Requires a SPARQLStore instance"); } $sparqlDatabase = $this->store->getConnection(); if (!$sparqlDatabase->setConnectionTimeoutInSeconds(5)->ping()) { $this->markTestSkipped("Can't connect to the SPARQL database"); } $sparqlDatabase->deleteAll(); $this->queryResultValidator = new QueryResultValidator(); $this->semanticDataFactory = new SemanticDataFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); }
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); }