Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php |
— | — | @@ -302,19 +302,19 @@ |
303 | 303 | /*********************************************************************/ |
304 | 304 | |
305 | 305 | public function getShortWikiText($linked = NULL) { |
306 | | - $this->getUserValue(); |
| 306 | + return $this->getUserValue(); |
307 | 307 | } |
308 | 308 | |
309 | 309 | public function getShortHTMLText($linker = NULL) { |
310 | | - $this->getUserValue(); |
| 310 | + return $this->getUserValue(); |
311 | 311 | } |
312 | 312 | |
313 | 313 | public function getLongWikiText($linked = NULL) { |
314 | | - $this->getValueDescription(); |
| 314 | + return $this->getValueDescription(); |
315 | 315 | } |
316 | 316 | |
317 | 317 | public function getLongHTMLText($linker = NULL) { |
318 | | - $this->getValueDescription(); |
| 318 | + return $this->getValueDescription(); |
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -46,7 +46,32 @@ |
47 | 47 | static function newTypedValue(SMWTypeHandler $type, $value=false) { |
48 | 48 | return SMWDataValueFactory::newTypeHandlerValue($type, $value); |
49 | 49 | } |
| 50 | + |
| 51 | + /*********************************************************************/ |
| 52 | + /* Legacy methods for compatiblity */ |
| 53 | + /*********************************************************************/ |
50 | 54 | |
| 55 | + /** |
| 56 | + * @DEPRECATED |
| 57 | + */ |
| 58 | + public function getUserValue() { |
| 59 | + return $this->getShortWikiText(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @DEPRECATED |
| 64 | + */ |
| 65 | + public function getValueDescription() { |
| 66 | + return $this->getLongWikiText(); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @DEPRECATED |
| 71 | + */ |
| 72 | + public function getTooltip() { |
| 73 | + return ''; |
| 74 | + } |
| 75 | + |
51 | 76 | /*********************************************************************/ |
52 | 77 | /* Set methods */ |
53 | 78 | /*********************************************************************/ |
— | — | @@ -65,18 +90,6 @@ |
66 | 91 | abstract public function setXSDValue($value, $unit); |
67 | 92 | |
68 | 93 | /** |
69 | | - * Set some other representation for this value. See documentation for |
70 | | - * SMWDataValue->others. |
71 | | - */ |
72 | | - abstract public function setPrintoutString($string, $key = ''); |
73 | | - |
74 | | - /** |
75 | | - * Select the input value among the given representations. See documentation |
76 | | - * for SMWDataValue->others. |
77 | | - */ |
78 | | - abstract public function setInput($key); |
79 | | - |
80 | | - /** |
81 | 94 | * Set the attribute to which this value refers. Used to generate search links. |
82 | 95 | * The atriubte is given as a simple wiki text title, without namespace prefix. |
83 | 96 | */ |
— | — | @@ -155,7 +168,7 @@ |
156 | 169 | abstract public function getUnit(); |
157 | 170 | |
158 | 171 | /** |
159 | | - * Return error string or false if no error occured. |
| 172 | + * Return error string or an empty string if no error occured. |
160 | 173 | */ |
161 | 174 | abstract public function getError(); |
162 | 175 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | |
96 | 96 | //set text for result |
97 | 97 | if ('' == $valueCaption) { |
98 | | - $result = $attr->getUserValue(); |
| 98 | + $result = $attr->getShortWikitext(true); |
99 | 99 | } else { |
100 | 100 | $result = mb_substr( $valueCaption, 1 ); // remove initial '|' |
101 | 101 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | |
104 | 104 | if ($special !== false) { |
105 | 105 | $type = SMWTypeHandlerFactory::getSpecialTypeHandler($special); |
106 | | - if ($type->getID() != 'error') { //Oops! This is not a relation! |
| 106 | + if ( ($type->getID() != 'error') && ($special != SMW_SP_HAS_TYPE) ) { //Oops! This is not a relation! |
107 | 107 | //Note that this still changes the behaviour, since the [[ ]] |
108 | 108 | //are not removed! A cleaner solution would be to print a |
109 | 109 | //helpful message into the factbox, based on a new "print value as |
— | — | @@ -283,7 +283,7 @@ |
284 | 284 | } |
285 | 285 | $i+=1; |
286 | 286 | |
287 | | - $text .= $attributeValue->getValueDescription(); |
| 287 | + $text .= $attributeValue->getLongWikiText(true); |
288 | 288 | |
289 | 289 | $sep = '<!-- --> '; // the comment is needed to prevent MediaWiki from linking URL-strings together with the nbsps! |
290 | 290 | foreach ($attributeValue->getInfolinks() as $link) { |
— | — | @@ -348,8 +348,12 @@ |
349 | 349 | $specialPropertyName = $specprops[$specialProperty]; |
350 | 350 | foreach ($valueArray as $value) { |
351 | 351 | if ($value instanceof SMWDataValue) { |
352 | | - $vt = $value->getValueDescription(); |
353 | | - $vn = $wgContLang->getNsText(SMW_NS_ATTRIBUTE); |
| 352 | + $vt = $value->getLongWikiText(true); |
| 353 | + if ($specialProperty != SMW_SP_HAS_TYPE) { |
| 354 | + $vn = $wgContLang->getNsText(SMW_NS_ATTRIBUTE); |
| 355 | + } else { |
| 356 | + $vn = $wgContLang->getNsText(SMW_NS_RELATION); //HACK |
| 357 | + } |
354 | 358 | } elseif ($value instanceof Title) { |
355 | 359 | $vt = '[[' . $value->getPrefixedText() . ']]'; |
356 | 360 | $vn = $wgContLang->getNsText(SMW_NS_RELATION); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -0,0 +1,111 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * This datavalue implements special processing suitable for defining |
| 6 | + * types of properties (n-ary or binary). |
| 7 | + */ |
| 8 | +class SMWTypesValue extends SMWDataValue { |
| 9 | + |
| 10 | + private $m_typevalues = array(); |
| 11 | + private $m_error = ''; |
| 12 | + |
| 13 | + /*********************************************************************/ |
| 14 | + /* Set methods */ |
| 15 | + /*********************************************************************/ |
| 16 | + |
| 17 | + public function setUserValue($value) { |
| 18 | + $this->m_typevalues = array(); |
| 19 | + $types = explode(';', $value); |
| 20 | + foreach ($types as $type) { |
| 21 | + $type = ltrim($type, ' ['); |
| 22 | + $type = rtrim($type, ' ]'); |
| 23 | + $ttype = Title::newFromText($type,SMW_NS_TYPE); |
| 24 | + if ($ttype->getNamespace() == SMW_NS_TYPE) { |
| 25 | + $this->m_typevalues[] = $ttype->getText(); |
| 26 | + } // else: wrong namespace given -- what now? TODO |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public function setXSDValue($value, $unit) { |
| 31 | + $this->setUserValue($value); // no units, compatible syntax |
| 32 | + } |
| 33 | + |
| 34 | + public function setAttribute($attribute) { // ignore |
| 35 | + } |
| 36 | + |
| 37 | + /*********************************************************************/ |
| 38 | + /* Get methods */ |
| 39 | + /*********************************************************************/ |
| 40 | + |
| 41 | + public function getShortWikiText($linked = NULL) { |
| 42 | + if ( ($linked === NULL) || ($linked === false) ) { |
| 43 | + return implode(', ', $this->m_typevalues); |
| 44 | + } else { |
| 45 | + global $wgContLang; |
| 46 | + $result = ''; |
| 47 | + $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE); |
| 48 | + $first = true; |
| 49 | + foreach ($this->m_typevalues as $type) { |
| 50 | + if ($first) { |
| 51 | + $first = false; |
| 52 | + } else { |
| 53 | + $result .= ', '; |
| 54 | + } |
| 55 | + $result .= '[[' . $typenamespace . ':' . $type . '|' . $type . ']]'; |
| 56 | + } |
| 57 | + return $result; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public function getShortHTMLText($linker = NULL) { |
| 62 | + return implode(', ', $this->m_typevalues); |
| 63 | + } |
| 64 | + |
| 65 | + public function getLongWikiText($linked = NULL) { |
| 66 | + return $this->getShortWikiText($linked); |
| 67 | + } |
| 68 | + |
| 69 | + public function getLongHTMLText($linker = NULL) { |
| 70 | + return $this->getShortHTMLText($linker); |
| 71 | + } |
| 72 | + |
| 73 | + public function getXSDValue() { |
| 74 | + if ($this->isValid()) { |
| 75 | + return str_replace(' ','_',implode(', ', $this->m_typevalues)); |
| 76 | + } else { |
| 77 | + return false; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public function getNumericValue() { |
| 82 | + return NULL; |
| 83 | + } |
| 84 | + |
| 85 | + public function getUnit() { |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + public function getError() { |
| 90 | + return $this->m_error; |
| 91 | + } |
| 92 | + |
| 93 | + public function getInfolinks() { |
| 94 | + return array(); |
| 95 | + } |
| 96 | + |
| 97 | + public function getHash() { |
| 98 | + return implode('[]', $this->m_typevalues); |
| 99 | + } |
| 100 | + |
| 101 | + public function isValid() { |
| 102 | + return ( ($this->m_error == '') && (count($this->m_typevalues)>0) ); |
| 103 | + } |
| 104 | + |
| 105 | + public function isNumeric() { |
| 106 | + return false; |
| 107 | + } |
| 108 | + |
| 109 | + |
| 110 | +} |
| 111 | + |
| 112 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 113 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -60,8 +60,29 @@ |
61 | 61 | */ |
62 | 62 | static public function newSpecialValue($specialprop, $value=false) { |
63 | 63 | ///TODO |
64 | | - $type = SMWTypeHandlerFactory::getSpecialTypeHandler($specialprop); |
65 | | - $result = new SMWOldDataValue($type); |
| 64 | + switch ($specialprop) { |
| 65 | + case SMW_SP_HAS_TYPE: |
| 66 | + global $smwgIP; |
| 67 | + include_once($smwgIP . '/includes/SMW_DV_Types.php'); |
| 68 | + $result = new SMWTypesValue(); |
| 69 | + break; |
| 70 | + ///TODO: |
| 71 | + case SMW_SP_HAS_URI: |
| 72 | + //return new SMWURITypeHandler(SMW_URI_MODE_URI); |
| 73 | + case SMW_SP_MAIN_DISPLAY_UNIT: case SMW_SP_DISPLAY_UNIT: case SMW_SP_SERVICE_LINK: |
| 74 | + //return new SMWStringTypeHandler(); |
| 75 | + case SMW_SP_CONVERSION_FACTOR: case SMW_SP_POSSIBLE_VALUE: |
| 76 | + //return new SMWStringTypeHandler(); |
| 77 | + case SMW_SP_CONVERSION_FACTOR_SI: |
| 78 | + //return new SMWStringTypeHandler(); // TODO: change this into an appropriate handler |
| 79 | + default: |
| 80 | + //global $smwgContLang; |
| 81 | + //$specprops = $smwgContLang->getSpecialPropertiesArray(); |
| 82 | + //return new SMWErrorTypeHandler(wfMsgForContent('smw_noattribspecial',$specprops[$special])); |
| 83 | + $type = SMWTypeHandlerFactory::getSpecialTypeHandler($specialprop); |
| 84 | + $result = new SMWOldDataValue($type); |
| 85 | + } |
| 86 | + |
66 | 87 | if ($value !== false) { |
67 | 88 | $result->setUserValue($value); |
68 | 89 | } |