Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -210,6 +210,7 @@ |
211 | 211 | } |
212 | 212 | |
213 | 213 | SMWOutputs::commitToParser( $parser ); |
| 214 | + |
214 | 215 | return $result; |
215 | 216 | } |
216 | 217 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | } else { |
43 | 43 | $queryfeatures = $smwgQFeatures; |
44 | 44 | } |
| 45 | + |
45 | 46 | $qp = new SMWQueryParser( $queryfeatures ); |
46 | 47 | $qp->setDefaultNamespaces( $smwgQDefaultNamespaces ); |
47 | 48 | $desc = $qp->getQueryDescription( $querystring ); |
— | — | @@ -48,6 +49,7 @@ |
49 | 50 | if ( $format == '' ) { |
50 | 51 | $format = SMWQueryProcessor::getResultFormat( $params ); |
51 | 52 | } |
| 53 | + |
52 | 54 | if ( $format == 'count' ) { |
53 | 55 | $querymode = SMWQuery::MODE_COUNT; |
54 | 56 | } elseif ( $format == 'debug' ) { |
— | — | @@ -62,6 +64,7 @@ |
63 | 65 | } else { |
64 | 66 | $mainlabel = $qp->getLabel(); |
65 | 67 | } |
| 68 | + |
66 | 69 | if ( ( $querymode == SMWQuery::MODE_NONE ) || |
67 | 70 | ( ( !$desc->isSingleton() || |
68 | 71 | ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 ) |
— | — | @@ -81,8 +84,10 @@ |
82 | 85 | if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset'] + 0 ) ) ) { |
83 | 86 | $query->setOffset( max( 0, trim( $params['offset'] ) + 0 ) ); |
84 | 87 | } |
| 88 | + |
85 | 89 | if ( $query->querymode == SMWQuery::MODE_COUNT ) { // largest possible limit for "count", even inline |
86 | 90 | global $smwgQMaxLimit; |
| 91 | + |
87 | 92 | $query->setOffset( 0 ); |
88 | 93 | $query->setLimit( $smwgQMaxLimit, false ); |
89 | 94 | } else { |
— | — | @@ -96,9 +101,11 @@ |
97 | 102 | $query->setLimit( $smwgQDefaultLimit ); |
98 | 103 | } |
99 | 104 | } |
| 105 | + |
100 | 106 | // determine sortkeys and ascendings: |
101 | 107 | if ( array_key_exists( 'order', $params ) ) { |
102 | 108 | $orders = explode( ',', $params['order'] ); |
| 109 | + |
103 | 110 | foreach ( $orders as $key => $order ) { // normalise |
104 | 111 | $order = strtolower( trim( $order ) ); |
105 | 112 | if ( ( $order == 'descending' ) || ( $order == 'reverse' ) || ( $order == 'desc' ) ) { |
— | — | @@ -112,24 +119,30 @@ |
113 | 120 | } else { |
114 | 121 | $orders = array(); |
115 | 122 | } |
| 123 | + |
116 | 124 | reset( $orders ); |
117 | 125 | |
118 | 126 | if ( array_key_exists( 'sort', $params ) ) { |
119 | 127 | $query->sort = true; |
120 | 128 | $query->sortkeys = array(); |
| 129 | + |
121 | 130 | foreach ( explode( ',', trim( $params['sort'] ) ) as $sort ) { |
122 | 131 | $sort = smwfNormalTitleDBKey( trim( $sort ) ); // slight normalisation |
123 | 132 | $order = current( $orders ); |
| 133 | + |
124 | 134 | if ( $order === false ) { // default |
125 | 135 | $order = 'ASC'; |
126 | 136 | } |
| 137 | + |
127 | 138 | if ( array_key_exists( $sort, $query->sortkeys ) ) { |
128 | 139 | // maybe throw an error here? |
129 | 140 | } else { |
130 | 141 | $query->sortkeys[$sort] = $order; |
131 | 142 | } |
| 143 | + |
132 | 144 | next( $orders ); |
133 | 145 | } |
| 146 | + |
134 | 147 | if ( current( $orders ) !== false ) { // sort key remaining, apply to page name |
135 | 148 | $query->sortkeys[''] = current( $orders ); |
136 | 149 | } |
— | — | @@ -151,26 +164,31 @@ |
152 | 165 | * objects, which are filled into call-by-ref parameters. |
153 | 166 | * $showmode is true if the input should be treated as if given by #show |
154 | 167 | */ |
155 | | - static public function processFunctionParams( $rawparams, &$querystring, &$params, &$printouts, $showmode = false ) { |
| 168 | + static public function processFunctionParams( array $rawparams, &$querystring, &$params, &$printouts, $showmode = false ) { |
156 | 169 | global $wgContLang; |
| 170 | + |
157 | 171 | $querystring = ''; |
158 | 172 | $printouts = array(); |
159 | 173 | $lastprintout = null; |
160 | 174 | $params = array(); |
| 175 | + |
161 | 176 | foreach ( $rawparams as $name => $param ) { |
162 | 177 | // special handling for arrays - this can happen if the |
163 | 178 | // param came from a checkboxes input in Special:Ask |
164 | 179 | if ( is_array( $param ) ) { |
165 | 180 | $param = implode( ',', array_keys( $param ) ); |
166 | 181 | } |
| 182 | + |
167 | 183 | if ( is_string( $name ) && ( $name != '' ) ) { // accept 'name' => 'value' just as '' => 'name=value' |
168 | 184 | $param = $name . '=' . $param; |
169 | 185 | } |
| 186 | + |
170 | 187 | if ( $param == '' ) { |
171 | 188 | } elseif ( $param { 0 } == '?' ) { // print statement |
172 | 189 | $param = substr( $param, 1 ); |
173 | 190 | $parts = explode( '=', $param, 2 ); |
174 | 191 | $propparts = explode( '#', $parts[0], 2 ); |
| 192 | + |
175 | 193 | if ( trim( $propparts[0] ) == '' ) { // print "this" |
176 | 194 | $printmode = SMWPrintRequest::PRINT_THIS; |
177 | 195 | $label = ''; // default |
— | — | @@ -186,6 +204,7 @@ |
187 | 205 | if ( $title === null ) { // too bad, this is no legal property/category name, ignore |
188 | 206 | continue; |
189 | 207 | } |
| 208 | + |
190 | 209 | if ( $title->getNamespace() == SMW_NS_PROPERTY ) { |
191 | 210 | $printmode = SMWPrintRequest::PRINT_PROP; |
192 | 211 | $property = SMWPropertyValue::makeUserProperty( trim( $propparts[0] ) ); |
— | — | @@ -197,14 +216,17 @@ |
198 | 217 | $label = $showmode ? '':$title->getText(); // default |
199 | 218 | } // else? |
200 | 219 | } |
| 220 | + |
201 | 221 | if ( count( $propparts ) == 1 ) { // no outputformat found, leave empty |
202 | 222 | $propparts[] = false; |
203 | 223 | } elseif ( trim( $propparts[1] ) == '' ) { // "plain printout", avoid empty string to avoid confusions with "false" |
204 | 224 | $propparts[1] = '-'; |
205 | 225 | } |
| 226 | + |
206 | 227 | if ( count( $parts ) > 1 ) { // label found, use this instead of default |
207 | 228 | $label = trim( $parts[1] ); |
208 | 229 | } |
| 230 | + |
209 | 231 | $lastprintout = new SMWPrintRequest( $printmode, $label, $data, trim( $propparts[1] ) ); |
210 | 232 | $printouts[] = $lastprintout; |
211 | 233 | } elseif ( $param[0] == '+' ) { // print request parameter |
— | — | @@ -215,6 +237,7 @@ |
216 | 238 | } |
217 | 239 | } else { // parameter or query |
218 | 240 | $parts = explode( '=', $param, 2 ); |
| 241 | + |
219 | 242 | if ( count( $parts ) >= 2 ) { |
220 | 243 | $params[strtolower( trim( $parts[0] ) )] = $parts[1]; // don't trim here, some params care for " " |
221 | 244 | } else { |
— | — | @@ -222,6 +245,7 @@ |
223 | 246 | } |
224 | 247 | } |
225 | 248 | } |
| 249 | + |
226 | 250 | $querystring = str_replace( array( '<', '>' ), array( '<', '>' ), $querystring ); |
227 | 251 | if ( $showmode ) $querystring = "[[:$querystring]]"; |
228 | 252 | } |
— | — | @@ -236,7 +260,7 @@ |
237 | 261 | * obtain actual parameters, printout requests, and the query string for |
238 | 262 | * further processing. |
239 | 263 | */ |
240 | | - static public function getResultFromFunctionParams( $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) { |
| 264 | + static public function getResultFromFunctionParams( array $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) { |
241 | 265 | SMWQueryProcessor::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode ); |
242 | 266 | return SMWQueryProcessor::getResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context ); |
243 | 267 | } |
— | — | @@ -249,7 +273,7 @@ |
250 | 274 | * certain general settings. Finally, $extraprintouts supplies additional |
251 | 275 | * printout requests for the query results. |
252 | 276 | */ |
253 | | - static public function getResultFromQueryString( $querystring, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) { |
| 277 | + static public function getResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) { |
254 | 278 | wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' ); |
255 | 279 | $format = SMWQueryProcessor::getResultFormat( $params ); |
256 | 280 | $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, $format, $extraprintouts ); |
— | — | @@ -258,7 +282,7 @@ |
259 | 283 | return $result; |
260 | 284 | } |
261 | 285 | |
262 | | - static public function getResultFromQuery( $query, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) { |
| 286 | + static public function getResultFromQuery( $query, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) { |
263 | 287 | wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
264 | 288 | // Query routing allows extensions to provide alternative stores as data sources |
265 | 289 | // 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. |
— | — | @@ -293,7 +317,7 @@ |
294 | 318 | /** |
295 | 319 | * Determine format label from parameters. |
296 | 320 | */ |
297 | | - static protected function getResultFormat( $params ) { |
| 321 | + static protected function getResultFormat( array $params ) { |
298 | 322 | $format = 'auto'; |
299 | 323 | if ( array_key_exists( 'format', $params ) ) { |
300 | 324 | $format = strtolower( trim( $params['format'] ) ); |
— | — | @@ -324,6 +348,4 @@ |
325 | 349 | return new $formatclass( $format, ( $context != SMWQueryProcessor::SPECIAL_PAGE ) ); |
326 | 350 | } |
327 | 351 | |
328 | | -} |
329 | | - |
330 | | - |
| 352 | +} |
\ No newline at end of file |