http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89217
Revision: 89217
Author: mkroetzsch
Date: 2011-05-31 14:58:39 +0000 (Tue, 31 May 2011)
Log Message:
-----------
fixed outdated type-related methods in DVProperty, and their use on
Special:Properties
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
Modified:
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
2011-05-31 14:01:13 UTC (rev 89216)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
2011-05-31 14:58:39 UTC (rev 89217)
@@ -46,12 +46,6 @@
* @var SMWTypesValue
*/
private $mPropTypeValue;
-
- /**
- * Cache for type ID of this property, or '' if not calculated yet.
- * @var string
- */
- private $mPropTypeId;
/**
* Static function for creating a new property object from a
@@ -105,7 +99,6 @@
*/
protected function parseUserValue( $value ) {
$this->mPropTypeValue = null;
- $this->mPropTypeId = '';
unset( $this->m_wikipage );
if ( $this->m_caption === false ) { // always use this as
caption
@@ -137,7 +130,6 @@
if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) {
$this->m_dataitem = $dataItem;
$this->mPropTypeValue = null;
- $this->mPropTypeId = '';
unset( $this->m_wikipage );
$this->m_caption = false;
return true;
@@ -222,52 +214,32 @@
}
/**
- * Return an SMWTypesValue object representing the datatype of this
property.
+ * Return an SMWTypesValue object representing the datatype of this
+ * property.
+ * @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.
*/
public function getTypesValue() {
- global $smwgPDefaultType;
- if ( $this->mPropTypeValue === null ) {
- if ( !$this->isValid() ) { // errors in property,
return invalid types value with same errors
- $result = SMWDataValueFactory::newTypeIDValue(
'__typ' );
- $result->setDBkeys( array( '__err' ) );
- $result->addError( $this->getErrors() );
- } elseif ( $this->m_dataitem->isUserDefined() ) { //
normal property
- $typearray = smwfGetStore()->getPropertyValues(
$this->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) );
- if ( count( $typearray ) == 1 ) { // unique
type given
- $result = current( $typearray );
- } elseif ( count( $typearray ) == 0 ) { // no
type given
- $result =
SMWDataValueFactory::newTypeIDValue( '__typ' );
- $result->setDBkeys( array(
$smwgPDefaultType ) );
- } else { // many types given, error
- smwfLoadExtensionMessages(
'SemanticMediaWiki' );
- $result =
SMWDataValueFactory::newTypeIDValue( '__typ' );
- $result->setDBkeys( array( '__err' ) );
- $result->addError( wfMsgForContent(
'smw_manytypes' ) );
- }
- } else { // pre-defined property
- $propertyTypeId =
SMWDIProperty::getPredefinedPropertyTypeId( $this->m_dataitem->getKey() );
- $result = SMWTypesValue::newFromTypeId(
$propertyTypeId );
- }
- $this->mPropTypeValue = $result;
+ $result = SMWTypesValue::newFromTypeId(
$this->getPropertyTypeID() );
+ if ( !$this->isValid() ) {
+ $result->addError( $this->getErrors() );
}
- return $this->mPropTypeValue;
+ return $result;
}
/**
- * Quickly get the type id of some property without necessarily making
- * another datavalue. Note that this is not the same as getTypeID(),
which
- * returns the id of this property datavalue.
+ * Convenience method to find the type id of this property. Most callers
+ * should rather use SMWDIProperty::findPropertyTypeId() directly. Note
+ * that this is not the same as getTypeID(), which returns the id of
+ * this property datavalue.
+ *
+ * @return string
*/
public function getPropertyTypeID() {
- if ( $this->mPropTypeId === '' ) {
- $type = $this->getTypesValue();
- if ( $type instanceof SMWTypesValue ) {
- $this->mPropTypeId = $type->getDBkey();
- } else {
- $this->mPropTypeId = '__err';
- }
+ if ( !$this->isValid() ) {
+ return $this->m_dataitem->findPropertyTypeId();
+ } else {
+ return '__err';
}
- return $this->mPropTypeId;
}
/**
Modified:
trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
2011-05-31 14:01:13 UTC (rev 89216)
+++
trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
2011-05-31 14:58:39 UTC (rev 89217)
@@ -54,16 +54,15 @@
function formatResult( $skin, $result ) {
$typestring = '';
$errors = array();
+
$diWikiPage = $result[0]->getDiWikiPage();
- if ( $diWikiPage !== null ) {
- $title = Title::makeTitle( $diWikiPage->getNamespace(),
$diWikiPage->getDBkey() );
- } else {
- $title = null;
- }
+ $title = $diWikiPage !== null ? $diWikiPage->getTitle() : null;
+
if ( $result[0]->isUserDefined() && ( $result[1] <= 5 ) ) {
$errors[] = wfMsg( 'smw_propertyhardlyused' );
}
- if ( $result[0]->isUserDefined() && ( $title !== null ) &&
$title->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood
+
+ if ( $result[0]->isUserDefined() && $title !== null &&
$title->exists() ) {
$typeProperty = new SMWDIProperty( '_TYPE' );
$types = smwfGetStore()->getPropertyValues(
$diWikiPage, $typeProperty );
if ( count( $types ) >= 1 ) {
@@ -71,27 +70,28 @@
$typestring = $typeDataValue->getLongHTMLText(
$skin );
}
$proplink = $skin->makeKnownLinkObj( $title,
$result[0]->getLabel() );
- } elseif ( $result[0]->isUserDefined() && ( $title !== null ) )
{
+ } elseif ( $result[0]->isUserDefined() && $title !== null ) {
$errors[] = wfMsg( 'smw_propertylackspage' );
$proplink = $skin->makeBrokenLinkObj( $title,
$result[0]->getLabel(), 'action=view' );
} else { // predefined property
- $type = $result[0]->getTypesValue();
- $typestring = $type->getLongHTMLText( $skin );
+ $typeid = $result[0]->findPropertyTypeID();
+ $typeDataValue = SMWTypesValue::newFromTypeId( $typeid
);
+ $propertyDataValue =
SMWDataValueFactory::newDataItemValue( $result[0], null );
+ $typestring = $typeDataValue->getLongHTMLText( $skin );
if ( $typestring == '' ) $typestring = '–'; /// FIXME
some types of builtin props have no name, and another message should be used
then
- $proplink = $result[0]->getLongHTMLText( $skin );
+ $proplink = $propertyDataValue->getLongHTMLText( $skin
);
}
+
if ( $typestring == '' ) {
global $smwgPDefaultType;
- $typepagedbkey = str_replace( ' ', '_',
SMWDataValueFactory::findTypeLabel( $smwgPDefaultType ) );
- $diTypePage = new SMWDIWikiPage( $typepagedbkey,
SMW_NS_TYPE, '', '__typ' );
- $dvTypePage = SMWDataValueFactory::newTypeIdValue(
'__typ' );
- $dvTypePage->setDataItem( $diTypePage );
- $typestring = $dvTypePage->getLongHTMLText( $skin );
- if ( ( $title !== null ) && ( $title->exists() ) ) { //
print only when we did not print a "nopage" warning yet
+ $typeDataValue = SMWTypesValue::newFromTypeId(
$smwgPDefaultType );
+ $typestring = $typeDataValue->getLongHTMLText( $skin );
+ if ( $title !== null && $title->exists() ) { // print
only when we did not print a "nopage" warning yet
$errors[] = wfMsg( 'smw_propertylackstype',
$typestring );
}
}
- return wfMsg( 'smw_property_template', $proplink, $typestring,
$result[1] ) . ' ' . smwfEncodeMessages( $errors );
+
+ return wfMsg( 'smw_property_template', $proplink, $typestring,
$result[1] ) . ' ' . smwfEncodeMessages( $errors, 'warning', ' <!--br-->',
false );
}
function getResults( $requestoptions ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs