r22971 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22970‎ | r22971 | r22972 >
Date:20:23, 13 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Editing support for n-ary types (storage support still pending). Better use of new datavalue interfaces.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /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)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php
@@ -302,19 +302,19 @@
303303 /*********************************************************************/
304304
305305 public function getShortWikiText($linked = NULL) {
306 - $this->getUserValue();
 306+ return $this->getUserValue();
307307 }
308308
309309 public function getShortHTMLText($linker = NULL) {
310 - $this->getUserValue();
 310+ return $this->getUserValue();
311311 }
312312
313313 public function getLongWikiText($linked = NULL) {
314 - $this->getValueDescription();
 314+ return $this->getValueDescription();
315315 }
316316
317317 public function getLongHTMLText($linker = NULL) {
318 - $this->getValueDescription();
 318+ return $this->getValueDescription();
319319 }
320320
321321 /**
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -46,7 +46,32 @@
4747 static function newTypedValue(SMWTypeHandler $type, $value=false) {
4848 return SMWDataValueFactory::newTypeHandlerValue($type, $value);
4949 }
 50+
 51+ /*********************************************************************/
 52+ /* Legacy methods for compatiblity */
 53+ /*********************************************************************/
5054
 55+ /**
 56+ * @DEPRECATED
 57+ */
 58+ public function getUserValue() {
 59+ return $this->getShortWikiText();
 60+ }
 61+
 62+ /**
 63+ * @DEPRECATED
 64+ */
 65+ public function getValueDescription() {
 66+ return $this->getLongWikiText();
 67+ }
 68+
 69+ /**
 70+ * @DEPRECATED
 71+ */
 72+ public function getTooltip() {
 73+ return '';
 74+ }
 75+
5176 /*********************************************************************/
5277 /* Set methods */
5378 /*********************************************************************/
@@ -65,18 +90,6 @@
6691 abstract public function setXSDValue($value, $unit);
6792
6893 /**
69 - * Set some other representation for this value. See documentation for
70 - * SMWDataValue->others.
71 - */
72 - abstract public function setPrintoutString($string, $key = '');
73 -
74 - /**
75 - * Select the input value among the given representations. See documentation
76 - * for SMWDataValue->others.
77 - */
78 - abstract public function setInput($key);
79 -
80 - /**
8194 * Set the attribute to which this value refers. Used to generate search links.
8295 * The atriubte is given as a simple wiki text title, without namespace prefix.
8396 */
@@ -155,7 +168,7 @@
156169 abstract public function getUnit();
157170
158171 /**
159 - * Return error string or false if no error occured.
 172+ * Return error string or an empty string if no error occured.
160173 */
161174 abstract public function getError();
162175
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -94,7 +94,7 @@
9595
9696 //set text for result
9797 if ('' == $valueCaption) {
98 - $result = $attr->getUserValue();
 98+ $result = $attr->getShortWikitext(true);
9999 } else {
100100 $result = mb_substr( $valueCaption, 1 ); // remove initial '|'
101101 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -102,7 +102,7 @@
103103
104104 if ($special !== false) {
105105 $type = SMWTypeHandlerFactory::getSpecialTypeHandler($special);
106 - if ($type->getID() != 'error') { //Oops! This is not a relation!
 106+ if ( ($type->getID() != 'error') && ($special != SMW_SP_HAS_TYPE) ) { //Oops! This is not a relation!
107107 //Note that this still changes the behaviour, since the [[ ]]
108108 //are not removed! A cleaner solution would be to print a
109109 //helpful message into the factbox, based on a new "print value as
@@ -283,7 +283,7 @@
284284 }
285285 $i+=1;
286286
287 - $text .= $attributeValue->getValueDescription();
 287+ $text .= $attributeValue->getLongWikiText(true);
288288
289289 $sep = '<!-- -->&nbsp;&nbsp;'; // the comment is needed to prevent MediaWiki from linking URL-strings together with the nbsps!
290290 foreach ($attributeValue->getInfolinks() as $link) {
@@ -348,8 +348,12 @@
349349 $specialPropertyName = $specprops[$specialProperty];
350350 foreach ($valueArray as $value) {
351351 if ($value instanceof SMWDataValue) {
352 - $vt = $value->getValueDescription();
353 - $vn = $wgContLang->getNsText(SMW_NS_ATTRIBUTE);
 352+ $vt = $value->getLongWikiText(true);
 353+ if ($specialProperty != SMW_SP_HAS_TYPE) {
 354+ $vn = $wgContLang->getNsText(SMW_NS_ATTRIBUTE);
 355+ } else {
 356+ $vn = $wgContLang->getNsText(SMW_NS_RELATION); //HACK
 357+ }
354358 } elseif ($value instanceof Title) {
355359 $vt = '[[' . $value->getPrefixedText() . ']]';
356360 $vn = $wgContLang->getNsText(SMW_NS_RELATION);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
@@ -0,0 +1,111 @@
 2+<?php
 3+
 4+/**
 5+ * This datavalue implements special processing suitable for defining
 6+ * types of properties (n-ary or binary).
 7+ */
 8+class SMWTypesValue extends SMWDataValue {
 9+
 10+ private $m_typevalues = array();
 11+ private $m_error = '';
 12+
 13+ /*********************************************************************/
 14+ /* Set methods */
 15+ /*********************************************************************/
 16+
 17+ public function setUserValue($value) {
 18+ $this->m_typevalues = array();
 19+ $types = explode(';', $value);
 20+ foreach ($types as $type) {
 21+ $type = ltrim($type, ' [');
 22+ $type = rtrim($type, ' ]');
 23+ $ttype = Title::newFromText($type,SMW_NS_TYPE);
 24+ if ($ttype->getNamespace() == SMW_NS_TYPE) {
 25+ $this->m_typevalues[] = $ttype->getText();
 26+ } // else: wrong namespace given -- what now? TODO
 27+ }
 28+ }
 29+
 30+ public function setXSDValue($value, $unit) {
 31+ $this->setUserValue($value); // no units, compatible syntax
 32+ }
 33+
 34+ public function setAttribute($attribute) { // ignore
 35+ }
 36+
 37+ /*********************************************************************/
 38+ /* Get methods */
 39+ /*********************************************************************/
 40+
 41+ public function getShortWikiText($linked = NULL) {
 42+ if ( ($linked === NULL) || ($linked === false) ) {
 43+ return implode(', ', $this->m_typevalues);
 44+ } else {
 45+ global $wgContLang;
 46+ $result = '';
 47+ $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE);
 48+ $first = true;
 49+ foreach ($this->m_typevalues as $type) {
 50+ if ($first) {
 51+ $first = false;
 52+ } else {
 53+ $result .= ', ';
 54+ }
 55+ $result .= '[[' . $typenamespace . ':' . $type . '|' . $type . ']]';
 56+ }
 57+ return $result;
 58+ }
 59+ }
 60+
 61+ public function getShortHTMLText($linker = NULL) {
 62+ return implode(', ', $this->m_typevalues);
 63+ }
 64+
 65+ public function getLongWikiText($linked = NULL) {
 66+ return $this->getShortWikiText($linked);
 67+ }
 68+
 69+ public function getLongHTMLText($linker = NULL) {
 70+ return $this->getShortHTMLText($linker);
 71+ }
 72+
 73+ public function getXSDValue() {
 74+ if ($this->isValid()) {
 75+ return str_replace(' ','_',implode(', ', $this->m_typevalues));
 76+ } else {
 77+ return false;
 78+ }
 79+ }
 80+
 81+ public function getNumericValue() {
 82+ return NULL;
 83+ }
 84+
 85+ public function getUnit() {
 86+ return false;
 87+ }
 88+
 89+ public function getError() {
 90+ return $this->m_error;
 91+ }
 92+
 93+ public function getInfolinks() {
 94+ return array();
 95+ }
 96+
 97+ public function getHash() {
 98+ return implode('[]', $this->m_typevalues);
 99+ }
 100+
 101+ public function isValid() {
 102+ return ( ($this->m_error == '') && (count($this->m_typevalues)>0) );
 103+ }
 104+
 105+ public function isNumeric() {
 106+ return false;
 107+ }
 108+
 109+
 110+}
 111+
 112+?>
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
___________________________________________________________________
Added: svn:eol-style
1113 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -60,8 +60,29 @@
6161 */
6262 static public function newSpecialValue($specialprop, $value=false) {
6363 ///TODO
64 - $type = SMWTypeHandlerFactory::getSpecialTypeHandler($specialprop);
65 - $result = new SMWOldDataValue($type);
 64+ switch ($specialprop) {
 65+ case SMW_SP_HAS_TYPE:
 66+ global $smwgIP;
 67+ include_once($smwgIP . '/includes/SMW_DV_Types.php');
 68+ $result = new SMWTypesValue();
 69+ break;
 70+ ///TODO:
 71+ case SMW_SP_HAS_URI:
 72+ //return new SMWURITypeHandler(SMW_URI_MODE_URI);
 73+ case SMW_SP_MAIN_DISPLAY_UNIT: case SMW_SP_DISPLAY_UNIT: case SMW_SP_SERVICE_LINK:
 74+ //return new SMWStringTypeHandler();
 75+ case SMW_SP_CONVERSION_FACTOR: case SMW_SP_POSSIBLE_VALUE:
 76+ //return new SMWStringTypeHandler();
 77+ case SMW_SP_CONVERSION_FACTOR_SI:
 78+ //return new SMWStringTypeHandler(); // TODO: change this into an appropriate handler
 79+ default:
 80+ //global $smwgContLang;
 81+ //$specprops = $smwgContLang->getSpecialPropertiesArray();
 82+ //return new SMWErrorTypeHandler(wfMsgForContent('smw_noattribspecial',$specprops[$special]));
 83+ $type = SMWTypeHandlerFactory::getSpecialTypeHandler($specialprop);
 84+ $result = new SMWOldDataValue($type);
 85+ }
 86+
6687 if ($value !== false) {
6788 $result->setUserValue($value);
6889 }

Status & tagging log