Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php |
— | — | @@ -115,8 +115,6 @@ |
116 | 116 | var $attribute; // wiki name (without namespace) of the attribute that this value was |
117 | 117 | // assigned to, or FALSE if no attribute was given. |
118 | 118 | /**#@-*/ |
119 | | - |
120 | | - private $byxsd = false; // hack hack hack (temporary to ease DV transition) |
121 | 119 | |
122 | 120 | /** |
123 | 121 | * Just initialise variables. To create value objects, use one of the |
— | — | @@ -139,9 +137,11 @@ |
140 | 138 | /** |
141 | 139 | * Set the user value (and compute other representations if possible) |
142 | 140 | */ |
143 | | - function setUserValue($value) { |
| 141 | + protected function parseUserValue($value) { |
| 142 | + if ($this->m_caption === false) { |
| 143 | + $this->m_caption = $value; |
| 144 | + } |
144 | 145 | $this->clear(); |
145 | | - $this->byxsd = false; // DV transition hack to distinguish this case and to use others[0] for XSD-values |
146 | 146 | $this->vuser = $value; |
147 | 147 | //this is needed since typehandlers are not strictly required to |
148 | 148 | //set the user value, especially if errors are reported. |
— | — | @@ -156,8 +156,7 @@ |
157 | 157 | /** |
158 | 158 | * Set the xsd value (and compute other representations if possible) |
159 | 159 | */ |
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) { |
162 | 161 | $this->vxsd = $value; |
163 | 162 | if ($this->type_handler === NULL) { |
164 | 163 | return false; |
— | — | @@ -315,18 +314,21 @@ |
316 | 315 | /*********************************************************************/ |
317 | 316 | |
318 | 317 | 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) { |
322 | 319 | if ( count($this->others) > 0 ) { |
323 | 320 | reset($this->others); |
324 | | - return current($this->others); // return first element |
| 321 | + $result = current($this->others); // return first element |
325 | 322 | } else { |
326 | | - return $this->vuser; |
| 323 | + $result = $this->vuser; |
327 | 324 | } |
328 | 325 | } else { |
329 | | - return $this->vuser; |
| 326 | + $result = $this->m_caption; |
330 | 327 | } |
| 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; |
331 | 333 | } |
332 | 334 | |
333 | 335 | public function getShortHTMLText($linker = NULL) { |
— | — | @@ -491,7 +493,7 @@ |
492 | 494 | foreach ($this->others as $id => $other) { |
493 | 495 | if ( $id !== $this->input ) { |
494 | 496 | $this->tooltip .= $sep . $other; |
495 | | - $sep = ' = '; |
| 497 | + $sep = ' <br /> '; |
496 | 498 | } |
497 | 499 | } |
498 | 500 | } 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 @@ |
10 | 10 | */ |
11 | 11 | abstract class SMWDataValue { |
12 | 12 | |
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 |
14 | 15 | |
15 | | - /*********************************************************************/ |
16 | | - /* Static methods for initialisation */ |
17 | | - /*********************************************************************/ |
| 16 | +///// Set methods ///// |
18 | 17 | |
19 | 18 | /** |
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. |
25 | 22 | */ |
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 |
29 | 28 | } |
30 | 29 | |
31 | 30 | /** |
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 | | - /** |
95 | 31 | * Set the xsd value (and compute other representations if possible). |
96 | 32 | * The given value is a string that was provided by getXSDValue() (all |
97 | 33 | * implementations should support round-tripping). |
98 | 34 | */ |
99 | | - abstract public function setXSDValue($value, $unit); |
| 35 | + public function setXSDValue($value, $unit) { |
| 36 | + $this->m_caption = false; |
| 37 | + $this->parseXSDValue($value, $unit); |
| 38 | + } |
100 | 39 | |
101 | 40 | /** |
102 | 41 | * Set the attribute to which this value refers. Used to generate search links and |
— | — | @@ -116,11 +55,25 @@ |
117 | 56 | */ |
118 | 57 | abstract public function setOutputFormat($formatstring); |
119 | 58 | |
120 | | - /*********************************************************************/ |
121 | | - /* Get methods */ |
122 | | - /*********************************************************************/ |
| 59 | +///// Abstract processing methods ///// |
123 | 60 | |
124 | 61 | /** |
| 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 | + /** |
125 | 78 | * Returns a short textual representation for this data value. If the value |
126 | 79 | * was initialised from a user supplied string, then this original string |
127 | 80 | * should be reflected in this short version (i.e. no normalisation should |
— | — | @@ -234,6 +187,77 @@ |
235 | 188 | */ |
236 | 189 | abstract public function isNumeric(); |
237 | 190 | |
| 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 | + |
238 | 262 | } |
239 | 263 | |
240 | 264 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Error.php |
— | — | @@ -11,52 +11,54 @@ |
12 | 12 | private $m_value; |
13 | 13 | private $m_infolinks = Array(); |
14 | 14 | |
15 | | - public function SMWErrorValue($errormsg = '', $uservalue = '') { |
| 15 | + public function SMWErrorValue($errormsg = '', $uservalue = '', $caption = false) { |
16 | 16 | $this->m_error = $errormsg; |
17 | | - $this->m_value = $uservalue; |
| 17 | + $this->setUserValue($uservalue, $caption); |
18 | 18 | } |
19 | 19 | |
20 | | - public function setUserValue($value) { |
| 20 | + protected function parseUserValue($value) { |
| 21 | + if ($this->m_caption === false) { |
| 22 | + $this->m_caption = $value; |
| 23 | + } |
21 | 24 | $this->m_value = $value; |
22 | 25 | return true; |
23 | 26 | } |
24 | 27 | |
25 | | - public function setXSDValue($value, $unit) { |
| 28 | + protected function parseXSDValue($value, $unit) { |
26 | 29 | $this->setUserValue($value); // no units, compatible syntax |
27 | 30 | } |
28 | 31 | |
29 | 32 | public function setOutputFormat($formatstring){ |
30 | | - //do nothing |
| 33 | + // no output formats |
31 | 34 | } |
32 | 35 | public function setError($errormsg){ |
33 | 36 | $this->m_error = $errormsg; |
34 | 37 | } |
35 | 38 | |
36 | 39 | public function getShortWikiText($linked = NULL) { |
37 | | - //TODO: support linking |
38 | | - return $this->m_value; |
| 40 | + //TODO: support linking? |
| 41 | + return $this->m_caption; |
39 | 42 | } |
40 | 43 | |
41 | 44 | public function getShortHTMLText($linker = NULL) { |
42 | | - return $this->getShortWikiText($linker); |
| 45 | + return htmlspecialchars($this->getShortWikiText($linker)); |
43 | 46 | } |
44 | 47 | |
45 | 48 | public function getLongWikiText($linked = NULL) { |
46 | | - //TODO: support linking |
| 49 | + //TODO: support linking? |
47 | 50 | return '<span class="smwwarning">'.$this->m_error.'</span>'; |
48 | | - |
49 | 51 | } |
50 | 52 | |
51 | | - public function getLongHTMLText($linker = NULL) { |
| 53 | + public function getLongHTMLText($linker = NULL) { |
52 | 54 | return $this->getLongWikiText($linker); |
53 | 55 | } |
54 | 56 | |
55 | 57 | public function getXSDValue() { |
56 | | - return $this->getShortWikiText(false); |
| 58 | + return $this->getShortWikiText(); ///TODO: really? (errors are not meant to be saved, or are they?) |
57 | 59 | } |
58 | 60 | |
59 | 61 | public function getWikiValue(){ |
60 | | - return $this->getShortWikiText(false); |
| 62 | + return $this->getShortWikiText(); /// FIXME: wikivalue must not be influenced by the caption |
61 | 63 | } |
62 | 64 | |
63 | 65 | public function getNumericValue() { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php |
— | — | @@ -82,79 +82,20 @@ |
83 | 83 | if (array_key_exists(3,$semanticLink)) { |
84 | 84 | $value = $semanticLink[3]; |
85 | 85 | } 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; } |
89 | 89 | |
90 | 90 | //extract annotations and create tooltip |
91 | 91 | $attributes = explode(':=', $attribute); |
92 | 92 | foreach($attributes as $singleAttribute) { |
93 | | - $attr = SMWFactbox::addAttribute($singleAttribute,$value); |
| 93 | + $attr = SMWFactbox::addAttribute($singleAttribute,$value,$valueCaption); |
94 | 94 | } |
95 | 95 | |
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); |
109 | 97 | } |
110 | 98 | |
111 | 99 | |
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 | | - |
159 | 100 | //// Saving, deleting, and moving articles |
160 | 101 | |
161 | 102 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | * It returns an array which contains the result of the operation in |
53 | 53 | * various formats. |
54 | 54 | */ |
55 | | - static function addAttribute($attribute, $value) { |
| 55 | + static function addAttribute($attribute, $value, $caption) { |
56 | 56 | global $smwgContLang, $smwgStoreActive; |
57 | 57 | // See if this attribute is a special one like e.g. "Has unit" |
58 | 58 | $attribute = smwfNormalTitleText($attribute); //slightly normalize label |
— | — | @@ -60,23 +60,23 @@ |
61 | 61 | |
62 | 62 | switch ($special) { |
63 | 63 | case false: // normal attribute |
64 | | - $result = SMWDataValueFactory::newAttributeValue($attribute,$value); |
| 64 | + $result = SMWDataValueFactory::newAttributeValue($attribute,$value,$caption); |
65 | 65 | if ($smwgStoreActive) { |
66 | 66 | SMWFactbox::$semdata->addAttributeTextValue($attribute,$result); |
67 | 67 | } |
68 | 68 | return $result; |
69 | 69 | case SMW_SP_IMPORTED_FROM: // this requires special handling |
70 | | - return SMWFactbox::addImportedDefinition($value); |
| 70 | + return SMWFactbox::addImportedDefinition($value,$caption); |
71 | 71 | default: // generic special attribute |
72 | 72 | if ( $special === SMW_SP_SERVICE_LINK ) { // do some custom formatting in this case |
73 | 73 | global $wgContLang; |
74 | 74 | $v = str_replace(' ', '_', $value); //normalize slightly since messages distinguish '_' and ' ' |
75 | | - $result = SMWDataValueFactory::newSpecialValue($special,$v); |
| 75 | + $result = SMWDataValueFactory::newSpecialValue($special,$v,$caption); |
76 | 76 | $v = $result->getXSDValue(); //possibly further sanitized, so let's be cautious |
77 | 77 | $result->setProcessedValues($value,$v); //set user value back to the input version |
78 | 78 | $result->setPrintoutString('[[' . $wgContLang->getNsText(NS_MEDIAWIKI) . ':smw_service_' . $v . "|$value]]"); |
79 | 79 | } else { // standard processing |
80 | | - $result = SMWDataValueFactory::newSpecialValue($special,$value); |
| 80 | + $result = SMWDataValueFactory::newSpecialValue($special,$value,$caption); |
81 | 81 | } |
82 | 82 | if ($smwgStoreActive) { |
83 | 83 | SMWFactbox::$semdata->addSpecialValue($special,$result); |
— | — | @@ -125,14 +125,15 @@ |
126 | 126 | * the factbox, since some do not have a translated name (and thus also |
127 | 127 | * could not be specified directly). |
128 | 128 | */ |
129 | | - static private function addImportedDefinition($value) { |
| 129 | + static private function addImportedDefinition($value,$caption) { |
130 | 130 | global $wgContLang, $smwgStoreActive; |
131 | 131 | |
132 | 132 | list($onto_ns,$onto_section) = explode(':',$value,2); |
133 | 133 | $msglines = preg_split("([\n][\s]?)",wfMsgForContent("smw_import_$onto_ns")); // get the definition for "$namespace:$section" |
134 | 134 | |
135 | 135 | 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); |
137 | 138 | if ($smwgStoreActive) { |
138 | 139 | SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM,$datavalue); |
139 | 140 | } |
— | — | @@ -187,13 +188,17 @@ |
188 | 189 | } |
189 | 190 | |
190 | 191 | 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); |
192 | 194 | if ($smwgStoreActive) { |
193 | 195 | SMWFactbox::$semdata->addSpecialValue(SMW_SP_IMPORTED_FROM, $datavalue); |
194 | 196 | } |
195 | 197 | return $datavalue; |
196 | 198 | } |
197 | 199 | |
| 200 | + |
| 201 | + ///TODO: use new DVs |
| 202 | + |
198 | 203 | // Note: the following just overwrites any existing values for the given |
199 | 204 | // special properties, since they can only have one value anyway; this |
200 | 205 | // might hide errors -- should we care? |
— | — | @@ -212,7 +217,7 @@ |
213 | 218 | } |
214 | 219 | |
215 | 220 | // 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); |
217 | 222 | // TODO: Unfortunatelly, the following line can break the tooltip code if $onto_name has markup. -- mak |
218 | 223 | // if ('' != $onto_name) $datavalue->setPrintoutString($onto_name, 'onto_name'); |
219 | 224 | 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 @@ |
12 | 12 | define('SMW_URI_MODE_URL',1); |
13 | 13 | define('SMW_URI_MODE_URI',2); |
14 | 14 | 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 | + */ |
16 | 21 | class SMWURIValue extends SMWDataValue { |
17 | 22 | |
18 | 23 | private $m_error = ''; |
— | — | @@ -34,7 +39,10 @@ |
35 | 40 | } |
36 | 41 | } |
37 | 42 | |
38 | | - public function setUserValue($value) { |
| 43 | + protected function parseUserValue($value) { |
| 44 | + if ($this->m_caption === false) { |
| 45 | + $this->m_caption = $value; |
| 46 | + } |
39 | 47 | if ($value!='') { //do not accept empty strings |
40 | 48 | switch ($this->m_mode) { |
41 | 49 | case SMW_URI_MODE_URL: |
— | — | @@ -57,22 +65,21 @@ |
58 | 66 | } else { |
59 | 67 | $this->m_error = (wfMsgForContent('smw_emptystring')); |
60 | 68 | } |
61 | | - |
62 | 69 | return true; |
63 | 70 | |
64 | 71 | } |
65 | 72 | |
66 | | - public function setXSDValue($value, $unit) { |
67 | | - $this-> setUserValue($value); |
| 73 | + protected function parseXSDValue($value, $unit) { |
| 74 | + $this->setUserValue($value); |
68 | 75 | } |
69 | 76 | |
70 | 77 | public function setOutputFormat($formatstring){ |
71 | 78 | //TODO |
72 | 79 | } |
73 | 80 | |
74 | | - public function getShortWikiText($linked = NULL) { |
| 81 | + public function getShortWikiText($linked = NULL) { |
75 | 82 | //TODO: Support linking |
76 | | - wfDebug("\r\n getShortWikiText: ".$this->m_value); |
| 83 | + wfDebug("\r\n getShortWikiText: ".$this->m_caption); |
77 | 84 | return $this->m_value; |
78 | 85 | } |
79 | 86 | |
— | — | @@ -80,24 +87,24 @@ |
81 | 88 | return $this->getShortWikiText($linker); |
82 | 89 | } |
83 | 90 | |
84 | | - public function getLongWikiText($linked = NULL) { |
| 91 | + public function getLongWikiText($linked = NULL) { |
85 | 92 | 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 { |
88 | 95 | return $this->getShortWikiText($linked); |
89 | | - } |
| 96 | + } |
90 | 97 | } |
91 | 98 | |
92 | 99 | 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>'; |
94 | 101 | } |
95 | 102 | |
96 | 103 | public function getXSDValue() { |
97 | | - return $this->getShortWikiText(false); |
| 104 | + return $this->getShortWikiText(false); ///FIXME |
98 | 105 | } |
99 | 106 | |
100 | 107 | public function getWikiValue(){ |
101 | | - return $this->getShortWikiText(false); |
| 108 | + return $this->getShortWikiText(false); /// FIXME (wikivalue must not be influenced by the caption) |
102 | 109 | } |
103 | 110 | |
104 | 111 | public function getNumericValue() { |
— | — | @@ -117,7 +124,7 @@ |
118 | 125 | case SMW_URI_MODE_URL: return 'url'; |
119 | 126 | case SMW_URI_MODE_URI: return 'uri'; |
120 | 127 | case SMW_URI_MODE_ANNOURI: return 'annouri'; |
121 | | - } |
| 128 | + } |
122 | 129 | return 'uri'; |
123 | 130 | } |
124 | 131 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -111,7 +111,6 @@ |
112 | 112 | $wgHooks['ParserAfterStrip'][] = 'smwfParserHook'; //default setting |
113 | 113 | } |
114 | 114 | |
115 | | - $wgHooks['ParserAfterTidy'][] = 'smwfParserAfterTidyHook'; |
116 | 115 | $wgHooks['ArticleSaveComplete'][] = 'smwfSaveHook'; |
117 | 116 | $wgHooks['ArticleDelete'][] = 'smwfDeleteHook'; |
118 | 117 | $wgHooks['TitleMoveComplete'][]='smwfMoveHook'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | private $m_error = ''; |
17 | 17 | private $m_xsdvalue = false; |
18 | 18 | |
19 | | - public function setUserValue($value) { |
| 19 | + protected function parseUserValue($value) { |
20 | 20 | // no use for being lazy here: plain user values are never useful |
21 | 21 | $this->m_typelabels = array(); |
22 | 22 | $types = explode(';', $value); |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | | - public function setXSDValue($value, $unit) { |
| 33 | + protected function parseXSDValue($value, $unit) { |
34 | 34 | $this->m_xsdvalue = $value; // lazy parsing |
35 | 35 | } |
36 | 36 | |
— | — | @@ -39,8 +39,15 @@ |
40 | 40 | |
41 | 41 | public function getShortWikiText($linked = NULL) { |
42 | 42 | 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 | + } |
44 | 48 | } else { |
| 49 | + if ($this->m_caption !== false) { ///TODO: how can we support linking for nary texts? |
| 50 | + return $this->m_caption; |
| 51 | + } |
45 | 52 | global $wgContLang; |
46 | 53 | $result = ''; |
47 | 54 | $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -39,16 +39,16 @@ |
40 | 40 | * If no value is given, an empty container is created, the value of which |
41 | 41 | * can be set later on. |
42 | 42 | */ |
43 | | - static public function newAttributeValue($attstring, $value=false) { |
| 43 | + static public function newAttributeValue($attstring, $value=false, $caption=false) { |
44 | 44 | 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); |
46 | 46 | } // else: find type for attribute: |
47 | 47 | |
48 | 48 | $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE); |
49 | 49 | if ($atitle !== NULL) { |
50 | | - return SMWDataValueFactory::newAttributeObjectValue($atitle,$value); |
| 50 | + return SMWDataValueFactory::newAttributeObjectValue($atitle,$value,$caption); |
51 | 51 | } else { |
52 | | - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value); |
| 52 | + return new SMWErrorValue(wfMsgForContent('smw_notype'),$value,$caption); |
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
— | — | @@ -57,23 +57,23 @@ |
58 | 58 | * If no value is given, an empty container is created, the value of which |
59 | 59 | * can be set later on. |
60 | 60 | */ |
61 | | - static public function newAttributeObjectValue(Title $att, $value=false) { |
| 61 | + static public function newAttributeObjectValue(Title $att, $value=false, $caption=false) { |
62 | 62 | SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG |
63 | 63 | $attstring = $att->getText(); |
64 | 64 | 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); |
66 | 66 | } // else: find type for attribute: |
67 | 67 | |
68 | 68 | $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE); |
69 | 69 | if (count($typearray)==1) { |
70 | 70 | 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); |
72 | 72 | SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid |
73 | 73 | return $result; |
74 | 74 | } elseif (count($typearray)==0) { |
75 | | - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value); |
| 75 | + return new SMWErrorValue(wfMsgForContent('smw_notype'), $value, $caption); |
76 | 76 | } else { |
77 | | - return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value); |
| 77 | + return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value, $caption); |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | * If no value is given, an empty container is created, the value of which |
85 | 85 | * can be set later on. |
86 | 86 | */ |
87 | | - static public function newSpecialValue($specialprop, $value=false) { |
| 87 | + static public function newSpecialValue($specialprop, $value=false, $caption=false) { |
88 | 88 | ///TODO |
89 | 89 | switch ($specialprop) { |
90 | 90 | case SMW_SP_HAS_TYPE: |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | } |
111 | 111 | |
112 | 112 | if ($value !== false) { |
113 | | - $result->setUserValue($value); |
| 113 | + $result->setUserValue($value,$caption); |
114 | 114 | } |
115 | 115 | return $result; |
116 | 116 | } |
— | — | @@ -120,9 +120,10 @@ |
121 | 121 | * can be set later on. |
122 | 122 | * @param $typevalue datavalue representing the type of the object |
123 | 123 | * @param $value user value string, or false if unknown |
| 124 | + * @param $caption user-defined caption or false if none given |
124 | 125 | * @param $attstring text name of according attribute, or false (may be relevant for getting further parameters) |
125 | 126 | */ |
126 | | - static public function newTypedValue(SMWDataValue $typevalue, $value=false, $attstring=false) { |
| 127 | + static public function newTypedValue(SMWDataValue $typevalue, $value=false, $caption=false, $attstring=false) { |
127 | 128 | if (array_key_exists($typevalue->getWikiValue(), SMWDataValueFactory::$m_valueclasses)) { |
128 | 129 | $vc = SMWDataValueFactory::$m_valueclasses[$typevalue->getWikiValue()]; |
129 | 130 | // check if class file was already included for this class |
— | — | @@ -146,7 +147,7 @@ |
147 | 148 | include_once($smwgIP . '/includes/SMW_DV_NAry.php'); |
148 | 149 | SMWDataValueFactory::$m_naryincluded = true; |
149 | 150 | } |
150 | | - return new SMWNAryValue($typevalue, $value); |
| 151 | + return new SMWNAryValue($typevalue, $value, $caption); |
151 | 152 | } else { |
152 | 153 | ///TODO migrate to new system |
153 | 154 | $type = SMWTypeHandlerFactory::getTypeHandlerByLabel($typevalue->getWikiValue()); |
— | — | @@ -158,7 +159,7 @@ |
159 | 160 | $result->setAttribute($attstring); |
160 | 161 | } |
161 | 162 | if ($value !== false) { |
162 | | - $result->setUserValue($value); |
| 163 | + $result->setUserValue($value,$caption); |
163 | 164 | } |
164 | 165 | return $result; |
165 | 166 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php |
— | — | @@ -13,13 +13,16 @@ |
14 | 14 | private $m_xsdvalue = ''; |
15 | 15 | private $m_infolinks = Array(); |
16 | 16 | |
17 | | - public function setUserValue($value) { |
| 17 | + protected function parseUserValue($value) { |
| 18 | + if ($this->m_caption === false) { |
| 19 | + $this->m_caption = $value; |
| 20 | + } |
18 | 21 | if ($value!='') { |
19 | 22 | $this->m_xsdvalue = smwfXMLContentEncode($value); |
20 | 23 | // 255 below matches smw_attributes.value_xsd definition in smwfMakeSemanticTables() |
21 | 24 | if (strlen($this->m_xsdvalue) > 255) { |
22 | 25 | $this->m_error = wfMsgForContent('smw_maxstring', $this->m_xsdvalue); |
23 | | - $this->m_value = $this->m_xsdvalue; |
| 26 | + $this->m_value = $this->m_xsdvalue; |
24 | 27 | } else { |
25 | 28 | $this->m_value = $this->m_xsdvalue; |
26 | 29 | $this->m_infolinks[] = SMWInfolink::newAttributeSearchLink('+', $this->m_attribute, $this->m_value); |
— | — | @@ -30,41 +33,46 @@ |
31 | 34 | return true; |
32 | 35 | } |
33 | 36 | |
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 |
36 | 40 | } |
37 | 41 | |
38 | | - public function setOutputFormat($formatstring){ |
39 | | - //ToDo |
| 42 | + public function setOutputFormat($formatstring) { |
| 43 | + // no output formats |
40 | 44 | } |
41 | 45 | |
42 | 46 | public function getShortWikiText($linked = NULL) { |
43 | | - //TODO: Support linking |
44 | | - return $this->m_value; |
| 47 | + //TODO: Support linking? |
| 48 | + return $this->m_caption; |
45 | 49 | } |
46 | 50 | |
47 | 51 | public function getShortHTMLText($linker = NULL) { |
48 | | - return $this->getShortWikiText($linker); |
| 52 | + return htmlspecialchars($this->getShortWikiText($linker)); |
49 | 53 | } |
50 | 54 | |
51 | 55 | public function getLongWikiText($linked = NULL) { |
52 | 56 | if (! ($this->m_error === '')){ |
53 | 57 | return ('<span class="smwwarning">' . $this->m_error . '</span>'); |
54 | | - }else { |
| 58 | + } else { |
55 | 59 | return $this->getShortWikiText($linked); |
56 | 60 | } |
57 | 61 | } |
58 | 62 | |
59 | 63 | 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 | + } |
61 | 69 | } |
62 | 70 | |
63 | 71 | public function getXSDValue() { |
64 | | - return $this->getShortWikiText(); |
| 72 | + return $this->getShortWikiText(); /// FIXME: not correct for special symbols like "Ü" and "&"? |
65 | 73 | } |
66 | 74 | |
67 | 75 | public function getWikiValue(){ |
68 | | - return $this->getShortWikiText(false); |
| 76 | + return $this->getShortWikiText(); /// FIXME: wikivalue must not be influenced by the caption |
69 | 77 | } |
70 | 78 | |
71 | 79 | public function getNumericValue() { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php |
— | — | @@ -26,8 +26,10 @@ |
27 | 27 | /** |
28 | 28 | * constructor to create n-ary data value types and set their initial |
29 | 29 | * value appropriately. |
| 30 | + * |
| 31 | + * TODO: move all setup of values to parseUserValue and only call setUserValue here. |
30 | 32 | */ |
31 | | - function SMWNAryValue($type, $value) { |
| 33 | + function SMWNAryValue($type, $value,$caption=false) { |
32 | 34 | $this->m_type = $type; |
33 | 35 | |
34 | 36 | $types = $type->getTypeValues(); |
— | — | @@ -51,7 +53,7 @@ |
52 | 54 | // Methods derived from abstract class |
53 | 55 | // |
54 | 56 | |
55 | | - public function setUserValue($value) { |
| 57 | + protected function parseUserValue($value) { |
56 | 58 | // get DVtypes |
57 | 59 | $types = $this->m_type->getTypeValues(); |
58 | 60 | // get values supplied by user |
— | — | @@ -67,7 +69,7 @@ |
68 | 70 | } |
69 | 71 | } |
70 | 72 | |
71 | | - public function setXSDValue($value, $unit) { |
| 73 | + protected function parseXSDValue($value, $unit) { |
72 | 74 | // get DVtypes |
73 | 75 | $types = $this->m_type->getTypeValues(); |
74 | 76 | // get values supplied by user |