00001 <?php
00035 class SMWPropertyValue extends SMWDataValue {
00036
00042 protected $m_wikipage = null;
00043
00048 private $mPropTypeValue;
00049
00061 static public function makeUserProperty( $propertyName ) {
00062 $property = new SMWPropertyValue( '__pro' );
00063 $property->setUserValue( $propertyName );
00064 return $property;
00065 }
00066
00079 static public function makeProperty( $propertyid ) {
00080 $diProperty = new SMWDIProperty( $propertyid );
00081 $dvProperty = new SMWPropertyValue( '__pro' );
00082 $dvProperty->setDataItem( $diProperty );
00083 return $dvProperty;
00084 }
00085
00091 public function __clone() {
00092 if ( !is_null( $this->m_wikipage ) ) $this->m_wikipage = clone $this->m_wikipage;
00093 }
00094
00100 protected function parseUserValue( $value ) {
00101 $this->mPropTypeValue = null;
00102 $this->m_wikipage = null;
00103
00104 if ( $this->m_caption === false ) {
00105 $this->m_caption = $value;
00106 }
00107 $propertyName = smwfNormalTitleText( ltrim( rtrim( $value, ' ]' ), ' [' ) );
00108 $inverse = false;
00109 if ( ( $propertyName !== '' ) && ( $propertyName { 0 } == '-' ) ) {
00110 $propertyName = (string)substr( $value, 1 );
00112 $inverse = true;
00113 }
00114
00115 try {
00116 $this->m_dataitem = SMWDIProperty::newFromUserLabel( $propertyName, $inverse, $this->m_typeid );
00117 } catch ( SMWDataItemException $e ) {
00118 $this->addError( wfMsgForContent( 'smw_noproperty', $value ) );
00119 $this->m_dataitem = new SMWDIProperty( 'ERROR', false );
00120 }
00121 }
00122
00128 protected function loadDataItem( SMWDataItem $dataItem ) {
00129 if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) {
00130 $this->m_dataitem = $dataItem;
00131 $this->mPropTypeValue = null;
00132 unset( $this->m_wikipage );
00133 $this->m_caption = false;
00134 return true;
00135 } else {
00136 return false;
00137 }
00138 }
00139
00140 public function setCaption( $caption ) {
00141 parent::setCaption( $caption );
00142 if ( $this->getWikiPageValue() instanceof SMWDataValue ) {
00143 $this->m_wikipage->setCaption( $caption );
00144 }
00145 }
00146
00147 public function setOutputFormat( $formatstring ) {
00148 $this->m_outformat = $formatstring;
00149 if ( $this->m_wikipage instanceof SMWDataValue ) {
00150 $this->m_wikipage->setOutputFormat( $formatstring );
00151 }
00152 }
00153
00154 public function setInverse( $isinverse ) {
00155 return $this->m_dataitem = new SMWDIProperty( $this->m_dataitem->getKey(), ( $isinverse == true ) );
00156 }
00157
00164 public function getWikiPageValue() {
00165 if ( !isset( $this->m_wikipage ) ) {
00166 $diWikiPage = $this->m_dataitem->getDiWikiPage();
00167 if ( !is_null( $diWikiPage ) ) {
00168 $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, null, $this->m_caption );
00169 $this->m_wikipage->setOutputFormat( $this->m_outformat );
00170 $this->addError( $this->m_wikipage->getErrors() );
00171 } else {
00172 $this->m_wikipage = null;
00173 }
00174 }
00175 return $this->m_wikipage;
00176 }
00177
00183 public function isVisible() {
00184 return $this->isValid() && ( $this->m_dataitem->isUserDefined() || $this->m_dataitem->getLabel() !== '' );
00185 }
00186
00187 public function getShortWikiText( $linked = null ) {
00188 if ( $this->isVisible() ) {
00189 $wikiPageValue = $this->getWikiPageValue();
00190 return is_null( $wikiPageValue ) ? '' : $this->highlightText( $wikiPageValue->getShortWikiText( $linked ) );
00191 } else {
00192 return '';
00193 }
00194 }
00195
00196 public function getShortHTMLText( $linked = null ) {
00197 if ( $this->isVisible() ) {
00198 $wikiPageValue = $this->getWikiPageValue();
00199 return is_null( $wikiPageValue ) ? '' : $this->highlightText( $wikiPageValue->getShortHTMLText( $linked ) );
00200 } else {
00201 return '';
00202 }
00203 }
00204
00205 public function getLongWikiText( $linked = null ) {
00206 if ( $this->isVisible() ) {
00207 $wikiPageValue = $this->getWikiPageValue();
00208 return is_null( $wikiPageValue ) ? '' : $this->highlightText( $wikiPageValue->getLongWikiText( $linked ) );
00209 } else {
00210 return '';
00211 }
00212 }
00213
00214 public function getLongHTMLText( $linked = null ) {
00215 if ( $this->isVisible() ) {
00216 $wikiPageValue = $this->getWikiPageValue();
00217 return is_null( $wikiPageValue ) ? '' : $this->highlightText( $wikiPageValue->getLongHTMLText( $linked ) );
00218 } else {
00219 return '';
00220 }
00221 }
00222
00223 public function getWikiValue() {
00224 return $this->isVisible() ? ( ( $this->isInverse() ? '-' : '' ) . $this->m_dataitem->getLabel() ) : '';
00225 }
00226
00231 public function getPropertyID() {
00232 return $this->m_dataitem->isUserDefined() ? false : $this->m_dataitem->getKey();
00233 }
00234
00240 public function getTypesValue() {
00241 $result = SMWTypesValue::newFromTypeId( $this->getPropertyTypeID() );
00242 if ( !$this->isValid() ) {
00243 $result->addError( $this->getErrors() );
00244 }
00245 return $result;
00246 }
00247
00256 public function getPropertyTypeID() {
00257 if ( $this->isValid() ) {
00258 return $this->m_dataitem->findPropertyTypeId();
00259 } else {
00260 return '__err';
00261 }
00262 }
00263
00267 protected function highlightText( $text ) {
00268 if ( $this->m_dataitem->isUserDefined() ) {
00269 return $text;
00270 } else {
00271 SMWOutputs::requireResource( 'ext.smw.tooltips' );
00272 return '<span class="smwttinline"><span class="smwbuiltin">' . $text .
00273 '</span><span class="smwttcontent">' . wfMsgForContent( 'smw_isspecprop' ) . '</span></span>';
00274 }
00275 }
00276
00284 static public function registerProperty( $id, $typeid, $label = false, $show = false ) {
00285 SMWDIProperty::registerProperty( $id, $typeid, $label, $show );
00286 }
00287
00295 static public function registerPropertyAlias( $id, $label ) {
00296 SMWDIProperty::registerPropertyAlias( $id, $label );
00297 }
00298
00304 public function isUserDefined() {
00305 return $this->m_dataitem->isUserDefined();
00306 }
00307
00313 public function isShown() {
00314 return $this->m_dataitem->isShown();
00315 }
00316
00322 public function isInverse() {
00323 return $this->m_dataitem->isInverse();
00324 }
00325
00334 public function getDBkey() {
00335 return $this->m_dataitem->getKey();
00336 }
00337
00343 public function getText() {
00344 return $this->m_dataitem->getLabel();
00345 }
00346
00347 }