r23847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23846‎ | r23847 | r23848 >
Date:17:14, 7 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
set attribute name for datavalues if known (enables searching and attribute-specific customisation of display)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -40,15 +40,16 @@
4141 * can be set later on.
4242 */
4343 static public function newAttributeValue($attstring, $value=false) {
44 - if(!array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) {
45 - $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE);
46 - if ($atitle !== NULL) {
47 - return SMWDataValueFactory::newAttributeObjectValue($atitle,$value);
48 - } else {
49 - return new SMWOldDataValue(new SMWErrorTypeHandler(wfMsgForContent('smw_notype')));
50 - }
 44+ if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache
 45+ return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 46+ } // else: find type for attribute:
 47+
 48+ $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE);
 49+ if ($atitle !== NULL) {
 50+ return SMWDataValueFactory::newAttributeObjectValue($atitle,$value);
 51+ } else {
 52+ return new SMWErrorValue(wfMsgForContent('smw_notype'), $value);
5153 }
52 - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value);
5354 }
5455
5556 /**
@@ -57,22 +58,23 @@
5859 * can be set later on.
5960 */
6061 static public function newAttributeObjectValue(Title $att, $value=false) {
 62+ SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG
6163 $attstring = $att->getText();
62 - SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG
63 - if(!array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) {
64 - $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE);
65 - if (count($typearray)==1) {
66 - SMWDataValueFactory::$m_typelabels[$attstring] = $typearray[0];
67 - $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value);
68 - SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid
69 - return $result;
70 - } elseif (count($typearray)==0) {
71 - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value);
72 - } else {
73 - return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value);
74 - }
 64+ if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache
 65+ return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 66+ } // else: find type for attribute:
 67+
 68+ $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE);
 69+ if (count($typearray)==1) {
 70+ SMWDataValueFactory::$m_typelabels[$attstring] = $typearray[0];
 71+ $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 72+ SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid
 73+ return $result;
 74+ } elseif (count($typearray)==0) {
 75+ return new SMWErrorValue(wfMsgForContent('smw_notype'), $value);
 76+ } else {
 77+ return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value);
7578 }
76 - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value);
7779 }
7880
7981 /**
@@ -116,8 +118,11 @@
117119 * Create a value from a type value (basically containing strings).
118120 * If no $value is given, an empty container is created, the value of which
119121 * can be set later on.
 122+ * @param $typevalue datavalue representing the type of the object
 123+ * @param $value user value string, or false if unknown
 124+ * @param $attstring text name of according attribute, or false (may be relevant for getting further parameters)
120125 */
121 - static public function newTypedValue(SMWDataValue $typevalue, $value=false) {
 126+ static public function newTypedValue(SMWDataValue $typevalue, $value=false, $attstring=false) {
122127 if (array_key_exists($typevalue->getWikiValue(), SMWDataValueFactory::$m_valueclasses)) {
123128 $vc = SMWDataValueFactory::$m_valueclasses[$typevalue->getWikiValue()];
124129 // check if class file was already included for this class
@@ -149,6 +154,9 @@
150155 }
151156 }
152157
 158+ if ($attstring != false) {
 159+ $result->setAttribute($attstring);
 160+ }
153161 if ($value !== false) {
154162 $result->setUserValue($value);
155163 }

Status & tagging log