00001 <?php
00018 class SMWImportValue extends SMWDataValue {
00019
00020 protected $m_qname = '';
00021 protected $m_uri = '';
00022 protected $m_namespace = '';
00023 protected $m_section = '';
00024 protected $m_name = '';
00025
00026 protected function parseUserValue( $value ) {
00027 global $wgContLang;
00028
00029 $this->m_qname = $value;
00030
00031 list( $onto_ns, $onto_section ) = explode( ':', $this->m_qname, 2 );
00032 $msglines = preg_split( "([\n][\s]?)", wfMsgForContent( "smw_import_$onto_ns" ) );
00033
00034 if ( count( $msglines ) < 2 ) {
00035 $this->addError( wfMsgForContent( 'smw_unknown_importns', $onto_ns ) );
00036 $this->m_dataitem = new SMWDIString( 'ERROR' );
00037 return;
00038 }
00039
00040
00041 list( $onto_uri, $onto_name ) = explode( '|', array_shift( $msglines ), 2 );
00042 if ( $onto_uri[0] == ' ' ) $onto_uri = mb_substr( $onto_uri, 1 );
00043
00044 $this->m_uri = $onto_uri;
00045 $this->m_namespace = $onto_ns;
00046 $this->m_section = $onto_section;
00047 $this->m_name = $onto_name;
00048
00049 foreach ( $msglines as $msgline ) {
00050 list( $secname, $typestring ) = explode( '|', $msgline, 2 );
00051 if ( $secname === $onto_section ) {
00052 list( $namespace, ) = explode( ':', $typestring, 2 );
00053
00054 switch ( $namespace ) {
00055 case $wgContLang->getNsText( SMW_NS_TYPE ):
00056 $elemtype = SMW_NS_PROPERTY;
00057 break;
00058 case $wgContLang->getNsText( SMW_NS_PROPERTY ):
00059 $elemtype = SMW_NS_PROPERTY;
00060 break;
00061 case $wgContLang->getNsText( NS_CATEGORY ):
00062 $elemtype = NS_CATEGORY;
00063 break;
00064 case $wgContLang->getNsText( SMW_NS_CONCEPT ):
00065 $elemtype = NS_CATEGORY;
00066 break;
00067 default:
00068 $elemtype = NS_MAIN;
00069 }
00070 break;
00071 }
00072 }
00073
00074
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 try {
00101 $this->m_dataitem = new SMWDIString( $this->m_namespace . ' ' . $this->m_section . ' ' . $this->m_uri );
00102 } catch ( SMWStringLengthException $e ) {
00103 $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $this->m_namespace . ' ' . $this->m_section . ' ' . $this->m_uri . '"' ) );
00104 $this->m_dataitem = new SMWDIString( 'ERROR' );
00105 }
00106
00107
00108 if ( $this->m_caption === false ) {
00109 $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")";
00110 }
00111 }
00112
00118 protected function loadDataItem( SMWDataItem $dataItem ) {
00119 if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
00120 $this->m_dataitem = $dataItem;
00121 $parts = explode( ' ', $dataItem->getString(), 3 );
00122 if ( count( $parts ) != 3 ) {
00123 $this->addError( wfMsgForContent( 'smw_parseerror' ) );
00124 } else {
00125 $this->m_namespace = $parts[0];
00126 $this->m_section = $parts[1];
00127 $this->m_uri = $parts[2];
00128 $this->m_qname = $this->m_namespace . ':' . $this->m_section;
00129 $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")";
00130 }
00131 return true;
00132 } else {
00133 return false;
00134 }
00135 }
00136
00137 public function getShortWikiText( $linked = null ) {
00138 return $this->m_caption;
00139 }
00140
00141 public function getShortHTMLText( $linker = null ) {
00142 return htmlspecialchars( $this->m_qname );
00143 }
00144
00145 public function getLongWikiText( $linked = null ) {
00146 if ( !$this->isValid() ) {
00147 return $this->getErrorText();
00148 } else {
00149 return "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")";
00150 }
00151 }
00152
00153 public function getLongHTMLText( $linker = null ) {
00154 if ( !$this->isValid() ) {
00155 return $this->getErrorText();
00156 } else {
00157 return htmlspecialchars( $this->m_qname );
00158 }
00159 }
00160
00161 public function getWikiValue() {
00162 return $this->m_qname;
00163 }
00164
00165 public function getNS() {
00166 return $this->m_uri;
00167 }
00168
00169 public function getNSID() {
00170 return $this->m_namespace;
00171 }
00172
00173 public function getLocalName() {
00174 return $this->m_section;
00175 }
00176 }