r89217 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89216‎ | r89217 | r89218 >
Date:14:58, 31 May 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
fixed outdated type-related methods in DVProperty, and their use on Special:Properties
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -54,16 +54,15 @@
5555 function formatResult( $skin, $result ) {
5656 $typestring = '';
5757 $errors = array();
 58+
5859 $diWikiPage = $result[0]->getDiWikiPage();
59 - if ( $diWikiPage !== null ) {
60 - $title = Title::makeTitle( $diWikiPage->getNamespace(), $diWikiPage->getDBkey() );
61 - } else {
62 - $title = null;
63 - }
 60+ $title = $diWikiPage !== null ? $diWikiPage->getTitle() : null;
 61+
6462 if ( $result[0]->isUserDefined() && ( $result[1] <= 5 ) ) {
6563 $errors[] = wfMsg( 'smw_propertyhardlyused' );
6664 }
67 - if ( $result[0]->isUserDefined() && ( $title !== null ) && $title->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood
 65+
 66+ if ( $result[0]->isUserDefined() && $title !== null && $title->exists() ) {
6867 $typeProperty = new SMWDIProperty( '_TYPE' );
6968 $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty );
7069 if ( count( $types ) >= 1 ) {
@@ -71,27 +70,28 @@
7271 $typestring = $typeDataValue->getLongHTMLText( $skin );
7372 }
7473 $proplink = $skin->makeKnownLinkObj( $title, $result[0]->getLabel() );
75 - } elseif ( $result[0]->isUserDefined() && ( $title !== null ) ) {
 74+ } elseif ( $result[0]->isUserDefined() && $title !== null ) {
7675 $errors[] = wfMsg( 'smw_propertylackspage' );
7776 $proplink = $skin->makeBrokenLinkObj( $title, $result[0]->getLabel(), 'action=view' );
7877 } else { // predefined property
79 - $type = $result[0]->getTypesValue();
80 - $typestring = $type->getLongHTMLText( $skin );
 78+ $typeid = $result[0]->findPropertyTypeID();
 79+ $typeDataValue = SMWTypesValue::newFromTypeId( $typeid );
 80+ $propertyDataValue = SMWDataValueFactory::newDataItemValue( $result[0], null );
 81+ $typestring = $typeDataValue->getLongHTMLText( $skin );
8182 if ( $typestring == '' ) $typestring = '–'; /// FIXME some types of builtin props have no name, and another message should be used then
82 - $proplink = $result[0]->getLongHTMLText( $skin );
 83+ $proplink = $propertyDataValue->getLongHTMLText( $skin );
8384 }
 85+
8486 if ( $typestring == '' ) {
8587 global $smwgPDefaultType;
86 - $typepagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $smwgPDefaultType ) );
87 - $diTypePage = new SMWDIWikiPage( $typepagedbkey, SMW_NS_TYPE, '', '__typ' );
88 - $dvTypePage = SMWDataValueFactory::newTypeIdValue( '__typ' );
89 - $dvTypePage->setDataItem( $diTypePage );
90 - $typestring = $dvTypePage->getLongHTMLText( $skin );
91 - if ( ( $title !== null ) && ( $title->exists() ) ) { // print only when we did not print a "nopage" warning yet
 88+ $typeDataValue = SMWTypesValue::newFromTypeId( $smwgPDefaultType );
 89+ $typestring = $typeDataValue->getLongHTMLText( $skin );
 90+ if ( $title !== null && $title->exists() ) { // print only when we did not print a "nopage" warning yet
9291 $errors[] = wfMsg( 'smw_propertylackstype', $typestring );
9392 }
9493 }
95 - return wfMsg( 'smw_property_template', $proplink, $typestring, $result[1] ) . ' ' . smwfEncodeMessages( $errors );
 94+
 95+ return wfMsg( 'smw_property_template', $proplink, $typestring, $result[1] ) . ' ' . smwfEncodeMessages( $errors, 'warning', ' <!--br-->', false );
9696 }
9797
9898 function getResults( $requestoptions ) {
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
@@ -46,12 +46,6 @@
4747 * @var SMWTypesValue
4848 */
4949 private $mPropTypeValue;
50 -
51 - /**
52 - * Cache for type ID of this property, or '' if not calculated yet.
53 - * @var string
54 - */
55 - private $mPropTypeId;
5650
5751 /**
5852 * Static function for creating a new property object from a
@@ -105,7 +99,6 @@
106100 */
107101 protected function parseUserValue( $value ) {
108102 $this->mPropTypeValue = null;
109 - $this->mPropTypeId = '';
110103 unset( $this->m_wikipage );
111104
112105 if ( $this->m_caption === false ) { // always use this as caption
@@ -137,7 +130,6 @@
138131 if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) {
139132 $this->m_dataitem = $dataItem;
140133 $this->mPropTypeValue = null;
141 - $this->mPropTypeId = '';
142134 unset( $this->m_wikipage );
143135 $this->m_caption = false;
144136 return true;
@@ -222,52 +214,32 @@
223215 }
224216
225217 /**
226 - * Return an SMWTypesValue object representing the datatype of this property.
 218+ * Return an SMWTypesValue object representing the datatype of this
 219+ * property.
 220+ * @deprecated Types values are not a good way to exchange SMW type information. They are for input only. Use getPropertyTypeID() if you want the type id. This method will vanish in SMW 1.7.
227221 */
228222 public function getTypesValue() {
229 - global $smwgPDefaultType;
230 - if ( $this->mPropTypeValue === null ) {
231 - if ( !$this->isValid() ) { // errors in property, return invalid types value with same errors
232 - $result = SMWDataValueFactory::newTypeIDValue( '__typ' );
233 - $result->setDBkeys( array( '__err' ) );
234 - $result->addError( $this->getErrors() );
235 - } elseif ( $this->m_dataitem->isUserDefined() ) { // normal property
236 - $typearray = smwfGetStore()->getPropertyValues( $this->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) );
237 - if ( count( $typearray ) == 1 ) { // unique type given
238 - $result = current( $typearray );
239 - } elseif ( count( $typearray ) == 0 ) { // no type given
240 - $result = SMWDataValueFactory::newTypeIDValue( '__typ' );
241 - $result->setDBkeys( array( $smwgPDefaultType ) );
242 - } else { // many types given, error
243 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
244 - $result = SMWDataValueFactory::newTypeIDValue( '__typ' );
245 - $result->setDBkeys( array( '__err' ) );
246 - $result->addError( wfMsgForContent( 'smw_manytypes' ) );
247 - }
248 - } else { // pre-defined property
249 - $propertyTypeId = SMWDIProperty::getPredefinedPropertyTypeId( $this->m_dataitem->getKey() );
250 - $result = SMWTypesValue::newFromTypeId( $propertyTypeId );
251 - }
252 - $this->mPropTypeValue = $result;
 223+ $result = SMWTypesValue::newFromTypeId( $this->getPropertyTypeID() );
 224+ if ( !$this->isValid() ) {
 225+ $result->addError( $this->getErrors() );
253226 }
254 - return $this->mPropTypeValue;
 227+ return $result;
255228 }
256229
257230 /**
258 - * Quickly get the type id of some property without necessarily making
259 - * another datavalue. Note that this is not the same as getTypeID(), which
260 - * returns the id of this property datavalue.
 231+ * Convenience method to find the type id of this property. Most callers
 232+ * should rather use SMWDIProperty::findPropertyTypeId() directly. Note
 233+ * that this is not the same as getTypeID(), which returns the id of
 234+ * this property datavalue.
 235+ *
 236+ * @return string
261237 */
262238 public function getPropertyTypeID() {
263 - if ( $this->mPropTypeId === '' ) {
264 - $type = $this->getTypesValue();
265 - if ( $type instanceof SMWTypesValue ) {
266 - $this->mPropTypeId = $type->getDBkey();
267 - } else {
268 - $this->mPropTypeId = '__err';
269 - }
 239+ if ( !$this->isValid() ) {
 240+ return $this->m_dataitem->findPropertyTypeId();
 241+ } else {
 242+ return '__err';
270243 }
271 - return $this->mPropTypeId;
272244 }
273245
274246 /**

Status & tagging log