Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -275,41 +275,52 @@ |
276 | 276 | */ |
277 | 277 | static public function getResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) { |
278 | 278 | wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' ); |
| 279 | + |
279 | 280 | $format = SMWQueryProcessor::getResultFormat( $params ); |
280 | 281 | $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, $format, $extraprintouts ); |
281 | 282 | $result = SMWQueryProcessor::getResultFromQuery( $query, $params, $extraprintouts, $outputmode, $context, $format ); |
282 | 283 | wfProfileOut( 'SMWQueryProcessor::getResultFromQueryString (SMW)' ); |
| 284 | + |
283 | 285 | return $result; |
284 | 286 | } |
285 | 287 | |
286 | 288 | static public function getResultFromQuery( $query, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) { |
287 | 289 | wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
| 290 | + |
288 | 291 | // Query routing allows extensions to provide alternative stores as data sources |
289 | 292 | // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store. |
290 | 293 | ///TODO: case-insensitive |
291 | 294 | global $smwgQuerySources; |
| 295 | + |
292 | 296 | if ( array_key_exists( "source", $params ) && array_key_exists( $params["source"], $smwgQuerySources ) ) { |
293 | 297 | $store = new $smwgQuerySources[$params["source"]](); |
294 | 298 | $query->params = $params; // this is a hack |
295 | 299 | } else { |
296 | 300 | $store = smwfGetStore(); // default store |
297 | 301 | } |
| 302 | + |
298 | 303 | $res = $store->getQueryResult( $query ); |
299 | 304 | |
300 | 305 | if ( ( $query->querymode == SMWQuery::MODE_INSTANCES ) || ( $query->querymode == SMWQuery::MODE_NONE ) ) { |
301 | 306 | wfProfileIn( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' ); |
| 307 | + |
302 | 308 | if ( $format == '' ) { |
303 | 309 | $format = SMWQueryProcessor::getResultFormat( $params ); |
304 | 310 | } |
| 311 | + |
305 | 312 | $printer = SMWQueryProcessor::getResultPrinter( $format, $context, $res ); |
306 | 313 | $result = $printer->getResult( $res, $params, $outputmode ); |
| 314 | + |
307 | 315 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' ); |
308 | 316 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
| 317 | + |
309 | 318 | return $result; |
310 | 319 | } else { // result for counting or debugging is just a string |
311 | 320 | if ( array_key_exists( 'intro', $params ) ) $res = str_replace( '_', ' ', $params['intro'] ) . $res; |
312 | 321 | if ( array_key_exists( 'outro', $params ) ) $res .= str_replace( '_', ' ', $params['outro'] ); |
| 322 | + |
313 | 323 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
| 324 | + |
314 | 325 | return $res . smwfEncodeMessages( $query->getErrors() ); |
315 | 326 | } |
316 | 327 | } |
— | — | @@ -319,24 +330,37 @@ |
320 | 331 | */ |
321 | 332 | static protected function getResultFormat( array $params ) { |
322 | 333 | $format = 'auto'; |
| 334 | + |
323 | 335 | if ( array_key_exists( 'format', $params ) ) { |
| 336 | + global $smwgResultFormats; |
| 337 | + |
324 | 338 | $format = strtolower( trim( $params['format'] ) ); |
325 | | - global $smwgResultAliases, $smwgResultFormats; |
| 339 | + |
326 | 340 | if ( !array_key_exists( $format, $smwgResultFormats ) ) { |
327 | | - $is_alias = false; |
328 | | - foreach ( $smwgResultAliases as $main_format => $aliases ) { |
329 | | - if ( in_array( $format, $aliases ) ) { |
330 | | - $format = $main_format; |
331 | | - $is_alias = true; |
332 | | - break; |
333 | | - } |
334 | | - } |
335 | | - if ( !$is_alias ) $format = 'auto'; // If it is an unknown format, defaults to list/table again |
| 341 | + $isAlias = self::resolveFormatAliases( $format ); |
| 342 | + if ( !$isAlias ) $format = 'auto'; // If it is an unknown format, defaults to list/table again |
336 | 343 | } |
337 | 344 | } |
| 345 | + |
338 | 346 | return $format; |
339 | 347 | } |
| 348 | + |
| 349 | + static protected function resolveFormatAliases( &$format ) { |
| 350 | + global $smwgResultAliases; |
340 | 351 | |
| 352 | + $isAlias = false; |
| 353 | + |
| 354 | + foreach ( $smwgResultAliases as $mainFormat => $aliases ) { |
| 355 | + if ( in_array( $format, $aliases ) ) { |
| 356 | + $format = $mainFormat; |
| 357 | + $isAlias = true; |
| 358 | + break; |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + return $isAlias; |
| 363 | + } |
| 364 | + |
341 | 365 | /** |
342 | 366 | * Find suitable SMWResultPrinter for the given format. The context in which the query is to be |
343 | 367 | * used determines some basic settings of the returned printer object. Possible contexts are |
— | — | @@ -344,8 +368,13 @@ |
345 | 369 | */ |
346 | 370 | static public function getResultPrinter( $format, $context = SMWQueryProcessor::SPECIAL_PAGE ) { |
347 | 371 | global $smwgResultFormats; |
348 | | - $formatclass = ( array_key_exists( $format, $smwgResultFormats ) ) ? $smwgResultFormats[$format]:'SMWAutoResultPrinter'; |
349 | | - return new $formatclass( $format, ( $context != SMWQueryProcessor::SPECIAL_PAGE ) ); |
| 372 | + |
| 373 | + self::resolveFormatAliases( $format ); |
| 374 | + |
| 375 | + // TODO: this seems to contain the same logic as found in getResultFormat - a single function for this might be better. |
| 376 | + $formatClass = array_key_exists( $format, $smwgResultFormats ) ? $smwgResultFormats[$format] : 'SMWAutoResultPrinter'; |
| 377 | + |
| 378 | + return new $formatClass( $format, ( $context != SMWQueryProcessor::SPECIAL_PAGE ) ); |
350 | 379 | } |
351 | 380 | |
352 | 381 | } |
\ No newline at end of file |