|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SEQL\ByHttpRequest; |
|
4
|
|
|
|
|
5
|
|
|
use SMWInfolink as Infolink; |
|
6
|
|
|
use SMWQueryResult as RootQueryResult; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @license GNU GPL v2+ |
|
10
|
|
|
* @since 1.0 |
|
11
|
|
|
* |
|
12
|
|
|
* @author mwjames |
|
13
|
|
|
*/ |
|
14
|
|
|
class QueryResult extends RootQueryResult { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $remoteTargetUrl = ''; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var JsonResponseParser |
|
23
|
|
|
*/ |
|
24
|
|
|
private $jsonResponseParser; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @since 1.0 |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $remoteTargetUrl |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function setRemoteTargetUrl( $remoteTargetUrl ) { |
|
32
|
1 |
|
$this->remoteTargetUrl = $remoteTargetUrl; |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @since 1.0 |
|
37
|
|
|
* |
|
38
|
|
|
* @param JsonResponseParser $jsonResponseParser |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function setJsonResponseParser( JsonResponseParser $jsonResponseParser ) { |
|
41
|
2 |
|
$this->jsonResponseParser = $jsonResponseParser; |
|
42
|
2 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @since 1.0 |
|
46
|
|
|
* |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function toArray() { |
|
50
|
1 |
|
return $this->jsonResponseParser->getRawResponseResult(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @since 1.0 |
|
55
|
|
|
* |
|
56
|
|
|
* @return CannedResultArray[]|false |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getNext() { |
|
59
|
1 |
|
$page = current( $this->mResults ); |
|
60
|
1 |
|
next( $this->mResults ); |
|
61
|
|
|
|
|
62
|
1 |
|
if ( $page === false ) { |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
$row = array(); |
|
67
|
|
|
|
|
68
|
1 |
|
foreach ( $this->mPrintRequests as $p ) { |
|
69
|
1 |
|
$row[] = new CannedResultArray( $page, $p, $this->jsonResponseParser ); |
|
70
|
1 |
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
return $row; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @since 1.0 |
|
77
|
|
|
* |
|
78
|
|
|
* @return SMWInfolink |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getLink() { |
|
81
|
1 |
|
$params = array( trim( $this->getQuery()->getQueryString() ) ); |
|
82
|
|
|
|
|
83
|
1 |
|
foreach ( $this->getQuery()->getExtraPrintouts() as $printout ) { |
|
84
|
1 |
|
$serialization = $printout->getSerialisation(); |
|
85
|
|
|
|
|
86
|
|
|
// TODO: this is a hack to get rid of the mainlabel param in case it was automatically added |
|
87
|
|
|
// by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone. |
|
88
|
1 |
|
if ( $serialization !== '?#' ) { |
|
89
|
1 |
|
$params[] = $serialization; |
|
90
|
1 |
|
} |
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
// Note: the initial : prevents SMW from reparsing :: in the query string. |
|
94
|
1 |
|
return Infolink::newExternalLink( '', $this->remoteTargetUrl . 'Special:Ask', false, $params ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|