Index: trunk/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | */ |
31 | 31 | public static function doCompoundQuery( Parser &$parser ) { |
32 | 32 | global $smwgQEnabled, $smwgIQRunningNumber; |
33 | | - |
| 33 | + |
34 | 34 | if ( !$smwgQEnabled ) { |
35 | 35 | return smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) ); |
36 | 36 | } |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | |
43 | 43 | $other_params = array(); |
44 | 44 | $results = array(); |
| 45 | + $printRequests = array(); |
45 | 46 | $queryParams = array(); |
46 | 47 | |
47 | 48 | foreach ( $params as $param ) { |
— | — | @@ -57,40 +58,40 @@ |
58 | 59 | } |
59 | 60 | } |
60 | 61 | } |
61 | | - |
| 62 | + |
62 | 63 | foreach ( $queryParams as $param ) { |
63 | 64 | $subQueryParams = self::getSubParams( $param ); |
64 | | - |
| 65 | + |
65 | 66 | if ( array_key_exists( 'format', $other_params ) && !array_key_exists( 'format', $subQueryParams ) ) { |
66 | 67 | $subQueryParams['format'] = $other_params['format']; |
67 | 68 | } |
68 | | - |
| 69 | + |
69 | 70 | $next_result = self::getQueryResultFromFunctionParams( |
70 | 71 | $subQueryParams, |
71 | 72 | SMW_OUTPUT_WIKI |
72 | 73 | ); |
73 | 74 | |
74 | 75 | $results = self::mergeSMWQueryResults( $results, $next_result->getResults() ); |
| 76 | + $printRequests = self::mergeSMWPrintRequests( $printRequests, $next_result->getPrintRequests() ); |
75 | 77 | } |
76 | 78 | |
77 | 79 | // Sort results so that they'll show up by page name |
78 | 80 | uasort( $results, array( 'SCQQueryProcessor', 'compareQueryResults' ) ); |
79 | 81 | |
80 | | - $query_result = new SCQQueryResult( $next_result->getPrintRequests(), new SMWQuery(), $results, smwfGetStore() ); |
81 | | - |
| 82 | + $query_result = new SCQQueryResult( $printRequests, new SMWQuery(), $results, smwfGetStore() ); |
| 83 | + |
82 | 84 | if ( version_compare( SMW_VERSION, '1.6.1', '>' ) ) { |
83 | | - $printouts = $next_result->getPrintRequests(); |
84 | | - SMWQueryProcessor::addThisPrintout( $printouts, $other_params ); |
85 | | - $other_params = parent::getProcessedParams( $other_params, $printouts ); |
| 85 | + SMWQueryProcessor::addThisPrintout( $printRequests, $other_params ); |
| 86 | + $other_params = parent::getProcessedParams( $other_params, $printRequests ); |
86 | 87 | } |
87 | | - |
| 88 | + |
88 | 89 | return self::getResultFromQueryResult( |
89 | 90 | $query_result, |
90 | 91 | $other_params, |
91 | 92 | SMW_OUTPUT_WIKI |
92 | 93 | ); |
93 | | - } |
94 | | - |
| 94 | + } |
| 95 | + |
95 | 96 | /** |
96 | 97 | * An alternative to explode() - that function won't work here, |
97 | 98 | * because we don't want to split the string on all semicolons, just |
— | — | @@ -104,28 +105,28 @@ |
105 | 106 | $sub_params = array(); |
106 | 107 | $sub_param = ''; |
107 | 108 | $uncompleted_square_brackets = 0; |
108 | | - |
| 109 | + |
109 | 110 | for ( $i = 0; $i < strlen( $param ); $i++ ) { |
110 | 111 | $c = $param[$i]; |
111 | | - |
| 112 | + |
112 | 113 | if ( ( $c == ';' ) && ( $uncompleted_square_brackets <= 0 ) ) { |
113 | 114 | $sub_params[] = trim( $sub_param ); |
114 | 115 | $sub_param = ''; |
115 | 116 | } else { |
116 | 117 | $sub_param .= $c; |
117 | | - |
| 118 | + |
118 | 119 | if ( $c == '[' ) { |
119 | 120 | $uncompleted_square_brackets++; |
120 | 121 | } |
121 | | - |
| 122 | + |
122 | 123 | elseif ( $c == ']' ) { |
123 | 124 | $uncompleted_square_brackets--; |
124 | 125 | } |
125 | 126 | } |
126 | 127 | } |
127 | | - |
| 128 | + |
128 | 129 | $sub_params[] = trim( $sub_param ); |
129 | | - |
| 130 | + |
130 | 131 | return $sub_params; |
131 | 132 | } |
132 | 133 | |
— | — | @@ -138,6 +139,7 @@ |
139 | 140 | * @return SMWQueryResult |
140 | 141 | */ |
141 | 142 | protected static function getQueryResultFromFunctionParams( $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) { |
| 143 | + $printouts = null; |
142 | 144 | self::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode ); |
143 | 145 | return self::getQueryResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context ); |
144 | 146 | } |
— | — | @@ -154,9 +156,8 @@ |
155 | 157 | if ( $result1 == null ) { |
156 | 158 | return $result2; |
157 | 159 | } |
158 | | - |
159 | 160 | $existing_page_names = array(); |
160 | | - |
| 161 | + |
161 | 162 | foreach ( $result1 as $r1 ) { |
162 | 163 | // SMW 1.6+ |
163 | 164 | if ( $r1 instanceof SMWDIWikiPage ) { |
— | — | @@ -165,22 +166,37 @@ |
166 | 167 | $existing_page_names[] = $r1->getWikiValue(); |
167 | 168 | } |
168 | 169 | } |
169 | | - |
| 170 | + |
170 | 171 | foreach ( $result2 as $r2 ) { |
171 | | - if ( $r1 instanceof SMWDIWikiPage ) { |
| 172 | + if ( $r2 instanceof SMWDIWikiPage ) { |
172 | 173 | $page_name = $r2->getDBkey(); |
173 | 174 | } else { |
174 | 175 | $page_name = $r2->getWikiValue(); |
175 | 176 | } |
176 | | - |
| 177 | + |
177 | 178 | if ( ! in_array( $page_name, $existing_page_names ) ) { |
178 | 179 | $result1[] = $r2; |
179 | 180 | } |
180 | 181 | } |
181 | | - |
| 182 | + |
182 | 183 | return $result1; |
183 | 184 | } |
184 | 185 | |
| 186 | + protected static function mergeSMWPrintRequests( $printRequests1, $printRequests2 ) { |
| 187 | + $existingPrintoutLabels = array(); |
| 188 | + foreach ( $printRequests1 as $p1 ) { |
| 189 | + $existingPrintoutLabels[] = $p1->getLabel(); |
| 190 | + } |
| 191 | + |
| 192 | + foreach ( $printRequests2 as $p2 ) { |
| 193 | + $label = $p2->getLabel(); |
| 194 | + if ( ! in_array( $label, $existingPrintoutLabels ) ) { |
| 195 | + $printRequests1[] = $p2; |
| 196 | + } |
| 197 | + } |
| 198 | + return $printRequests1; |
| 199 | + } |
| 200 | + |
185 | 201 | /** |
186 | 202 | * @param $querystring |
187 | 203 | * @param array $params |
— | — | @@ -192,24 +208,24 @@ |
193 | 209 | */ |
194 | 210 | protected static function getQueryResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) { |
195 | 211 | wfProfileIn( 'SCQQueryProcessor::getQueryResultFromQueryString' ); |
196 | | - |
| 212 | + |
197 | 213 | if ( version_compare( SMW_VERSION, '1.6.1', '>' ) ) { |
198 | 214 | SMWQueryProcessor::addThisPrintout( $extraprintouts, $params ); |
199 | 215 | $params = self::getProcessedParams( $params, $extraprintouts, false ); |
200 | 216 | } |
201 | | - |
| 217 | + |
202 | 218 | $query = self::createQuery( $querystring, $params, $context, null, $extraprintouts ); |
203 | 219 | $query_result = smwfGetStore()->getQueryResult( $query ); |
204 | | - |
| 220 | + |
205 | 221 | foreach ( $query_result->getResults() as $wiki_page ) { |
206 | 222 | $wiki_page->display_options = $params; |
207 | 223 | } |
208 | 224 | |
209 | 225 | wfProfileOut( 'SCQQueryProcessor::getQueryResultFromQueryString' ); |
210 | | - |
| 226 | + |
211 | 227 | return $query_result; |
212 | 228 | } |
213 | | - |
| 229 | + |
214 | 230 | /** |
215 | 231 | * Matches getResultFromQueryResult() from SMWQueryProcessor, |
216 | 232 | * except that formats of type 'debug' and 'count' aren't handled. |
— | — | @@ -231,13 +247,13 @@ |
232 | 248 | else { |
233 | 249 | $format = self::getResultFormat( $params ); |
234 | 250 | } |
235 | | - |
| 251 | + |
236 | 252 | $printer = self::getResultPrinter( $format, $context, $res ); |
237 | 253 | $result = $printer->getResult( $res, $params, $outputmode ); |
238 | | - |
| 254 | + |
239 | 255 | wfProfileOut( 'SCQQueryProcessor::getResultFromQueryResult' ); |
240 | | - |
| 256 | + |
241 | 257 | return $result; |
242 | 258 | } |
243 | | - |
| 259 | + |
244 | 260 | } |