|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
//namespace SFS; # for some reason, this was not working with API registration via extension.json |
|
4
|
|
|
|
|
5
|
|
|
use ApiBase; |
|
6
|
|
|
use Parser; |
|
7
|
|
|
use ParserOptions; |
|
8
|
|
|
use ParserOutput; |
|
9
|
|
|
use Title; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* API modules to communicate with the back-end |
|
13
|
|
|
* |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
* @since 1.2 |
|
16
|
|
|
* |
|
17
|
|
|
* @author Jason Zhang |
|
18
|
|
|
* @author Toni Hermoso Pulido |
|
19
|
|
|
*/ |
|
20
|
|
|
class ApiSemanticFormsSelect extends ApiBase { |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @see ApiBase::execute |
|
24
|
|
|
*/ |
|
25
|
|
|
public function execute() { |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$parser = new Parser( $GLOBALS['wgParserConf'] ); |
|
28
|
|
|
$parser->setTitle( Title::newFromText( 'NO TITLE' ) ); |
|
29
|
|
|
$parser->mOptions = new ParserOptions(); |
|
30
|
|
|
$parser->mOutput = new ParserOutput(); |
|
31
|
|
|
|
|
32
|
|
|
$apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor( $parser ); |
|
33
|
|
|
$apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] ); |
|
34
|
|
|
|
|
35
|
|
|
$resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters( |
|
36
|
|
|
$this->extractRequestParams() |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$result = $this->getResult(); |
|
40
|
|
|
$result->setIndexedTagName( $resultValues->values, 'value' ); |
|
41
|
|
|
$result->addValue( $this->getModuleName(), 'values', $resultValues->values ); |
|
42
|
|
|
$result->addValue( $this->getModuleName(), 'count', $resultValues->count ); |
|
43
|
|
|
|
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @see ApiBase::getAllowedParams |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getAllowedParams() { |
|
51
|
|
|
return array( |
|
52
|
|
|
'approach' => array( |
|
53
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
54
|
|
|
ApiBase::PARAM_REQUIRED => true |
|
55
|
|
|
), |
|
56
|
|
|
'query' => array( |
|
57
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
58
|
|
|
ApiBase::PARAM_REQUIRED => true |
|
59
|
|
|
), |
|
60
|
|
|
'sep' => array( |
|
61
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
62
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
63
|
|
|
) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @see ApiBase::getDescription |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getDescription() { |
|
71
|
|
|
return array( |
|
72
|
|
|
'API for providing SemanticFormsSelect values' |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @see ApiBase::getParamDescription |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getParamDescription() { |
|
80
|
|
|
return array( |
|
81
|
|
|
'approach' => 'The actual approach: function or smw', |
|
82
|
|
|
'query' => 'The query of the former' |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @see ApiBase::getVersion |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getVersion() { |
|
90
|
|
|
return __CLASS__ . ': 1.1'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.