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 $qp->getError(); |
| 77 | + return $gp->getErrorString(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | if (array_key_exists('mainlabel', $params)) { |
— | — | @@ -86,6 +86,8 @@ |
87 | 87 | } |
88 | 88 | |
89 | 89 | $query = new SMWQuery($desc); |
| 90 | + $query->setQueryString($querystring); |
| 91 | + $query->addErrors($qp->getErrors()); // keep parsing errors for later output |
90 | 92 | if ($format == '') { |
91 | 93 | $format = SMWQueryProcessor::getResultFormat($params); |
92 | 94 | } |
— | — | @@ -151,8 +153,8 @@ |
152 | 154 | } else { // result for counting or debugging is just a string |
153 | 155 | return $res; |
154 | 156 | } |
155 | | - } else { // error string: return escaped version |
156 | | - return htmlspecialchars($query); ///TODO: improve error reporting format ... |
| 157 | + } else { // error string (should be HTML-safe) |
| 158 | + return $query; ///TODO: improve error reporting format ... |
157 | 159 | } |
158 | 160 | } |
159 | 161 | |
— | — | @@ -206,7 +208,7 @@ |
207 | 209 | |
208 | 210 | protected $m_sepstack; // list of open blocks ("parentheses") that need closing at current step |
209 | 211 | protected $m_curstring; // remaining string to be parsed (parsing eats query string from the front) |
210 | | - protected $m_error; // false if all went right, string otherwise |
| 212 | + protected $m_errors; // empty array if all went right, array of strings otherwise |
211 | 213 | protected $m_label; //label of the main query result |
212 | 214 | protected $m_defaultns; //description of the default namespace restriction, or NULL if not used |
213 | 215 | |
— | — | @@ -236,7 +238,7 @@ |
237 | 239 | * false if there were errors. |
238 | 240 | */ |
239 | 241 | public function getQueryDescription($querystring) { |
240 | | - $this->m_error = false; |
| 242 | + $this->m_errors = array(); |
241 | 243 | $this->m_label = ''; |
242 | 244 | $this->m_curstring = $querystring; |
243 | 245 | $this->m_sepstack = array(); |
— | — | @@ -245,13 +247,30 @@ |
246 | 248 | } |
247 | 249 | |
248 | 250 | /** |
249 | | - * Return error message or false if no error occurred. |
| 251 | + * Return array of error messages (possibly empty). |
250 | 252 | */ |
251 | | - public function getError() { |
252 | | - return $this->m_error; |
| 253 | + public function getErrors() { |
| 254 | + return $this->m_errors; |
253 | 255 | } |
254 | 256 | |
255 | 257 | /** |
| 258 | + * Return error message or empty string if no error occurred. |
| 259 | + */ |
| 260 | + public function getErrorString() { |
| 261 | + $result = ''; |
| 262 | + $first = true; |
| 263 | + foreach ($qp->getError() as $e) { |
| 264 | + if ($first) { |
| 265 | + $first = false; |
| 266 | + } else { |
| 267 | + $result .= ', '; |
| 268 | + } |
| 269 | + $result .= '<span class="smwwarning">' . htmlspecialchars($e) . '</span>'; |
| 270 | + } |
| 271 | + return $result; |
| 272 | + } |
| 273 | + |
| 274 | + /** |
256 | 275 | * Return label for the results of this query (which |
257 | 276 | * might be empty if no such information was passed). |
258 | 277 | */ |
— | — | @@ -333,7 +352,7 @@ |
334 | 353 | if ($this->popDelimiter('</q>')) { |
335 | 354 | $continue = false; // leave the loop |
336 | 355 | } else { |
337 | | - $this->m_error = 'There appear to be too many occurences of \'' . $chunk . '\' in the query.'; |
| 356 | + $this->m_errors[] = 'There appear to be too many occurences of \'' . $chunk . '\' in the query.'; |
338 | 357 | return NULL; |
339 | 358 | } |
340 | 359 | } elseif ($chunk == '') { |
— | — | @@ -341,7 +360,7 @@ |
342 | 361 | } |
343 | 362 | break; |
344 | 363 | default: // error: unexpected $chunk |
345 | | - $this->m_error = 'The part \'' . $chunk . '\' in the query was not understood. Results might not be as expected.'; // TODO: internationalise |
| 364 | + $this->m_errors[] = 'The part \'' . $chunk . '\' in the query was not understood. Results might not be as expected.'; // TODO: internationalise |
346 | 365 | return NULL; |
347 | 366 | } |
348 | 367 | if ($setsubNS) { // namespace restrictions encountered in current conjunct |
— | — | @@ -356,7 +375,7 @@ |
357 | 376 | $result = NULL; |
358 | 377 | foreach ($disjuncts as $d) { |
359 | 378 | if ($d === NULL) { |
360 | | - $this->m_error = 'No condition in subquery.'; |
| 379 | + $this->m_errors[] = 'No condition in subquery.'; |
361 | 380 | $setNS = false; |
362 | 381 | return NULL; |
363 | 382 | } else { |
— | — | @@ -364,7 +383,7 @@ |
365 | 384 | } |
366 | 385 | } |
367 | 386 | } else { |
368 | | - $this->m_error = 'No condition in subquery.'; |
| 387 | + $this->m_errors[] = 'No condition in subquery.'; |
369 | 388 | $setNS = false; |
370 | 389 | return NULL; |
371 | 390 | } |
— | — | @@ -432,7 +451,7 @@ |
433 | 452 | if ($chunk == ']]') { |
434 | 453 | return new SMWPrintRequest(SMW_PRINT_CATS, $label); |
435 | 454 | } else { |
436 | | - $this->m_error = 'Misshaped print statement.'; //TODO: internationalise |
| 455 | + $this->m_errors[] = 'Misshaped print statement.'; //TODO: internationalise |
437 | 456 | return NULL; |
438 | 457 | } |
439 | 458 | break; |
— | — | @@ -482,7 +501,7 @@ |
483 | 502 | if ($chunk == ']]') { |
484 | 503 | return new SMWPrintRequest(SMW_PRINT_RELS, $label, $rel); |
485 | 504 | } else { |
486 | | - $this->m_error = 'Misshaped print statement.'; //TODO: internationalise |
| 505 | + $this->m_errors[] = 'Misshaped print statement.'; //TODO: internationalise |
487 | 506 | return NULL; |
488 | 507 | } |
489 | 508 | break; |
— | — | @@ -532,8 +551,8 @@ |
533 | 552 | // get values, including values with internal [[...]] |
534 | 553 | $open = 1; |
535 | 554 | $value = ''; |
536 | | - $chunk = 'NONEMPTY'; |
537 | | - while ( ($open > 0) && ($chunk != '') ) { |
| 555 | + $continue = true; |
| 556 | + while ( ($open > 0) && ($continue) ) { |
538 | 557 | $chunk = $this->readChunk('\[\[|\]\]|\|'); |
539 | 558 | switch ($chunk) { |
540 | 559 | case '[[': // open new [[ ]] |
— | — | @@ -547,12 +566,15 @@ |
548 | 567 | $open = 0; |
549 | 568 | } |
550 | 569 | break; |
| 570 | + case '': // this is not good ... TODO:report error |
| 571 | + $continue = false; |
| 572 | + break; |
551 | 573 | } |
552 | 574 | if ($open != 0) { |
553 | 575 | $value .= $chunk; |
554 | 576 | } |
555 | 577 | } |
556 | | - // note that at this point, we already read one more chunk behind the value |
| 578 | + // note that at this point, we normally already read one more chunk behind the value |
557 | 579 | $list = preg_split('/^\*/',$value,2); |
558 | 580 | if (count($list) == 2) { //hit |
559 | 581 | $value = '*'; |
— | — | @@ -576,7 +598,7 @@ |
577 | 599 | if ($chunk == ']]') { |
578 | 600 | return new SMWPrintRequest(SMW_PRINT_ATTS, $label, $att, $printmodifier); |
579 | 601 | } else { |
580 | | - $this->m_error = 'Misshaped print statement.'; //TODO: internationalise |
| 602 | + $this->m_errors[] = 'Misshaped print statement.'; //TODO: internationalise |
581 | 603 | return NULL; |
582 | 604 | } |
583 | 605 | break; |
— | — | @@ -603,8 +625,8 @@ |
604 | 626 | // TODO: needs extension for n-ary values |
605 | 627 | $dv = SMWDataValueFactory::newAttributeObjectValue($att, $value); |
606 | 628 | if (!$dv->isValid()) { |
607 | | - $this->m_error = $dv->getError(); |
608 | | - $vd = new SMWValueDescription(NULL, SMW_CMP_ANY); |
| 629 | + $this->m_errors[] = $dv->getError(); |
| 630 | + $vd = new SMWValueDescription($dv, SMW_CMP_ANY); |
609 | 631 | } else { |
610 | 632 | $vd = new SMWValueDescription($dv, $comparator); |
611 | 633 | } |
— | — | @@ -628,7 +650,7 @@ |
629 | 651 | //$innerdesc = NULL; |
630 | 652 | while ($continue) { |
631 | 653 | if ($chunk == '<q>') { // no subqueries of the form [[<q>...</q>]] (not needed) |
632 | | - $this->m_error = 'Subqueries not allowed here.'; //TODO |
| 654 | + $this->m_errors[] = 'Subqueries not allowed here.'; //TODO |
633 | 655 | return NULL; |
634 | 656 | } |
635 | 657 | $list = preg_split('/:/', $chunk, 3); // ":Category:Foo" "User:bar" ":baz" ":+" |
— | — | @@ -662,7 +684,7 @@ |
663 | 685 | |
664 | 686 | protected function finishLinkDescription($chunk, $hasNamespaces, $result, &$setNS, &$label) { |
665 | 687 | if ($result === NULL) { // no useful information or concrete error found |
666 | | - $this->m_error = 'Syntax error in part of query.'; //TODO internationalise |
| 688 | + $this->m_errors[] = 'Syntax error in part of query.'; //TODO internationalise |
667 | 689 | return NULL; |
668 | 690 | } |
669 | 691 | |
— | — | @@ -690,9 +712,9 @@ |
691 | 713 | // link content (as in [[Category:Test<q>]]) and there was no label to |
692 | 714 | // eat it. Or the closing ]] are just missing entirely. |
693 | 715 | if ($chunk != '') { //TODO: internationalise errors |
694 | | - $this->m_error = 'The symbol \'' . $chunk . '\' was used in a place where it is not useful.'; |
| 716 | + $this->m_errors[] = 'The symbol \'' . $chunk . '\' was used in a place where it is not useful.'; |
695 | 717 | } else { |
696 | | - $this->m_error = 'Some use of \'[[\' in your query was not closed by a matching \']]\'.'; |
| 718 | + $this->m_errors[] = 'Some use of \'[[\' in your query was not closed by a matching \']]\'.'; |
697 | 719 | } |
698 | 720 | return NULL; |
699 | 721 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | ///// Reading methods ///// |
40 | 40 | |
41 | 41 | function getSpecialValues(Title $subject, $specialprop, $requestoptions = NULL) { |
42 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 42 | + $db =& wfGetDB( DB_SLAVE ); // TODO: Is '=&' needed in PHP5? |
43 | 43 | |
44 | 44 | // TODO: this method currently supports no ordering or boundary. This is probably best anyway ... |
45 | 45 | |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | } |
94 | 94 | |
95 | 95 | function getSpecialSubjects($specialprop, $value, $requestoptions = NULL) { |
96 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 96 | + $db =& wfGetDB( DB_SLAVE ); |
97 | 97 | |
98 | 98 | $result = array(); |
99 | 99 | |
— | — | @@ -169,7 +169,7 @@ |
170 | 170 | |
171 | 171 | |
172 | 172 | function getAttributeValues(Title $subject, Title $attribute, $requestoptions = NULL, $outputformat = '') { |
173 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 173 | + $db =& wfGetDB( DB_SLAVE ); |
174 | 174 | $result = array(); |
175 | 175 | |
176 | 176 | $id = SMWDataValueFactory::getAttributeObjectTypeID($attribute); |
— | — | @@ -221,7 +221,7 @@ |
222 | 222 | return array(); |
223 | 223 | } |
224 | 224 | |
225 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 225 | + $db =& wfGetDB( DB_SLAVE ); |
226 | 226 | $sql = 'value_xsd=' . $db->addQuotes($value->getXSDValue()) . |
227 | 227 | ' AND value_unit=' . $db->addQuotes($value->getUnit()) . |
228 | 228 | ' AND attribute_title=' . $db->addQuotes($attribute->getDBKey()) . |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | } |
245 | 245 | |
246 | 246 | function getAllAttributeSubjects(Title $attribute, $requestoptions = NULL) { |
247 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 247 | + $db =& wfGetDB( DB_SLAVE ); |
248 | 248 | $sql = 'attribute_title=' . $db->addQuotes($attribute->getDBkey()) . |
249 | 249 | $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
250 | 250 | |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | } |
280 | 280 | |
281 | 281 | function getAttributes(Title $subject, $requestoptions = NULL) { |
282 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 282 | + $db =& wfGetDB( DB_SLAVE ); |
283 | 283 | $sql = 'subject_id=' . $db->addQuotes($subject->getArticleID()) . $this->getSQLConditions($requestoptions,'attribute_title','attribute_title'); |
284 | 284 | |
285 | 285 | $result = array(); |
— | — | @@ -305,7 +305,7 @@ |
306 | 306 | } |
307 | 307 | |
308 | 308 | function getRelationObjects(Title $subject, Title $relation, $requestoptions = NULL) { |
309 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 309 | + $db =& wfGetDB( DB_SLAVE ); |
310 | 310 | $sql = 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
311 | 311 | ' AND relation_title=' . $db->addQuotes($relation->getDBKey()) . |
312 | 312 | $this->getSQLConditions($requestoptions,'object_title','object_title'); |
— | — | @@ -326,7 +326,7 @@ |
327 | 327 | } |
328 | 328 | |
329 | 329 | function getRelationSubjects(Title $relation, Title $object, $requestoptions = NULL) { |
330 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 330 | + $db =& wfGetDB( DB_SLAVE ); |
331 | 331 | $sql = 'object_namespace=' . $db->addQuotes($object->getNamespace()) . |
332 | 332 | ' AND object_title=' . $db->addQuotes($object->getDBKey()) . |
333 | 333 | ' AND relation_title=' . $db->addQuotes($relation->getDBKey()) . |
— | — | @@ -348,7 +348,7 @@ |
349 | 349 | } |
350 | 350 | |
351 | 351 | function getAllRelationSubjects(Title $relation, $requestoptions = NULL) { |
352 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 352 | + $db =& wfGetDB( DB_SLAVE ); |
353 | 353 | $sql = 'relation_title=' . $db->addQuotes($relation->getDBkey()) . |
354 | 354 | $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
355 | 355 | |
— | — | @@ -368,7 +368,7 @@ |
369 | 369 | } |
370 | 370 | |
371 | 371 | function getOutRelations(Title $subject, $requestoptions = NULL) { |
372 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 372 | + $db =& wfGetDB( DB_SLAVE ); |
373 | 373 | $sql = 'subject_id=' . $db->addQuotes($subject->getArticleID()) . |
374 | 374 | $this->getSQLConditions($requestoptions,'relation_title','relation_title'); |
375 | 375 | |
— | — | @@ -388,7 +388,7 @@ |
389 | 389 | } |
390 | 390 | |
391 | 391 | function getInRelations(Title $object, $requestoptions = NULL) { |
392 | | - $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
| 392 | + $db =& wfGetDB( DB_SLAVE ); |
393 | 393 | $sql = 'object_namespace=' . $db->addQuotes($object->getNamespace()) . |
394 | 394 | ' AND object_title=' . $db->addQuotes($object->getDBKey()) . |
395 | 395 | $this->getSQLConditions($requestoptions,'relation_title','relation_title'); |
— | — | @@ -555,7 +555,7 @@ |
556 | 556 | // Build main query |
557 | 557 | $this->m_sortkey = $query->sortkey; |
558 | 558 | $this->m_sortfield = false; |
559 | | - |
| 559 | + |
560 | 560 | $pagetable = $db->tableName('page'); |
561 | 561 | $from = $pagetable; |
562 | 562 | $where = ''; |
— | — | @@ -586,6 +586,7 @@ |
587 | 587 | $sql_options ); |
588 | 588 | $row = $db->fetchObject($res); |
589 | 589 | return $row->count; |
| 590 | + // TODO: report query errors? |
590 | 591 | } elseif ($query->querymode == SMWQuery::MODE_DEBUG) { |
591 | 592 | list( $startOpts, $useIndex, $tailOpts ) = $db->makeSelectOptions( $sql_options ); |
592 | 593 | $result = '<div style="border: 1px dotted black; background: #A1FB00; padding: 20px; ">' . |
— | — | @@ -599,6 +600,7 @@ |
600 | 601 | $result .= " $key=$value"; |
601 | 602 | } |
602 | 603 | $result .= '</div>'; |
| 604 | + /// TODO: report query errors! |
603 | 605 | return $result; |
604 | 606 | } // else: continue |
605 | 607 | |
— | — | @@ -621,7 +623,7 @@ |
622 | 624 | |
623 | 625 | // Create result by executing print statements for everything that was fetched |
624 | 626 | ///TODO: use limit (and offset?) values for printouts? |
625 | | - $result = new SMWQueryResult($prs, ( ($count > $query->limit) && ($query->limit >= 0) ) ); |
| 627 | + $result = new SMWQueryResult($prs, $query, ( ($count > $query->limit) && ($query->limit >= 0) ) ); |
626 | 628 | foreach ($qr as $qt) { |
627 | 629 | $row = array(); |
628 | 630 | foreach ($prs as $pr) { |
— | — | @@ -761,7 +763,7 @@ |
762 | 764 | protected function getSQLConditions($requestoptions, $valuecol, $labelcol = NULL) { |
763 | 765 | $sql_conds = ''; |
764 | 766 | if ($requestoptions !== NULL) { |
765 | | - $db =& wfGetDB( DB_MASTER ); // TODO: use slave? |
| 767 | + $db =& wfGetDB( DB_SLAVE ); |
766 | 768 | if ($requestoptions->boundary !== NULL) { // apply value boundary |
767 | 769 | if ($requestoptions->ascending) { |
768 | 770 | if ($requestoptions->include_boundary) { |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php |
— | — | @@ -18,18 +18,26 @@ |
19 | 19 | * returned by this object has the same number of elements (columns). |
20 | 20 | */ |
21 | 21 | class SMWQueryResult { |
22 | | - protected $content; //an array (table) of arrays (rows) of arrays (fields, SMWResultArray) |
23 | | - protected $printrequests; //an array of SMWPrintRequest objects, indexed by their natural hash keys |
24 | | - protected $furtherres; |
| 22 | + protected $m_content; //an array (table) of arrays (rows) of arrays (fields, SMWResultArray) |
| 23 | + protected $m_printrequests; //an array of SMWPrintRequest objects, indexed by their natural hash keys |
| 24 | + protected $m_furtherres; |
| 25 | + protected $m_errors; // error array (simple string messages, possibly empty) |
| 26 | + protected $m_querystring; // string (inline query) version of query |
| 27 | + protected $m_ascending; // order ascending? |
| 28 | + protected $m_sortkey; // by which property to sort (false: do not sort) |
25 | 29 | |
26 | 30 | /** |
27 | 31 | * Initialise the object with an array of SMWPrintRequest objects, which |
28 | 32 | * define the structure of the result "table" (one for each column). |
29 | 33 | */ |
30 | | - public function SMWQueryResult($printrequests, $furtherres=false) { |
31 | | - $this->content = array(); |
32 | | - $this->printrequests = $printrequests; |
33 | | - $this->furtherres = $furtherres; |
| 34 | + public function SMWQueryResult($printrequests, $query, $furtherres=false) { |
| 35 | + $this->m_content = array(); |
| 36 | + $this->m_printrequests = $printrequests; |
| 37 | + $this->m_furtherres = $furtherres; |
| 38 | + $this->m_errors = $query->getErrors(); |
| 39 | + $this->m_querystring = $query->getQueryString(); |
| 40 | + $this->m_ascending = $query->ascending; |
| 41 | + $this->m_sortkey = $query->sortkey; |
34 | 42 | } |
35 | 43 | |
36 | 44 | /** |
— | — | @@ -39,8 +47,8 @@ |
40 | 48 | */ |
41 | 49 | public function addRow($row) { |
42 | 50 | reset($row); |
43 | | - reset($this->printrequests); |
44 | | - $pr = current($this->printrequests); |
| 51 | + reset($this->m_printrequests); |
| 52 | + $pr = current($this->m_printrequests); |
45 | 53 | $ra = current($row); |
46 | 54 | |
47 | 55 | while ( $pr !== false ) { |
— | — | @@ -51,14 +59,14 @@ |
52 | 60 | if ($pr->getHash() !== $ra->getPrintRequest()->getHash()) { |
53 | 61 | return false; |
54 | 62 | } |
55 | | - $pr = next($this->printrequests); |
| 63 | + $pr = next($this->m_printrequests); |
56 | 64 | $ra = next($row); |
57 | 65 | } |
58 | 66 | if ($ra !== false) { |
59 | 67 | return false; |
60 | 68 | } |
61 | | - $this->content[] = $row; |
62 | | - reset($this->content); |
| 69 | + $this->m_content[] = $row; |
| 70 | + reset($this->m_content); |
63 | 71 | return true; |
64 | 72 | } |
65 | 73 | |
— | — | @@ -68,8 +76,8 @@ |
69 | 77 | * SMWResultArray objects. |
70 | 78 | */ |
71 | 79 | public function getNext() { |
72 | | - $result = current($this->content); |
73 | | - next($this->content); |
| 80 | + $result = current($this->m_content); |
| 81 | + next($this->m_content); |
74 | 82 | return $result; |
75 | 83 | } |
76 | 84 | |
— | — | @@ -77,7 +85,7 @@ |
78 | 86 | * Return number of available results. |
79 | 87 | */ |
80 | 88 | public function getCount() { |
81 | | - return count($this->content); |
| 89 | + return count($this->m_content); |
82 | 90 | } |
83 | 91 | |
84 | 92 | /** |
— | — | @@ -85,7 +93,7 @@ |
86 | 94 | * in this result set contains. |
87 | 95 | */ |
88 | 96 | public function getColumnCount() { |
89 | | - return count($this->printrequests); |
| 97 | + return count($this->m_printrequests); |
90 | 98 | } |
91 | 99 | |
92 | 100 | /** |
— | — | @@ -93,7 +101,7 @@ |
94 | 102 | * property labels). |
95 | 103 | */ |
96 | 104 | public function getPrintRequests() { |
97 | | - return $this->printrequests; |
| 105 | + return $this->m_printrequests; |
98 | 106 | } |
99 | 107 | |
100 | 108 | /** |
— | — | @@ -101,16 +109,34 @@ |
102 | 110 | * not shown due to a limit? |
103 | 111 | */ |
104 | 112 | public function hasFurtherResults() { |
105 | | - return $this->furtherres; |
| 113 | + return $this->m_furtherres; |
106 | 114 | } |
107 | 115 | |
108 | 116 | /** |
| 117 | + * Return error array, possibly empty. |
| 118 | + */ |
| 119 | + public function getErrors() { |
| 120 | + return $this->m_errors; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
109 | 124 | * Return URL of a page that displays those search results |
110 | 125 | * (and enables browsing results, and is accessible even without |
111 | 126 | * JavaScript enabled browsers). |
112 | 127 | */ |
113 | 128 | public function getQueryURL() { |
114 | 129 | /// TODO implement (requires some way of generating/maintaining this URL as part of the query, and setting it when creating this result) |
| 130 | + $title = Title::makeTitle(NS_SPECIAL, 'ask'); |
| 131 | + $params = 'query=' . urlencode($this->m_querystring); |
| 132 | + if ($this->m_sortkey != false) { |
| 133 | + $params .= '&sort=' . urlencode($this->m_sortkey); |
| 134 | + if ($this->m_ascending) { |
| 135 | + $params .= '&order=ASC'; |
| 136 | + } else { |
| 137 | + $params .= '&order=DESC'; |
| 138 | + } |
| 139 | + } |
| 140 | + return $title->getLocalURL($params); |
115 | 141 | } |
116 | 142 | } |
117 | 143 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Query.php |
— | — | @@ -32,9 +32,12 @@ |
33 | 33 | public $querymode = SMWQuery::MODE_INSTANCES; |
34 | 34 | |
35 | 35 | protected $m_description; |
| 36 | + protected $m_errors; // keep any errors that occurred so far |
| 37 | + protected $m_querystring = false; // string (inline query) version (if fixed and known) |
36 | 38 | |
37 | 39 | public function SMWQuery($description = NULL) { |
38 | 40 | $this->m_description = $description; |
| 41 | + $this->m_errors = array(); |
39 | 42 | } |
40 | 43 | |
41 | 44 | public function setDescription(SMWDescription $description) { |
— | — | @@ -44,6 +47,29 @@ |
45 | 48 | public function getDescription() { |
46 | 49 | return $this->m_description; |
47 | 50 | } |
| 51 | + |
| 52 | + public function getErrors() { |
| 53 | + return $this->m_errors; |
| 54 | + } |
| 55 | + |
| 56 | + public function addErrors($errors) { |
| 57 | + $this->m_errors = array_merge($this->m_errors, $errors); |
| 58 | + } |
| 59 | + |
| 60 | + public function setQueryString($querystring) { |
| 61 | + $this->m_querystring = $querystring; |
| 62 | + } |
| 63 | + |
| 64 | + public function getQueryString() { |
| 65 | + if ($this->m_querystring !== false) { |
| 66 | + return $this->m_querystring; |
| 67 | + } elseif ($this->m_description !== NULL) { |
| 68 | + return $this->m_description->getQueryString(); |
| 69 | + } else { |
| 70 | + return ''; |
| 71 | + } |
| 72 | + } |
| 73 | + |
48 | 74 | } |
49 | 75 | |
50 | 76 | ?> |
\ No newline at end of file |