Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | $qp->setDefaultNamespaces($smwgIQSearchNamespaces); |
75 | 75 | $desc = $qp->getQueryDescription($querystring); |
76 | 76 | if ($desc === NULL) { //abort with failure |
77 | | - return $gp->getErrorString(); |
| 77 | + return $qp->getErrorString(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | if (array_key_exists('mainlabel', $params)) { |
— | — | @@ -259,13 +259,13 @@ |
260 | 260 | public function getErrorString() { |
261 | 261 | $result = ''; |
262 | 262 | $first = true; |
263 | | - foreach ($qp->getError() as $e) { |
| 263 | + foreach ($this->m_errors as $e) { |
264 | 264 | if ($first) { |
265 | 265 | $first = false; |
266 | 266 | } else { |
267 | 267 | $result .= ', '; |
268 | 268 | } |
269 | | - $result .= '<span class="smwwarning">' . htmlspecialchars($e) . '</span>'; |
| 269 | + $result .= '<span class="smwwarning">' . $e . '</span>'; |
270 | 270 | } |
271 | 271 | return $result; |
272 | 272 | } |
— | — | @@ -315,11 +315,9 @@ |
316 | 316 | switch ($chunk) { |
317 | 317 | case '[[': // start new link block |
318 | 318 | $ld = $this->getLinkDescription($setsubNS, $label); |
319 | | - if ($ld === NULL) { |
320 | | - return NULL; |
321 | | - } elseif ($ld instanceof SMWPrintRequest) { |
| 319 | + if ($ld instanceof SMWPrintRequest) { |
322 | 320 | $printrequests[] = $ld; |
323 | | - } else { |
| 321 | + } elseif ($ld instanceof SMWDescription) { |
324 | 322 | $conjunction = $this->addDescription($conjunction,$ld); |
325 | 323 | } |
326 | 324 | break; |
— | — | @@ -479,6 +477,10 @@ |
480 | 478 | protected function getRelationDescription($relname, &$setNS, &$label) { |
481 | 479 | $innerdesc = NULL; |
482 | 480 | $rel = Title::newFromText($relname, SMW_NS_RELATION); |
| 481 | + if ($rel === NULL) { |
| 482 | + $this->m_errors[] .= 'Sorry, but ' . htmlspecialchars($relname) . ' is no valid page title.'; // TODO internationalise |
| 483 | + return NULL;///TODO: read some more chunks and try to finish [[ ]] |
| 484 | + } |
483 | 485 | |
484 | 486 | $this->readChunk(); // consume seperator "::" |
485 | 487 | $continue = true; |
— | — | @@ -528,11 +530,15 @@ |
529 | 531 | $continue = ($chunk == '||'); |
530 | 532 | } |
531 | 533 | |
532 | | - if ($innerdesc !== NULL) { |
533 | | - $result = new SMWSomeRelation($rel,$innerdesc); |
534 | | - } else { |
535 | | - $result = NULL; |
| 534 | + if ($innerdesc === NULL) { // make a wildcard search |
| 535 | + if ($this->m_defaultns !== NULL) { |
| 536 | + $innerdesc = $this->addDescription($innerdesc, $this->m_defaultns, false); |
| 537 | + } else { |
| 538 | + $innerdesc = $this->addDescription($innerdesc, new SMWThingDescription(), false); |
| 539 | + } |
| 540 | + $this->m_errors[] = 'Value of relation ' . $rel->getText() . ' was not understood.'; // TODO internationalise |
536 | 541 | } |
| 542 | + $result = new SMWSomeRelation($rel,$innerdesc); |
537 | 543 | |
538 | 544 | return $this->finishLinkDescription($chunk, false, $result, $setNS, $label); |
539 | 545 | } |
— | — | @@ -546,6 +552,10 @@ |
547 | 553 | protected function getAttributeDescription($attname, &$setNS, &$label) { |
548 | 554 | $this->readChunk(); // consume seperator ":=" |
549 | 555 | $att = Title::newFromText($attname, SMW_NS_ATTRIBUTE); |
| 556 | + if ($att === NULL) { |
| 557 | + $this->m_errors[] .= 'Sorry, but ' . htmlspecialchars($attname) . ' is no valid page title.'; // TODO internationalise |
| 558 | + return NULL; ///TODO: read some more chunks and try to finish [[ ]] |
| 559 | + } |
550 | 560 | ///TODO: currently no support for disjunctions in data values (needs extension of query processor) |
551 | 561 | |
552 | 562 | // get values, including values with internal [[...]] |
— | — | @@ -684,40 +694,41 @@ |
685 | 695 | |
686 | 696 | protected function finishLinkDescription($chunk, $hasNamespaces, $result, &$setNS, &$label) { |
687 | 697 | if ($result === NULL) { // no useful information or concrete error found |
688 | | - $this->m_errors[] = 'Syntax error in part of query.'; //TODO internationalise |
689 | | - return NULL; |
690 | | - } |
691 | | - |
692 | | - if (!$hasNamespaces && $setNS && ($this->m_defaultns !== NULL) ) { |
| 698 | + $this->m_errors[] = 'Some part [#x005B;&hellip]] of the query was not understood.'; |
| 699 | + //TODO internationalise |
| 700 | + } elseif (!$hasNamespaces && $setNS && ($this->m_defaultns !== NULL) ) { |
693 | 701 | $result = $this->addDescription($result, $this->m_defaultns); |
694 | 702 | $hasNamespaces = true; |
695 | 703 | } |
696 | 704 | $setNS = $hasNamespaces; |
697 | 705 | |
698 | 706 | // terminate link (assuming that next chunk was read already) |
699 | | - if ($chunk == '|') { // label, TODO |
| 707 | + if ($chunk == '|') { |
700 | 708 | $chunk = $this->readChunk('\]\]'); |
701 | 709 | if ($chunk != ']]') { |
702 | 710 | $label .= $chunk; |
703 | 711 | $chunk = $this->readChunk('\]\]'); |
704 | | - } else { |
705 | | - // empty label does not add to overall label |
| 712 | + } else { // empty label does not add to overall label |
706 | 713 | $chunk = ']]'; |
707 | 714 | } |
708 | 715 | } |
709 | | - if ($chunk == ']]') { // expected termination |
710 | | - return $result; |
711 | | - } else { |
| 716 | + if ($chunk != ']]') { |
712 | 717 | // What happended? We found some chunk that could not be processed as |
713 | 718 | // link content (as in [[Category:Test<q>]]) and there was no label to |
714 | 719 | // eat it. Or the closing ]] are just missing entirely. |
715 | | - if ($chunk != '') { //TODO: internationalise errors |
716 | | - $this->m_errors[] = 'The symbol \'' . $chunk . '\' was used in a place where it is not useful.'; |
717 | | - } else { |
718 | | - $this->m_errors[] = 'Some use of \'[[\' in your query was not closed by a matching \']]\'.'; |
| 720 | + if ($chunk != '') { |
| 721 | + $this->m_errors[] = 'The symbol \'' . htmlspecialchars($chunk) . '\' was used in a place where it is not useful.'; |
| 722 | + // try to find a later closing ]] to finish this misshaped subpart |
| 723 | + $chunk = $this->readChunk('\]\]'); |
| 724 | + if ($chunk != ']]') { |
| 725 | + $chunk = $this->readChunk('\]\]'); |
| 726 | + } |
719 | 727 | } |
720 | | - return NULL; |
| 728 | + if ($chunk == '') { |
| 729 | + $this->m_errors[] = 'Some use of \'[[\' in your query was not closed by a matching \']]\'.'; |
| 730 | + } |
721 | 731 | } |
| 732 | + return $result; |
722 | 733 | } |
723 | 734 | |
724 | 735 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -587,10 +587,10 @@ |
588 | 588 | $row = $db->fetchObject($res); |
589 | 589 | return $row->count; |
590 | 590 | // TODO: report query errors? |
591 | | - } elseif ($query->querymode == SMWQuery::MODE_DEBUG) { |
| 591 | + } elseif ($query->querymode == SMWQuery::MODE_DEBUG) { /// TODO: internationalise |
592 | 592 | list( $startOpts, $useIndex, $tailOpts ) = $db->makeSelectOptions( $sql_options ); |
593 | 593 | $result = '<div style="border: 1px dotted black; background: #A1FB00; padding: 20px; ">' . |
594 | | - '<b>Generated Wiki Query</b><br />' . |
| 594 | + '<b>Generated Wiki-Query</b><br />' . |
595 | 595 | htmlspecialchars($query->getDescription()->getQueryString()) . '<br />' . |
596 | 596 | '<b>SQL-Query</b><br />' . |
597 | 597 | "SELECT DISTINCT $pagetable.page_title as title, $pagetable.page_namespace as namespace" . |
— | — | @@ -599,6 +599,10 @@ |
600 | 600 | foreach ($sql_options as $key => $value) { |
601 | 601 | $result .= " $key=$value"; |
602 | 602 | } |
| 603 | + $result .= '<br /><b>Errors and Warnings</b><br />'; |
| 604 | + foreach ($query->getErrors() as $error) { |
| 605 | + $result .= $error . '<br />'; |
| 606 | + } |
603 | 607 | $result .= '</div>'; |
604 | 608 | /// TODO: report query errors! |
605 | 609 | return $result; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinters.php |
— | — | @@ -108,6 +108,31 @@ |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
| 112 | + /** |
| 113 | + * Provides a simple formatted string of all the error messages that occurred. |
| 114 | + * Can be used if not specific error formatting is desired. Compatible with HTML |
| 115 | + * and Wiki. |
| 116 | + * |
| 117 | + * TODO: use joined code for this and the similar method in SMWQueryParser? |
| 118 | + */ |
| 119 | + protected function getErrorString($res) { |
| 120 | + $result = ''; |
| 121 | + $first = true; |
| 122 | + foreach ($res->getErrors() as $e) { |
| 123 | + if ($first) { |
| 124 | + $first = false; |
| 125 | + } else { |
| 126 | + $result .= ', '; |
| 127 | + } |
| 128 | + $result .= '<span class="smwwarning">' . $e . '</span>'; |
| 129 | + } |
| 130 | + if ($result != '') { |
| 131 | + $result = '(' . $result . ')'; |
| 132 | + } |
| 133 | + return $result; |
| 134 | + } |
| 135 | + |
| 136 | + |
112 | 137 | } |
113 | 138 | |
114 | 139 | /** |
— | — | @@ -160,6 +185,7 @@ |
161 | 186 | } |
162 | 187 | } |
163 | 188 | $result .= "\t</table>"; // print footer |
| 189 | + $result .= $this->getErrorString($res); // just append error messages |
164 | 190 | return $result; |
165 | 191 | } |
166 | 192 | } |
— | — | @@ -296,6 +322,7 @@ |
297 | 323 | |
298 | 324 | // print footer |
299 | 325 | $result .= $footer; |
| 326 | + $result .= $this->getErrorString($res); // just append error messages |
300 | 327 | |
301 | 328 | return $result; |
302 | 329 | } |
— | — | @@ -485,6 +512,7 @@ |
486 | 513 | |
487 | 514 | // print footer |
488 | 515 | $result .= "</div>"; |
| 516 | + $result .= $this->getErrorString($res); // just append error messages |
489 | 517 | return $result; |
490 | 518 | } |
491 | 519 | } |
— | — | @@ -557,6 +585,7 @@ |
558 | 586 | } |
559 | 587 | |
560 | 588 | $smwgStoreActive = $old_smwgStoreActive; |
| 589 | + $result .= $this->getErrorString($res); // just append error messages |
561 | 590 | return $result; |
562 | 591 | } |
563 | 592 | } |
— | — | @@ -668,6 +697,7 @@ |
669 | 698 | } |
670 | 699 | } |
671 | 700 | $result .= $footer; |
| 701 | + $result .= $this->getErrorString($res); // just append error messages |
672 | 702 | |
673 | 703 | $smwgStoreActive = $old_smwgStoreActive; |
674 | 704 | return $result; |