r24124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24123‎ | r24124 | r24125 >
Date:12:26, 15 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Removed dedicated relation handling from parsing. All are properties now.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -25,13 +25,9 @@
2626 // In the regexp matches below, leading ':' escapes the markup, as
2727 // known for Categories.
2828 // 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);
3131
32 - // Parse links to extract attribute values
33 - $semanticLinkPattern = '(\[\[(([^:][^]]*):=)+((?:[^|\[\]]|\[\[[^]]*\]\])*)(\|([^]]*))?\]\])';
34 - $text = preg_replace_callback($semanticLinkPattern, 'smwfParseAttributesCallback', $text);
35 -
3632 // print the results if enabled (we have to parse them in any case, in order to
3733 // clean the wiki source for further processing)
3834 if ( smwfIsSemanticsProcessed($parser->getTitle()->getNamespace()) ) {
@@ -42,40 +38,10 @@
4339 }
4440
4541 /**
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 - /**
7642 * This callback function strips out the semantic attributes from a wiki
7743 * link.
7844 */
79 - function smwfParseAttributesCallback($semanticLink) {
 45+ function smwfParsePropertiesCallback($semanticLink) {
8046 if (array_key_exists(2,$semanticLink)) {
8147 $attribute = $semanticLink[2];
8248 } else { $attribute = ''; }
@@ -89,7 +55,7 @@
9056 //extract annotations and create tooltip
9157 $attributes = explode(':=', $attribute);
9258 foreach($attributes as $singleAttribute) {
93 - $attr = SMWFactbox::addAttribute($singleAttribute,$value,$valueCaption);
 59+ $attr = SMWFactbox::addProperty($singleAttribute,$value,$valueCaption);
9460 }
9561
9662 return $attr->getShortWikitext(true);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -53,18 +53,18 @@
5454 * It returns an array which contains the result of the operation in
5555 * various formats.
5656 */
57 - static function addAttribute($attribute, $value, $caption) {
 57+ static function addProperty($propertyname, $value, $caption) {
5858 global $smwgContLang, $smwgStoreActive;
5959 // 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
6161 $specprops = $smwgContLang->getSpecialPropertiesArray();
62 - $special = array_search($attribute, $specprops);
 62+ $special = array_search($propertyname, $specprops);
6363
6464 switch ($special) {
6565 case false: // normal attribute
66 - $result = SMWDataValueFactory::newPropertyValue($attribute,$value,$caption);
 66+ $result = SMWDataValueFactory::newPropertyValue($propertyname,$value,$caption);
6767 if ($smwgStoreActive) {
68 - SMWFactbox::$semdata->addPropertyValue($attribute,$result);
 68+ SMWFactbox::$semdata->addPropertyValue($propertyname,$result);
6969 }
7070 return $result;
7171 case SMW_SP_IMPORTED_FROM: // this requires special handling
@@ -88,34 +88,6 @@
8989 }
9090
9191 /**
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 - /**
12092 * This method adds multiple special properties needed to use the given
12193 * article for representing an element from a whitelisted external
12294 * ontology element. It does various feasibility checks (typing etc.)
@@ -299,70 +271,6 @@
300272 }
301273
302274 /**
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]/','&nbsp;',$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 = '<!-- -->&nbsp;&nbsp;'; // 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 = ' &nbsp;&nbsp;'; // 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() . '&nbsp;';
342 - $text .= '<tr><td class="smwrelname">[[' . $relation->getPrefixedText() . '|' . preg_replace('/[\s]/','&nbsp;',$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 .= '&nbsp;&nbsp;' . $searchlink->getWikiText();
360 - }
361 - $text .= "</td></tr>\n";
362 - }*/
363 - }
364 -
365 -
366 - /**
367275 * This method prints special properties at the bottom of an article.
368276 */
369277 static protected function printSpecialProperties(&$text) {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -101,8 +101,11 @@
102102 case SMW_SP_CONVERSION_FACTOR_SI:
103103 $result = SMWDataValueFactory::newTypeIDValue('_str', $value, $caption);
104104 break; // TODO: change this into an appropriate handler
 105+ case SMW_SP_SUBPROPERTY_OF:
 106+ $result = SMWDataValueFactory::newTypeIDValue('_wpg', $value, $caption);
 107+ break;
105108 default: // no special property
106 - $result = new SMWErrorValue(wfMsgForContent('smw_noattribspecial',$specprops[$special]));
 109+ $result = new SMWErrorValue(wfMsgForContent('smw_noattribspecial',$specialprop));
107110 }
108111
109112 if ($value !== false) {

Status & tagging log