@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Comparison helper function, used in sorting results. |
24 | 24 | */ |
25 | - public static function compareQueryResults( $a, $b ) { |
|
25 | + public static function compareQueryResults($a, $b) { |
|
26 | 26 | |
27 | - if ( $a->getSerialization() == $b->getSerialization() ) { |
|
27 | + if ($a->getSerialization() == $b->getSerialization()) { |
|
28 | 28 | return 0; |
29 | 29 | } |
30 | 30 | |
31 | - return ( $a->getSerialization() < $b->getSerialization() ) ? -1 : 1; |
|
31 | + return ($a->getSerialization() < $b->getSerialization()) ? -1 : 1; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public static function doCompoundQuery( Parser &$parser ) { |
|
41 | + public static function doCompoundQuery(Parser&$parser) { |
|
42 | 42 | global $smwgQEnabled, $smwgIQRunningNumber; |
43 | 43 | |
44 | - if ( !$smwgQEnabled ) { |
|
45 | - return smwfEncodeMessages( [ wfMessage( 'smw_iq_disabled' )->inContentLanguage()->text() ] ); |
|
44 | + if (!$smwgQEnabled) { |
|
45 | + return smwfEncodeMessages([wfMessage('smw_iq_disabled')->inContentLanguage()->text()]); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $smwgIQRunningNumber++; |
49 | 49 | |
50 | 50 | $params = func_get_args(); |
51 | - array_shift( $params ); // We already know the $parser. |
|
51 | + array_shift($params); // We already know the $parser. |
|
52 | 52 | |
53 | - list( $queryParams, $otherParams ) = self::separateParams( $params ); |
|
54 | - list( $queryResult, $otherParams ) = self::queryAndMergeResults( $queryParams, $otherParams ); |
|
53 | + list($queryParams, $otherParams) = self::separateParams($params); |
|
54 | + list($queryResult, $otherParams) = self::queryAndMergeResults($queryParams, $otherParams); |
|
55 | 55 | |
56 | 56 | return self::getResultFromQueryResult( |
57 | 57 | $queryResult, |
@@ -66,25 +66,25 @@ discard block |
||
66 | 66 | * @param $params |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public static function separateParams( $params ) { |
|
69 | + public static function separateParams($params) { |
|
70 | 70 | $queryParams = []; |
71 | 71 | $otherParams = []; |
72 | 72 | |
73 | - foreach ( $params as $param ) { |
|
73 | + foreach ($params as $param) { |
|
74 | 74 | // Very primitive heuristic - if the parameter |
75 | 75 | // includes a square bracket, then it's a |
76 | 76 | // sub-query; otherwise it's a regular parameter. |
77 | - if ( strpos( $param, '[' ) !== false ) { |
|
77 | + if (strpos($param, '[') !== false) { |
|
78 | 78 | $queryParams[] = $param; |
79 | 79 | } else { |
80 | - $parts = explode( '=', $param, 2 ); |
|
80 | + $parts = explode('=', $param, 2); |
|
81 | 81 | |
82 | - if ( count( $parts ) >= 2 ) { |
|
83 | - $otherParams[strtolower( trim( $parts[0] ) )] = $parts[1]; // don't trim here, some params care for " " |
|
82 | + if (count($parts) >= 2) { |
|
83 | + $otherParams[strtolower(trim($parts[0]))] = $parts[1]; // don't trim here, some params care for " " |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | } |
87 | - return [ $queryParams, $otherParams ]; |
|
87 | + return [$queryParams, $otherParams]; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,36 +94,36 @@ discard block |
||
94 | 94 | * @param $otherParams |
95 | 95 | * @return array |
96 | 96 | */ |
97 | - public static function queryAndMergeResults( $queryParams, $otherParams ) { |
|
97 | + public static function queryAndMergeResults($queryParams, $otherParams) { |
|
98 | 98 | $results = []; |
99 | 99 | $printRequests = []; |
100 | 100 | |
101 | - foreach ( $queryParams as $param ) { |
|
102 | - $subQueryParams = self::getSubParams( $param ); |
|
101 | + foreach ($queryParams as $param) { |
|
102 | + $subQueryParams = self::getSubParams($param); |
|
103 | 103 | |
104 | - if ( array_key_exists( 'format', $otherParams ) && !array_key_exists( 'format', $subQueryParams ) ) { |
|
104 | + if (array_key_exists('format', $otherParams) && !array_key_exists('format', $subQueryParams)) { |
|
105 | 105 | $subQueryParams['format'] = $otherParams['format']; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $nextResult = self::getQueryResultFromFunctionParams($subQueryParams); |
109 | 109 | |
110 | - $results = self::mergeSMWQueryResults( $results, $nextResult->getResults() ); |
|
111 | - $printRequests = self::mergeSMWPrintRequests( $printRequests, $nextResult->getPrintRequests() ); |
|
110 | + $results = self::mergeSMWQueryResults($results, $nextResult->getResults()); |
|
111 | + $printRequests = self::mergeSMWPrintRequests($printRequests, $nextResult->getPrintRequests()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // Sort results so that they'll show up by page name |
115 | - if( !isset($otherParams['unsorted']) || !strcmp( $otherParams['unsorted'], 'on' ) ) { |
|
116 | - uasort( $results, [ '\SCQ\CompoundQueryProcessor', 'compareQueryResults' ] ); |
|
115 | + if (!isset($otherParams['unsorted']) || !strcmp($otherParams['unsorted'], 'on')) { |
|
116 | + uasort($results, ['\SCQ\CompoundQueryProcessor', 'compareQueryResults']); |
|
117 | 117 | } |
118 | 118 | |
119 | - $queryResult = new CompoundQueryResult( $printRequests, new Query(), $results, smwfGetStore() ); |
|
119 | + $queryResult = new CompoundQueryResult($printRequests, new Query(), $results, smwfGetStore()); |
|
120 | 120 | |
121 | - if ( version_compare( SMW_VERSION, '1.6.1', '>' ) ) { |
|
122 | - self::addThisPrintout( $printRequests, $otherParams ); |
|
123 | - $otherParams = self::getProcessedParams( $otherParams, $printRequests ); |
|
121 | + if (version_compare(SMW_VERSION, '1.6.1', '>')) { |
|
122 | + self::addThisPrintout($printRequests, $otherParams); |
|
123 | + $otherParams = self::getProcessedParams($otherParams, $printRequests); |
|
124 | 124 | } |
125 | 125 | |
126 | - return [ $queryResult, $otherParams ]; |
|
126 | + return [$queryResult, $otherParams]; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -135,31 +135,31 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - protected static function getSubParams( $param ) { |
|
138 | + protected static function getSubParams($param) { |
|
139 | 139 | $sub_params = []; |
140 | 140 | $sub_param = ''; |
141 | 141 | $uncompleted_square_brackets = 0; |
142 | 142 | |
143 | - for ( $i = 0; $i < strlen( $param ); $i++ ) { |
|
143 | + for ($i = 0; $i < strlen($param); $i++) { |
|
144 | 144 | $c = $param[$i]; |
145 | 145 | |
146 | - if ( ( $c == ';' ) && ( $uncompleted_square_brackets <= 0 ) ) { |
|
147 | - $sub_params[] = trim( $sub_param ); |
|
146 | + if (($c == ';') && ($uncompleted_square_brackets <= 0)) { |
|
147 | + $sub_params[] = trim($sub_param); |
|
148 | 148 | $sub_param = ''; |
149 | 149 | } else { |
150 | 150 | $sub_param .= $c; |
151 | 151 | |
152 | - if ( $c == '[' ) { |
|
152 | + if ($c == '[') { |
|
153 | 153 | $uncompleted_square_brackets++; |
154 | 154 | } |
155 | 155 | |
156 | - elseif ( $c == ']' ) { |
|
156 | + elseif ($c == ']') { |
|
157 | 157 | $uncompleted_square_brackets--; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | - $sub_params[] = trim( $sub_param ); |
|
162 | + $sub_params[] = trim($sub_param); |
|
163 | 163 | |
164 | 164 | return $sub_params; |
165 | 165 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return QueryResult |
173 | 173 | */ |
174 | - protected static function getQueryResultFromFunctionParams( $rawParams, $context = QueryProcessor::INLINE_QUERY, $showMode = false ) { |
|
175 | - list( $querystring, $params, $printouts ) = self::getComponentsFromFunctionParams( $rawParams, $showMode ); |
|
174 | + protected static function getQueryResultFromFunctionParams($rawParams, $context = QueryProcessor::INLINE_QUERY, $showMode = false) { |
|
175 | + list($querystring, $params, $printouts) = self::getComponentsFromFunctionParams($rawParams, $showMode); |
|
176 | 176 | |
177 | - return self::getQueryResultFromQueryString( $querystring, $params, $printouts, $context ); |
|
177 | + return self::getQueryResultFromQueryString($querystring, $params, $printouts, $context); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return array |
187 | 187 | */ |
188 | - protected static function mergeSMWQueryResults( $result1, $result2 ) { |
|
189 | - if ( $result1 == null ) { |
|
188 | + protected static function mergeSMWQueryResults($result1, $result2) { |
|
189 | + if ($result1 == null) { |
|
190 | 190 | return $result2; |
191 | 191 | } |
192 | 192 | |
193 | 193 | $existing_page_names = []; |
194 | - foreach ( $result1 as $r1 ) { |
|
194 | + foreach ($result1 as $r1) { |
|
195 | 195 | $existing_page_names[] = $r1->getSerialization(); |
196 | 196 | } |
197 | 197 | |
198 | - foreach ( $result2 as $r2 ) { |
|
198 | + foreach ($result2 as $r2) { |
|
199 | 199 | $page_name = $r2->getSerialization(); |
200 | - if ( ! in_array( $page_name, $existing_page_names ) ) { |
|
200 | + if (!in_array($page_name, $existing_page_names)) { |
|
201 | 201 | $result1[] = $r2; |
202 | 202 | } |
203 | 203 | } |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | return $result1; |
206 | 206 | } |
207 | 207 | |
208 | - protected static function mergeSMWPrintRequests( $printRequests1, $printRequests2 ) { |
|
208 | + protected static function mergeSMWPrintRequests($printRequests1, $printRequests2) { |
|
209 | 209 | $existingPrintoutLabels = []; |
210 | - foreach ( $printRequests1 as $p1 ) { |
|
210 | + foreach ($printRequests1 as $p1) { |
|
211 | 211 | $existingPrintoutLabels[] = $p1->getLabel(); |
212 | 212 | } |
213 | 213 | |
214 | - foreach ( $printRequests2 as $p2 ) { |
|
214 | + foreach ($printRequests2 as $p2) { |
|
215 | 215 | $label = $p2->getLabel(); |
216 | - if ( ! in_array( $label, $existingPrintoutLabels ) ) { |
|
216 | + if (!in_array($label, $existingPrintoutLabels)) { |
|
217 | 217 | $printRequests1[] = $p2; |
218 | 218 | } |
219 | 219 | } |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return QueryResult |
231 | 231 | */ |
232 | - protected static function getQueryResultFromQueryString( $querystring, array $params, $extraPrintouts, $context = QueryProcessor::INLINE_QUERY ) { |
|
232 | + protected static function getQueryResultFromQueryString($querystring, array $params, $extraPrintouts, $context = QueryProcessor::INLINE_QUERY) { |
|
233 | 233 | |
234 | - if ( version_compare( SMW_VERSION, '1.6.1', '>' ) ) { |
|
235 | - QueryProcessor::addThisPrintout( $extraPrintouts, $params ); |
|
236 | - $params = self::getProcessedParams( $params, $extraPrintouts, false ); |
|
234 | + if (version_compare(SMW_VERSION, '1.6.1', '>')) { |
|
235 | + QueryProcessor::addThisPrintout($extraPrintouts, $params); |
|
236 | + $params = self::getProcessedParams($params, $extraPrintouts, false); |
|
237 | 237 | } |
238 | 238 | |
239 | - $query = self::createQuery( $querystring, $params, $context, null, $extraPrintouts ); |
|
240 | - $queryResult = smwfGetStore()->getQueryResult( $query ); |
|
239 | + $query = self::createQuery($querystring, $params, $context, null, $extraPrintouts); |
|
240 | + $queryResult = smwfGetStore()->getQueryResult($query); |
|
241 | 241 | |
242 | 242 | $parameters = []; |
243 | 243 | |
244 | - if ( version_compare( SMW_VERSION, '1.7.2', '>' ) ) { |
|
245 | - foreach ( $params as $param ) { |
|
244 | + if (version_compare(SMW_VERSION, '1.7.2', '>')) { |
|
245 | + foreach ($params as $param) { |
|
246 | 246 | $parameters[$param->getName()] = $param->getValue(); |
247 | 247 | } |
248 | 248 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $parameters = $params; |
251 | 251 | } |
252 | 252 | |
253 | - foreach ( $queryResult->getResults() as $wikiPage ) { |
|
253 | + foreach ($queryResult->getResults() as $wikiPage) { |
|
254 | 254 | $wikiPage->display_options = $parameters; |
255 | 255 | } |
256 | 256 | |
@@ -269,20 +269,20 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - protected static function getResultFromQueryResult( CompoundQueryResult $res, array $params, $outputmode, $context = QueryProcessor::INLINE_QUERY, $format = '' ) { |
|
272 | + protected static function getResultFromQueryResult(CompoundQueryResult $res, array $params, $outputmode, $context = QueryProcessor::INLINE_QUERY, $format = '') { |
|
273 | 273 | |
274 | - if ( version_compare( SMW_VERSION, '1.6.1', '>' ) ) { |
|
274 | + if (version_compare(SMW_VERSION, '1.6.1', '>')) { |
|
275 | 275 | $format = $params['format']; |
276 | 276 | |
277 | - if ( version_compare( SMW_VERSION, '1.7.2', '>' ) ) { |
|
277 | + if (version_compare(SMW_VERSION, '1.7.2', '>')) { |
|
278 | 278 | $format = $format->getValue(); |
279 | 279 | } |
280 | 280 | } else { |
281 | - $format = self::getResultFormat( $params ); |
|
281 | + $format = self::getResultFormat($params); |
|
282 | 282 | } |
283 | 283 | |
284 | - $printer = self::getResultPrinter( $format, $context ); |
|
285 | - $result = $printer->getResult( $res, $params, $outputmode ); |
|
284 | + $printer = self::getResultPrinter($format, $context); |
|
285 | + $result = $printer->getResult($res, $params, $outputmode); |
|
286 | 286 | |
287 | 287 | return $result; |
288 | 288 | } |