/**
  * 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);
 }
 /**
  * @dataProvider magicWordDataProvider
  */
 public function testStripMagicWords($namespace, $text, array $expected)
 {
     $parserData = new ParserData(Title::newFromText(__METHOD__, $namespace), new ParserOutput());
     $magicWordsFinder = new MagicWordsFinder($parserData->getOutput());
     $instance = new InTextAnnotationParser($parserData, $magicWordsFinder, new RedirectTargetFinder());
     $instance->parse($text);
     $this->assertEquals($expected, $magicWordsFinder->getMagicWords());
 }
예제 #3
0
 protected function doStripMagicWordsFromText(&$text)
 {
     $words = array();
     $this->magicWordFinder->setOutput($this->parserData->getOutput());
     foreach (array('SMW_NOFACTBOX', 'SMW_SHOWFACTBOX') as $magicWord) {
         $words = $words + $this->magicWordFinder->matchAndRemove($magicWord, $text);
     }
     $this->magicWordFinder->pushMagicWordsToParserOutput($words);
     return $words;
 }
예제 #4
0
 protected function doStripMagicWordsFromText(&$text)
 {
     $words = array();
     $this->magicWordsFinder->setOutput($this->parserData->getOutput());
     $magicWords = array('SMW_NOFACTBOX', 'SMW_SHOWFACTBOX');
     Hooks::run('SMW::Parser::BeforeMagicWordsFinder', array(&$magicWords));
     foreach ($magicWords as $magicWord) {
         $words[] = $this->magicWordsFinder->findMagicWordInText($magicWord, $text);
     }
     $this->magicWordsFinder->pushMagicWordsToParserOutput($words);
     return $words;
 }
예제 #5
0
 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());
 }
 /**
  * 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;
 }
예제 #7
0
파일: Factbox.php 프로젝트: whysasse/kmwiki
 /**
  * Returns magic words attached to the ParserOutput object
  *
  * @since 1.9
  *
  * @return string|null
  */
 protected function getMagicWords()
 {
     $settings = $this->applicationFactory->getSettings();
     $parserOutput = $this->parserData->getOutput();
     // Prior MW 1.21 mSMWMagicWords is used (see SMW\ParserTextProcessor)
     if (method_exists($parserOutput, 'getExtensionData')) {
         $smwMagicWords = $parserOutput->getExtensionData('smwmagicwords');
         $mws = $smwMagicWords === null ? array() : $smwMagicWords;
     } else {
         // @codeCoverageIgnoreStart
         $mws = isset($parserOutput->mSMWMagicWords) ? $parserOutput->mSMWMagicWords : array();
         // @codeCoverageIgnoreEnd
     }
     if (in_array('SMW_SHOWFACTBOX', $mws)) {
         $showfactbox = SMW_FACTBOX_NONEMPTY;
     } elseif (in_array('SMW_NOFACTBOX', $mws)) {
         $showfactbox = SMW_FACTBOX_HIDDEN;
     } elseif ($this->useInPreview) {
         $showfactbox = $settings->get('smwgShowFactboxEdit');
     } else {
         $showfactbox = $settings->get('smwgShowFactbox');
     }
     return $showfactbox;
 }
예제 #8
0
 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());
 }