http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95733
Revision: 95733
Author: jeroendedauw
Date: 2011-08-30 00:24:22 +0000 (Tue, 30 Aug 2011)
Log Message:
-----------
adding base for query api modules
Added Paths:
-----------
trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php
trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
Property Changed:
----------------
trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php
Added: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php
(rev 0)
+++ trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php 2011-08-30
00:24:22 UTC (rev 95733)
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * API module to query SMW by providing a query in the ask language.
+ *
+ * @since 1.6.2
+ *
+ * @file ApiAsk.php
+ * @ingroup SMW
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiAsk extends ApiSMWQuery {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $this->requireParameters( $params, array( 'query' ) );
+
+ $queryResult = $this->getQueryResult( $this->getQuery(
$params['query'] ) );
+ $this->addQueryResult( $queryResult );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'query' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ),
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'query' => 'The query string in ask-language'
+ );
+ }
+
+ public function getDescription() {
+ return array(
+ 'API module to query SMW by providing a query in the
ask language.'
+ );
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(), array(
+ ) );
+ }
+
+ protected function getExamples() {
+ return array(
+ 'api.php?action=ask&query=[[Modification
date::+]]|%3FModification date|sort%3DModification date|order%3Ddesc',
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id: $';
+ }
+
+}
Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php
___________________________________________________________________
Added: ApiAskArgs.php
+ Id
Added: svn:eol-style
+ native
Added: trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
(rev 0)
+++ trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
2011-08-30 00:24:22 UTC (rev 95733)
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * API module to query SMW by providing a query specified as
+ * a list of conditions, printeouts and parameters.
+ *
+ * @since 1.6.2
+ *
+ * @file ApiAskArgs.php
+ * @ingroup SMW
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiAskArgs extends ApiSMWQuery {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $this->requireParameters( $params, array( 'conditions' ) );
+
+ $query = $this->getQuery( ); // TODO
+
+ $this->addQueryResult( $this->getQueryResult( $query ) );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'conditions' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ 'printeouts' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => '',
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ 'parameters' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => '',
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'conditions' => 'The query conditions, ie the
requirements for a subject to be included',
+ 'printeouts' => 'The query printeouts, ie the
properties to show per subject',
+ 'parameters' => 'The query parameters, ie all
non-condition and non-printeout arguments',
+ );
+ }
+
+ public function getDescription() {
+ return array(
+ 'API module to query SMW by providing a query specified
as a list of conditions, printeouts and parameters.'
+ );
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(), array(
+ ) );
+ }
+
+ protected function getExamples() {
+ return array(
+ 'api.php?action=askargs&conditions=Modification
date::+&printeouts=Modification date¶meters=|sort%3DModification
date|order%3Ddesc',
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id: $';
+ }
+
+}
Property changes on:
trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
___________________________________________________________________
Added: svn:eol-style
+ native
Property changes on:
trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php
___________________________________________________________________
Added: ApiAskArgs.php
+ Id
Added: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
(rev 0)
+++ trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
2011-08-30 00:24:22 UTC (rev 95733)
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * Base for API modules that query SMW.
+ *
+ * @since 1.6.2
+ *
+ * @file ApiSMWQuery.php
+ * @ingroup SMW
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+abstract class ApiSMWQuery extends ApiBase {
+
+ /**
+ * Query parameters.
+ *
+ * @since 1.6.2
+ * @var array
+ */
+ protected $parameters;
+
+ /**
+ * Query printeouts.
+ *
+ * @since 1.6.2
+ * @var array
+ */
+ protected $printeouts;
+
+ /**
+ *
+ * @return SMWQuery
+ */
+ protected function getQuery( $queryString ) {
+ // SMWQueryProcessor::processFunctionParams( $rawparams,
$queryString, $m_params, $m_printouts);
+ return SMWQueryProcessor::createQuery( $queryString,
$this->parameters, SMWQueryProcessor::SPECIAL_PAGE );
+ }
+
+ /**
+ *
+ * @param SMWQuery $query
+ *
+ * @return SMWQueryResult
+ */
+ protected function getQueryResult( SMWQuery $query ) {
+ smwfGetStore()->getQueryResult( $query );
+ }
+
+ protected function addQueryResult( SMWQueryResult $queryResult ) {
+ // TODO: create general SMWQueryResult serialization method
that can then also be used for JSON printer
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(), array(
+ ) );
+ }
+
+ protected function requireParameters( array $params, array $required ) {
+ foreach ( $required as $param ) {
+ if ( !isset( $params[$param] ) ) {
+ $this->dieUsageMsg( array( 'missingparam',
$param ) );
+ }
+ }
+ }
+
+}
Property changes on:
trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
___________________________________________________________________
Added: ApiAskArgs.php
+ Id
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs