Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php |
— | — | @@ -54,16 +54,15 @@ |
55 | 55 | function formatResult( $skin, $result ) { |
56 | 56 | $typestring = ''; |
57 | 57 | $errors = array(); |
| 58 | + |
58 | 59 | $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 | + |
64 | 62 | if ( $result[0]->isUserDefined() && ( $result[1] <= 5 ) ) { |
65 | 63 | $errors[] = wfMsg( 'smw_propertyhardlyused' ); |
66 | 64 | } |
67 | | - if ( $result[0]->isUserDefined() && ( $title !== null ) && $title->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood |
| 65 | + |
| 66 | + if ( $result[0]->isUserDefined() && $title !== null && $title->exists() ) { |
68 | 67 | $typeProperty = new SMWDIProperty( '_TYPE' ); |
69 | 68 | $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty ); |
70 | 69 | if ( count( $types ) >= 1 ) { |
— | — | @@ -71,27 +70,28 @@ |
72 | 71 | $typestring = $typeDataValue->getLongHTMLText( $skin ); |
73 | 72 | } |
74 | 73 | $proplink = $skin->makeKnownLinkObj( $title, $result[0]->getLabel() ); |
75 | | - } elseif ( $result[0]->isUserDefined() && ( $title !== null ) ) { |
| 74 | + } elseif ( $result[0]->isUserDefined() && $title !== null ) { |
76 | 75 | $errors[] = wfMsg( 'smw_propertylackspage' ); |
77 | 76 | $proplink = $skin->makeBrokenLinkObj( $title, $result[0]->getLabel(), 'action=view' ); |
78 | 77 | } 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 ); |
81 | 82 | 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 ); |
83 | 84 | } |
| 85 | + |
84 | 86 | if ( $typestring == '' ) { |
85 | 87 | 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 |
92 | 91 | $errors[] = wfMsg( 'smw_propertylackstype', $typestring ); |
93 | 92 | } |
94 | 93 | } |
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 ); |
96 | 96 | } |
97 | 97 | |
98 | 98 | function getResults( $requestoptions ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php |
— | — | @@ -46,12 +46,6 @@ |
47 | 47 | * @var SMWTypesValue |
48 | 48 | */ |
49 | 49 | private $mPropTypeValue; |
50 | | - |
51 | | - /** |
52 | | - * Cache for type ID of this property, or '' if not calculated yet. |
53 | | - * @var string |
54 | | - */ |
55 | | - private $mPropTypeId; |
56 | 50 | |
57 | 51 | /** |
58 | 52 | * Static function for creating a new property object from a |
— | — | @@ -105,7 +99,6 @@ |
106 | 100 | */ |
107 | 101 | protected function parseUserValue( $value ) { |
108 | 102 | $this->mPropTypeValue = null; |
109 | | - $this->mPropTypeId = ''; |
110 | 103 | unset( $this->m_wikipage ); |
111 | 104 | |
112 | 105 | if ( $this->m_caption === false ) { // always use this as caption |
— | — | @@ -137,7 +130,6 @@ |
138 | 131 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) { |
139 | 132 | $this->m_dataitem = $dataItem; |
140 | 133 | $this->mPropTypeValue = null; |
141 | | - $this->mPropTypeId = ''; |
142 | 134 | unset( $this->m_wikipage ); |
143 | 135 | $this->m_caption = false; |
144 | 136 | return true; |
— | — | @@ -222,52 +214,32 @@ |
223 | 215 | } |
224 | 216 | |
225 | 217 | /** |
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. |
227 | 221 | */ |
228 | 222 | 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() ); |
253 | 226 | } |
254 | | - return $this->mPropTypeValue; |
| 227 | + return $result; |
255 | 228 | } |
256 | 229 | |
257 | 230 | /** |
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 |
261 | 237 | */ |
262 | 238 | 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'; |
270 | 243 | } |
271 | | - return $this->mPropTypeId; |
272 | 244 | } |
273 | 245 | |
274 | 246 | /** |