r22958 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22957‎ | r22958 | r22959 >
Date:15:48, 13 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Prepared infrastructure for n-ary relations.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -60,7 +60,7 @@
6161
6262 switch ($special) {
6363 case false: // normal attribute
64 - $result = SMWDataValue::newAttributeValue($attribute,$value);
 64+ $result = SMWDataValueFactory::newAttributeValue($attribute,$value);
6565 if ($smwgStoreActive) {
6666 SMWFactbox::$semdata->addAttributeTextValue($attribute,$result);
6767 }
@@ -71,12 +71,12 @@
7272 if ( $special === SMW_SP_SERVICE_LINK ) { // do some custom formatting in this case
7373 global $wgContLang;
7474 $v = str_replace(' ', '_', $value); //normalize slightly since messages distinguish '_' and ' '
75 - $result = SMWDataValue::newSpecialValue($special,$v);
 75+ $result = SMWDataValueFactory::newSpecialValue($special,$v);
7676 $v = $result->getXSDValue(); //possibly further sanitized, so let's be cautious
7777 $result->setProcessedValues($value,$v); //set user value back to the input version
7878 $result->setPrintoutString('[[' . $wgContLang->getNsText(NS_MEDIAWIKI) . ':smw_service_' . $v . "|$value]]");
7979 } else { // standard processing
80 - $result = SMWDataValue::newSpecialValue($special,$value);
 80+ $result = SMWDataValueFactory::newSpecialValue($special,$value);
8181 }
8282 if ($smwgStoreActive) {
8383 SMWFactbox::$semdata->addSpecialValue($special,$result);
@@ -132,7 +132,7 @@
133133 $msglines = preg_split("([\n][\s]?)",wfMsgForContent("smw_import_$onto_ns")); // get the definition for "$namespace:$section"
134134
135135 if ( count($msglines) < 2 ) { //error: no elements for this namespace
136 - $datavalue = SMWDataValue::newTypedValue(new SMWErrorTypeHandler(wfMsgForContent('smw_unknown_importns',$onto_ns)),$value);
 136+ $datavalue = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler(wfMsgForContent('smw_unknown_importns',$onto_ns)),$value);
137137 if ($smwgStoreActive) {
138138 SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM,$datavalue);
139139 }
@@ -187,7 +187,7 @@
188188 }
189189
190190 if (NULL != $error) {
191 - $datavalue = SMWDataValue::newTypedValue(new SMWErrorTypeHandler($error),$value);
 191+ $datavalue = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler($error),$value);
192192 if ($smwgStoreActive) {
193193 SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM, $datavalue);
194194 }
@@ -200,11 +200,11 @@
201201 $sth = new SMWStringTypeHandler(); // making one is enough ...
202202
203203 if ($smwgStoreActive) {
204 - $datavalue = SMWDataValue::newTypedValue($sth,$onto_uri);
 204+ $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,$onto_uri);
205205 SMWFactbox::$semdata->addSpecialValue(SMW_SP_EXT_BASEURI,$datavalue);
206 - $datavalue = SMWDataValue::newTypedValue($sth,$onto_ns);
 206+ $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,$onto_ns);
207207 SMWFactbox::$semdata->addSpecialValue(SMW_SP_EXT_NSID,$datavalue);
208 - $datavalue = SMWDataValue::newTypedValue($sth,$onto_section);
 208+ $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,$onto_section);
209209 SMWFactbox::$semdata->addSpecialValue(SMW_SP_EXT_SECTION,$datavalue);
210210 if (NULL !== $datatype) {
211211 SMWFactbox::$semdata->addSpecialValue(SMW_SP_HAS_TYPE,$datatype);
@@ -212,7 +212,7 @@
213213 }
214214
215215 // print the input (this property is usually not stored, see SMW_SQLStore.php)
216 - $datavalue = SMWDataValue::newTypedValue($sth,"[$onto_uri$onto_section $value]");
 216+ $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,"[$onto_uri$onto_section $value]");
217217 // TODO: Unfortunatelly, the following line can break the tooltip code if $onto_name has markup. -- mak
218218 // if ('' != $onto_name) $datavalue->setPrintoutString($onto_name, 'onto_name');
219219 if ('' != $onto_name) $datavalue->setPrintoutString("[$onto_uri$onto_section $value] ($onto_name)");
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -20,9 +20,14 @@
2121 /**
2222 * Cache for type labels, indexed by attribute name (both without namespace prefix).
2323 */
24 - static private $m_attributelabels = array();
 24+ static private $m_attributelabels = array('testnary' => 'String;Integer;Wikipage;Date'); ///DEBUG
2525
2626 /**
 27+ * Was code for handling n-ary properties already included?
 28+ */
 29+ static private $m_naryincluded = false;
 30+
 31+ /**
2732 * Create a value from a string supplied by a user for a given attribute.
2833 * If no value is given, an empty container is created, the value of which
2934 * can be set later on.
@@ -87,13 +92,24 @@
8893 }
8994 return new $dv[2]($dv[3]);
9095 } else {
91 - ///TODO
92 - $type = SMWTypeHandlerFactory::getTypeHandlerByLabel($typestring);
93 - $result = new SMWOldDataValue($type);
94 - if ($value !== false) {
95 - $result->setUserValue($value);
 96+ // check for n-ary types
 97+ $types = explode($typestring, ';');
 98+ if (count($types)>1) {
 99+ if (SMWDataValueFactory::$m_naryincluded == false) {
 100+ global $smwgIP;
 101+ include_once($smwgIP . '/includes/SMW_DV_NAry.php');
 102+ SMWDataValueFactory::$m_naryincluded = true;
 103+ }
 104+ return new SMWNAryValue($types, $value);
 105+ } else {
 106+ ///TODO
 107+ $type = SMWTypeHandlerFactory::getTypeHandlerByLabel($typestring);
 108+ $result = new SMWOldDataValue($type);
 109+ if ($value !== false) {
 110+ $result->setUserValue($value);
 111+ }
 112+ return $result;
96113 }
97 - return $result;
98114 }
99115 }
100116
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -0,0 +1,5 @@
 2+<?php
 3+
 4+///TODO
 5+
 6+?>
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
___________________________________________________________________
Added: svn:eol-style
17 + native

Status & tagging log