Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -14,7 +14,10 @@ |
15 | 15 | protected $m_errors = array(); /// Array of error text messages |
16 | 16 | protected $m_isset = false; /// True if a value was set. |
17 | 17 | protected $m_typeid; /// The type id for this value object |
| 18 | + protected $m_infolinks = array(); /// Array of infolink objects |
18 | 19 | |
| 20 | + private $m_hasssearchlink; /// used to control the addition of the standard search link |
| 21 | + |
19 | 22 | public function SMWDataValue($typeid) { |
20 | 23 | $this->m_typeid = $typeid; |
21 | 24 | } |
— | — | @@ -28,6 +31,8 @@ |
29 | 32 | */ |
30 | 33 | public function setUserValue($value, $caption = false) { |
31 | 34 | $this->m_errors = array(); // clear errors |
| 35 | + $this->m_infolinks = array(); // clear links |
| 36 | + $this->m_hasssearchlink = false; |
32 | 37 | if ($caption !== false) { |
33 | 38 | $this->m_caption = $caption; |
34 | 39 | } |
— | — | @@ -42,6 +47,8 @@ |
43 | 48 | */ |
44 | 49 | public function setXSDValue($value, $unit = '') { |
45 | 50 | $this->m_errors = array(); // clear errors |
| 51 | + $this->m_infolinks = array(); // clear links |
| 52 | + $this->m_hasssearchlink = false; |
46 | 53 | $this->m_caption = false; |
47 | 54 | $this->parseXSDValue($value, $unit); |
48 | 55 | $this->m_isset = true; |
— | — | @@ -56,6 +63,10 @@ |
57 | 64 | $this->m_attribute = $attstring; |
58 | 65 | } |
59 | 66 | |
| 67 | + public function addInfoLink(SMWInfoLink $link) { |
| 68 | + $this->m_infolinks[] = $link; |
| 69 | + } |
| 70 | + |
60 | 71 | /** |
61 | 72 | * Define a particular output format. Output formats are user-supplied strings |
62 | 73 | * that the datavalue may (or may not) use to customise its return value. For |
— | — | @@ -184,7 +195,13 @@ |
185 | 196 | * Captions can contain some HTML markup which is admissible for wiki |
186 | 197 | * text, but no more. Result might have no entries but is always an array. |
187 | 198 | */ |
188 | | - abstract public function getInfolinks(); |
| 199 | + public function getInfolinks() { |
| 200 | + if (!$this->m_hasssearchlink && $this->isValid() && $this->m_attribute) { |
| 201 | + $this->m_hasssearchlink = true; |
| 202 | + $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $this->getWikiValue()); |
| 203 | + } |
| 204 | + return $this->m_infolinks; |
| 205 | + } |
189 | 206 | |
190 | 207 | /** |
191 | 208 | * Return a string that identifies the value of the object, and that can |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Error.php |
— | — | @@ -8,7 +8,6 @@ |
9 | 9 | class SMWErrorValue extends SMWDataValue { |
10 | 10 | |
11 | 11 | private $m_value; |
12 | | - private $m_infolinks = Array(); |
13 | 12 | |
14 | 13 | public function SMWErrorValue($errormsg = '', $uservalue = '', $caption = false) { |
15 | 14 | $this->setUserValue($uservalue, $caption); |
— | — | @@ -65,10 +64,6 @@ |
66 | 65 | return ''; // empty unit |
67 | 66 | } |
68 | 67 | |
69 | | - public function getInfolinks() { |
70 | | - return $this->m_infolinks; |
71 | | - } |
72 | | - |
73 | 68 | public function getHash() { |
74 | 69 | return $this->getLongWikiText(); // use only error for hash so as not to display the same error twice |
75 | 70 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -95,10 +95,7 @@ |
96 | 96 | $relation = smwfNormalTitleText($relation); |
97 | 97 | $srels = $smwgContLang->getSpecialPropertiesArray(); |
98 | 98 | $special = array_search($relation, $srels); |
99 | | - $object = Title::newFromText($target); |
100 | | - if ($object === NULL) { // not possible to make a Title, maybe illegal name, give up |
101 | | - return; |
102 | | - } |
| 99 | + $value = SMWDataValueFactory::newTypeIDValue('_wpg',$target, false, $relation); |
103 | 100 | |
104 | 101 | if ($special !== false) { |
105 | 102 | $type = SMWTypeHandlerFactory::getSpecialTypeHandler($special); |
— | — | @@ -109,10 +106,10 @@ |
110 | 107 | //error" datatype handler. FIXME |
111 | 108 | SMWFactbox::addAttribute($relation, $target, false); |
112 | 109 | } else { |
113 | | - SMWFactbox::$semdata->addSpecialValue($special, $object); |
| 110 | + SMWFactbox::$semdata->addSpecialValue($special, $value); |
114 | 111 | } |
115 | 112 | } else { |
116 | | - SMWFactbox::$semdata->addRelationTextObject($relation, $object); |
| 113 | + SMWFactbox::$semdata->addRelationTextValue($relation, $value); |
117 | 114 | } |
118 | 115 | } |
119 | 116 | |
— | — | @@ -307,7 +304,36 @@ |
308 | 305 | if(!SMWFactbox::$semdata->hasRelations()) { return true; } |
309 | 306 | |
310 | 307 | //$text .= ' <tr><th class="relhead"></th><th class="relhead">' . wfMsgForContent('smw_rel_head') . "</th></tr>\n"; |
| 308 | + |
| 309 | + foreach(SMWFactbox::$semdata->getRelations() as $relation) { |
| 310 | + $relValueArray = SMWFactbox::$semdata->getRelationValues($relation); |
| 311 | + $text .= '<tr><td class="smwattname">'; |
| 312 | + $text .= ' [[' . $relation->getPrefixedText() . '|' . preg_replace('/[\s]/',' ',$relation->getText(),2) . ']] </td><td class="smwatts">'; |
| 313 | + // TODO: the preg_replace is a kind of hack to ensure that the left column does not get too narrow; maybe we can find something nicer later |
311 | 314 | |
| 315 | + $l = count($relValueArray); |
| 316 | + $i=0; |
| 317 | + foreach ($relValueArray as $relValue) { |
| 318 | + if ($i!=0) { |
| 319 | + if ($i>$l-2) { |
| 320 | + $text .= wfMsgForContent('smw_finallistconjunct') . ' '; |
| 321 | + } else { |
| 322 | + $text .= ', '; |
| 323 | + } |
| 324 | + } |
| 325 | + $i+=1; |
| 326 | + |
| 327 | + $text .= $relValue->getLongWikiText(true); |
| 328 | + |
| 329 | + $sep = '<!-- --> '; // the comment is needed to prevent MediaWiki from linking URL-strings together with the nbsps! |
| 330 | + foreach ($relValue->getInfolinks() as $link) { |
| 331 | + $text .= $sep . $link->getWikiText(); |
| 332 | + $sep = ' '; // allow breaking for longer lists of infolinks |
| 333 | + } |
| 334 | + } |
| 335 | + $text .= '</td></tr>'; |
| 336 | + } |
| 337 | +/* |
312 | 338 | foreach(SMWFactbox::$semdata->getRelations() as $relation) { |
313 | 339 | $relationObjectArray = SMWFactbox::$semdata->getRelationObjects($relation); |
314 | 340 | //$text .= ' ' . SMWFactbox::$semdata->getSubject()->getPrefixedText() . ' '; |
— | — | @@ -331,7 +357,7 @@ |
332 | 358 | $text .= ' ' . $searchlink->getWikiText(); |
333 | 359 | } |
334 | 360 | $text .= "</td></tr>\n"; |
335 | | - } |
| 361 | + }*/ |
336 | 362 | } |
337 | 363 | |
338 | 364 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | */ |
18 | 18 | class SMWSemanticData { |
19 | 19 | protected $relobjs = Array(); // text keys and arrays of title objects |
20 | | - protected $reltitles = Array(); // text keys and title objects |
| 20 | + protected $reltitles = Array(); // text keys and wikipage values, TODO: join with attributes when namespaces were merged |
21 | 21 | protected $attribvals = Array(); // text keys and arrays of datavalue objects |
22 | 22 | protected $attribtitles = Array(); // text keys and title objects |
23 | 23 | protected $specprops = Array(); // integer keys and mixed subarrays |
— | — | @@ -114,11 +114,11 @@ |
115 | 115 | /** |
116 | 116 | * Get the array of all stored objects for some relation. |
117 | 117 | */ |
118 | | - public function getRelationObjects(Title $relation) { |
| 118 | + public function getRelationValues(Title $relation) { |
119 | 119 | if (array_key_exists($relation->getText(), $this->relobjs)) { |
120 | 120 | return $this->relobjs[$relation->getText()]; |
121 | 121 | } else { |
122 | | - return Array(); |
| 122 | + return array(); |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
— | — | @@ -130,6 +130,35 @@ |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
| 134 | + * Store a value for a relation identified by its title. Duplicate |
| 135 | + * object entries are ignored. |
| 136 | + */ |
| 137 | + public function addRelationValue(Title $relation, SMWDataValue $value) { |
| 138 | + if (!array_key_exists($relation->getText(), $this->relobjs)) { |
| 139 | + $this->relobjs[$relation->getText()] = Array(); |
| 140 | + $this->reltitles[$relation->getText()] = $relation; |
| 141 | + } |
| 142 | + $this->relobjs[$relation->getText()][$value->getHash()] = $value; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Store a value for a given relation identified by its text label (without |
| 147 | + * namespace prefix). Duplicate value entries are ignored. |
| 148 | + */ |
| 149 | + public function addRelationTextvalue($relationtext, SMWDataValue $value) { |
| 150 | + if (array_key_exists($relationtext, $this->reltitles)) { |
| 151 | + $relation = $this->reltitles[$relationtext]; |
| 152 | + } else { |
| 153 | + $relation = Title::newFromText($relationtext, SMW_NS_RELATION); |
| 154 | + if ($relation === NULL) { // error, maybe illegal title text |
| 155 | + return; |
| 156 | + } |
| 157 | + } |
| 158 | + $this->addRelationValue($relation, $value); |
| 159 | + } |
| 160 | + |
| 161 | + |
| 162 | + /** |
134 | 163 | * Store an object for a relation identified by its title. Duplicate |
135 | 164 | * object entries are ignored. |
136 | 165 | */ |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php |
— | — | @@ -10,7 +10,6 @@ |
11 | 11 | |
12 | 12 | private $m_value = ''; |
13 | 13 | private $m_xsdvalue = ''; |
14 | | - private $m_infolinks = Array(); |
15 | 14 | |
16 | 15 | protected function parseUserValue($value) { |
17 | 16 | if ($this->m_caption === false) { |
— | — | @@ -24,7 +23,7 @@ |
25 | 24 | $this->m_value = $this->m_xsdvalue; |
26 | 25 | } else { |
27 | 26 | $this->m_value = $this->m_xsdvalue; |
28 | | - $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $this->m_value); |
| 27 | + //$this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $this->m_value); |
29 | 28 | } |
30 | 29 | } else { |
31 | 30 | $this->addError(wfMsgForContent('smw_emptystring')); |
— | — | @@ -82,10 +81,6 @@ |
83 | 82 | return ''; // empty unit |
84 | 83 | } |
85 | 84 | |
86 | | - public function getInfolinks() { |
87 | | - return $this->m_infolinks; |
88 | | - } |
89 | | - |
90 | 85 | public function getHash() { |
91 | 86 | return $this->getLongWikiText(false) . $this->m_xsdvalue ; |
92 | 87 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php |
— | — | @@ -14,11 +14,6 @@ |
15 | 15 | private $m_values = Array(); |
16 | 16 | |
17 | 17 | /** |
18 | | - * This variable represents the content returned when asking vor getInfolinks() |
19 | | - */ |
20 | | - private $m_infolinks = Array(); |
21 | | - |
22 | | - /** |
23 | 18 | * Is this n-ary datavalue valid? |
24 | 19 | */ |
25 | 20 | private $isValid; |
— | — | @@ -74,7 +69,7 @@ |
75 | 70 | $this->m_values[$i] = SMWDataValueFactory::newTypeObjectValue($types[$i], false); |
76 | 71 | } |
77 | 72 | } |
78 | | - $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $value); |
| 73 | + //$this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $value); |
79 | 74 | } |
80 | 75 | |
81 | 76 | protected function parseXSDValue($value, $unit) { |
— | — | @@ -224,10 +219,6 @@ |
225 | 220 | return implode(';', $units); |
226 | 221 | } |
227 | 222 | |
228 | | - public function getInfolinks() { |
229 | | - return $this->m_infolinks; |
230 | | - } |
231 | | - |
232 | 223 | public function getHash() { |
233 | 224 | $hash = ''; |
234 | 225 | foreach ($this->m_values as $value) { |