Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php |
— | — | @@ -7,13 +7,85 @@ |
8 | 8 | /** |
9 | 9 | * Objects of this class represent properties in SMW. |
10 | 10 | * |
| 11 | + * This class represents both normal (user-defined) properties and |
| 12 | + * predefined ("special") properties. The internal value ("XSD value") |
| 13 | + * is either the page DB key (normal properties) or the internal |
| 14 | + * property identifier (predefined properties). |
| 15 | + * |
| 16 | + * Internally, the fields of the parent class SMWWikiPageValue are used |
| 17 | + * to store the data that is displayed, but not necessarily to represent |
| 18 | + * the internal id (if the property is pre-defined). Hence, most output |
| 19 | + * methods can be used, but input methods and internal data outputs must |
| 20 | + * be re-implemented/extended. |
| 21 | + * |
| 22 | + * @note The internal IDs provide a way to keep the internal storage |
| 23 | + * language independent: pre-defined properties will have different names |
| 24 | + * for different languages, yet they can use a single id that can be |
| 25 | + * addressed in code and stored on disk. Thus internal code does not need |
| 26 | + * to take language settings into account. |
| 27 | + * |
11 | 28 | * @author Markus Krötzsch |
12 | 29 | * @ingroup SMWDataValues |
13 | 30 | */ |
14 | 31 | class SMWPropertyValue extends SMWWikiPageValue { |
15 | | - |
| 32 | + |
| 33 | + /// This value contains the property's DB key (normal property) or internal id (predefined properties). |
| 34 | + protected $m_propertyid; |
| 35 | + |
16 | 36 | public function __construct($typeid) { |
17 | 37 | parent::__construct($typeid); |
18 | 38 | $this->m_fixNamespace = SMW_NS_PROPERTY; |
19 | 39 | } |
| 40 | + |
| 41 | + /** |
| 42 | + * Extended parsing function to first check whether value refers to pre-defined |
| 43 | + * property, resolve aliases, and set internal property id accordingly. |
| 44 | + */ |
| 45 | + protected function parseUserValue($value) { |
| 46 | + global $smwgContLang; |
| 47 | + $value = smwfNormalTitleText(ltrim(rtrim($value,' ]'),' [')); //slightly normalise label |
| 48 | + $special = $smwgContLang->findSpecialPropertyID($value); |
| 49 | + if ($special !== false) { |
| 50 | + if ($this->m_caption === false) { |
| 51 | + $this->m_caption = $value; |
| 52 | + } |
| 53 | + $value = $smwgContLang->findSpecialPropertyLabel($special); |
| 54 | + $this->m_propertyid = $special; |
| 55 | + } else { |
| 56 | + $this->m_propertyid = false; |
| 57 | + } |
| 58 | + parent::parseUserValue($value); |
| 59 | + $this->m_propertyid = ($special !== false)?$special:$this->m_dbkeyform; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Extended parsing function to first check whether value is the id of a |
| 64 | + * pre-defined property, to resolve property names and aliases, and to set |
| 65 | + * internal property id accordingly. |
| 66 | + */ |
| 67 | + protected function unstub() { |
| 68 | + global $smwgContLang; |
| 69 | + if (is_array($this->m_stubdata)) { |
| 70 | + $this->m_propertyid = false; |
| 71 | + if ($this->m_stubdata[0][0] == '_') { // internal id, consume |
| 72 | + $special = $this->m_stubdata[0]; |
| 73 | + } else { // possibly name of special property |
| 74 | + $special = $smwgContLang->findSpecialPropertyID(str_replace('_',' ',$this->m_stubdata[0])); |
| 75 | + } |
| 76 | + if ($special !== false) { |
| 77 | + $this->m_stubdata[0] = $smwgContLang->findSpecialPropertyLabel($this->m_propertyid); |
| 78 | + } |
| 79 | + parent::unstub(); // note that this will destroy stubdata array |
| 80 | + $this->m_propertyid = ($special !== false)?$special:$this->m_dbkeyform; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Return internal property id as the main way of storing property references. |
| 86 | + */ |
| 87 | + public function getXSDValue() { |
| 88 | + $this->unstub(); |
| 89 | + return $this->m_propertyid; |
| 90 | + } |
| 91 | + |
20 | 92 | } |