r23863 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23862‎ | r23863 | r23864 >
Date:11:14, 8 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Tooltip creation sinmplified via new script, one hook less, better layout control for datavalue implementations,
tooltips possible in query results
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_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php (modified) (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_GlobalFunctions.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
@@ -115,8 +115,6 @@
116116 var $attribute; // wiki name (without namespace) of the attribute that this value was
117117 // assigned to, or FALSE if no attribute was given.
118118 /**#@-*/
119 -
120 - private $byxsd = false; // hack hack hack (temporary to ease DV transition)
121119
122120 /**
123121 * Just initialise variables. To create value objects, use one of the
@@ -139,9 +137,11 @@
140138 /**
141139 * Set the user value (and compute other representations if possible)
142140 */
143 - function setUserValue($value) {
 141+ protected function parseUserValue($value) {
 142+ if ($this->m_caption === false) {
 143+ $this->m_caption = $value;
 144+ }
144145 $this->clear();
145 - $this->byxsd = false; // DV transition hack to distinguish this case and to use others[0] for XSD-values
146146 $this->vuser = $value;
147147 //this is needed since typehandlers are not strictly required to
148148 //set the user value, especially if errors are reported.
@@ -156,8 +156,7 @@
157157 /**
158158 * Set the xsd value (and compute other representations if possible)
159159 */
160 - function setXSDValue($value, $unit) {
161 - $this->byxsd = true; // DV transition hack to distinguish this case and to use others[0] for XSD-values
 160+ protected function parseXSDValue($value, $unit) {
162161 $this->vxsd = $value;
163162 if ($this->type_handler === NULL) {
164163 return false;
@@ -315,18 +314,21 @@
316315 /*********************************************************************/
317316
318317 public function getShortWikiText($linked = NULL) {
319 - // behave like old getUserValue if DV was initialised from user value,
320 - // else behave like old getStringValue. Transition hack.
321 - if ($this->byxsd) {
 318+ if ($this->m_caption === false) {
322319 if ( count($this->others) > 0 ) {
323320 reset($this->others);
324 - return current($this->others); // return first element
 321+ $result = current($this->others); // return first element
325322 } else {
326 - return $this->vuser;
 323+ $result = $this->vuser;
327324 }
328325 } else {
329 - return $this->vuser;
 326+ $result = $this->m_caption;
330327 }
 328+ // add tooltip (only if "linking" is enabled)
 329+ if ( ($linked !== NULL) && ($linked !==false) && ($this->getTooltip() != '') ) {
 330+ $result = '<span class="smwttinline">' . $result . '<span class="smwttcontent">' . $this->getTooltip() . '</span></span>';
 331+ }
 332+ return $result;
331333 }
332334
333335 public function getShortHTMLText($linker = NULL) {
@@ -491,7 +493,7 @@
492494 foreach ($this->others as $id => $other) {
493495 if ( $id !== $this->input ) {
494496 $this->tooltip .= $sep . $other;
495 - $sep = ' = ';
 497+ $sep = ' <br /> ';
496498 }
497499 }
498500 } else { $this->tooltip = ''; } // TODO: returning $this->error; does not fully work with the JScript pre-parsing right now
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -9,93 +9,32 @@
1010 */
1111 abstract class SMWDataValue {
1212
13 - protected $m_attribute = false;
 13+ protected $m_attribute = false; /// The text label of the respective attribute or false if none given
 14+ protected $m_caption = false; /// The text label to be used for output or false if none given
1415
15 - /*********************************************************************/
16 - /* Static methods for initialisation */
17 - /*********************************************************************/
 16+///// Set methods /////
1817
1918 /**
20 - * Create a value from a string supplied by a user for a given attribute.
21 - * If no value is given, an empty container is created, the value of which
22 - * can be set later on.
23 - *
24 - * @DEPRECATED
 19+ * Set the user value (and compute other representations if possible).
 20+ * The given value is a string as supplied by some user. An alternative
 21+ * label for printout might also be specified.
2522 */
26 - static function newAttributeValue($attribute, $value=false) {
27 - trigger_error("The function SMWDataValue::newAttributeValue() is deprecated.", E_USER_NOTICE);
28 - return SMWDataValueFactory::newAttributeValue($attribute, $value);
 23+ public function setUserValue($value, $caption = false) {
 24+ if ($caption !== false) {
 25+ $this->m_caption = $caption;
 26+ }
 27+ $this->parseUserValue($value); // may set caption if not set yet, depending on datavalue
2928 }
3029
3130 /**
32 - * Create a value from a string supplied by a user for a given special
33 - * property, encoded as a numeric constant.
34 - * If no value is given, an empty container is created, the value of which
35 - * can be set later on.
36 - *
37 - * @DEPRECATED
38 - */
39 - static function newSpecialValue($specialprop, $value=false) {
40 - trigger_error("The function SMWDataValue::newSpecialValue() is deprecated.", E_USER_NOTICE);
41 - return SMWDataValueFactory::newSpecialValue($specialprop, $value);
42 - }
43 -
44 - /**
45 - * Create a value from a user-supplied string for which a type handler is known
46 - * If no value is given, an empty container is created, the value of which
47 - * can be set later on.
48 - *
49 - * @DEPRECATED
50 - */
51 - static function newTypedValue(SMWTypeHandler $type, $value=false) {
52 - trigger_error("The function SMWDataValue::newTypedValue() is deprecated.", E_USER_NOTICE);
53 - return SMWDataValueFactory::newTypeHandlerValue($type, $value);
54 - }
55 -
56 - /*********************************************************************/
57 - /* Legacy methods for compatiblity */
58 - /*********************************************************************/
59 -
60 - /**
61 - * @DEPRECATED
62 - */
63 - public function getUserValue() {
64 - trigger_error("The function SMWDataValue::getUserValue() is deprecated.", E_USER_NOTICE);
65 - return $this->getShortWikiText();
66 - }
67 -
68 - /**
69 - * @DEPRECATED
70 - */
71 - public function getValueDescription() {
72 - trigger_error("The function SMWDataValue::getValueDescription() is deprecated.", E_USER_NOTICE);
73 - return $this->getLongWikiText();
74 - }
75 -
76 - /**
77 - * @DEPRECATED
78 - */
79 - public function getTooltip() {
80 - //trigger_error("The function SMWDataValue::getTooltip() is deprecated.", E_USER_NOTICE);
81 - return '';
82 - }
83 -
84 - /*********************************************************************/
85 - /* Set methods */
86 - /*********************************************************************/
87 -
88 - /**
89 - * Set the user value (and compute other representations if possible).
90 - * The given value is a string as supplied by some user.
91 - */
92 - abstract public function setUserValue($value);
93 -
94 - /**
9531 * Set the xsd value (and compute other representations if possible).
9632 * The given value is a string that was provided by getXSDValue() (all
9733 * implementations should support round-tripping).
9834 */
99 - abstract public function setXSDValue($value, $unit);
 35+ public function setXSDValue($value, $unit) {
 36+ $this->m_caption = false;
 37+ $this->parseXSDValue($value, $unit);
 38+ }
10039
10140 /**
10241 * Set the attribute to which this value refers. Used to generate search links and
@@ -116,11 +55,25 @@
11756 */
11857 abstract public function setOutputFormat($formatstring);
11958
120 - /*********************************************************************/
121 - /* Get methods */
122 - /*********************************************************************/
 59+///// Abstract processing methods /////
12360
12461 /**
 62+ * Initialise the datavalue from the given value string.
 63+ * The format of this strings might be any acceptable user input
 64+ * and especially includes the output of getWikiValue().
 65+ */
 66+ abstract protected function parseUserValue($value);
 67+
 68+ /**
 69+ * Initialise the datavalue from the given value string and unit.
 70+ * The format of both strings strictly corresponds to the output
 71+ * of this implementation for getXSDValue() and getUnit().
 72+ */
 73+ abstract protected function parseXSDValue($value, $unit);
 74+
 75+///// Get methods /////
 76+
 77+ /**
12578 * Returns a short textual representation for this data value. If the value
12679 * was initialised from a user supplied string, then this original string
12780 * should be reflected in this short version (i.e. no normalisation should
@@ -234,6 +187,77 @@
235188 */
236189 abstract public function isNumeric();
237190
 191+
 192+
 193+ /*********************************************************************/
 194+ /* Static methods for initialisation */
 195+ /*********************************************************************/
 196+
 197+ /**
 198+ * Create a value from a string supplied by a user for a given attribute.
 199+ * If no value is given, an empty container is created, the value of which
 200+ * can be set later on.
 201+ *
 202+ * @DEPRECATED
 203+ */
 204+ static function newAttributeValue($attribute, $value=false) {
 205+ trigger_error("The function SMWDataValue::newAttributeValue() is deprecated.", E_USER_NOTICE);
 206+ return SMWDataValueFactory::newAttributeValue($attribute, $value);
 207+ }
 208+
 209+ /**
 210+ * Create a value from a string supplied by a user for a given special
 211+ * property, encoded as a numeric constant.
 212+ * If no value is given, an empty container is created, the value of which
 213+ * can be set later on.
 214+ *
 215+ * @DEPRECATED
 216+ */
 217+ static function newSpecialValue($specialprop, $value=false) {
 218+ trigger_error("The function SMWDataValue::newSpecialValue() is deprecated.", E_USER_NOTICE);
 219+ return SMWDataValueFactory::newSpecialValue($specialprop, $value);
 220+ }
 221+
 222+ /**
 223+ * Create a value from a user-supplied string for which a type handler is known
 224+ * If no value is given, an empty container is created, the value of which
 225+ * can be set later on.
 226+ *
 227+ * @DEPRECATED
 228+ */
 229+ static function newTypedValue(SMWTypeHandler $type, $value=false) {
 230+ trigger_error("The function SMWDataValue::newTypedValue() is deprecated.", E_USER_NOTICE);
 231+ return SMWDataValueFactory::newTypeHandlerValue($type, $value);
 232+ }
 233+
 234+ /*********************************************************************/
 235+ /* Legacy methods for compatiblity */
 236+ /*********************************************************************/
 237+
 238+ /**
 239+ * @DEPRECATED
 240+ */
 241+ public function getUserValue() {
 242+ trigger_error("The function SMWDataValue::getUserValue() is deprecated.", E_USER_NOTICE);
 243+ return $this->getShortWikiText();
 244+ }
 245+
 246+ /**
 247+ * @DEPRECATED
 248+ */
 249+ public function getValueDescription() {
 250+ trigger_error("The function SMWDataValue::getValueDescription() is deprecated.", E_USER_NOTICE);
 251+ return $this->getLongWikiText();
 252+ }
 253+
 254+ /**
 255+ * @DEPRECATED
 256+ */
 257+ public function getTooltip() {
 258+ trigger_error("The function SMWDataValue::getTooltip() is deprecated.", E_USER_NOTICE);
 259+ return '';
 260+ }
 261+
238262 }
239263
240264
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Error.php
@@ -11,52 +11,54 @@
1212 private $m_value;
1313 private $m_infolinks = Array();
1414
15 - public function SMWErrorValue($errormsg = '', $uservalue = '') {
 15+ public function SMWErrorValue($errormsg = '', $uservalue = '', $caption = false) {
1616 $this->m_error = $errormsg;
17 - $this->m_value = $uservalue;
 17+ $this->setUserValue($uservalue, $caption);
1818 }
1919
20 - public function setUserValue($value) {
 20+ protected function parseUserValue($value) {
 21+ if ($this->m_caption === false) {
 22+ $this->m_caption = $value;
 23+ }
2124 $this->m_value = $value;
2225 return true;
2326 }
2427
25 - public function setXSDValue($value, $unit) {
 28+ protected function parseXSDValue($value, $unit) {
2629 $this->setUserValue($value); // no units, compatible syntax
2730 }
2831
2932 public function setOutputFormat($formatstring){
30 - //do nothing
 33+ // no output formats
3134 }
3235 public function setError($errormsg){
3336 $this->m_error = $errormsg;
3437 }
3538
3639 public function getShortWikiText($linked = NULL) {
37 - //TODO: support linking
38 - return $this->m_value;
 40+ //TODO: support linking?
 41+ return $this->m_caption;
3942 }
4043
4144 public function getShortHTMLText($linker = NULL) {
42 - return $this->getShortWikiText($linker);
 45+ return htmlspecialchars($this->getShortWikiText($linker));
4346 }
4447
4548 public function getLongWikiText($linked = NULL) {
46 - //TODO: support linking
 49+ //TODO: support linking?
4750 return '<span class="smwwarning">'.$this->m_error.'</span>';
48 -
4951 }
5052
51 - public function getLongHTMLText($linker = NULL) {
 53+ public function getLongHTMLText($linker = NULL) {
5254 return $this->getLongWikiText($linker);
5355 }
5456
5557 public function getXSDValue() {
56 - return $this->getShortWikiText(false);
 58+ return $this->getShortWikiText(); ///TODO: really? (errors are not meant to be saved, or are they?)
5759 }
5860
5961 public function getWikiValue(){
60 - return $this->getShortWikiText(false);
 62+ return $this->getShortWikiText(); /// FIXME: wikivalue must not be influenced by the caption
6163 }
6264
6365 public function getNumericValue() {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -82,79 +82,20 @@
8383 if (array_key_exists(3,$semanticLink)) {
8484 $value = $semanticLink[3];
8585 } else { $value = ''; }
86 - if (array_key_exists(4,$semanticLink)) {
87 - $valueCaption = $semanticLink[4];
88 - } else { $valueCaption = ''; }
 86+ if (array_key_exists(5,$semanticLink)) {
 87+ $valueCaption = $semanticLink[5];
 88+ } else { $valueCaption = false; }
8989
9090 //extract annotations and create tooltip
9191 $attributes = explode(':=', $attribute);
9292 foreach($attributes as $singleAttribute) {
93 - $attr = SMWFactbox::addAttribute($singleAttribute,$value);
 93+ $attr = SMWFactbox::addAttribute($singleAttribute,$value,$valueCaption);
9494 }
9595
96 - //set text for result
97 - if ('' == $valueCaption) {
98 - $result = $attr->getShortWikitext(true);
99 - } else {
100 - $result = mb_substr( $valueCaption, 1 ); // remove initial '|'
101 - }
102 -
103 - // Set tooltip for result. smwfParserAfterTidyHook() matches this
104 - // HTML to add JavaScript to the final article.
105 - if ($attr->getTooltip() != '') {
106 - $result = '<span id="SMWtt" title="' . $attr->getTooltip() . '" style="color:#B70">' . $result . '</span>';
107 - } //TODO: the above suggests significant technical improvements
108 - return $result;
 96+ return $attr->getShortWikitext(true);
10997 }
11098
11199
112 -//// Creating tooltips
113 -
114 - /**
115 - * This hook is triggered later during parsing. It inserts HTML code that
116 - * would otherwise be escaped by the MediaWiki parser. Currently it is
117 - * used to build the JavaScript tooltips.
118 - */
119 - function smwfParserAfterTidyHook(&$parser, &$text) {
120 - // Parse span tags around semantic links containing tooltip info.
121 - // Note this must match the exact HTML smwfParseAttributesCallback() adds.
122 - $text = preg_replace_callback(
123 - '{
124 - <span\s*id="SMWtt"\s*title=" # look for HTML of attribute span tag with a title
125 - ([^"]*) # capture title up to closing quote
126 - "[^>]*> # ignore everything to end of opening span tag
127 - (.*?) # capture everything up to closing span tag with a minimal match
128 - </span>
129 - }x',
130 - 'smwfParseAttributesAfterTidyCallback', $text);
131 -
132 - return true; // always return true, in order not to stop MW's hook processing!
133 - }
134 -
135 - /**
136 - * This callback creates a tooltip based on JavaScript. The creation of
137 - * the respective tags has to be performed after "TidyParse" in order to
138 - * push the required HTML Tags (a, script) to the code. These would be
139 - * escaped when inserted at an earlier stage.
140 - */
141 - function smwfParseAttributesAfterTidyCallback($semanticLink) {
142 - // Here we read the data hosted in the "span"-container. A toolTip
143 - // is created to show the attribute values. To invoke the tooltip,
144 - // we have to use a javaScript function (createToolTip) which writes
145 - // a toolTip (div-Tag) to the document. Since the script-Tag would cause
146 - // a line break, we have to surround everything with a span-Tag.
147 -
148 - // if the tip is given as an array, we print each value as a line;
149 - if ((strstr(' = ', $semanticLink[1]) != -1) or (strstr(', ', $semanticLink[1]))) {
150 - $tip = str_replace(array(' = ', ', '),'<br/>', $semanticLink[1]);
151 - } else {
152 - $tip = $semanticLink[1];
153 - }
154 - $result = '<span class="smwttinline">' . $semanticLink[2] . '<span class="smwttcontent">' . $tip . '</span></span>';
155 - return $result;
156 - }
157 -
158 -
159100 //// Saving, deleting, and moving articles
160101
161102 /**
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -51,7 +51,7 @@
5252 * It returns an array which contains the result of the operation in
5353 * various formats.
5454 */
55 - static function addAttribute($attribute, $value) {
 55+ static function addAttribute($attribute, $value, $caption) {
5656 global $smwgContLang, $smwgStoreActive;
5757 // See if this attribute is a special one like e.g. "Has unit"
5858 $attribute = smwfNormalTitleText($attribute); //slightly normalize label
@@ -60,23 +60,23 @@
6161
6262 switch ($special) {
6363 case false: // normal attribute
64 - $result = SMWDataValueFactory::newAttributeValue($attribute,$value);
 64+ $result = SMWDataValueFactory::newAttributeValue($attribute,$value,$caption);
6565 if ($smwgStoreActive) {
6666 SMWFactbox::$semdata->addAttributeTextValue($attribute,$result);
6767 }
6868 return $result;
6969 case SMW_SP_IMPORTED_FROM: // this requires special handling
70 - return SMWFactbox::addImportedDefinition($value);
 70+ return SMWFactbox::addImportedDefinition($value,$caption);
7171 default: // generic special attribute
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 = SMWDataValueFactory::newSpecialValue($special,$v);
 75+ $result = SMWDataValueFactory::newSpecialValue($special,$v,$caption);
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 = SMWDataValueFactory::newSpecialValue($special,$value);
 80+ $result = SMWDataValueFactory::newSpecialValue($special,$value,$caption);
8181 }
8282 if ($smwgStoreActive) {
8383 SMWFactbox::$semdata->addSpecialValue($special,$result);
@@ -125,14 +125,15 @@
126126 * the factbox, since some do not have a translated name (and thus also
127127 * could not be specified directly).
128128 */
129 - static private function addImportedDefinition($value) {
 129+ static private function addImportedDefinition($value,$caption) {
130130 global $wgContLang, $smwgStoreActive;
131131
132132 list($onto_ns,$onto_section) = explode(':',$value,2);
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 = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler(wfMsgForContent('smw_unknown_importns',$onto_ns)),$value);
 136+ /// TODO: use new Error DV
 137+ $datavalue = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler(wfMsgForContent('smw_unknown_importns',$onto_ns)),$value,$caption);
137138 if ($smwgStoreActive) {
138139 SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM,$datavalue);
139140 }
@@ -187,13 +188,17 @@
188189 }
189190
190191 if (NULL != $error) {
191 - $datavalue = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler($error),$value);
 192+ /// TODO: use new Error DV
 193+ $datavalue = SMWDataValueFactory::newTypeHandlerValue(new SMWErrorTypeHandler($error),$value,$caption);
192194 if ($smwgStoreActive) {
193195 SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM, $datavalue);
194196 }
195197 return $datavalue;
196198 }
197199
 200+
 201+ ///TODO: use new DVs
 202+
198203 // Note: the following just overwrites any existing values for the given
199204 // special properties, since they can only have one value anyway; this
200205 // might hide errors -- should we care?
@@ -212,7 +217,7 @@
213218 }
214219
215220 // print the input (this property is usually not stored, see SMW_SQLStore.php)
216 - $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,"[$onto_uri$onto_section $value]");
 221+ $datavalue = SMWDataValueFactory::newTypeHandlerValue($sth,"[$onto_uri$onto_section $value]",$caption);
217222 // TODO: Unfortunatelly, the following line can break the tooltip code if $onto_name has markup. -- mak
218223 // if ('' != $onto_name) $datavalue->setPrintoutString($onto_name, 'onto_name');
219224 if ('' != $onto_name) $datavalue->setPrintoutString("[$onto_uri$onto_section $value] ($onto_name)");
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
@@ -11,7 +11,12 @@
1212 define('SMW_URI_MODE_URL',1);
1313 define('SMW_URI_MODE_URI',2);
1414 define('SMW_URI_MODE_ANNOURI',3);
15 -
 15+
 16+
 17+/**
 18+ * FIXME: correctly support caption ($this->m_caption).
 19+ * FIXME: correctly create safe HTML and Wiki text.
 20+ */
1621 class SMWURIValue extends SMWDataValue {
1722
1823 private $m_error = '';
@@ -34,7 +39,10 @@
3540 }
3641 }
3742
38 - public function setUserValue($value) {
 43+ protected function parseUserValue($value) {
 44+ if ($this->m_caption === false) {
 45+ $this->m_caption = $value;
 46+ }
3947 if ($value!='') { //do not accept empty strings
4048 switch ($this->m_mode) {
4149 case SMW_URI_MODE_URL:
@@ -57,22 +65,21 @@
5866 } else {
5967 $this->m_error = (wfMsgForContent('smw_emptystring'));
6068 }
61 -
6269 return true;
6370
6471 }
6572
66 - public function setXSDValue($value, $unit) {
67 - $this-> setUserValue($value);
 73+ protected function parseXSDValue($value, $unit) {
 74+ $this->setUserValue($value);
6875 }
6976
7077 public function setOutputFormat($formatstring){
7178 //TODO
7279 }
7380
74 - public function getShortWikiText($linked = NULL) {
 81+ public function getShortWikiText($linked = NULL) {
7582 //TODO: Support linking
76 - wfDebug("\r\n getShortWikiText: ".$this->m_value);
 83+ wfDebug("\r\n getShortWikiText: ".$this->m_caption);
7784 return $this->m_value;
7885 }
7986
@@ -80,24 +87,24 @@
8188 return $this->getShortWikiText($linker);
8289 }
8390
84 - public function getLongWikiText($linked = NULL) {
 91+ public function getLongWikiText($linked = NULL) {
8592 if (! ($this->m_error === '')){
86 - return ('<span class="smwwarning">' . $this->m_error . '</span>');
87 - }else {
 93+ return ('<span class="smwwarning">' . $this->m_error . '</span>');
 94+ } else {
8895 return $this->getShortWikiText($linked);
89 - }
 96+ }
9097 }
9198
9299 public function getLongHTMLText($linker = NULL) {
93 - return '<span class="external free">'.$this->m_value.'</span>';
 100+ return '<span class="external free">'.$this->m_caption.'</span>';
94101 }
95102
96103 public function getXSDValue() {
97 - return $this->getShortWikiText(false);
 104+ return $this->getShortWikiText(false); ///FIXME
98105 }
99106
100107 public function getWikiValue(){
101 - return $this->getShortWikiText(false);
 108+ return $this->getShortWikiText(false); /// FIXME (wikivalue must not be influenced by the caption)
102109 }
103110
104111 public function getNumericValue() {
@@ -117,7 +124,7 @@
118125 case SMW_URI_MODE_URL: return 'url';
119126 case SMW_URI_MODE_URI: return 'uri';
120127 case SMW_URI_MODE_ANNOURI: return 'annouri';
121 - }
 128+ }
122129 return 'uri';
123130 }
124131
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -111,7 +111,6 @@
112112 $wgHooks['ParserAfterStrip'][] = 'smwfParserHook'; //default setting
113113 }
114114
115 - $wgHooks['ParserAfterTidy'][] = 'smwfParserAfterTidyHook';
116115 $wgHooks['ArticleSaveComplete'][] = 'smwfSaveHook';
117116 $wgHooks['ArticleDelete'][] = 'smwfDeleteHook';
118117 $wgHooks['TitleMoveComplete'][]='smwfMoveHook';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
@@ -15,7 +15,7 @@
1616 private $m_error = '';
1717 private $m_xsdvalue = false;
1818
19 - public function setUserValue($value) {
 19+ protected function parseUserValue($value) {
2020 // no use for being lazy here: plain user values are never useful
2121 $this->m_typelabels = array();
2222 $types = explode(';', $value);
@@ -29,7 +29,7 @@
3030 }
3131 }
3232
33 - public function setXSDValue($value, $unit) {
 33+ protected function parseXSDValue($value, $unit) {
3434 $this->m_xsdvalue = $value; // lazy parsing
3535 }
3636
@@ -39,8 +39,15 @@
4040
4141 public function getShortWikiText($linked = NULL) {
4242 if ( ($linked === NULL) || ($linked === false) ) {
43 - return str_replace('_',' ',implode(', ', $this->getTypeLabels()));
 43+ if ($this->m_caption === false) {
 44+ return str_replace('_',' ',implode(', ', $this->getTypeLabels()));
 45+ } else {
 46+ return $this->m_caption;
 47+ }
4448 } else {
 49+ if ($this->m_caption !== false) { ///TODO: how can we support linking for nary texts?
 50+ return $this->m_caption;
 51+ }
4552 global $wgContLang;
4653 $result = '';
4754 $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -39,16 +39,16 @@
4040 * If no value is given, an empty container is created, the value of which
4141 * can be set later on.
4242 */
43 - static public function newAttributeValue($attstring, $value=false) {
 43+ static public function newAttributeValue($attstring, $value=false, $caption=false) {
4444 if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache
45 - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 45+ return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $caption, $attstring);
4646 } // else: find type for attribute:
4747
4848 $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE);
4949 if ($atitle !== NULL) {
50 - return SMWDataValueFactory::newAttributeObjectValue($atitle,$value);
 50+ return SMWDataValueFactory::newAttributeObjectValue($atitle,$value,$caption);
5151 } else {
52 - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value);
 52+ return new SMWErrorValue(wfMsgForContent('smw_notype'),$value,$caption);
5353 }
5454 }
5555
@@ -57,23 +57,23 @@
5858 * If no value is given, an empty container is created, the value of which
5959 * can be set later on.
6060 */
61 - static public function newAttributeObjectValue(Title $att, $value=false) {
 61+ static public function newAttributeObjectValue(Title $att, $value=false, $caption=false) {
6262 SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG
6363 $attstring = $att->getText();
6464 if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache
65 - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 65+ return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $caption, $attstring);
6666 } // else: find type for attribute:
6767
6868 $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE);
6969 if (count($typearray)==1) {
7070 SMWDataValueFactory::$m_typelabels[$attstring] = $typearray[0];
71 - $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring);
 71+ $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $caption, $attstring);
7272 SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid
7373 return $result;
7474 } elseif (count($typearray)==0) {
75 - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value);
 75+ return new SMWErrorValue(wfMsgForContent('smw_notype'), $value, $caption);
7676 } else {
77 - return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value);
 77+ return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value, $caption);
7878 }
7979 }
8080
@@ -83,7 +83,7 @@
8484 * If no value is given, an empty container is created, the value of which
8585 * can be set later on.
8686 */
87 - static public function newSpecialValue($specialprop, $value=false) {
 87+ static public function newSpecialValue($specialprop, $value=false, $caption=false) {
8888 ///TODO
8989 switch ($specialprop) {
9090 case SMW_SP_HAS_TYPE:
@@ -109,7 +109,7 @@
110110 }
111111
112112 if ($value !== false) {
113 - $result->setUserValue($value);
 113+ $result->setUserValue($value,$caption);
114114 }
115115 return $result;
116116 }
@@ -120,9 +120,10 @@
121121 * can be set later on.
122122 * @param $typevalue datavalue representing the type of the object
123123 * @param $value user value string, or false if unknown
 124+ * @param $caption user-defined caption or false if none given
124125 * @param $attstring text name of according attribute, or false (may be relevant for getting further parameters)
125126 */
126 - static public function newTypedValue(SMWDataValue $typevalue, $value=false, $attstring=false) {
 127+ static public function newTypedValue(SMWDataValue $typevalue, $value=false, $caption=false, $attstring=false) {
127128 if (array_key_exists($typevalue->getWikiValue(), SMWDataValueFactory::$m_valueclasses)) {
128129 $vc = SMWDataValueFactory::$m_valueclasses[$typevalue->getWikiValue()];
129130 // check if class file was already included for this class
@@ -146,7 +147,7 @@
147148 include_once($smwgIP . '/includes/SMW_DV_NAry.php');
148149 SMWDataValueFactory::$m_naryincluded = true;
149150 }
150 - return new SMWNAryValue($typevalue, $value);
 151+ return new SMWNAryValue($typevalue, $value, $caption);
151152 } else {
152153 ///TODO migrate to new system
153154 $type = SMWTypeHandlerFactory::getTypeHandlerByLabel($typevalue->getWikiValue());
@@ -158,7 +159,7 @@
159160 $result->setAttribute($attstring);
160161 }
161162 if ($value !== false) {
162 - $result->setUserValue($value);
 163+ $result->setUserValue($value,$caption);
163164 }
164165 return $result;
165166 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
@@ -13,13 +13,16 @@
1414 private $m_xsdvalue = '';
1515 private $m_infolinks = Array();
1616
17 - public function setUserValue($value) {
 17+ protected function parseUserValue($value) {
 18+ if ($this->m_caption === false) {
 19+ $this->m_caption = $value;
 20+ }
1821 if ($value!='') {
1922 $this->m_xsdvalue = smwfXMLContentEncode($value);
2023 // 255 below matches smw_attributes.value_xsd definition in smwfMakeSemanticTables()
2124 if (strlen($this->m_xsdvalue) > 255) {
2225 $this->m_error = wfMsgForContent('smw_maxstring', $this->m_xsdvalue);
23 - $this->m_value = $this->m_xsdvalue;
 26+ $this->m_value = $this->m_xsdvalue;
2427 } else {
2528 $this->m_value = $this->m_xsdvalue;
2629 $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $this->m_value);
@@ -30,41 +33,46 @@
3134 return true;
3235 }
3336
34 - public function setXSDValue($value, $unit) {
35 - $this->setUserValue($value); // no units, XML compatible syntax
 37+ protected function parseXSDValue($value, $unit) {
 38+ $this->parseUserValue($value); // no units, XML compatible syntax
 39+ $this->m_caption = $this->m_value; // this is our output text
3640 }
3741
38 - public function setOutputFormat($formatstring){
39 - //ToDo
 42+ public function setOutputFormat($formatstring) {
 43+ // no output formats
4044 }
4145
4246 public function getShortWikiText($linked = NULL) {
43 - //TODO: Support linking
44 - return $this->m_value;
 47+ //TODO: Support linking?
 48+ return $this->m_caption;
4549 }
4650
4751 public function getShortHTMLText($linker = NULL) {
48 - return $this->getShortWikiText($linker);
 52+ return htmlspecialchars($this->getShortWikiText($linker));
4953 }
5054
5155 public function getLongWikiText($linked = NULL) {
5256 if (! ($this->m_error === '')){
5357 return ('<span class="smwwarning">' . $this->m_error . '</span>');
54 - }else {
 58+ } else {
5559 return $this->getShortWikiText($linked);
5660 }
5761 }
5862
5963 public function getLongHTMLText($linker = NULL) {
60 - return $this->getLongWikiText($linker);
 64+ if (! ($this->m_error === '')){
 65+ return ('<span class="smwwarning">' . $this->m_error . '</span>');
 66+ } else {
 67+ return $this->getShortHTMLText($linked);
 68+ }
6169 }
6270
6371 public function getXSDValue() {
64 - return $this->getShortWikiText();
 72+ return $this->getShortWikiText(); /// FIXME: not correct for special symbols like "Ü" and "&"?
6573 }
6674
6775 public function getWikiValue(){
68 - return $this->getShortWikiText(false);
 76+ return $this->getShortWikiText(); /// FIXME: wikivalue must not be influenced by the caption
6977 }
7078
7179 public function getNumericValue() {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -26,8 +26,10 @@
2727 /**
2828 * constructor to create n-ary data value types and set their initial
2929 * value appropriately.
 30+ *
 31+ * TODO: move all setup of values to parseUserValue and only call setUserValue here.
3032 */
31 - function SMWNAryValue($type, $value) {
 33+ function SMWNAryValue($type, $value,$caption=false) {
3234 $this->m_type = $type;
3335
3436 $types = $type->getTypeValues();
@@ -51,7 +53,7 @@
5254 // Methods derived from abstract class
5355 //
5456
55 - public function setUserValue($value) {
 57+ protected function parseUserValue($value) {
5658 // get DVtypes
5759 $types = $this->m_type->getTypeValues();
5860 // get values supplied by user
@@ -67,7 +69,7 @@
6870 }
6971 }
7072
71 - public function setXSDValue($value, $unit) {
 73+ protected function parseXSDValue($value, $unit) {
7274 // get DVtypes
7375 $types = $this->m_type->getTypeValues();
7476 // get values supplied by user

Status & tagging log