Esempio n. 1
0
 /**
  * Create special highlighting for hinting at special properties.
  */
 protected function highlightText($text)
 {
     if ($this->m_dataitem->isUserDefined()) {
         return $text;
     } else {
         $highlighter = SMW\Highlighter::factory(SMW\Highlighter::TYPE_PROPERTY);
         $highlighter->setContent(array('caption' => $text, 'content' => wfMessage('smw_isspecprop')->text()));
         return $highlighter->getHtml();
     }
 }
 /**
  * Create special highlighting for hinting at special properties.
  */
 protected function highlightText($text, $linker = null)
 {
     if (!$this->m_dataitem->isUserDefined()) {
         $msgKey = 'smw-pa-property-predefined' . strtolower($this->m_dataitem->getKey());
         $content = '';
         if (wfMessage($msgKey)->exists()) {
             $content = $linker === null ? wfMessage($msgKey, $this->getText())->escaped() : wfMessage($msgKey, $this->getText())->parse();
         }
         $highlighter = SMW\Highlighter::factory(SMW\Highlighter::TYPE_PROPERTY);
         $highlighter->setContent(array('caption' => $text, 'content' => $content !== '' ? $content : wfMessage('smw_isspecprop')->text()));
         return $highlighter->getHtml();
     }
     return $text;
 }
Esempio n. 3
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 . NumberFormatter::getInstance()->formatNumberToLocalizedText($value);
                 if ($unit !== '') {
                     $tooltip .= ' ' . $unit;
                 }
                 $sep = ' <br />';
                 $i++;
                 if ($i >= 5) {
                     // limit number of printouts in tooltip
                     break;
                 }
             }
         }
         if ($tooltip !== '') {
             $highlighter = SMW\Highlighter::factory(SMW\Highlighter::TYPE_QUANTITY);
             $highlighter->setContent(array('caption' => $this->m_caption, 'content' => $tooltip));
             return $highlighter->getHtml();
         } else {
             return $this->m_caption;
         }
     }
 }
/**
 * 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)
{
    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>';
        }
        // Type will be converted internally
        $highlighter = SMW\Highlighter::factory($type);
        $highlighter->setContent(array('caption' => null, 'content' => $errorList));
        return $highlighter->getHtml();
    } else {
        return '';
    }
}
/**
 * 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 '';
    }
}
 /**
  * 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 {
             $highlighter = SMW\Highlighter::factory(SMW\Highlighter::TYPE_TEXT);
             $highlighter->setContent(array('caption' => ' … ', 'content' => $value));
             $ellipsis = $highlighter->getHtml();
         }
         return mb_substr($value, 0, 42) . $ellipsis . mb_substr($value, $length - 42);
     } else {
         return $value;
     }
 }