Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
— | — | @@ -22,6 +22,10 @@ |
23 | 23 | global $smwgIQRunningNumber; |
24 | 24 | SMWOutputs::requireHeadItem(SMW_HEADER_SORTTABLE); |
25 | 25 | |
| 26 | + $printrequestparameters = array(); |
| 27 | + foreach ($res->getPrintRequests() as $pr) |
| 28 | + $printrequestparameters[] = $pr->getParams(); |
| 29 | + |
26 | 30 | // print header |
27 | 31 | $result = '<table class="smwtable"' . |
28 | 32 | ('broadtable' == $this->mFormat?' width="100%"':'') . |
— | — | @@ -38,8 +42,19 @@ |
39 | 43 | while ( $row = $res->getNext() ) { |
40 | 44 | $result .= "\t<tr>\n"; |
41 | 45 | $firstcol = true; |
| 46 | + $fieldcount = -1; |
42 | 47 | foreach ($row as $field) { |
43 | | - $result .= "\t\t<td>"; |
| 48 | + $fieldcount = $fieldcount + 1; |
| 49 | + |
| 50 | + $result .= "\t\t<td"; |
| 51 | + if (array_key_exists('align', $printrequestparameters[$fieldcount])) { |
| 52 | + $alignment = $printrequestparameters[$fieldcount]['align']; |
| 53 | + // check the content, otherwise evil people could inject here anything they wanted |
| 54 | + if (($alignment == 'right') || ($alignment == 'left')) |
| 55 | + $result .= " style=\"text-align:" . $printrequestparameters[$fieldcount]['align'] . ";\""; |
| 56 | + } |
| 57 | + $result .= ">"; |
| 58 | + |
44 | 59 | $first = true; |
45 | 60 | while ( ($object = $field->getNextObject()) !== false ) { |
46 | 61 | if ($first) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -181,6 +181,7 @@ |
182 | 182 | global $wgContLang; |
183 | 183 | $querystring = ''; |
184 | 184 | $printouts = array(); |
| 185 | + $lastprintout = NULL; |
185 | 186 | $params = array(); |
186 | 187 | foreach ($rawparams as $name => $param) { |
187 | 188 | if ( is_string($name) && ($name != '') ) { // accept 'name' => 'value' just as '' => 'name=value' |
— | — | @@ -225,7 +226,14 @@ |
226 | 227 | if (count($parts) > 1) { // label found, use this instead of default |
227 | 228 | $label = trim($parts[1]); |
228 | 229 | } |
229 | | - $printouts[] = new SMWPrintRequest($printmode, $label, $data, trim($propparts[1])); |
| 230 | + $lastprintout = new SMWPrintRequest($printmode, $label, $data, trim($propparts[1])); |
| 231 | + $printouts[] = $lastprintout; |
| 232 | + } elseif ($param[0] == '+') { // print request parameter |
| 233 | + if ($lastprintout != NULL) { |
| 234 | + $param = substr($param,1); |
| 235 | + $parts = explode('=',$param,2); |
| 236 | + $lastprintout->setParam($parts[0], $parts[1]); |
| 237 | + } |
230 | 238 | } else { // parameter or query |
231 | 239 | $parts = explode('=',$param,2); |
232 | 240 | if (count($parts) >= 2) { |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php |
— | — | @@ -28,15 +28,17 @@ |
29 | 29 | protected $m_typeid = false; // id of the datatype of the printed objects, if applicable |
30 | 30 | protected $m_outputformat; // output format string for formatting results, if applicable |
31 | 31 | protected $m_hash = false; // cache your hash (currently useful since SMWQueryResult accesses the hash many times, might be dropped at some point) |
32 | | - |
| 32 | + protected $m_params = array(); |
| 33 | + |
33 | 34 | /** |
34 | 35 | * Create a print request. |
35 | 36 | * @param $mode a constant defining what to printout |
36 | 37 | * @param $label the string label to describe this printout |
37 | 38 | * @param $data optional data for specifying some request, might be a property object, title, or something else; interpretation depends on $mode |
38 | 39 | * @param $outputformat optional string for specifying an output format, e.g. an output unit |
| 40 | + * @param $params optional array of further, named parameters for the print request |
39 | 41 | */ |
40 | | - public function __construct($mode, $label, $data = NULL, $outputformat = false) { |
| 42 | + public function __construct($mode, $label, $data = NULL, $outputformat = false, $params = NULL) { |
41 | 43 | $this->m_mode = $mode; |
42 | 44 | $this->m_label = $label; |
43 | 45 | $this->m_data = $data; |
— | — | @@ -47,6 +49,7 @@ |
48 | 50 | if ($this->m_data instanceof SMWDataValue) { |
49 | 51 | $this->m_data->setCaption($label); |
50 | 52 | } |
| 53 | + if (NULL != $params) $m_params = $params; |
51 | 54 | } |
52 | 55 | |
53 | 56 | public function getMode() { |
— | — | @@ -139,6 +142,9 @@ |
140 | 143 | * print requests. The hash also includes the chosen label, |
141 | 144 | * so it is possible to print the same date with different |
142 | 145 | * labels. |
| 146 | + * TODO: For now, the params are not part of the Hash, but |
| 147 | + * maybe they should? But the hash is used for some things, |
| 148 | + * check that first! |
143 | 149 | */ |
144 | 150 | public function getHash() { |
145 | 151 | if ($this->m_hash === false) { |
— | — | @@ -155,8 +161,14 @@ |
156 | 162 | |
157 | 163 | /** |
158 | 164 | * Serialise this object like print requests given in \#ask. |
| 165 | + * @param $params boolean that sets if the serialization should |
| 166 | + * include the extra print request parameters |
159 | 167 | */ |
160 | | - public function getSerialisation() { |
| 168 | + public function getSerialisation($showparams = false) { |
| 169 | + $parameters = ''; |
| 170 | + if ($showparams) foreach ( $this->m_params as $key => $value ) { |
| 171 | + $parameters .= "|+" . $key . "=" . $value; |
| 172 | + } |
161 | 173 | switch ($this->m_mode) { |
162 | 174 | case SMWPrintRequest::PRINT_CATS: |
163 | 175 | global $wgContLang; |
— | — | @@ -165,7 +177,7 @@ |
166 | 178 | if ($this->m_label != $catlabel) { |
167 | 179 | $result .= '=' . $this->m_label; |
168 | 180 | } |
169 | | - return $result; |
| 181 | + return $result . $parameters; |
170 | 182 | case SMWPrintRequest::PRINT_PROP: case SMWPrintRequest::PRINT_CCAT: |
171 | 183 | if ($this->m_mode == SMWPrintRequest::PRINT_CCAT) { |
172 | 184 | $printname = $this->m_data->getPrefixedText(); |
— | — | @@ -183,9 +195,46 @@ |
184 | 196 | if ( $printname != $this->m_label ) { |
185 | 197 | $result .= '=' . $this->m_label; |
186 | 198 | } |
187 | | - return $result; |
| 199 | + return $result . $parameters; |
188 | 200 | case SMWPrintRequest::PRINT_THIS: default: return ''; // no current serialisation |
189 | 201 | } |
190 | 202 | } |
191 | 203 | |
| 204 | + /** |
| 205 | + * Returns the value of a named parameter. |
| 206 | + * @param $key string the name of the parameter key |
| 207 | + * @return string Value of the paramer, if set (else '') |
| 208 | + */ |
| 209 | + public function getParam($key) { |
| 210 | + if (array_key_exists($key, $this->m_params)) |
| 211 | + return $this->m_params[$key]; |
| 212 | + else |
| 213 | + return ''; |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Returns if a named parameter is set. |
| 218 | + * @param $key string the name of the parameter |
| 219 | + * @return boolean True if the parameter is set, false otherwise |
| 220 | + */ |
| 221 | + public function hasParam($key) { |
| 222 | + return array_key_exists($key, $this->m_params); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Returns the array of parameters, where a string is mapped to a string. |
| 227 | + * @return array Map of parameter names to values. |
| 228 | + */ |
| 229 | + public function getParams() { |
| 230 | + return $this->m_params; |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * Sets a print request parameter. |
| 235 | + * @param $key string Name of the parameter |
| 236 | + * @param $value string Value for the parameter |
| 237 | + */ |
| 238 | + public function setParam($key, $value) { |
| 239 | + $this->m_params[$key] = $value; |
| 240 | + } |
192 | 241 | } |
\ No newline at end of file |