/**
  * @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);
 }
 /**
  * @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;
 }
 /**
  * Adds property values to the ParserOutput instance
  *
  * @since 1.9
  *
  * @param array $properties
  *
  * @return string
  */
 protected function addPropertyValue(array $properties, $value, $valueCaption)
 {
     $subject = $this->parserData->getSubject();
     if (($propertyLink = $this->getPropertyLink($subject, $properties, $value, $valueCaption)) !== '') {
         return $propertyLink;
     }
     // Add properties to the semantic container
     foreach ($properties as $property) {
         $dataValue = $this->dataValueFactory->newDataValueByText($property, $value, $valueCaption, $subject);
         if ($this->isEnabledNamespace && $this->isAnnotation && $this->parserData->canModifySemanticData()) {
             $this->parserData->addDataValue($dataValue);
         }
     }
     // Return the text representation
     $result = $dataValue->getShortWikitext(true);
     // If necessary add an error text
     if ($this->settings->get('smwgInlineErrors') && $this->isEnabledNamespace && $this->isAnnotation && !$dataValue->isValid()) {
         // Encode `:` to avoid a comment block and instead of the nowiki tag
         // use &#58; as placeholder
         $result = str_replace(':', '&#58;', $result) . $dataValue->getErrorText();
     }
     return $result;
 }
 public function testCanModifySemanticData()
 {
     $title = $this->getMockBuilder('Title')->disableOriginalConstructor()->getMock();
     $title->expects($this->once())->method('getNamespace')->will($this->returnValue(-1));
     $parserOutput = new ParserOutput();
     // FIXME 1.21+
     if (!method_exists($parserOutput, 'getExtensionData')) {
         $this->markTestSkipped('getExtensionData is not available.');
     }
     $instance = new ParserData($title, $parserOutput);
     $this->assertTrue($instance->canModifySemanticData());
     $parserOutput->setExtensionData('smw-blockannotation', true);
     $this->assertFalse($instance->canModifySemanticData());
 }