00001 <?php
00002
00016 class ApiAskArgs extends ApiSMWQuery {
00017
00018 public function execute() {
00019 $params = $this->extractRequestParams();
00020 $this->requireParameters( $params, array( 'conditions' ) );
00021
00022 foreach ( $params['parameters'] as $param ) {
00023 $parts = explode( '=', $param, 2 );
00024
00025 if ( count( $parts ) == 2 ) {
00026 $this->parameters[$parts[0]] = $parts[1];
00027 }
00028 }
00029
00030 $query = $this->getQuery(
00031 implode( array_map( array( __CLASS__, 'wrapCondition' ), $params['conditions'] ) ),
00032 array_map( array( __CLASS__, 'printoutFromString' ), $params['printouts'] )
00033 );
00034
00035 $this->addQueryResult( $this->getQueryResult( $query ) );
00036 }
00037
00038 public static function wrapCondition( $c ) {
00039 return "[[$c]]";
00040 }
00041
00042 public static function printoutFromString( $printout ) {
00043 return new SMWPrintRequest(
00044 SMWPrintRequest::PRINT_PROP,
00045 $printout,
00046 SMWPropertyValue::makeUserProperty( $printout )
00047 );
00048 }
00049
00050 public function getAllowedParams() {
00051 return array(
00052 'conditions' => array(
00053 ApiBase::PARAM_TYPE => 'string',
00054 ApiBase::PARAM_ISMULTI => true,
00055 ),
00056 'printouts' => array(
00057 ApiBase::PARAM_TYPE => 'string',
00058 ApiBase::PARAM_DFLT => '',
00059 ApiBase::PARAM_ISMULTI => true,
00060 ),
00061 'parameters' => array(
00062 ApiBase::PARAM_TYPE => 'string',
00063 ApiBase::PARAM_DFLT => '',
00064 ApiBase::PARAM_ISMULTI => true,
00065 ),
00066 );
00067 }
00068
00069 public function getParamDescription() {
00070 return array(
00071 'conditions' => 'The query conditions, i.e. the requirements for a subject to be included',
00072 'printouts' => 'The query printouts, i.e. the properties to show per subject',
00073 'parameters' => 'The query parameters, i.e. all non-condition and non-printout arguments',
00074 );
00075 }
00076
00077 public function getDescription() {
00078 return array(
00079 'API module to query SMW by providing a query specified as a list of conditions, printouts and parameters.
00080 This API module is in alpha stage, and likely to see changes in upcomming versions of SMW.'
00081 );
00082 }
00083
00084 protected function getExamples() {
00085 return array(
00086 'api.php?action=askargs&conditions=Modification%20date::%2B&printouts=Modification%20date¶meters=|sort%3DModification%20date|order%3Ddesc',
00087 );
00088 }
00089
00090 public function getVersion() {
00091 return __CLASS__ . ': $Id: ApiAskArgs.php 112438 2012-02-26 14:21:22Z nikerabbit $';
00092 }
00093
00094 }