Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | $desc2->addPrintRequest($pr1); |
53 | 53 | $pr2 = new SMWPrintrequest(SMW_PRINT_RELS, 'Borders', Title::newFromText('Relation:Borders')); |
54 | 54 | $desc->addPrintRequest($pr2); |
| 55 | + $desc2->addPrintRequest($pr2); |
55 | 56 | $pr3 = new SMWPrintrequest(SMW_PRINT_ATTS, 'Population', Title::newFromText('Attribute:Population')); |
56 | 57 | $desc->addPrintRequest($pr3); |
57 | 58 | $desc2->addPrintRequest($pr3); |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php |
— | — | @@ -150,19 +150,28 @@ |
151 | 151 | |
152 | 152 | /** |
153 | 153 | * Return the main text representation of the next result object |
154 | | - * (Title or SMWDataValue). Convenience method that would not be |
155 | | - * required if Titles would be but special SMWDataValues. |
| 154 | + * (Title or SMWDataValue) as HTML. Convenience method that would |
| 155 | + * not be required if Titles would be but special SMWDataValues. |
| 156 | + * |
| 157 | + * The parameter $linker controls linking of title values and should |
| 158 | + * be some Linker object (or NULL for no linking). At some stage its |
| 159 | + * interpretation should be part of the generalised SMWDataValue. |
156 | 160 | */ |
157 | | - public function getNextText() { |
| 161 | + public function getNextHTMLText($linker = NULL) { |
158 | 162 | $object = current($this->content); |
159 | 163 | next($this->content); |
160 | 164 | if ($object instanceof SMWDataValue) { //print data values |
161 | | - return $object->getStringValue(); |
| 165 | + return htmlspecialchars($object->getStringValue()); ///TODO: escaping will be done in SMWDataValue |
162 | 166 | } elseif ($object instanceof Title) { // print Title objects |
163 | | - return $object->getPrefixedText(); ///TODO: support optional linking of titles |
164 | | - /// As long as SMWDataValue is not re-implemented to support linking and optional HTML, |
165 | | - /// all solutions here can only be hacks, returning complete HTML links based on some |
166 | | - /// Boolean parameter. |
| 167 | + if ($linker === NULL) { |
| 168 | + return htmlspecialchars($object->getPrefixedText()); |
| 169 | + } else { |
| 170 | + if ($this->printrequest->getMode() == SMW_PRINT_THIS) { // "this" results must exist |
| 171 | + return $linker->makeKnownLinkObj($object); |
| 172 | + } else { |
| 173 | + return $linker->makeLinkObj($object); |
| 174 | + } |
| 175 | + } |
167 | 176 | } else { |
168 | 177 | return false; |
169 | 178 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinters.php |
— | — | @@ -16,12 +16,13 @@ |
17 | 17 | protected $mFormat; // a string identifier describing a valid format |
18 | 18 | protected $mIntro = ''; // text to print before the output in case it is *not* empty |
19 | 19 | protected $mSearchlabel = NULL; // text to use for link to further results, or empty if link should not be shown |
20 | | - protected $mLinkSubj; // should article names of the (unique) subjects be linked? |
21 | | - protected $mLinkObj; // should article names of the objects be linked? |
| 20 | + protected $mLinkFirst; // should article names of the first column be linked? |
| 21 | + protected $mLinkOthers; // should article names of other columns (besides the first) be linked? |
22 | 22 | protected $mDefault = ''; // default return value for empty queries |
23 | 23 | protected $mShowHeaders = true; // should the headers (property names) be printed? |
24 | 24 | protected $mMainLabel = NULL; // label used for displaying the subject, or NULL if none was given |
25 | 25 | protected $mInline; // is this query result "inline" in some page (only then a link to unshown results is created, error handling may also be affected) |
| 26 | + protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time. |
26 | 27 | |
27 | 28 | /** |
28 | 29 | * Constructor. The parameter $format is a format string |
— | — | @@ -31,8 +32,9 @@ |
32 | 33 | global $smwgIQDefaultLinking; |
33 | 34 | $this->mFormat = $format; |
34 | 35 | $this->mInline = $inline; |
35 | | - $this->mLinkSubj = ($smwgIQDefaultLinking != 'none'); |
36 | | - $this->mLinkObj = ($smwgIQDefaultLinking == 'all'); |
| 36 | + $this->mLinkFirst = ($smwgIQDefaultLinking != 'none'); |
| 37 | + $this->mLinkOthers = ($smwgIQDefaultLinking == 'all'); |
| 38 | + $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)? |
37 | 39 | } |
38 | 40 | |
39 | 41 | /** |
— | — | @@ -62,16 +64,16 @@ |
63 | 65 | if (array_key_exists('link', $params)) { |
64 | 66 | switch (strtolower($params['link'])) { |
65 | 67 | case 'head': case 'subject': |
66 | | - $this->mLinkSubj = true; |
67 | | - $this->mLinkObj = false; |
| 68 | + $this->mLinkFirst = true; |
| 69 | + $this->mLinkOthers = false; |
68 | 70 | break; |
69 | 71 | case 'all': |
70 | | - $this->mLinkSubj = true; |
71 | | - $this->mLinkObj = true; |
| 72 | + $this->mLinkFirst = true; |
| 73 | + $this->mLinkOthers = true; |
72 | 74 | break; |
73 | 75 | case 'none': |
74 | | - $this->mLinkSubj = false; |
75 | | - $this->mLinkObj = false; |
| 76 | + $this->mLinkFirst = false; |
| 77 | + $this->mLinkOthers = false; |
76 | 78 | break; |
77 | 79 | } |
78 | 80 | } |
— | — | @@ -96,6 +98,20 @@ |
97 | 99 | */ |
98 | 100 | abstract protected function getHTML($res); |
99 | 101 | |
| 102 | + /** |
| 103 | + * Depending on current linking settings, returns a linker object |
| 104 | + * for making hyperlinks or NULL if no links should be created. |
| 105 | + * |
| 106 | + * @param $firstrow True of this is the first result row (having special linkage settings). |
| 107 | + */ |
| 108 | + protected function getLinker($firstcol = false) { |
| 109 | + if ( ($firstcol && $this->mLinkFirst) || (!$firstcol && $this->mLinkOthers) ) { |
| 110 | + return $this->mLinker; |
| 111 | + } else { |
| 112 | + return NULL; |
| 113 | + } |
| 114 | + } |
| 115 | + |
100 | 116 | } |
101 | 117 | |
102 | 118 | /** |
— | — | @@ -127,7 +143,7 @@ |
128 | 144 | foreach ($row as $field) { |
129 | 145 | $result .= "<td>"; |
130 | 146 | $first = true; |
131 | | - while ( ($text = $field->getNextText()) !== false) { |
| 147 | + while ( ($text = $field->getNextHTMLText($this->getLinker($firstcol))) !== false) { |
132 | 148 | if ($first) $first = false; else $result .= '<br />'; |
133 | 149 | $result .= $text; |
134 | 150 | } |