r66354 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66353‎ | r66354 | r66355 >
Date:15:26, 13 May 2010
Author:yaron
Status:deferred
Tags:
Comment:
Better fix, suggested by Jeroen: class now inherits from SMWQueryProcessor, so it can call protected functions
Modified paths:
  • /trunk/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php
@@ -4,13 +4,12 @@
55
66 /**
77 * Class that holds static functions for handling compound queries.
8 - * This class is heavily based on Semantic MediaWiki's SMWQueryProcessor,
9 - * and calls that class's functions when possible.
 8+ * This class inherits from Semantic MediaWiki's SMWQueryProcessor.
109 *
1110 * @ingroup SemanticCompoundQueries
1211 * @author Yaron Koren
1312 */
14 -class SCQQueryProcessor {
 13+class SCQQueryProcessor extends SMWQueryProcessor {
1514
1615 /**
1716 * An alternative to explode() - that function won't work here,
@@ -54,8 +53,8 @@
5554 // includes a square bracket, then it's a
5655 // sub-query; otherwise it's a regular parameter
5756 if ( strpos( $param, '[' ) !== false ) {
58 - $sub_params = SCQQueryProcessor::getSubParams( $param );
59 - $next_result = SCQQueryProcessor::getQueryResultFromFunctionParams( $sub_params, SMW_OUTPUT_WIKI );
 57+ $sub_params = self::getSubParams( $param );
 58+ $next_result = self::getQueryResultFromFunctionParams( $sub_params, SMW_OUTPUT_WIKI );
6059 if ( method_exists( $next_result, 'getResults' ) ) { // SMW 1.5+
6160 $results = self::mergeSMWQueryResults( $results, $next_result->getResults() );
6261 } else {
@@ -81,8 +80,8 @@
8281 }
8382
8483 static function getQueryResultFromFunctionParams( $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) {
85 - SMWQueryProcessor::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
86 - return SCQQueryProcessor::getQueryResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context );
 84+ self::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
 85+ return self::getQueryResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context );
8786 }
8887
8988 /**
@@ -105,31 +104,9 @@
106105 return $result1;
107106 }
108107
109 - // this method is an exact copy of SMWQueryProcessor's function,
110 - // but it needs to be duplicated because there it's protected
111 - static function getResultFormat( $params ) {
112 - $format = 'auto';
113 - if ( array_key_exists( 'format', $params ) ) {
114 - $format = strtolower( trim( $params['format'] ) );
115 - global $smwgResultAliases, $smwgResultFormats;
116 - if ( !array_key_exists( $format, $smwgResultFormats ) ) {
117 - $is_alias = false;
118 - foreach ( $smwgResultAliases as $main_format => $aliases ) {
119 - if ( in_array( $format, $aliases ) ) {
120 - $format = $main_format;
121 - $is_alias = true;
122 - break;
123 - }
124 - }
125 - if ( !$is_alias ) $format = 'auto'; // If it is an unknown format, defaults to list/table again
126 - }
127 - }
128 - return $format;
129 - }
130 -
131108 static function getQueryResultFromQueryString( $querystring, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) {
132109 wfProfileIn( 'SCQQueryProcessor::getQueryResultFromQueryString' );
133 - $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, null, $extraprintouts );
 110+ $query = self::createQuery( $querystring, $params, $context, null, $extraprintouts );
134111 $query_result = smwfGetStore()->getQueryResult( $query );
135112 $display_options = array();
136113 foreach ( $params as $key => $value ) {
@@ -165,8 +142,8 @@
166143 */
167144 static function getResultFromQueryResult( $res, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) {
168145 wfProfileIn( 'SCQQueryProcessor::getResultFromQueryResult' );
169 - $format = SCQQueryProcessor::getResultFormat( $params );
170 - $printer = SMWQueryProcessor::getResultPrinter( $format, $context, $res );
 146+ $format = self::getResultFormat( $params );
 147+ $printer = self::getResultPrinter( $format, $context, $res );
171148 $result = $printer->getResult( $res, $params, $outputmode );
172149 wfProfileOut( 'SCQQueryProcessor::getResultFromQueryResult' );
173150 return $result;

Status & tagging log