/** * @dataProvider templateDataProvider */ public function testPreprocessTemplateAndParse($namespace, array $settings, $text, $tmplValue, array $expected) { $parserOutput = new ParserOutput(); $title = Title::newFromText(__METHOD__, $namespace); $outputText = $this->runTemplateTransclusion($title, $text, $tmplValue); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($settings)); $parserData = new ParserData($title, $parserOutput); $instance = new InTextAnnotationParser($parserData, new MagicWordsFinder(), new RedirectTargetFinder()); $instance->parse($outputText); $this->assertContains($expected['resultText'], $outputText); $parserData = new ParserData($title, $parserOutput); $this->assertInstanceOf('\\SMW\\SemanticData', $parserData->getSemanticData()); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); }
/** * @since 2.4 * * @param DIProperty $property * @param array|string $errorMsg * * @return DIContainer */ public function getContainerFor(DIProperty $property = null, $errorMsg = '') { if ($property !== null && $property->isInverse()) { $property = new DIProperty($property->getKey()); } $errorMsg = is_array($errorMsg) ? implode(' ', $errorMsg) : $errorMsg; $subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), '_ERR' . md5(($property !== null ? $property->getKey() : 'UNKNOWN') . $errorMsg)); // Encode brackets to avoid an annotion is created/included return $this->newDiContainer($subject, $property, InTextAnnotationParser::obscureAnnotation($errorMsg)); }
/** * @since 2.0 * * @return InTextAnnotationParser */ public function newInTextAnnotationParser(ParserData $parserData) { $mwCollaboratorFactory = $this->newMwCollaboratorFactory(); $inTextAnnotationParser = new InTextAnnotationParser($parserData, $mwCollaboratorFactory->newMagicWordsFinder(), $mwCollaboratorFactory->newRedirectTargetFinder()); $inTextAnnotationParser->setStrictModeState($this->getSettings()->get('smwgEnabledInTextAnnotationParserStrictMode')); return $inTextAnnotationParser; }
/** * @dataProvider stripTextWithAnnotationProvider */ public function testStrip($text, $expectedRemoval, $expectedObscuration) { $this->assertEquals($expectedRemoval, InTextAnnotationParser::removeAnnotation($text)); $this->assertEquals($expectedObscuration, InTextAnnotationParser::obscureAnnotation($text)); }
public function testRedirectAnnotationFromInjectedRedirectTarget() { $namespace = NS_MAIN; $text = ''; $redirectTarget = Title::newFromText('Foo'); $expected = array('propertyCount' => 1, 'property' => new DIProperty('_REDI'), 'propertyValues' => array('Foo')); $settings = array('smwgNamespacesWithSemanticLinks' => array($namespace => true), 'smwgLinksInValues' => false, 'smwgInlineErrors' => true); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($settings)); $parserData = new ParserData(Title::newFromText(__METHOD__, $namespace), new ParserOutput()); $redirectTargetFinder = new RedirectTargetFinder(); $instance = new InTextAnnotationParser($parserData, new MagicWordsFinder(), $redirectTargetFinder); $instance->setRedirectTarget($redirectTarget); $instance->parse($text); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); }
/** * Return an SMWDataValue object for the next SMWDataItem object or * false if no further object exists. * * @since 1.6 * * @return SMWDataValue|false */ public function getNextDataValue() { $di = $this->getNextDataItem(); if ($di === false) { return false; } if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_rec') !== false && $this->mPrintRequest->getParameter('index') !== false) { // Not efficient, but correct: we need to find the right property for // the selected index of the record here. $pos = $this->mPrintRequest->getParameter('index') - 1; $recordValue = \SMW\DataValueFactory::getInstance()->newDataItemValue($di, $this->mPrintRequest->getData()->getDataItem()); $diProperties = $recordValue->getPropertyDataItems(); if (array_key_exists($pos, $diProperties) && !is_null($diProperties[$pos])) { $diProperty = $diProperties[$pos]; } else { $diProperty = null; } } elseif ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP) { $diProperty = $this->mPrintRequest->getData()->getDataItem(); } else { $diProperty = null; } // refs #1314 if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_txt') !== false) { $di = new DIBlob(InTextAnnotationParser::removeAnnotation($di->getString())); } $dv = \SMW\DataValueFactory::getInstance()->newDataItemValue($di, $diProperty); if ($this->mPrintRequest->getOutputFormat()) { $dv->setOutputFormat($this->mPrintRequest->getOutputFormat()); } return $dv; }
/** * Return an SMWDataValue object for the next SMWDataItem object or * false if no further object exists. * * @since 1.6 * * @return SMWDataValue|false */ public function getNextDataValue() { $dataItem = $this->getNextDataItem(); if ($dataItem === false) { return false; } if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_rec') !== false && $this->mPrintRequest->getParameter('index') !== false) { $recordValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $this->mPrintRequest->getData()->getDataItem()); $diProperty = $recordValue->getPropertyDataItemByIndex($this->mPrintRequest->getParameter('index')); } elseif ($this->mPrintRequest->isMode(PrintRequest::PRINT_PROP)) { $diProperty = $this->mPrintRequest->getData()->getDataItem(); } elseif ($this->mPrintRequest->isMode(PrintRequest::PRINT_CHAIN)) { $diProperty = $this->mPrintRequest->getData()->getLastPropertyChainValue()->getDataItem(); } else { $diProperty = null; } // refs #1314 if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_txt') !== false && $dataItem instanceof DIBlob) { $dataItem = new DIBlob(InTextAnnotationParser::removeAnnotation($dataItem->getString())); } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $diProperty); $dataValue->setContextPage($this->mResult); if ($this->mPrintRequest->getOutputFormat()) { $dataValue->setOutputFormat($this->mPrintRequest->getOutputFormat()); } if ($this->entityListAccumulator !== null && $dataItem instanceof DataItem) { $this->entityListAccumulator->addToEntityList($dataItem, $diProperty); } return $dataValue; }
/** * Processing and reparsing of the Factbox content */ private function rebuild(Title $title, ParserOutput $parserOutput, $requestContext) { $text = null; $applicationFactory = ApplicationFactory::getInstance(); $factbox = $applicationFactory->newFactboxFactory()->newFactbox($applicationFactory->newParserData($title, $parserOutput), $requestContext); $factbox->useInPreview($requestContext->getRequest()->getCheck('wpPreview')); if ($factbox->doBuild()->isVisible()) { $contentParser = $applicationFactory->newContentParser($title); $contentParser->parse($factbox->getContent()); $text = InTextAnnotationParser::removeAnnotation($contentParser->getOutput()->getText()); } return $text; }