00001 <?php
00019 class SMWTypesValue extends SMWDataValue {
00020 protected $m_isAlias;
00021 protected $m_realLabel;
00022 protected $m_givenLabel;
00023 protected $m_typeId;
00024
00025 public static function newFromTypeId( $typeId ) {
00026 $result = new SMWTypesValue( '__typ' );
00027 try {
00028 $dataItem = self::getTypeUriFromTypeId( $typeId );
00029 } catch ( SMWDataItemException $e ) {
00030 $dataItem = self::getTypeUriFromTypeId( 'notype' );
00031 }
00032 $result->setDataItem( $dataItem );
00033 return $result;
00034 }
00035
00036 public static function getTypeUriFromTypeId( $typeId ) {
00037 return new SMWDIUri( 'http', 'semantic-mediawiki.org/swivt/1.0', '', $typeId );
00038 }
00039
00040 protected function parseUserValue( $value ) {
00041 global $wgContLang;
00042
00043 if ( $this->m_caption === false ) {
00044 $this->m_caption = $value;
00045 }
00046
00047 $valueParts = explode( ':', $value, 2 );
00048 if ( count( $valueParts ) > 1 ) {
00049 $namespace = smwfNormalTitleText( $valueParts[0] );
00050 $value = $valueParts[1];
00051 $typeNamespace = $wgContLang->getNsText( SMW_NS_TYPE );
00052 if ( $namespace != $typeNamespace ) {
00053 $this->addError( wfMsgForContent( 'smw_wrong_namespace', $typeNamespace ) );
00054 }
00055 }
00056
00057 $this->m_givenLabel = smwfNormalTitleText( $value );
00058 $this->m_typeId = SMWDataValueFactory::findTypeID( $this->m_givenLabel );
00059 if ( $this->m_typeId === '' ) {
00060 $this->addError( wfMsgForContent( 'smw_unknowntype', $this->m_givenLabel ) );
00061 $this->m_realLabel = $this->m_givenLabel;
00062 } else {
00063 $this->m_realLabel = SMWDataValueFactory::findTypeLabel( $this->m_typeId );
00064 }
00065 $this->m_isAlias = ( $this->m_realLabel === $this->m_givenLabel ) ? false : true;
00066
00067 try {
00068 $this->m_dataitem = self::getTypeUriFromTypeId( $this->m_typeId );
00069 } catch ( SMWDataItemException $e ) {
00070 $this->m_dataitem = self::getTypeUriFromTypeId( 'notype' );
00071 $this->addError( wfMsgForContent( 'smw_parseerror' ) );
00072 }
00073 }
00074
00080 protected function loadDataItem( SMWDataItem $dataItem ) {
00081 if ( ( $dataItem instanceof SMWDIUri ) && ( $dataItem->getScheme() == 'http' ) &&
00082 ( $dataItem->getHierpart() == 'semantic-mediawiki.org/swivt/1.0' ) &&
00083 ( $dataItem->getQuery() === '' ) ) {
00084 $this->m_isAlias = false;
00085 $this->m_typeId = $dataItem->getFragment();
00086 $this->m_realLabel = SMWDataValueFactory::findTypeLabel( $this->m_typeId );
00087 $this->m_caption = $this->m_givenLabel = $this->m_realLabel;
00088 $this->m_dataitem = $dataItem;
00089 return true;
00090 } else {
00091 return false;
00092 }
00093 }
00094
00095 public function getShortWikiText( $linker = null ) {
00096 global $wgContLang;
00097 if ( !$linker || $this->m_outformat === '-' || $this->m_caption === '' ) {
00098 return $this->m_caption;
00099 } else {
00100 $titleText = $this->getSpecialPageTitleText();
00101 $namespace = $wgContLang->getNsText( NS_SPECIAL );
00102 return "[[$namespace:$titleText|{$this->m_caption}]]";
00103 }
00104 }
00105
00106 public function getShortHTMLText( $linker = null ) {
00107 if ( !$linker || $this->m_outformat === '-' || $this->m_caption === '' ) {
00108 return htmlspecialchars( $this->m_caption );
00109 } else {
00110 $title = Title::makeTitle( NS_SPECIAL, $this->getSpecialPageTitleText() );
00111 return $linker->link( $title, htmlspecialchars( $this->m_caption ) );
00112 }
00113 }
00114
00115 public function getLongWikiText( $linker = null ) {
00116 global $wgContLang;
00117 if ( !$linker || $this->m_realLabel === '' ) {
00118 return $this->m_realLabel;
00119 } else {
00120 $titleText = $this->getSpecialPageTitleText();
00121 $namespace = $wgContLang->getNsText( NS_SPECIAL );
00122 return "[[$namespace:$titleText|{$this->m_realLabel}]]";
00123 }
00124 }
00125
00126 public function getLongHTMLText( $linker = null ) {
00127 if ( !$linker || $this->m_realLabel === '' ) {
00128 return htmlspecialchars( $this->m_realLabel );
00129 } else {
00130 $title = Title::makeTitle( NS_SPECIAL, $this->getSpecialPageTitleText() );
00131 return $linker->link( $title, htmlspecialchars( $this->m_realLabel ) );
00132 }
00133 }
00134
00145 protected function getSpecialPageTitleText() {
00146 return is_callable( array( 'SpecialPageFactory', 'getLocalNameFor' ) ) ?
00147 SpecialPageFactory::getLocalNameFor( 'Types', $this->m_realLabel )
00148 : SpecialPage::getLocalNameFor( 'Types', $this->m_realLabel );
00149 }
00150
00151 public function getWikiValue() {
00152 return $this->m_realLabel;
00153 }
00154
00155 public function getHash() {
00156 return $this->m_realLabel;
00157 }
00158
00164 public function getDBkey() {
00165 return ( $this->isValid() ) ? SMWDataValueFactory::findTypeID( $this->m_realLabel ) : '';
00166 }
00167
00174 public function isBuiltIn() {
00175 return true;
00176 }
00177
00184 public function isAlias() {
00185 return $this->m_isAlias;
00186 }
00187
00188 }
00189