/**
 * 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, $icon = 'warning', $seperator = ' <!--br-->', $escape = true)
{
    if (count($messages) > 0) {
        SMWOutputs::requireResource('ext.smw.tooltips');
        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>';
        }
        return smwfContextHighlighter(array('context' => 'persitent', 'class' => 'smwtticon ' . htmlspecialchars($icon), 'type' => htmlspecialchars($icon), 'title' => null, 'content' => $errorList));
    } else {
        return '';
    }
}
 /**
  * Create special highlighting for hinting at special properties.
  */
 protected function highlightText($text)
 {
     if ($this->m_dataitem->isUserDefined()) {
         return $text;
     } else {
         return smwfContextHighlighter(array('context' => 'inline', 'class' => 'smwbuiltin', 'type' => 'property', 'title' => $text, 'content' => wfMessage('smw_isspecprop')->inContentLanguage()->text()));
     }
 }
 /**
  * Make a possibly shortened printout string for displaying the value.
  * The value must be specified as an input since necessary HTML escaping
  * must be applied to it first, if desired. The result of getAbbValue()
  * may contain wiki-compatible HTML mark-up that should not be escaped.
  * @todo The method abbreviates very long strings for display by simply
  * taking substrings. This is not in all cases a good idea, since it may
  * break XML entities and mark-up.
  */
 protected function getAbbValue($linked, $value)
 {
     $len = mb_strlen($value);
     if ($len > 255 && $this->m_typeid != '_cod') {
         if (is_null($linked) || $linked === false) {
             return mb_substr($value, 0, 42) . ' <span class="smwwarning">…</span> ' . mb_substr($value, $len - 42);
         } else {
             return mb_substr($value, 0, 42) . smwfContextHighlighter(array('context' => 'persistent', 'class' => 'smwtext', 'type' => 'string', 'title' => ' … ', 'content' => $value)) . mb_substr($value, $len - 42);
         }
     } elseif ($this->m_typeid == '_cod') {
         return $this->getCodeDisplay($value, true);
     } else {
         return $value;
     }
 }
Example #4
0
 /**
  * Make a possibly shortened printout string for displaying the value.
  * The result is only escaped to be HTML-safe if this is requested
  * explicitly. The result will contain mark-up that must not be escaped
  * again.
  *
  * @todo The method abbreviates very long strings for display by simply
  * taking substrings. This is not in all cases a good idea, since it may
  * break XML entities and mark-up.
  *
  * @since 1.8
  * @param string $value
  * @param boolean $abbreviate limit overall display length?
  * @param boolean $linked should abbreviated values use tooltips?
  * @param boolean $forHtml should the result be escaped to be HTML-safe?
  * @return string
  */
 protected function getTextDisplay($value, $abbreviate, $linked, $forHtml)
 {
     if ($forHtml) {
         $value = smwfXMLContentEncode($value);
     }
     $length = mb_strlen($value);
     if ($abbreviate && $length > 255) {
         if (!$linked) {
             $ellipsis = ' <span class="smwwarning">…</span> ';
         } else {
             $ellipsis = smwfContextHighlighter(array('context' => 'persistent', 'class' => 'smwtext', 'type' => 'string', 'title' => ' … ', 'content' => $value));
         }
         return mb_substr($value, 0, 42) . $ellipsis . mb_substr($value, $length - 42);
     } else {
         return $value;
     }
 }
Example #5
0
 public function getShortWikiText($linked = null)
 {
     if (is_null($linked) || $linked === false || $this->m_outformat == '-' || $this->m_outformat == '-u' || $this->m_outformat == '-n' || !$this->isValid()) {
         return $this->m_caption;
     } else {
         $this->makeConversionValues();
         $tooltip = '';
         $i = 0;
         $sep = '';
         foreach ($this->m_unitvalues as $unit => $value) {
             if ($unit != $this->m_unitin) {
                 $tooltip .= $sep . smwfNumberFormat($value);
                 if ($unit !== '') {
                     $tooltip .= '&#160;' . $unit;
                 }
                 $sep = ' <br />';
                 $i++;
                 if ($i >= 5) {
                     // limit number of printouts in tooltip
                     break;
                 }
             }
         }
         if ($tooltip !== '') {
             return smwfContextHighlighter(array('context' => 'inline', 'class' => 'smwtext', 'type' => 'quantity', 'title' => $this->m_caption, 'content' => $tooltip));
         } else {
             return $this->m_caption;
         }
     }
 }