Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php |
— | — | @@ -25,13 +25,9 @@ |
26 | 26 | // In the regexp matches below, leading ':' escapes the markup, as |
27 | 27 | // known for Categories. |
28 | 28 | // Parse links to extract semantic relations |
29 | | - $semanticLinkPattern = '(\[\[(([^:][^]]*)::)+([^\|\]]*)(\|([^]]*))?\]\])'; |
30 | | - $text = preg_replace_callback($semanticLinkPattern, 'smwfParseRelationsCallback', $text); |
| 29 | + $semanticLinkPattern = '(\[\[(([^:][^]]*):[=|:])+((?:[^|\[\]]|\[\[[^]]*\]\])*)(\|([^]]*))?\]\])'; |
| 30 | + $text = preg_replace_callback($semanticLinkPattern, 'smwfParsePropertiesCallback', $text); |
31 | 31 | |
32 | | - // Parse links to extract attribute values |
33 | | - $semanticLinkPattern = '(\[\[(([^:][^]]*):=)+((?:[^|\[\]]|\[\[[^]]*\]\])*)(\|([^]]*))?\]\])'; |
34 | | - $text = preg_replace_callback($semanticLinkPattern, 'smwfParseAttributesCallback', $text); |
35 | | - |
36 | 32 | // print the results if enabled (we have to parse them in any case, in order to |
37 | 33 | // clean the wiki source for further processing) |
38 | 34 | if ( smwfIsSemanticsProcessed($parser->getTitle()->getNamespace()) ) { |
— | — | @@ -42,40 +38,10 @@ |
43 | 39 | } |
44 | 40 | |
45 | 41 | /** |
46 | | - * This callback function strips out the semantic relation from a |
47 | | - * wiki link. Retrieved data is stored in the static SMWFactbox. |
48 | | - */ |
49 | | - function smwfParseRelationsCallback($semanticLink) { |
50 | | - if (array_key_exists(2,$semanticLink)) { |
51 | | - $relation = $semanticLink[2]; |
52 | | - } else { $relation = ''; } |
53 | | - if (array_key_exists(3,$semanticLink)) { |
54 | | - $linkTarget = $semanticLink[3]; |
55 | | - } else { $linkTarget = ''; } |
56 | | - if (array_key_exists(4,$semanticLink)) { |
57 | | - $linkCaption = $semanticLink[4]; |
58 | | - // answer to bug #1479616 |
59 | | - // removes the extra : that comes in from the automatic | expansion in links |
60 | | - if (($linkCaption != '') && ($linkCaption[1] == ":")) { |
61 | | - $linkCaption = "|" . mb_substr($linkCaption, 2); |
62 | | - } |
63 | | - } else { $linkCaption = ''; } |
64 | | - |
65 | | - //extract annotations |
66 | | - $relations = explode('::', $relation); |
67 | | - foreach($relations as $singleRelation) { |
68 | | - SMWFactbox::addRelation($singleRelation,$linkTarget); |
69 | | - } |
70 | | - |
71 | | - //pass it back as a normal link |
72 | | - return '[[:' . $linkTarget . $linkCaption . ']]'; |
73 | | - } |
74 | | - |
75 | | - /** |
76 | 42 | * This callback function strips out the semantic attributes from a wiki |
77 | 43 | * link. |
78 | 44 | */ |
79 | | - function smwfParseAttributesCallback($semanticLink) { |
| 45 | + function smwfParsePropertiesCallback($semanticLink) { |
80 | 46 | if (array_key_exists(2,$semanticLink)) { |
81 | 47 | $attribute = $semanticLink[2]; |
82 | 48 | } else { $attribute = ''; } |
— | — | @@ -89,7 +55,7 @@ |
90 | 56 | //extract annotations and create tooltip |
91 | 57 | $attributes = explode(':=', $attribute); |
92 | 58 | foreach($attributes as $singleAttribute) { |
93 | | - $attr = SMWFactbox::addAttribute($singleAttribute,$value,$valueCaption); |
| 59 | + $attr = SMWFactbox::addProperty($singleAttribute,$value,$valueCaption); |
94 | 60 | } |
95 | 61 | |
96 | 62 | return $attr->getShortWikitext(true); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -53,18 +53,18 @@ |
54 | 54 | * It returns an array which contains the result of the operation in |
55 | 55 | * various formats. |
56 | 56 | */ |
57 | | - static function addAttribute($attribute, $value, $caption) { |
| 57 | + static function addProperty($propertyname, $value, $caption) { |
58 | 58 | global $smwgContLang, $smwgStoreActive; |
59 | 59 | // See if this attribute is a special one like e.g. "Has unit" |
60 | | - $attribute = smwfNormalTitleText($attribute); //slightly normalize label |
| 60 | + $propertyname = smwfNormalTitleText($propertyname); //slightly normalize label |
61 | 61 | $specprops = $smwgContLang->getSpecialPropertiesArray(); |
62 | | - $special = array_search($attribute, $specprops); |
| 62 | + $special = array_search($propertyname, $specprops); |
63 | 63 | |
64 | 64 | switch ($special) { |
65 | 65 | case false: // normal attribute |
66 | | - $result = SMWDataValueFactory::newPropertyValue($attribute,$value,$caption); |
| 66 | + $result = SMWDataValueFactory::newPropertyValue($propertyname,$value,$caption); |
67 | 67 | if ($smwgStoreActive) { |
68 | | - SMWFactbox::$semdata->addPropertyValue($attribute,$result); |
| 68 | + SMWFactbox::$semdata->addPropertyValue($propertyname,$result); |
69 | 69 | } |
70 | 70 | return $result; |
71 | 71 | case SMW_SP_IMPORTED_FROM: // this requires special handling |
— | — | @@ -88,34 +88,6 @@ |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | | - * This method adds a new relation with the given target to the storage. |
93 | | - */ |
94 | | - static function addRelation($relation, $target) { |
95 | | - global $smwgContLang, $smwgStoreActive; |
96 | | - if (!$smwgStoreActive) return; // no action required |
97 | | - // See if this relation is a special one like e.g. "Has type" |
98 | | - $relation = smwfNormalTitleText($relation); |
99 | | - $srels = $smwgContLang->getSpecialPropertiesArray(); |
100 | | - $special = array_search($relation, $srels); |
101 | | - $value = SMWDataValueFactory::newTypeIDValue('_wpg',$target, false, $relation); |
102 | | - |
103 | | - if ($special !== false) { |
104 | | - $type = SMWTypeHandlerFactory::getSpecialTypeHandler($special); |
105 | | - if ( ($type->getID() != 'error') && ($special != SMW_SP_HAS_TYPE) ) { //Oops! This is not a relation! |
106 | | - //Note that this still changes the behaviour, since the [[ ]] |
107 | | - //are not removed! A cleaner solution would be to print a |
108 | | - //helpful message into the factbox, based on a new "print value as |
109 | | - //error" datatype handler. FIXME |
110 | | - SMWFactbox::addAttribute($relation, $target, false); |
111 | | - } else { |
112 | | - SMWFactbox::$semdata->addSpecialValue($special, $value); |
113 | | - } |
114 | | - } else { |
115 | | - SMWFactbox::$semdata->addPropertyValue($relation, $value); |
116 | | - } |
117 | | - } |
118 | | - |
119 | | - /** |
120 | 92 | * This method adds multiple special properties needed to use the given |
121 | 93 | * article for representing an element from a whitelisted external |
122 | 94 | * ontology element. It does various feasibility checks (typing etc.) |
— | — | @@ -299,70 +271,6 @@ |
300 | 272 | } |
301 | 273 | |
302 | 274 | /** |
303 | | - * This method prints semantic relations at the bottom of an article. |
304 | | - */ |
305 | | - static protected function printRelations(&$text) { |
306 | | - if(!SMWFactbox::$semdata->hasRelations()) { return true; } |
307 | | - |
308 | | - //$text .= ' <tr><th class="relhead"></th><th class="relhead">' . wfMsgForContent('smw_rel_head') . "</th></tr>\n"; |
309 | | - |
310 | | - foreach(SMWFactbox::$semdata->getRelations() as $relation) { |
311 | | - $relValueArray = SMWFactbox::$semdata->getRelationValues($relation); |
312 | | - $text .= '<tr><td class="smwattname">'; |
313 | | - $text .= ' [[' . $relation->getPrefixedText() . '|' . preg_replace('/[\s]/',' ',$relation->getText(),2) . ']] </td><td class="smwatts">'; |
314 | | - // 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 |
315 | | - |
316 | | - $l = count($relValueArray); |
317 | | - $i=0; |
318 | | - foreach ($relValueArray as $relValue) { |
319 | | - if ($i!=0) { |
320 | | - if ($i>$l-2) { |
321 | | - $text .= wfMsgForContent('smw_finallistconjunct') . ' '; |
322 | | - } else { |
323 | | - $text .= ', '; |
324 | | - } |
325 | | - } |
326 | | - $i+=1; |
327 | | - |
328 | | - $text .= $relValue->getLongWikiText(true); |
329 | | - |
330 | | - $sep = '<!-- --> '; // the comment is needed to prevent MediaWiki from linking URL-strings together with the nbsps! |
331 | | - foreach ($relValue->getInfolinks() as $link) { |
332 | | - $text .= $sep . $link->getWikiText(); |
333 | | - $sep = ' '; // allow breaking for longer lists of infolinks |
334 | | - } |
335 | | - } |
336 | | - $text .= '</td></tr>'; |
337 | | - } |
338 | | -/* |
339 | | - foreach(SMWFactbox::$semdata->getRelations() as $relation) { |
340 | | - $relationObjectArray = SMWFactbox::$semdata->getRelationObjects($relation); |
341 | | - //$text .= ' ' . SMWFactbox::$semdata->getSubject()->getPrefixedText() . ' '; |
342 | | - $text .= '<tr><td class="smwrelname">[[' . $relation->getPrefixedText() . '|' . preg_replace('/[\s]/',' ',$relation->getText(),2) . ']]</td><td class="smwrels">'; |
343 | | - // TODO: the preg_replace is a kind of hack to ensure that the left column does ont get too narrow; maybe we can find something nicer later |
344 | | - |
345 | | - $l = count($relationObjectArray); |
346 | | - $i=0; |
347 | | - foreach ($relationObjectArray as $relationObject) { |
348 | | - if ($i!=0) { |
349 | | - if ($i>$l-2) { |
350 | | - $text .= wfMsgForContent('smw_finallistconjunct') . ' '; |
351 | | - } else { |
352 | | - $text .= ', '; |
353 | | - } |
354 | | - } |
355 | | - $i+=1; |
356 | | - |
357 | | - $text .= '[[:' . $relationObject->getPrefixedText() . ']]'; |
358 | | - $searchlink = SMWInfolink::newRelationSearchLink('+',$relation->getText(),$relationObject->getPrefixedText()); |
359 | | - $text .= ' ' . $searchlink->getWikiText(); |
360 | | - } |
361 | | - $text .= "</td></tr>\n"; |
362 | | - }*/ |
363 | | - } |
364 | | - |
365 | | - |
366 | | - /** |
367 | 275 | * This method prints special properties at the bottom of an article. |
368 | 276 | */ |
369 | 277 | static protected function printSpecialProperties(&$text) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -101,8 +101,11 @@ |
102 | 102 | case SMW_SP_CONVERSION_FACTOR_SI: |
103 | 103 | $result = SMWDataValueFactory::newTypeIDValue('_str', $value, $caption); |
104 | 104 | break; // TODO: change this into an appropriate handler |
| 105 | + case SMW_SP_SUBPROPERTY_OF: |
| 106 | + $result = SMWDataValueFactory::newTypeIDValue('_wpg', $value, $caption); |
| 107 | + break; |
105 | 108 | default: // no special property |
106 | | - $result = new SMWErrorValue(wfMsgForContent('smw_noattribspecial',$specprops[$special])); |
| 109 | + $result = new SMWErrorValue(wfMsgForContent('smw_noattribspecial',$specialprop)); |
107 | 110 | } |
108 | 111 | |
109 | 112 | if ($value !== false) { |