Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php |
— | — | @@ -167,8 +167,7 @@ |
168 | 168 | if ('' != $this->m_params['order']) $urltail .= '&order=' . $this->m_params['order']; |
169 | 169 | |
170 | 170 | if ($this->m_querystring != '') { |
171 | | - $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, false, '', $this->m_printouts); |
172 | | - $queryobj->querymode = SMWQuery::MODE_INSTANCES; ///TODO: Somewhat hacky (just as the query mode computation in SMWQueryProcessor::createQuery!) |
| 171 | + $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE , $this->m_params['format'], $this->m_printouts); |
173 | 172 | $res = smwfGetStore()->getQueryResult($queryobj); |
174 | 173 | // try to be smart for rss/ical if no description/title is given and we have a concept query: |
175 | 174 | if ($this->m_params['format'] == 'rss') { |
— | — | @@ -191,7 +190,7 @@ |
192 | 191 | } |
193 | 192 | } |
194 | 193 | } |
195 | | - $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE, $res); |
| 194 | + $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE); |
196 | 195 | $result_mime = $printer->getMimeType($res); |
197 | 196 | if ($result_mime == false) { |
198 | 197 | if ($res->getCount() > 0) { |
— | — | @@ -220,7 +219,7 @@ |
221 | 220 | $wgOut->disable(); |
222 | 221 | header( "Content-type: $result_mime; charset=UTF-8" ); |
223 | 222 | if ($result_name !== false) { |
224 | | - header( "Content-Disposition: attachment; filename=$result_name"); |
| 223 | + header( "content-disposition: attachment; filename=$result_name"); |
225 | 224 | } |
226 | 225 | print $result; |
227 | 226 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -31,10 +31,6 @@ |
32 | 32 | * The format string is used to specify the output format if already |
33 | 33 | * known. Otherwise it will be determined from the parameters when |
34 | 34 | * needed. This parameter is just for optimisation in a common case. |
35 | | - * |
36 | | - * @todo This method contains too many special cases for certain |
37 | | - * printouts. Especially the case of rss, icalendar, etc. (no query) |
38 | | - * should be specified differently. |
39 | 35 | */ |
40 | 36 | static public function createQuery($querystring, $params, $context = SMWQueryProcessor::INLINE_QUERY, $format = '', $extraprintouts = array()) { |
41 | 37 | global $smwgQDefaultNamespaces, $smwgQFeatures, $smwgQConceptFeatures; |
— | — | @@ -56,10 +52,9 @@ |
57 | 53 | $querymode = SMWQuery::MODE_COUNT; |
58 | 54 | } elseif ($format == 'debug') { |
59 | 55 | $querymode = SMWQuery::MODE_DEBUG; |
60 | | - } elseif (in_array($format, array('rss','icalendar','vcard','csv','json'))) { |
61 | | - $querymode = SMWQuery::MODE_NONE; |
62 | 56 | } else { |
63 | | - $querymode = SMWQuery::MODE_INSTANCES; |
| 57 | + $printer = SMWQueryProcessor::getResultPrinter($format, $context); |
| 58 | + $querymode = $printer->getQueryMode($context); |
64 | 59 | } |
65 | 60 | |
66 | 61 | if (array_key_exists('mainlabel', $params)) { |
— | — | @@ -282,12 +277,12 @@ |
283 | 278 | |
284 | 279 | static public function getResultFromQuery($query, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '') { |
285 | 280 | wfProfileIn('SMWQueryProcessor::getResultFromQuery (SMW)'); |
286 | | - if ($format == '') { |
287 | | - $format = SMWQueryProcessor::getResultFormat($params); |
288 | | - } |
289 | 281 | $res = smwfGetStore()->getQueryResult($query); |
290 | 282 | if ( ($query->querymode == SMWQuery::MODE_INSTANCES) || ($query->querymode == SMWQuery::MODE_NONE) ) { |
291 | 283 | wfProfileIn('SMWQueryProcessor::getResultFromQuery-printout (SMW)'); |
| 284 | + if ($format == '') { |
| 285 | + $format = SMWQueryProcessor::getResultFormat($params); |
| 286 | + } |
292 | 287 | $printer = SMWQueryProcessor::getResultPrinter($format, $context, $res); |
293 | 288 | $result = $printer->getResult($res, $params, $outputmode); |
294 | 289 | wfProfileOut('SMWQueryProcessor::getResultFromQuery-printout (SMW)'); |
— | — | @@ -315,19 +310,13 @@ |
316 | 311 | } |
317 | 312 | |
318 | 313 | /** |
319 | | - * Find suitable SMWResultPrinter for the given format. |
| 314 | + * Find suitable SMWResultPrinter for the given format. The context in which the query is to be |
| 315 | + * used determines some basic settings of the returned printer object. Possible contexts are |
| 316 | + * SMWQueryProcessor::SPECIAL_PAGE, SMWQueryProcessor::INLINE_QUERY, SMWQueryProcessor::CONCEPT_DESC. |
320 | 317 | */ |
321 | | - static public function getResultPrinter($format,$context,$res) { |
322 | | - if ( 'auto' == $format ) { |
323 | | - if ( ($res->getColumnCount()>1) && ($res->getColumnCount()>0) ) |
324 | | - $format = 'table'; |
325 | | - else $format = 'list'; |
326 | | - } |
| 318 | + static public function getResultPrinter($format, $context = SMWQueryProcessor::SPECIAL_PAGE) { |
327 | 319 | global $smwgResultFormats; |
328 | | - if (array_key_exists($format, $smwgResultFormats)) |
329 | | - $formatclass = $smwgResultFormats[$format]; |
330 | | - else |
331 | | - $formatclass = "SMWListResultPrinter"; |
| 320 | + $formatclass = (array_key_exists($format, $smwgResultFormats))?$smwgResultFormats[$format]:'SMWAutoResultPrinter'; |
332 | 321 | return new $formatclass($format, ($context != SMWQueryProcessor::SPECIAL_PAGE)); |
333 | 322 | } |
334 | 323 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Auto.php |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results in tables or lists, depending on their shape. |
| 5 | + * This implements the automatic printer selection used in SMW if no |
| 6 | + * query format is specified. |
| 7 | + * @author Markus Krötzsch |
| 8 | + * @file |
| 9 | + * @ingroup SMWQuery |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * New implementation of SMW's printer for automatically selecting the |
| 14 | + * format for printing a result. |
| 15 | + * |
| 16 | + * @ingroup SMWQuery |
| 17 | + */ |
| 18 | +class SMWAutoResultPrinter extends SMWResultPrinter { |
| 19 | + |
| 20 | + public function getResult($results, $params, $outputmode) { |
| 21 | + if ( ($results->getColumnCount()>1) && ($results->getColumnCount()>0) ) { |
| 22 | + $format = 'table'; |
| 23 | + } else { |
| 24 | + $format = 'list'; |
| 25 | + } |
| 26 | + $printer = SMWQueryProcessor::getResultPrinter($format, ($this->mInline?SMWQueryProcessor::INLINE_QUERY:SMWQueryProcessor::SPECIAL_PAGE)); |
| 27 | + return $printer->getResult($results, $params, $outputmode); |
| 28 | + } |
| 29 | + |
| 30 | + protected function getResultText($res, $outputmode) { |
| 31 | + return ''; // acutally not needed in this implementation |
| 32 | + } |
| 33 | + |
| 34 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Auto.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php |
— | — | @@ -26,6 +26,10 @@ |
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
| 30 | + public function getQueryMode($context) { |
| 31 | + return ($context==SMWQueryProcessor::SPECIAL_PAGE)?SMWQuery::MODE_INSTANCES:SMWQuery::MODE_NONE; |
| 32 | + } |
| 33 | + |
30 | 34 | protected function getResultText($res, $outputmode) { |
31 | 35 | global $smwgIQRunningNumber, $wgSitename, $wgServer, $wgScriptPath; |
32 | 36 | $result = ''; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -267,16 +267,31 @@ |
268 | 268 | * standalone files are produced. |
269 | 269 | * |
270 | 270 | * If this function returns something other than FALSE, then the printer will |
271 | | - * not be regarded as a printer that displays in-line results. In in-line mode, |
272 | | - * queries to that printer will not be executed, but behave as if the user |
273 | | - * would have set limit=-1. This saves effort for printers that do not show |
274 | | - * results in-line anyway, even if they would be part of the result. |
| 271 | + * not be regarded as a printer that displays in-line results. This is used to |
| 272 | + * determine if a file output should be generated in Special:Ask. |
275 | 273 | */ |
276 | 274 | public function getMimeType($res) { |
277 | 275 | return false; |
278 | 276 | } |
279 | 277 | |
280 | 278 | /** |
| 279 | + * This function determines the query mode that is to be used for this printer in |
| 280 | + * various contexts. The query mode influences how queries to that printer should |
| 281 | + * be processed to obtain a result. Possible values are SMWQuery::MODE_INSTANCES |
| 282 | + * (retrieve instances), SMWQuery::MODE_NONE (do nothing), SMWQuery::MODE_COUNT |
| 283 | + * (get number of results), SMWQuery::MODE_DEBUG (return debugging text). |
| 284 | + * Possible values for context are SMWQueryProcessor::SPECIAL_PAGE, |
| 285 | + * SMWQueryProcessor::INLINE_QUERY, SMWQueryProcessor::CONCEPT_DESC. |
| 286 | + * |
| 287 | + * The default implementation always returns SMWQuery::MODE_INSTANCES. File exports |
| 288 | + * like RSS will use MODE_INSTANCES on special pages (so that instances are |
| 289 | + * retrieved for the export) and MODE_NONE otherwise (displaying just a download link). |
| 290 | + */ |
| 291 | + public function getQueryMode($context) { |
| 292 | + return SMWQuery::MODE_INSTANCES; |
| 293 | + } |
| 294 | + |
| 295 | + /** |
281 | 296 | * Some printers can produce not only embeddable HTML or Wikitext, but |
282 | 297 | * can also produce stand-alone files. An example is RSS or iCalendar. |
283 | 298 | * This function returns a filename that is to be sent to the caller |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php |
— | — | @@ -36,6 +36,10 @@ |
37 | 37 | return 'application/rss+xml'; // or is rdf+xml better? Might be confused in either case (with RSS2.0 or RDF) |
38 | 38 | } |
39 | 39 | |
| 40 | + public function getQueryMode($context) { |
| 41 | + return ($context==SMWQueryProcessor::SPECIAL_PAGE)?SMWQuery::MODE_INSTANCES:SMWQuery::MODE_NONE; |
| 42 | + } |
| 43 | + |
40 | 44 | protected function getResultText($res, $outputmode) { |
41 | 45 | global $smwgIQRunningNumber, $wgSitename, $wgServer, $smwgRSSEnabled, $wgRequest; |
42 | 46 | $result = ''; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -117,6 +117,7 @@ |
118 | 118 | $wgAutoloadClasses['SMWConceptPage'] = $smwgIP . '/includes/articlepages/SMW_ConceptPage.php'; |
119 | 119 | //// printers |
120 | 120 | $wgAutoloadClasses['SMWResultPrinter'] = $smwgIP . '/includes/SMW_QueryPrinter.php'; |
| 121 | + $wgAutoloadClasses['SMWAutoResultPrinter'] = $smwgIP . '/includes/SMW_QP_Auto.php'; |
121 | 122 | $wgAutoloadClasses['SMWTableResultPrinter'] = $smwgIP . '/includes/SMW_QP_Table.php'; |
122 | 123 | $wgAutoloadClasses['SMWListResultPrinter'] = $smwgIP . '/includes/SMW_QP_List.php'; |
123 | 124 | $wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $smwgIP . '/includes/SMW_QP_Embedded.php'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_CSV.php |
— | — | @@ -31,6 +31,10 @@ |
32 | 32 | return 'result.csv'; |
33 | 33 | } |
34 | 34 | |
| 35 | + public function getQueryMode($context) { |
| 36 | + return ($context==SMWQueryProcessor::SPECIAL_PAGE)?SMWQuery::MODE_INSTANCES:SMWQuery::MODE_NONE; |
| 37 | + } |
| 38 | + |
35 | 39 | protected function getResultText($res, $outputmode) { |
36 | 40 | $result = ''; |
37 | 41 | if ($outputmode == SMW_OUTPUT_FILE) { // make CSV file |