/** * 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); }
private function transformParametersToArray(ArrayFormatter $parameters) { if ($this->useFirstElementForPropertyLabel) { $parameters->addParameter($parameters->getFirst(), $this->parserData->getTitle()->getPrefixedText()); } return $parameters->toArray(); }
private function createQueryProfile($query, $format, $duration) { $queryProfilerFactory = $this->applicationFactory->newQueryProfilerFactory(); $jointProfileAnnotator = $queryProfilerFactory->newJointProfileAnnotator($this->parserData->getTitle(), $query, $format, $duration); $jointProfileAnnotator->addAnnotation(); $this->parserData->getSemanticData()->addPropertyObjectValue($jointProfileAnnotator->getProperty(), $jointProfileAnnotator->getContainer()); }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $this->query->setSubject(DIWIkiPage::newFromTitle($this->parserData->getTitle())); $queryHash = $this->query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); $format = $this->params['format']->getValue(); // FIXME Parser should be injected into the ResultPrinter // Enables specific formats to import its annotation data from // a recursive parse process in the result format // e.g. using ask query to search/set an invert property value if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) { $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); } if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->circularReferenceGuard->unmark($queryHash); $this->createQueryProfile($this->query, $format, $queryDuration); return $result; }
public function testGetterInstances() { $title = Title::newFromText(__METHOD__); $parserOutput = new ParserOutput(); $instance = new ParserData($title, $parserOutput); $this->assertInstanceOf('Title', $instance->getTitle()); $this->assertInstanceOf('ParserOutput', $instance->getOutput()); $this->assertInstanceOf('\\SMW\\DIWikiPage', $instance->getSubject()); }
/** * 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()); }
/** * 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()); }
private function doPrepareParameters(ParserParameterProcessor $parserParameterProcessor) { if ($parserParameterProcessor->hasParameter(self::PARAM_LINKWITH)) { $val = $parserParameterProcessor->getParameterValuesByKey(self::PARAM_LINKWITH); $parserParameterProcessor->addParameter(end($val), $this->parserData->getTitle()->getPrefixedText()); $parserParameterProcessor->removeParameterByKey(self::PARAM_LINKWITH); } if ($this->isEnabledFirstElementAsPropertyLabel) { $parserParameterProcessor->addParameter($parserParameterProcessor->getFirst(), $this->parserData->getTitle()->getPrefixedText()); } $parameters = $parserParameterProcessor->toArray(); // FIXME 3.0 make sorting default by 3.0 // Only sort for a modified sobj otherwise existing ID will change $sort = false; // This ensures that an unordered array is ordered and will produce // the same ID even if elements are placed differently if ($sort) { ksort($parameters); } return $parameters; }
/** * 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()); }
/** * Returns Title object * * @since 1.9 * * @return string|null */ public function getTitle() { return $this->parserData->getTitle(); }