/**
  * 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('[', '&#x005B;', $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);
 }
 /**
  * @dataProvider messagesProvider
  */
 public function testNormalizeMessages($messages, $expected)
 {
     $this->assertEquals($expected, ProcessingErrorMsgHandler::normalizeMessages($messages, null, 'en'));
     $this->assertInternalType('string', ProcessingErrorMsgHandler::getMessagesAsString($messages, null, 'en'));
 }
/**
 * 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('&amp;', '&lt;', '&gt;', '&#160;', '<nowiki>', '</nowiki>', '['), array('&', '<', '>', ' ', '', '', '&#x005B;'), $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;
 }