summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticFormsSelect/src/ApiSemanticFormsSelect.php
blob: 86dabb5ed48c5803fd18541603bcac00784cb318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

/**
 * API modules to communicate with the back-end
 *
 * @license GNU GPL v2+
 * @since 1.2
 *
 * @author Jason Zhang
 * @author Toni Hermoso Pulido
 */

namespace SFS;

use ApiBase;
use Parser;
use ParserOptions;
use ParserOutput;
use Title;

class ApiSemanticFormsSelect extends ApiBase {

	/**
	 * @see ApiBase::execute
	 */
	public function execute() {

		$parser = new Parser( $GLOBALS['wgParserConf'] );
		$parser->setTitle( Title::newFromText( 'NO TITLE' ) );
		$parser->mOptions = new ParserOptions();
		$parser->mOutput = new ParserOutput();

		$apiRequestProcessor = new \SFS\ApiSemanticFormsSelectRequestProcessor( $parser );
		$apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] );

		$resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters(
			$this->extractRequestParams()
		);

		$result = $this->getResult();
		$result->setIndexedTagName( $resultValues->values, 'value' );
		$result->addValue( $this->getModuleName(), 'values', $resultValues->values );
		$result->addValue( $this->getModuleName(), 'count', $resultValues->count );

		return true;
	}

	/**
	 * @see ApiBase::getAllowedParams
	 */
	public function getAllowedParams() {
		return [
			'approach' => [
				ApiBase::PARAM_TYPE => 'string',
				ApiBase::PARAM_REQUIRED => true
			],
			'query' => [
				ApiBase::PARAM_TYPE => 'string',
				ApiBase::PARAM_REQUIRED => true
			],
			'sep' => [
				ApiBase::PARAM_TYPE => 'string',
				ApiBase::PARAM_REQUIRED => false
			]
		];
	}

	/**
	 * @see ApiBase::getDescription
	 */
	public function getDescription() {
		return [
			'API for providing SemanticFormsSelect values'
		];
	}

	/**
	 * @see ApiBase::getParamDescription
	 */
	public function getParamDescription() {
		return [
			'approach' => 'The actual approach: function or smw',
			'query' => 'The query of the former'
		];
	}

	/**
	 * @see ApiBase::getVersion
	 */
	public function getVersion() {
		return __CLASS__ . ': 1.1';
	}

}