public function testGetErrorContainerFromDataValue() { $instance = new ProcessingErrorMsgHandler(DIWikiPage::newFromText(__METHOD__)); $dataValue = $this->getMockBuilder('\\SMWDataValue')->disableOriginalConstructor()->setMethods(array('getErrors', 'getProperty'))->getMockForAbstractClass(); $dataValue->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array('Foo'))); $dataValue->expects($this->atLeastOnce())->method('getProperty')->will($this->returnValue($this->dataItemFactory->newDIProperty('Bar'))); $container = $instance->getErrorContainerFromDataValue($dataValue); $this->assertInstanceOf('\\SMWDIContainer', $container); $expected = array('propertyCount' => 2, 'propertyKeys' => array('_ERRP', '_ERRT')); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $container->getSemanticData()); }
/** * Generate textual debug output that shows an arbitrary list of informative * fields. Used for formatting query debug output. * * @note All strings given must be usable and safe in wiki and HTML * contexts. * * @param $storeName string name of the storage backend for which this is generated * @param $entries array of name => value of informative entries to display * @param $query SMWQuery or null, if given add basic data about this query as well * * @return string */ public static function getStringFrom($storeName, array $entries, Query $query = null) { if ($query instanceof Query) { $preEntries = array(); $preEntries['ASK Query'] = '<div class="smwpre">' . str_replace('[', '[', $query->getDescription()->getQueryString()) . '</div>'; $entries = array_merge($preEntries, $entries); $entries['Query Metrics'] = 'Query-Size:' . $query->getDescription()->getSize() . '<br />' . 'Query-Depth:' . $query->getDescription()->getDepth(); $errors = ''; $queryErrors = ProcessingErrorMsgHandler::normalizeMessages($query->getErrors()); foreach ($queryErrors as $error) { $errors .= $error . '<br />'; } if ($errors === '') { $errors = 'None'; } $entries['Errors and Warnings'] = $errors; } $result = '<div style="border: 5px dotted #ffcc00; background: #FFF0BD; padding: 20px; ">' . "<div class='smw-column-header'><big>{$storeName} debug output</big></div>"; foreach ($entries as $header => $information) { $result .= "<div class='smw-column-header'>{$header}</div>"; if ($information !== '') { $result .= "{$information}"; } } $result .= '</div>'; return $result; }
/** * @since 2.5 * * @param Query|null $query * * @return string */ public function getFormattedErrorString(Query $query = null) { if ($query === null || !is_array($query->getErrors()) || $query->getErrors() === array()) { return ''; } $errors = array(); foreach (ProcessingErrorMsgHandler::normalizeMessages($query->getErrors()) as $value) { if ($value === '') { continue; } if (is_array($value)) { $value = implode(" ", $value); } $errors[] = $value; } if (count($errors) > 1) { $error = '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } else { $error = implode(' ', $errors); } return Html::rawElement('div', array('class' => 'smw-callout smw-callout-error'), $error); }
/** * @since 1.9 * * @param SMWDataValue $dataValue */ public function addDataValue(SMWDataValue $dataValue) { if (!$dataValue->getProperty() instanceof DIProperty || !$dataValue->isValid()) { $processingErrorMsgHandler = new ProcessingErrorMsgHandler($this->getSubject()); $processingErrorMsgHandler->pushTo($this, $processingErrorMsgHandler->getErrorContainerFromDataValue($dataValue)); return $this->addError($dataValue->getErrors()); } $this->addPropertyObjectValue($dataValue->getProperty(), $dataValue->getDataItem()); }
private function getResultHtml() { $resultList = ''; if ($this->pageRequestOptions->propertyString === '' || !$this->pageRequestOptions->propertyString) { return array($this->messageBuilder->getMessage('smw_sbv_docu')->text(), '', 0); } // #1728 if (!$this->pageRequestOptions->property->isValid()) { return array(ProcessingErrorMsgHandler::getMessagesAsString($this->pageRequestOptions->property->getErrors()), '', 0); } if ($this->pageRequestOptions->valueString !== '' && !$this->pageRequestOptions->value->isValid()) { return array(ProcessingErrorMsgHandler::getMessagesAsString($this->pageRequestOptions->value->getErrors()), '', 0); } $exactResults = $this->queryResultLookup->doQuery($this->pageRequestOptions); $exactCount = count($exactResults); if ($this->canQueryNearbyResults($exactCount)) { return $this->getNearbyResults($exactResults, $exactCount); } if ($this->pageRequestOptions->valueString === '') { $resultMessageKey = 'smw-sp-searchbyproperty-nonvaluequery'; } else { $resultMessageKey = 'smw-sp-searchbyproperty-valuequery'; } $resultMessage = $this->messageBuilder->getMessage($resultMessageKey, $this->pageRequestOptions->property->getShortHTMLText($this->linker), $this->pageRequestOptions->value->getShortHTMLText($this->linker))->text(); if ($exactCount > 0) { $resultList = $this->makeResultList($exactResults, $this->pageRequestOptions->limit, true); } return array(str_replace('_', ' ', $resultMessage), $resultList, $exactCount); }
/** * Formats an array of message strings so that it appears as a tooltip. * $icon should be one of: 'warning' (default), 'info'. * * @param array $messages * @param string $icon Acts like an enum. Callers must ensure safety, since this value is used directly in the output. * @param string $seperator * @param boolean $escape Should the messages be escaped or not (ie when they already are) * * @return string */ function smwfEncodeMessages(array $messages, $type = 'warning', $seperator = ' <!--br-->', $escape = true) { $messages = ProcessingErrorMsgHandler::normalizeMessages($messages); if ($messages !== array()) { if ($escape) { $messages = array_map('htmlspecialchars', $messages); } if (count($messages) == 1) { $errorList = $messages[0]; } else { foreach ($messages as &$message) { $message = '<li>' . $message . '</li>'; } $errorList = '<ul>' . implode($seperator, $messages) . '</ul>'; } $errorList = str_replace(array('&', '<', '>', ' ', '<nowiki>', '</nowiki>', '['), array('&', '<', '>', ' ', '', '', '['), $errorList); // Type will be converted internally $highlighter = SMW\Highlighter::factory($type); $highlighter->setContent(array('caption' => null, 'content' => $errorList)); return $highlighter->getHtml(); } else { return ''; } }
/** * Adds an arbitrary array of messages which can either contain text * or/and Message objects * * @par Example: * @code * $msgFormatter = new MessageFormatter( $language ); * $msgFormatter->addFromArray( array( 'Foo', new Message( 'Bar' ) ) )->getHtml() * @endcode * * @since 1.9 * * @param array $messages * * @return MessageFormatter */ public function addFromArray(array $messages) { $messages = ProcessingErrorMsgHandler::normalizeMessages($messages); foreach ($messages as $message) { if (is_string($message)) { $this->messages[md5($message)] = $message; } else { $this->messages[] = $message; } } return $this; }
private function addProcessingError($errors) { $processingErrorMsgHandler = new ProcessingErrorMsgHandler($this->parserData->getSubject()); foreach ($errors as $error) { $processingErrorMsgHandler->pushTo($this->parserData->getSemanticData(), $processingErrorMsgHandler->getErrorContainerFromMsg($error, new DIProperty('_ASK'))); } }