/** * This method transforms the user-provided value of an * attribute into several output strings (one for XML, * one for printout, etc.) and reports parsing errors if * the value is not valid for the given data type. * * @access public */ public function parseUserValue($value) { if ($value == '') { //do not accept empty strings $this->addError(wfMsgForContent('smw_emptystring')); return true; } $this->m_xsdValue = smwfXMLContentEncode($value); // 255 below matches smw_attributes.value_xsd definition in smwfMakeSemanticTables() // Note that depending on database encoding and UTF-8 settings, longer or // shorter strings than this with int'l characters may exceed database field. if (strlen($this->m_xsdValue) > 255) { $this->addError(wfMsgForContent('smw_maxstring', $this->m_xsdValue)); } else { $res = $this->parseSIValueAndUnit($value); if ($res[SMW_DT_SI_ERR] != '') { // an error was detected $this->addError($value . ' (' . $res[SMW_DT_SI_ERR] . ')'); } else { $this->m_html = $this->createSIUnit($res, true); if ($this->m_caption === false) { $this->m_caption = $this->m_html; } $this->m_wikitext = $value; } } return true; }
protected function parseUserValue($value) { $value = trim($value); if ($value == '') { //do not accept empty strings $this->addError(wfMsgForContent('smw_emptystring')); } else { $this->m_xsdValue = smwfXMLContentEncode($value); $this->m_html = $value; if ($this->m_caption === false) { $this->m_caption = $this->m_html; } $this->m_wikitext = $value; } return true; }
protected function parseUserValue($value) { $value = trim($value); if ($value == '') { //do not accept empty strings $this->addError(wfMsgForContent('smw_emptystring')); } else { $parser = new ChemEqParser(); if ($parser->checkFormula($value) === true) { $this->m_xsdValue = smwfXMLContentEncode($parser->getWikiFormat()); $this->m_html = $parser->getHtmlFormat(); if ($this->m_caption === false) { $this->m_caption = $this->m_html; } $this->m_wikitext = $value; } else { $this->addError($value . ":" . $parser->getError() . "<br>"); } if ($this->m_caption === false) { $this->m_caption = $value; } } return true; }
protected function doFormatFinalOutputFor($type, $linker) { $text = $this->dataValue->getDataItem()->getString(); $length = mb_strlen($text); // 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. $abbreviate = $type === self::WIKI_LONG || $type === self::HTML_LONG; $requestedLength = intval($this->dataValue->getOutputFormat()); // Appease the MW parser to correctly apply formatting on the // first indent if ($text !== '' && ($text[0] === '*' || $text[0] === '#' || $text[0] === ':')) { $text = "\n" . $text . "\n"; } if ($requestedLength > 0 && $requestedLength < $length) { // Reduces the length and finish it with a whole word return Normalizer::reduceLengthTo($text, $requestedLength) . ' …'; } if ($type === self::HTML_SHORT || $type === self::HTML_LONG) { $text = smwfXMLContentEncode($text); } return $abbreviate && $length > 255 ? $this->getAbbreviatedText($text, $length, $linker) : $text; }
/** * 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; } }
/** * Method to create a dataitem from an array of DB keys. * * @param $dbkeys array of mixed * * @return SMWDataItem */ public function dataItemFromDBKeys($dbkeys) { if (count($dbkeys) == 5) { return new SMWDIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]); } else { throw new SMWDataItemException('Failed to create data item from DB keys.'); } }
/** * @todo Rather parse input to obtain properly formatted HTML. */ public function getLongHTMLText($linker = null) { return $this->isValid() ? $this->getAbbValue($linker, smwfXMLContentEncode($this->m_dataitem->getString())) : $this->getErrorText(); }
/** * Transform a (typically unit-) string into a normalised form, * so that, e.g., "km²" and "km<sup>2</sup>" do not need to be * distinguished. */ protected static function normalizeUnit($unit) { $unit = str_replace(array('[[', ']]'), '', trim($unit)); // allow simple links to be used inside annotations $unit = str_replace(array('²', '<sup>2</sup>'), '²', $unit); $unit = str_replace(array('³', '<sup>3</sup>'), '³', $unit); return smwfXMLContentEncode($unit); }
/** * @since 1.8 * * {@inheritDoc} */ public function dataItemFromDBKeys($dbkeys) { if (is_array($dbkeys) && count($dbkeys) == 5) { return new DIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]); } throw new DataItemHandlerException('Failed to create data item from DB keys.'); }
/** * 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; } }
/** * Method to create a dataitem from a type ID and array of DB keys. * Throws SMWDataItemException if problems occur, to get our callers * used to it. * * @param $typeid string id for the given type * @param $dbkeys array of mixed * * @return SMWDataItem */ public static function dataItemFromDBKeys($typeid, $dbkeys) { switch (SMWDataValueFactory::getDataItemId($typeid)) { case SMWDataItem::TYPE_ERROR: case SMWDataItem::TYPE_NOTYPE: break; case SMWDataItem::TYPE_NUMBER: return SMWDINumber::doUnserialize($dbkeys[0]); case SMWDataItem::TYPE_STRING: return new SMWDIString($dbkeys[0]); case SMWDataItem::TYPE_BLOB: return new SMWDIBlob($dbkeys[0]); case SMWDataItem::TYPE_BOOLEAN: return new SMWDIBoolean($dbkeys[0] == '1'); case SMWDataItem::TYPE_URI: if ($typeid == '__typ' && $dbkeys[0][0] == '_') { // b/c: old data stored as type ids return SMWTypesValue::getTypeUriFromTypeId($dbkeys[0]); } else { return SMWDIUri::doUnserialize($dbkeys[0]); } case SMWDataItem::TYPE_TIME: $timedate = explode('T', $dbkeys[0], 2); if (count($dbkeys) == 2 && count($timedate) == 2) { $date = reset($timedate); $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false; if (end($timedate) === '' || SMWTimeValue::parseTimeString(end($timedate), $hours, $minutes, $seconds, $timeoffset) == true) { $d = explode('/', $date, 3); if (count($d) == 3) { list($year, $month, $day) = $d; } elseif (count($d) == 2) { list($year, $month) = $d; } elseif (count($d) == 1) { list($year) = $d; } if ($month === '') { $month = false; } if ($day === '') { $day = false; } $calendarmodel = SMWDITime::CM_GREGORIAN; return new SMWDITime($calendarmodel, $year, $month, $day, $hours, $minutes, $seconds); } } break; case SMWDataItem::TYPE_GEO: return new SMWDIGeoCoord(array('lat' => (double) $dbkeys[0], 'lon' => (double) $dbkeys[1])); case SMWDataItem::TYPE_CONTAINER: // provided for backwards compatibility only; // today containers are read from the store as substructures, // not retrieved as single complex values $semanticData = SMWContainerSemanticData::makeAnonymousContainer(); foreach (reset($dbkeys) as $value) { if (is_array($value) && count($value) == 2) { $diP = new SMWDIProperty(reset($value), false); $diV = self::dataItemFromDBKeys($diP->findPropertyTypeID(), end($value)); $semanticData->addPropertyObjectValue($diP, $diV); } } return new SMWDIContainer($semanticData); case SMWDataItem::TYPE_WIKIPAGE: if ($typeid == '__spf') { $pagedbkey = str_replace(' ', '_', $dbkeys[0]); return new SMWDIWikiPage($pagedbkey, SF_NS_FORM, ''); } elseif (count($dbkeys) >= 5) { // with subobject name (and sortkey) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2], $dbkeys[4]); } elseif (count($dbkeys) >= 3) { // without subobject name (just for b/c) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2]); } break; case SMWDataItem::TYPE_CONCEPT: if (count($dbkeys) >= 5) { return new SMWDIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]); } break; case SMWDataItem::TYPE_PROPERTY: return new SMWDIProperty($dbkeys[0], false); } throw new SMWDataItemException('Failed to create data item from DB keys.'); }
/** * Creates the RSS output for the single item. */ public function text() { global $wgServer, $wgParser, $smwgShowFactbox, $smwgRSSWithPages; static $parser_options = null; $smwgShowFactbox = SMW_FACTBOX_HIDDEN; // just hide factbox; no need to restore this setting, I hope that nothing comes after FILE outputs $text = "\t<item rdf:about=\"{$this->uri}\">\n"; $text .= "\t\t<title>" . smwfXMLContentEncode($this->label) . "</title>\n"; $text .= "\t\t<link>" . smwfXMLContentEncode($this->uri) . "</link>\n"; foreach ($this->date as $date) { $text .= "\t\t<dc:date>{$date}</dc:date>\n"; } foreach ($this->creator as $creator) { $text .= "\t\t<dc:creator>" . smwfXMLContentEncode($creator) . "</dc:creator>\n"; } if ($smwgRSSWithPages) { $parser_options = new ParserOptions(); $parser_options->setEditSection(false); // embedded sections should not have edit links $parserOutput = $wgParser->parse('{{' . $this->articlename . '}}', $this->title, $parser_options); $content = $parserOutput->getText(); // Make absolute URLs out of the local ones: ///TODO is there maybe a way in the parser options to make the URLs absolute? $content = str_replace('<a href="/', '<a href="' . $wgServer . '/', $content); $text .= "\t\t<description>" . smwfXMLContentEncode($content) . "</description>\n"; $text .= "\t\t<content:encoded rdf:datatype=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral\"><![CDATA[{$content}]]></content:encoded>\n"; } $text .= "\t</item>\n"; return $text; }