Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php |
___________________________________________________________________ |
Added: ApiAskArgs.php |
1 | 1 | + Id |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to query SMW by providing a query specified as |
| 6 | + * a list of conditions, printeouts and parameters. |
| 7 | + * |
| 8 | + * @since 1.6.2 |
| 9 | + * |
| 10 | + * @file ApiAskArgs.php |
| 11 | + * @ingroup SMW |
| 12 | + * @ingroup API |
| 13 | + * |
| 14 | + * @licence GNU GPL v3+ |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
| 17 | +class ApiAskArgs extends ApiSMWQuery { |
| 18 | + |
| 19 | + public function execute() { |
| 20 | + $params = $this->extractRequestParams(); |
| 21 | + $this->requireParameters( $params, array( 'conditions' ) ); |
| 22 | + |
| 23 | + $query = $this->getQuery( ); // TODO |
| 24 | + |
| 25 | + $this->addQueryResult( $this->getQueryResult( $query ) ); |
| 26 | + } |
| 27 | + |
| 28 | + public function getAllowedParams() { |
| 29 | + return array( |
| 30 | + 'conditions' => array( |
| 31 | + ApiBase::PARAM_TYPE => 'string', |
| 32 | + ApiBase::PARAM_ISMULTI => true, |
| 33 | + ), |
| 34 | + 'printeouts' => array( |
| 35 | + ApiBase::PARAM_TYPE => 'string', |
| 36 | + ApiBase::PARAM_DFLT => '', |
| 37 | + ApiBase::PARAM_ISMULTI => true, |
| 38 | + ), |
| 39 | + 'parameters' => array( |
| 40 | + ApiBase::PARAM_TYPE => 'string', |
| 41 | + ApiBase::PARAM_DFLT => '', |
| 42 | + ApiBase::PARAM_ISMULTI => true, |
| 43 | + ), |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public function getParamDescription() { |
| 48 | + return array( |
| 49 | + 'conditions' => 'The query conditions, ie the requirements for a subject to be included', |
| 50 | + 'printeouts' => 'The query printeouts, ie the properties to show per subject', |
| 51 | + 'parameters' => 'The query parameters, ie all non-condition and non-printeout arguments', |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + public function getDescription() { |
| 56 | + return array( |
| 57 | + 'API module to query SMW by providing a query specified as a list of conditions, printeouts and parameters.' |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function getPossibleErrors() { |
| 62 | + return array_merge( parent::getPossibleErrors(), array( |
| 63 | + ) ); |
| 64 | + } |
| 65 | + |
| 66 | + protected function getExamples() { |
| 67 | + return array( |
| 68 | + 'api.php?action=askargs&conditions=Modification date::+&printeouts=Modification date¶meters=|sort%3DModification date|order%3Ddesc', |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + public function getVersion() { |
| 73 | + return __CLASS__ . ': $Id: $'; |
| 74 | + } |
| 75 | + |
| 76 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 77 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Base for API modules that query SMW. |
| 6 | + * |
| 7 | + * @since 1.6.2 |
| 8 | + * |
| 9 | + * @file ApiSMWQuery.php |
| 10 | + * @ingroup SMW |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +abstract class ApiSMWQuery extends ApiBase { |
| 17 | + |
| 18 | + /** |
| 19 | + * Query parameters. |
| 20 | + * |
| 21 | + * @since 1.6.2 |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + protected $parameters; |
| 25 | + |
| 26 | + /** |
| 27 | + * Query printeouts. |
| 28 | + * |
| 29 | + * @since 1.6.2 |
| 30 | + * @var array |
| 31 | + */ |
| 32 | + protected $printeouts; |
| 33 | + |
| 34 | + /** |
| 35 | + * |
| 36 | + * @return SMWQuery |
| 37 | + */ |
| 38 | + protected function getQuery( $queryString ) { |
| 39 | + // SMWQueryProcessor::processFunctionParams( $rawparams, $queryString, $m_params, $m_printouts); |
| 40 | + return SMWQueryProcessor::createQuery( $queryString, $this->parameters, SMWQueryProcessor::SPECIAL_PAGE ); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * |
| 45 | + * @param SMWQuery $query |
| 46 | + * |
| 47 | + * @return SMWQueryResult |
| 48 | + */ |
| 49 | + protected function getQueryResult( SMWQuery $query ) { |
| 50 | + smwfGetStore()->getQueryResult( $query ); |
| 51 | + } |
| 52 | + |
| 53 | + protected function addQueryResult( SMWQueryResult $queryResult ) { |
| 54 | + // TODO: create general SMWQueryResult serialization method that can then also be used for JSON printer |
| 55 | + } |
| 56 | + |
| 57 | + public function getPossibleErrors() { |
| 58 | + return array_merge( parent::getPossibleErrors(), array( |
| 59 | + ) ); |
| 60 | + } |
| 61 | + |
| 62 | + protected function requireParameters( array $params, array $required ) { |
| 63 | + foreach ( $required as $param ) { |
| 64 | + if ( !isset( $params[$param] ) ) { |
| 65 | + $this->dieUsageMsg( array( 'missingparam', $param ) ); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 71 | + native |
Added: ApiAskArgs.php |
2 | 72 | + Id |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to query SMW by providing a query in the ask language. |
| 6 | + * |
| 7 | + * @since 1.6.2 |
| 8 | + * |
| 9 | + * @file ApiAsk.php |
| 10 | + * @ingroup SMW |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiAsk extends ApiSMWQuery { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + $params = $this->extractRequestParams(); |
| 20 | + $this->requireParameters( $params, array( 'query' ) ); |
| 21 | + |
| 22 | + $queryResult = $this->getQueryResult( $this->getQuery( $params['query'] ) ); |
| 23 | + $this->addQueryResult( $queryResult ); |
| 24 | + } |
| 25 | + |
| 26 | + public function getAllowedParams() { |
| 27 | + return array( |
| 28 | + 'query' => array( |
| 29 | + ApiBase::PARAM_TYPE => 'string', |
| 30 | + ), |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function getParamDescription() { |
| 35 | + return array( |
| 36 | + 'query' => 'The query string in ask-language' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + public function getDescription() { |
| 41 | + return array( |
| 42 | + 'API module to query SMW by providing a query in the ask language.' |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public function getPossibleErrors() { |
| 47 | + return array_merge( parent::getPossibleErrors(), array( |
| 48 | + ) ); |
| 49 | + } |
| 50 | + |
| 51 | + protected function getExamples() { |
| 52 | + return array( |
| 53 | + 'api.php?action=ask&query=[[Modification date::+]]|%3FModification date|sort%3DModification date|order%3Ddesc', |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + public function getVersion() { |
| 58 | + return __CLASS__ . ': $Id: $'; |
| 59 | + } |
| 60 | + |
| 61 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |
Added: ApiAskArgs.php |
2 | 63 | + Id |