00001 <?php
00015 class SMWStringValue extends SMWDataValue {
00016
00017 protected function parseUserValue( $value ) {
00018 if ( $this->m_caption === false ) {
00019 $this->m_caption = ( $this->m_typeid == '_cod' ) ? $this->getCodeDisplay( $value ) : $value;
00020 }
00021 if ( $value === '' ) {
00022 $this->addError( wfMsgForContent( 'smw_emptystring' ) );
00023 }
00024
00025 if ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) {
00026 $this->m_dataitem = new SMWDIBlob( $value, $this->m_typeid );
00027 } else {
00028 try {
00029 $this->m_dataitem = new SMWDIString( $value, $this->m_typeid );
00030 } catch ( SMWStringLengthException $e ) {
00031 $this->addError( wfMsgForContent( 'smw_maxstring', '"' . mb_substr( $value, 0, 15 ) . ' … ' . mb_substr( $value, mb_strlen( $value ) - 15 ) . '"' ) );
00032 $this->m_dataitem = new SMWDIBlob( 'ERROR', $this->m_typeid );
00033 }
00034 }
00035 }
00036
00042 protected function loadDataItem( SMWDataItem $dataItem ) {
00043 $diType = ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING;
00044 if ( $dataItem->getDIType() == $diType ) {
00045 $this->m_dataitem = $dataItem;
00046 if ( $this->m_typeid == '_cod' ) {
00047 $this->m_caption = $this->getCodeDisplay( $this->m_dataitem->getString() );
00048 } else {
00049 $this->m_caption = $this->m_dataitem->getString();
00050 }
00051 return true;
00052 } else {
00053 return false;
00054 }
00055 }
00056
00057 public function getShortWikiText( $linked = null ) {
00058 return $this->m_caption;
00059 }
00060
00064 public function getShortHTMLText( $linker = null ) {
00065 return smwfXMLContentEncode( $this->getShortWikiText( $linker ) );
00066 }
00067
00068 public function getLongWikiText( $linked = null ) {
00069 return $this->isValid() ? $this->getAbbValue( $linked, $this->m_dataitem->getString() ) : $this->getErrorText();
00070 }
00071
00075 public function getLongHTMLText( $linker = null ) {
00076 return $this->isValid() ? $this->getAbbValue( $linker, smwfXMLContentEncode( $this->m_dataitem->getString() ) ) : $this->getErrorText();
00077 }
00078
00079 public function getWikiValue() {
00080 return $this->m_dataitem->getString();
00081 }
00082
00083 public function getInfolinks() {
00084 if ( ( $this->m_typeid != '_txt' ) && ( $this->m_typeid != '_cod' ) ) {
00085 return parent::getInfolinks();
00086 } else {
00087 return $this->m_infolinks;
00088 }
00089 }
00090
00091 protected function getServiceLinkParams() {
00092
00093
00094
00095 if ( ( $this->m_typeid != '_txt' ) && ( $this->m_typeid != '_cod' ) ) {
00096 return array( rawurlencode( $this->m_dataitem->getString() ) );
00097 } else {
00098 return false;
00099 }
00100 }
00101
00111 protected function getAbbValue( $linked, $value ) {
00112 $len = mb_strlen( $value );
00113 if ( ( $len > 255 ) && ( $this->m_typeid != '_cod' ) ) {
00114 if ( is_null( $linked ) || ( $linked === false ) ) {
00115 return mb_substr( $value, 0, 42 ) . ' <span class="smwwarning">…</span> ' . mb_substr( $value, $len - 42 );
00116 } else {
00117 SMWOutputs::requireResource( 'ext.smw.tooltips' );
00118 return mb_substr( $value, 0, 42 ) . ' <span class="smwttpersist"> … <span class="smwttcontent">' . $value . '</span></span> ' . mb_substr( $value, $len - 42 );
00119 }
00120 } elseif ( $this->m_typeid == '_cod' ) {
00121 return $this->getCodeDisplay( $value, true );
00122 } else {
00123 return $value;
00124 }
00125 }
00126
00130 protected function getCodeDisplay( $value, $scroll = false ) {
00131 SMWOutputs::requireResource( 'ext.smw.style' );
00132 $result = str_replace( array( '<', '>', ' ', '=', "'", ':', "\n" ), array( '<', '>', ' ', '=', ''', ':', "<br />" ), $value );
00133 if ( $scroll ) {
00134 $result = "<div style=\"height:5em; overflow:auto;\">$result</div>";
00135 }
00136 return "<div class=\"smwpre\">$result</div>";
00137 }
00138
00139 }