r24083 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24082‎ | r24083 | r24084 >
Date:10:55, 14 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
use wikipage datavalue objects instead of titles throughout parsing
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Error.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -14,7 +14,10 @@
1515 protected $m_errors = array(); /// Array of error text messages
1616 protected $m_isset = false; /// True if a value was set.
1717 protected $m_typeid; /// The type id for this value object
 18+ protected $m_infolinks = array(); /// Array of infolink objects
1819
 20+ private $m_hasssearchlink; /// used to control the addition of the standard search link
 21+
1922 public function SMWDataValue($typeid) {
2023 $this->m_typeid = $typeid;
2124 }
@@ -28,6 +31,8 @@
2932 */
3033 public function setUserValue($value, $caption = false) {
3134 $this->m_errors = array(); // clear errors
 35+ $this->m_infolinks = array(); // clear links
 36+ $this->m_hasssearchlink = false;
3237 if ($caption !== false) {
3338 $this->m_caption = $caption;
3439 }
@@ -42,6 +47,8 @@
4348 */
4449 public function setXSDValue($value, $unit = '') {
4550 $this->m_errors = array(); // clear errors
 51+ $this->m_infolinks = array(); // clear links
 52+ $this->m_hasssearchlink = false;
4653 $this->m_caption = false;
4754 $this->parseXSDValue($value, $unit);
4855 $this->m_isset = true;
@@ -56,6 +63,10 @@
5764 $this->m_attribute = $attstring;
5865 }
5966
 67+ public function addInfoLink(SMWInfoLink $link) {
 68+ $this->m_infolinks[] = $link;
 69+ }
 70+
6071 /**
6172 * Define a particular output format. Output formats are user-supplied strings
6273 * that the datavalue may (or may not) use to customise its return value. For
@@ -184,7 +195,13 @@
185196 * Captions can contain some HTML markup which is admissible for wiki
186197 * text, but no more. Result might have no entries but is always an array.
187198 */
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+ }
189206
190207 /**
191208 * 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 @@
99 class SMWErrorValue extends SMWDataValue {
1010
1111 private $m_value;
12 - private $m_infolinks = Array();
1312
1413 public function SMWErrorValue($errormsg = '', $uservalue = '', $caption = false) {
1514 $this->setUserValue($uservalue, $caption);
@@ -65,10 +64,6 @@
6665 return ''; // empty unit
6766 }
6867
69 - public function getInfolinks() {
70 - return $this->m_infolinks;
71 - }
72 -
7368 public function getHash() {
7469 return $this->getLongWikiText(); // use only error for hash so as not to display the same error twice
7570 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -95,10 +95,7 @@
9696 $relation = smwfNormalTitleText($relation);
9797 $srels = $smwgContLang->getSpecialPropertiesArray();
9898 $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);
103100
104101 if ($special !== false) {
105102 $type = SMWTypeHandlerFactory::getSpecialTypeHandler($special);
@@ -109,10 +106,10 @@
110107 //error" datatype handler. FIXME
111108 SMWFactbox::addAttribute($relation, $target, false);
112109 } else {
113 - SMWFactbox::$semdata->addSpecialValue($special, $object);
 110+ SMWFactbox::$semdata->addSpecialValue($special, $value);
114111 }
115112 } else {
116 - SMWFactbox::$semdata->addRelationTextObject($relation, $object);
 113+ SMWFactbox::$semdata->addRelationTextValue($relation, $value);
117114 }
118115 }
119116
@@ -307,7 +304,36 @@
308305 if(!SMWFactbox::$semdata->hasRelations()) { return true; }
309306
310307 //$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]/','&nbsp;',$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
311314
 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 = '<!-- -->&nbsp;&nbsp;'; // 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 = ' &nbsp;&nbsp;'; // allow breaking for longer lists of infolinks
 333+ }
 334+ }
 335+ $text .= '</td></tr>';
 336+ }
 337+/*
312338 foreach(SMWFactbox::$semdata->getRelations() as $relation) {
313339 $relationObjectArray = SMWFactbox::$semdata->getRelationObjects($relation);
314340 //$text .= ' ' . SMWFactbox::$semdata->getSubject()->getPrefixedText() . '&nbsp;';
@@ -331,7 +357,7 @@
332358 $text .= '&nbsp;&nbsp;' . $searchlink->getWikiText();
333359 }
334360 $text .= "</td></tr>\n";
335 - }
 361+ }*/
336362 }
337363
338364
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
@@ -16,7 +16,7 @@
1717 */
1818 class SMWSemanticData {
1919 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
2121 protected $attribvals = Array(); // text keys and arrays of datavalue objects
2222 protected $attribtitles = Array(); // text keys and title objects
2323 protected $specprops = Array(); // integer keys and mixed subarrays
@@ -114,11 +114,11 @@
115115 /**
116116 * Get the array of all stored objects for some relation.
117117 */
118 - public function getRelationObjects(Title $relation) {
 118+ public function getRelationValues(Title $relation) {
119119 if (array_key_exists($relation->getText(), $this->relobjs)) {
120120 return $this->relobjs[$relation->getText()];
121121 } else {
122 - return Array();
 122+ return array();
123123 }
124124 }
125125
@@ -130,6 +130,35 @@
131131 }
132132
133133 /**
 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+ /**
134163 * Store an object for a relation identified by its title. Duplicate
135164 * object entries are ignored.
136165 */
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
@@ -10,7 +10,6 @@
1111
1212 private $m_value = '';
1313 private $m_xsdvalue = '';
14 - private $m_infolinks = Array();
1514
1615 protected function parseUserValue($value) {
1716 if ($this->m_caption === false) {
@@ -24,7 +23,7 @@
2524 $this->m_value = $this->m_xsdvalue;
2625 } else {
2726 $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);
2928 }
3029 } else {
3130 $this->addError(wfMsgForContent('smw_emptystring'));
@@ -82,10 +81,6 @@
8382 return ''; // empty unit
8483 }
8584
86 - public function getInfolinks() {
87 - return $this->m_infolinks;
88 - }
89 -
9085 public function getHash() {
9186 return $this->getLongWikiText(false) . $this->m_xsdvalue ;
9287 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -14,11 +14,6 @@
1515 private $m_values = Array();
1616
1717 /**
18 - * This variable represents the content returned when asking vor getInfolinks()
19 - */
20 - private $m_infolinks = Array();
21 -
22 - /**
2318 * Is this n-ary datavalue valid?
2419 */
2520 private $isValid;
@@ -74,7 +69,7 @@
7570 $this->m_values[$i] = SMWDataValueFactory::newTypeObjectValue($types[$i], false);
7671 }
7772 }
78 - $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $value);
 73+ //$this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $value);
7974 }
8075
8176 protected function parseXSDValue($value, $unit) {
@@ -224,10 +219,6 @@
225220 return implode(';', $units);
226221 }
227222
228 - public function getInfolinks() {
229 - return $this->m_infolinks;
230 - }
231 -
232223 public function getHash() {
233224 $hash = '';
234225 foreach ($this->m_values as $value) {

Status & tagging log