/** * 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->dataValueFactory = DataValueFactory::getInstance(); $this->queryResultValidator = UtilityFactory::getInstance()->newValidatorFactory()->newQueryResultValidator(); $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); }
/** * @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 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); }
protected function setUp() { parent::setUp(); $this->testEnvironment = new TestEnvironment(); $this->semanticDataValidator = $this->testEnvironment->getUtilityFactory()->newValidatorFactory()->newSemanticDataValidator(); $this->dataValueFactory = DataValueFactory::getInstance(); }
protected function addDataValuesToSubobject(ParserParameterProcessor $parameters) { $subject = $this->parserData->getSemanticData()->getSubject(); // Named subobjects containing a "." in the first five characters are reserved to be // used by extensions only in order to separate them from user land and avoid them // accidentally to refer to the same named ID // (i.e. different access restrictions etc.) if (strpos(mb_substr($parameters->getFirst(), 0, 5), '.') !== false) { return $this->addErrorWithMsg($subject, wfMessage('smw-subobject-parser-invalid-naming-scheme', $parameters->getFirst())->escaped()); } $this->subobject->setEmptyContainerForId($this->createSubobjectId($parameters)); foreach ($this->transformParametersToArray($parameters) as $property => $values) { if ($property === self::PARAM_SORTKEY) { $property = DIProperty::TYPE_SORTKEY; } if ($property === self::PARAM_CATEGORY) { $property = DIProperty::TYPE_CATEGORY; } foreach ($values as $value) { $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, false, $subject); $this->subobject->addDataValue($dataValue); } } return true; }
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; }
/** * @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; }
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; }
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() { $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); }
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() { parent::setUp(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->semanticDataFactory = new SemanticDataFactory(); $this->exportDataValidator = new ExportDataValidator(); $this->fixturesProvider = new FixturesProvider(); }
protected function setUp() { parent::setUp(); $this->apiFactory = new MwApiFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $this->serializerFactory = new SerializerFactory(); $this->semanticDataFactory = new SemanticDataFactory(); }
/** * @see SMWDescription::getQueryString * * @since 0.6 * * @param boolean $asValue * @return string */ public function getQueryString($asValue = false) { if ($this->getDataItem() !== null) { $queryString = DataValueFactory::newDataItemValue($this->getDataItem(), $this->getPropertyCompat())->getWikiValue(); return $asValue ? $queryString : "[[{$queryString}]]"; } else { return $asValue ? '+' : ''; } }
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)); } }
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()); }
/** * @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; }
/** * @since 2.4 */ public function tearDown() { foreach ($this->configuration as $key => $value) { $GLOBALS[$key] = $value; $this->applicationFactory->getSettings()->set($key, $value); } $this->applicationFactory->clear(); $this->dataValueFactory->clear(); }
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(); }
public function testConstruct() { $geoDI = new SMWDIGeoCoord(23, 42); /** * @var SMGeoCoordsValue $geoValue */ $geoValue = DataValueFactory::newDataItemValue($geoDI); $this->assertInstanceOf('SMGeoCoordsValue', $geoValue); $this->assertEquals($geoDI, $geoValue->getDataItem()); $this->assertEquals('23° 0\' 0", 42° 0\' 0"', $geoValue->getShortWikiText()); }
/** * @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 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 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); }
protected function addDataValuesToSubobject(ArrayFormatter $parameters) { $subject = $this->parserData->getSemanticData()->getSubject(); $this->subobject->setEmptyContainerForId($this->createSubobjectId($parameters)); foreach ($this->transformParametersToArray($parameters) as $property => $values) { if ($property === self::PARAM_SORTKEY) { $property = DIProperty::TYPE_SORTKEY; } foreach ($values as $value) { $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, false, $subject); $this->subobject->addDataValue($dataValue); } } }
private function getPropertyLink($subject, $properties, $value, $valueCaption) { // #1855 if (substr($value, 0, 3) === '@@@') { $property = end($properties); $dataValue = $this->dataValueFactory->newPropertyValueByLabel($property, $valueCaption, $subject); if (($lang = Localizer::getAnnotatedLanguageCodeFrom($value)) !== false) { $dataValue->setOption($dataValue::OPT_USER_LANGUAGE, $lang); $dataValue->setCaption($valueCaption === false ? $dataValue->getWikiValue() : $valueCaption); } return $dataValue->getShortWikitext(smwfGetLinker()); } return ''; }
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; }
/** * @since 2.4 * * @param string $chunk * * @return Description|null */ public function getDescriptionForWikiPageValueChunk($chunk) { // Only create a simple WpgValue to initiate the query description target // operation. If the chunk contains something like "≤Issue/1220" then the // WpgValue would return with an error as it cannot parse ≤ as/ legal // character, the chunk itself is processed by // DataValue::getQueryDescription hence no need to use it as input for // the factory instance $dataValue = $this->dataValueFactory->newTypeIDValue('_wpg', 'QP_WPG_TITLE'); $description = null; $description = $dataValue->getQueryDescription($chunk); $this->addError($dataValue->getErrors()); return $description; }