Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -409,4 +409,4 @@ |
410 | 410 | ); |
411 | 411 | } |
412 | 412 | |
413 | | -} |
| 413 | +} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php |
— | — | @@ -211,12 +211,14 @@ |
212 | 212 | // This method is called when we encountered an opening '[['. The following |
213 | 213 | // block could be a Category-statement, fixed object, or property statement. |
214 | 214 | $chunk = $this->readChunk( '', true, false ); // NOTE: untrimmed, initial " " escapes prop. chains |
| 215 | + |
215 | 216 | if ( ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) || // category statement or |
216 | 217 | ( smwfNormalTitleText( $chunk ) == $this->m_conceptprefix ) ) { // concept statement |
217 | 218 | return $this->getClassDescription( $setNS, $label, |
218 | 219 | ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) ); |
219 | 220 | } else { // fixed subject, namespace restriction, property query, or subquery |
220 | 221 | $sep = $this->readChunk( '', false ); // do not consume hit, "look ahead" |
| 222 | + |
221 | 223 | if ( ( $sep == '::' ) || ( $sep == ':=' ) ) { |
222 | 224 | if ( $chunk { 0 } != ':' ) { // property statement |
223 | 225 | return $this->getPropertyDescription( $chunk, $setNS, $label ); |
— | — | @@ -239,8 +241,10 @@ |
240 | 242 | // note: no subqueries allowed here, inline disjunction allowed, wildcards allowed |
241 | 243 | $result = null; |
242 | 244 | $continue = true; |
| 245 | + |
243 | 246 | while ( $continue ) { |
244 | 247 | $chunk = $this->readChunk(); |
| 248 | + |
245 | 249 | if ( $chunk == '+' ) { |
246 | 250 | // wildcard, ignore for categories (semantically meaningless, everything is in some class) |
247 | 251 | } else { // assume category/concept title |
— | — | @@ -251,6 +255,7 @@ |
252 | 256 | $result = $this->addDescription( $result, $desc, false ); |
253 | 257 | } |
254 | 258 | } |
| 259 | + |
255 | 260 | $chunk = $this->readChunk(); |
256 | 261 | $continue = ( $chunk == '||' ) && $category; // disjunctions only for cateories |
257 | 262 | } |
— | — | @@ -267,21 +272,26 @@ |
268 | 273 | protected function getPropertyDescription( $propertyname, &$setNS, &$label ) { |
269 | 274 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
270 | 275 | $this->readChunk(); // consume separator ":=" or "::" |
| 276 | + |
271 | 277 | // first process property chain syntax (e.g. "property1.property2::value"), escaped by initial " ": |
272 | 278 | $propertynames = ( $propertyname { 0 } == ' ' ) ? array( $propertyname ):explode( '.', $propertyname ); |
273 | 279 | $properties = array(); |
274 | 280 | $typeid = '_wpg'; |
275 | 281 | $inverse = false; |
| 282 | + |
276 | 283 | foreach ( $propertynames as $name ) { |
277 | 284 | if ( $typeid != '_wpg' ) { // non-final property in chain was no wikipage: not allowed |
278 | 285 | $this->m_errors[] = wfMsgForContent( 'smw_valuesubquery', $prevname ); |
279 | 286 | return null; ///TODO: read some more chunks and try to finish [[ ]] |
280 | 287 | } |
| 288 | + |
281 | 289 | $property = SMWPropertyValue::makeUserProperty( $name ); |
| 290 | + |
282 | 291 | if ( !$property->isValid() ) { // illegal property identifier |
283 | 292 | $this->m_errors = array_merge( $this->m_errors, $property->getErrors() ); |
284 | 293 | return null; ///TODO: read some more chunks and try to finish [[ ]] |
285 | 294 | } |
| 295 | + |
286 | 296 | $typeid = $property->getPropertyTypeID(); |
287 | 297 | $inverse = $property->isInverse(); |
288 | 298 | $prevname = $name; |
— | — | @@ -290,8 +300,10 @@ |
291 | 301 | |
292 | 302 | $innerdesc = null; |
293 | 303 | $continue = true; |
| 304 | + |
294 | 305 | while ( $continue ) { |
295 | 306 | $chunk = $this->readChunk(); |
| 307 | + |
296 | 308 | switch ( $chunk ) { |
297 | 309 | case '+': // wildcard, add namespaces for page-type properties |
298 | 310 | if ( ( $this->m_defaultns !== null ) && ( ( $typeid == '_wpg' ) || $inverse ) ) { |
— | — | @@ -356,11 +368,15 @@ |
357 | 369 | $this->addDescription( $innerdesc, new SMWThingDescription(), false ); |
358 | 370 | $this->m_errors[] = wfMsgForContent( 'smw_propvalueproblem', $property->getWikiValue() ); |
359 | 371 | } |
| 372 | + |
360 | 373 | $properties = array_reverse( $properties ); |
| 374 | + |
361 | 375 | foreach ( $properties as $property ) { |
362 | 376 | $innerdesc = new SMWSomeProperty( $property, $innerdesc ); |
363 | 377 | } |
| 378 | + |
364 | 379 | $result = $innerdesc; |
| 380 | + |
365 | 381 | return $this->finishLinkDescription( $chunk, false, $result, $setNS, $label ); |
366 | 382 | } |
367 | 383 | |
— | — | @@ -373,33 +389,40 @@ |
374 | 390 | */ |
375 | 391 | protected function getArticleDescription( $firstchunk, &$setNS, &$label ) { |
376 | 392 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 393 | + |
377 | 394 | $chunk = $firstchunk; |
378 | 395 | $result = null; |
379 | 396 | $continue = true; |
380 | 397 | // $innerdesc = null; |
| 398 | + |
381 | 399 | while ( $continue ) { |
382 | 400 | if ( $chunk == '<q>' ) { // no subqueries of the form [[<q>...</q>]] (not needed) |
383 | 401 | $this->m_errors[] = wfMsgForContent( 'smw_misplacedsubquery' ); |
384 | 402 | return null; |
385 | 403 | } |
| 404 | + |
386 | 405 | $list = preg_split( '/:/', $chunk, 3 ); // ":Category:Foo" "User:bar" ":baz" ":+" |
| 406 | + |
387 | 407 | if ( ( $list[0] == '' ) && ( count( $list ) == 3 ) ) { |
388 | 408 | $list = array_slice( $list, 1 ); |
389 | 409 | } |
390 | 410 | if ( ( count( $list ) == 2 ) && ( $list[1] == '+' ) ) { // try namespace restriction |
391 | 411 | global $wgContLang; |
392 | 412 | $idx = $wgContLang->getNsIndex( $list[0] ); |
| 413 | + |
393 | 414 | if ( $idx !== false ) { |
394 | 415 | $result = $this->addDescription( $result, new SMWNamespaceDescription( $idx ), false ); |
395 | 416 | } |
396 | 417 | } else { |
397 | 418 | $value = SMWDataValueFactory::newTypeIDValue( '_wpg', $chunk ); |
| 419 | + |
398 | 420 | if ( $value->isValid() ) { |
399 | 421 | $result = $this->addDescription( $result, new SMWValueDescription( $value ), false ); |
400 | 422 | } |
401 | 423 | } |
402 | 424 | |
403 | 425 | $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' ); |
| 426 | + |
404 | 427 | if ( $chunk == '||' ) { |
405 | 428 | $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' ); |
406 | 429 | $continue = true; |
— | — | @@ -413,17 +436,20 @@ |
414 | 437 | |
415 | 438 | protected function finishLinkDescription( $chunk, $hasNamespaces, $result, &$setNS, &$label ) { |
416 | 439 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 440 | + |
417 | 441 | if ( $result === null ) { // no useful information or concrete error found |
418 | 442 | $this->m_errors[] = wfMsgForContent( 'smw_badqueryatom' ); |
419 | 443 | } elseif ( !$hasNamespaces && $setNS && ( $this->m_defaultns !== null ) ) { |
420 | 444 | $result = $this->addDescription( $result, $this->m_defaultns ); |
421 | 445 | $hasNamespaces = true; |
422 | 446 | } |
| 447 | + |
423 | 448 | $setNS = $hasNamespaces; |
424 | 449 | |
425 | 450 | // terminate link (assuming that next chunk was read already) |
426 | 451 | if ( $chunk == '|' ) { |
427 | 452 | $chunk = $this->readChunk( '\]\]' ); |
| 453 | + |
428 | 454 | if ( $chunk != ']]' ) { |
429 | 455 | $label .= $chunk; |
430 | 456 | $chunk = $this->readChunk( '\]\]' ); |
— | — | @@ -431,14 +457,17 @@ |
432 | 458 | $chunk = ']]'; |
433 | 459 | } |
434 | 460 | } |
| 461 | + |
435 | 462 | if ( $chunk != ']]' ) { |
436 | 463 | // What happended? We found some chunk that could not be processed as |
437 | 464 | // link content (as in [[Category:Test<q>]]) and there was no label to |
438 | 465 | // eat it. Or the closing ]] are just missing entirely. |
439 | 466 | if ( $chunk != '' ) { |
440 | 467 | $this->m_errors[] = wfMsgForContent( 'smw_misplacedsymbol', htmlspecialchars( $chunk ) ); |
| 468 | + |
441 | 469 | // try to find a later closing ]] to finish this misshaped subpart |
442 | 470 | $chunk = $this->readChunk( '\]\]' ); |
| 471 | + |
443 | 472 | if ( $chunk != ']]' ) { |
444 | 473 | $chunk = $this->readChunk( '\]\]' ); |
445 | 474 | } |
— | — | @@ -447,6 +476,7 @@ |
448 | 477 | $this->m_errors[] = wfMsgForContent( 'smw_noclosingbrackets' ); |
449 | 478 | } |
450 | 479 | } |
| 480 | + |
451 | 481 | return $result; |
452 | 482 | } |
453 | 483 | |
— | — | @@ -477,17 +507,20 @@ |
478 | 508 | if ( $consume ) { |
479 | 509 | $this->m_curstring = ''; |
480 | 510 | } |
| 511 | + |
481 | 512 | return $trim ? trim( $chunks[0] ):$chunks[0]; |
482 | 513 | } elseif ( count( $chunks ) == 3 ) { // this should generally happen if count is not 1 |
483 | 514 | if ( $chunks[0] == '' ) { // string started with delimiter |
484 | 515 | if ( $consume ) { |
485 | 516 | $this->m_curstring = $chunks[2]; |
486 | 517 | } |
| 518 | + |
487 | 519 | return $trim ? trim( $chunks[1] ):$chunks[1]; |
488 | 520 | } else { |
489 | 521 | if ( $consume ) { |
490 | 522 | $this->m_curstring = $chunks[1] . $chunks[2]; |
491 | 523 | } |
| 524 | + |
492 | 525 | return $trim ? trim( $chunks[0] ):$chunks[0]; |
493 | 526 | } |
494 | 527 | } else { return false; } // should never happen |
— | — | @@ -541,10 +574,12 @@ |
542 | 575 | } else { |
543 | 576 | $allowed = true; |
544 | 577 | } |
| 578 | + |
545 | 579 | if ( !$allowed ) { |
546 | 580 | $this->m_errors[] = wfMsgForContent( $notallowedmessage, str_replace( '[', '[', $newdesc->getQueryString() ) ); |
547 | 581 | return $curdesc; |
548 | 582 | } |
| 583 | + |
549 | 584 | if ( $newdesc === null ) { |
550 | 585 | return $curdesc; |
551 | 586 | } elseif ( $curdesc === null ) { |
— | — | @@ -571,4 +606,4 @@ |
572 | 607 | } |
573 | 608 | } |
574 | 609 | } |
575 | | -} |
| 610 | +} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -149,9 +149,9 @@ |
150 | 150 | } elseif ( $format == 'rss' ) { // unsorted RSS: use *descending* default order |
151 | 151 | ///TODO: the default sort field should be "modification date" (now it is the title, but |
152 | 152 | ///likely to be overwritten by printouts with label "date"). |
153 | | - $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ):'DESC'; |
| 153 | + $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'DESC'; |
154 | 154 | } else { // sort by page title (main column) by default |
155 | | - $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ):'ASC'; |
| 155 | + $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'ASC'; |
156 | 156 | } // TODO: check and report if there are further order statements? |
157 | 157 | |
158 | 158 | return $query; |
— | — | @@ -213,7 +213,7 @@ |
214 | 214 | } elseif ( $title->getNamespace() == NS_CATEGORY ) { |
215 | 215 | $printmode = SMWPrintRequest::PRINT_CCAT; |
216 | 216 | $data = $title; |
217 | | - $label = $showmode ? '':$title->getText(); // default |
| 217 | + $label = $showmode ? '' : $title->getText(); // default |
218 | 218 | } // else? |
219 | 219 | } |
220 | 220 | |