/** * @since 1.9 * * @param ArrayFormatter $params * * @return string|null */ public function parse(ArrayFormatter $parameters) { $this->addDataValuesToSubobject($parameters); $this->parserData->getSemanticData()->addSubobject($this->subobject); $this->parserData->pushSemanticDataToParserOutput(); return $this->messageFormatter->addFromArray($this->subobject->getErrors())->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml(); }
/** * @since 2.1 * * @param PPFrame $frame * @param array $args */ public function parse(PPFrame $frame, array $args) { // @todo Save as metadata if (!$frame->isTemplate()) { return ''; } $this->subject = $this->parserData->getSemanticData()->getSubject(); foreach ($args as $arg) { if (trim($arg) !== '') { $expanded = trim($frame->expand($arg)); $parts = explode('=', $expanded, 2); if (count($parts) == 1) { $propertystring = $expanded; $argumentname = $expanded; } else { $propertystring = $parts[0]; $argumentname = $parts[1]; } $propertyValue = PropertyValue::makeUserProperty($propertystring); $argument = $frame->getArgument($argumentname); $valuestring = $frame->expand($argument); if ($propertyValue->isValid()) { $this->matchValueArgument($propertyValue, $propertystring, $valuestring); } } } $this->parserData->pushSemanticDataToParserOutput(); return ''; }
/** * Parse parameters, return concept information box and update the * ParserOutput with the concept object * * @since 1.9 * * @param array $params * * @return string|null */ public function parse(array $rawParams) { $this->parserData->getOutput()->addModules('ext.smw.style'); $title = $this->parserData->getTitle(); $property = new DIProperty('_CONC'); if (!($title->getNamespace() === SMW_NS_CONCEPT)) { return $this->messageFormatter->addFromKey('smw_no_concept_namespace')->getHtml(); } elseif (count($this->parserData->getSemanticData()->getPropertyValues($property)) > 0) { return $this->messageFormatter->addFromKey('smw_multiple_concepts')->getHtml(); } // Remove parser object from parameters array if (isset($rawParams[0]) && $rawParams[0] instanceof Parser) { array_shift($rawParams); } // Use first parameter as concept (query) string $conceptQuery = array_shift($rawParams); // Use second parameter, if any as a description $conceptDocu = array_shift($rawParams); $query = $this->buildQuery($conceptQuery); $conceptQueryString = $query->getDescription()->getQueryString(); $this->parserData->getSemanticData()->addPropertyObjectValue($property, new DIConcept($conceptQueryString, $conceptDocu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth())); $this->messageFormatter->addFromArray($query->getErrors())->addFromArray($this->parserData->getErrors()); $this->addQueryProfile($query); $this->parserData->pushSemanticDataToParserOutput(); if ($this->messageFormatter->exists()) { return $this->messageFormatter->getHtml(); } return $this->buildConceptInfoBox($title, $conceptQueryString, $conceptDocu); }
/** * @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); }
/** * Builds content suitable for rendering a Factbox and * updating the ParserOuput accordingly * * @since 1.9 * * @return Factbox */ public function doBuild() { $this->content = $this->fetchContent($this->getMagicWords()); if ($this->content !== '') { $this->parserData->getOutput()->addModules($this->getModules()); $this->parserData->pushSemanticDataToParserOutput(); $this->isVisible = true; } return $this; }
public function testAddDataValueAndPushSemanticDataToParserOutput() { $title = Title::newFromText(__METHOD__); $parserOutput = new ParserOutput(); $instance = new ParserData($title, $parserOutput); $instance->addDataValue($this->dataValueFactory->newPropertyValue('Foo', 'Bar')); $this->assertFalse($instance->getSemanticData()->isEmpty()); $instance->pushSemanticDataToParserOutput(); $title = Title::newFromText(__METHOD__ . '-1'); $newInstance = new ParserData($title, $instance->getOutput()); $this->assertEquals($instance->getSemanticData()->getHash(), $newInstance->getSemanticData()->getHash()); }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); $this->doStripMagicWordsFromText($text); $this->setSemanticEnabledNamespaceState($title); $this->addRedirectTargetAnnotation($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); $this->parserData->getOutput()->addModules($this->getModules()); $this->parserData->pushSemanticDataToParserOutput(); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
/** * @dataProvider categoriesDataProvider */ public function testAddCategoriesWithParserDataUpdate(array $parameters, array $expected) { $semanticData = $this->semanticDataFactory->setSubject(new DIWikiPage(__METHOD__, $parameters['namespace'], ''))->newEmptySemanticData(); $title = $semanticData->getSubject()->getTitle(); $parserOutput = new ParserOutput(); $parserData = new ParserData($title, $parserOutput); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $instance = new CategoryPropertyAnnotator(new NullPropertyAnnotator($parserData->getSemanticData()), $parameters['categories']); $instance->addAnnotation(); $parserData->pushSemanticDataToParserOutput(); $parserDataAfterAnnotation = new ParserData($title, $parserOutput); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserDataAfterAnnotation->getSemanticData()); }
/** * @since 1.9 * * @param ParserParameterProcessor $params * * @return string|null */ public function parse(ParserParameterProcessor $parameters) { if ($this->parserData->canModifySemanticData() && $this->addDataValuesToSubobject($parameters) && !$this->subobject->getSemanticData()->isEmpty()) { $this->parserData->getSemanticData()->addSubobject($this->subobject); } $this->parserData->pushSemanticDataToParserOutput(); $html = $this->messageFormatter->addFromArray($this->subobject->getErrors())->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml(); // An empty output in MW forces an extra <br> element. //if ( $html == '' ) { // $html = '<p></p>'; //} return $html; }
/** * @since 1.9 * * @param ArrayFormatter $parameters * * @return string|null */ public function parse(ArrayFormatter $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) { foreach ($values as $value) { $dataValue = DataValueFactory::getInstance()->newPropertyValue($property, $value, false, $subject); $this->parserData->addDataValue($dataValue); $this->messageFormatter->addFromArray($dataValue->getErrors()); $this->addFieldsToTemplate($template, $dataValue, $property, $value, $count); } } $this->parserData->pushSemanticDataToParserOutput(); $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml(); return array($html, 'noparse' => true, 'isHTML' => true); }
/** * Parse parameters, return results from the query printer and update the * ParserOutput with meta data from the query * * FIXME $rawParams use IParameterFormatter -> QueryParameterFormatter class * Parse parameters and return query results to the ParserOutput * object and output result data from the SMWQueryProcessor * * @todo $rawParams should be of IParameterFormatter * QueryParameterFormatter class * * @since 1.9 * * @param array $params * * @return string|null */ public function parse(array $rawParams) { // Counter for what? Where and for what is it used? global $smwgIQRunningNumber; $smwgIQRunningNumber++; // Remove parser object from parameters array if (isset($rawParams[0]) && $rawParams[0] instanceof Parser) { array_shift($rawParams); } $this->applicationFactory = ApplicationFactory::getInstance(); $result = $this->doFetchResultsForRawParameters($rawParams); $this->parserData->pushSemanticDataToParserOutput(); return $result; }
/** * @dataProvider categoriesDataProvider */ public function testAddCategoriesWithParserDataUpdate(array $parameters, array $expected) { $semanticData = $this->semanticDataFactory->setSubject(new DIWikiPage(__METHOD__, $parameters['namespace'], ''))->newEmptySemanticData(); $title = $semanticData->getSubject()->getTitle(); $parserOutput = new ParserOutput(); $parserData = new ParserData($title, $parserOutput); $instance = new CategoryPropertyAnnotator(new NullPropertyAnnotator($parserData->getSemanticData()), $parameters['categories']); $instance->setShowHiddenCategoriesState($parameters['settings']['smwgShowHiddenCategories']); $instance->setCategoryInstanceUsageState($parameters['settings']['smwgCategoriesAsInstances']); $instance->setCategoryHierarchyUsageState($parameters['settings']['smwgUseCategoryHierarchy']); $instance->addAnnotation(); $parserData->pushSemanticDataToParserOutput(); $parserDataAfterAnnotation = new ParserData($title, $parserOutput); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserDataAfterAnnotation->getSemanticData()); }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); // Identifies the current parser run (especially when called recursively) $this->parserData->getSubject()->setContextReference('intp:' . uniqid()); $this->doStripMagicWordsFromText($text); $this->setSemanticEnabledNamespaceState($title); $this->addRedirectTargetAnnotation($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); if ($this->isEnabledNamespace) { $this->parserData->getOutput()->addModules($this->getModules()); } $this->parserData->pushSemanticDataToParserOutput(); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
/** * Parse parameters, return results from the query printer and update the * ParserOutput with meta data from the query * * FIXME $rawParams use IParameterFormatter -> QueryParameterFormatter class * Parse parameters and return query results to the ParserOutput * object and output result data from the SMWQueryProcessor * * @todo $rawParams should be of IParameterFormatter * QueryParameterFormatter class * * @since 1.9 * * @param array $params * * @return string|null */ public function parse(array $rawParams) { // Do we still need this? // Reference found in SRF_Exhibit.php, SRF_Ploticus.php, SRF_Timeline.php, SRF_JitGraph.php global $smwgIQRunningNumber; $smwgIQRunningNumber++; $this->applicationFactory = ApplicationFactory::getInstance(); $rawParams = $this->prepareRawParameters($rawParams); $result = $this->doFetchResultsForRawParameters($rawParams); $this->parserData->pushSemanticDataToParserOutput(); // 1.23+ add options so changes are recognized in case of: // - 'userlang' will trigger a cache fragmentation by user language // - 'dateformat' will trigger a cache fragmentation by date preference if (method_exists($this->parserData->getOutput(), 'recordOption')) { $this->parserData->getOutput()->recordOption('userlang'); $this->parserData->getOutput()->recordOption('dateformat'); } return $result; }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); $start = microtime(true); // Identifies the current parser run (especially when called recursively) $this->parserData->getSubject()->setContextReference('intp:' . uniqid()); $this->doStripMagicWordsFromText($text); $this->isEnabledNamespace = $this->isSemanticEnabledForNamespace($title); $this->addRedirectTargetAnnotationFromText($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); if ($this->isEnabledNamespace) { $this->parserData->getOutput()->addModules($this->getModules()); if (method_exists($this->parserData->getOutput(), 'recordOption')) { $this->parserData->getOutput()->recordOption('userlang'); } } $this->parserData->pushSemanticDataToParserOutput(); $this->parserData->addLimitReport('intext-parsertime', number_format(microtime(true) - $start, 3)); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
public function testImportFromParserOutput() { $import = new ParserData(Title::newFromText(__METHOD__), new ParserOutput()); $import->addDataValue($this->dataValueFactory->newDataValueByText('Foo', 'Bar')); $import->pushSemanticDataToParserOutput(); $instance = new ParserData(Title::newFromText(__METHOD__), new ParserOutput()); $instance->importFromParserOutput(null); $this->assertNotEquals($import->getSemanticData()->getHash(), $instance->getSemanticData()->getHash()); $instance->importFromParserOutput($import->getOutput()); $this->assertEquals($import->getSemanticData()->getHash(), $instance->getSemanticData()->getHash()); }