Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php |
— | — | @@ -226,6 +226,27 @@ |
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
| 230 | + |
| 231 | + public function serializeToArray() { |
| 232 | + $results = array(); |
| 233 | + |
| 234 | + foreach ( $this->mResults as /* SMWDIWikiPage */ $diWikiPage ) { |
| 235 | + switch ( $diWikiPage->getDIType() ) { |
| 236 | + case SMWDataItem::TYPE_NUMBER: |
| 237 | + $result = $diWikiPage->getNumber(); |
| 238 | + break; |
| 239 | + case SMWDataItem::TYPE_GEO: |
| 240 | + $result = $diWikiPage->getCoordinateSet(); |
| 241 | + break; |
| 242 | + default: |
| 243 | + $result = $diWikiPage->getSerialization(); |
| 244 | + } |
| 245 | + |
| 246 | + $results[$diWikiPage->getSerialization()] = $result; |
| 247 | + } |
| 248 | + |
| 249 | + return $results; |
| 250 | + } |
230 | 251 | |
231 | 252 | } |
232 | 253 | |
— | — | @@ -497,5 +518,5 @@ |
498 | 519 | |
499 | 520 | return $options; |
500 | 521 | } |
501 | | - |
| 522 | + |
502 | 523 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php |
— | — | @@ -18,11 +18,27 @@ |
19 | 19 | public function execute() { |
20 | 20 | $params = $this->extractRequestParams(); |
21 | 21 | $this->requireParameters( $params, array( 'conditions' ) ); |
| 22 | + $this->parameters = $params['parameters']; |
22 | 23 | |
23 | | - $query = $this->getQuery( ); // TODO |
| 24 | + $query = $this->getQuery( |
| 25 | + implode( array_map( array( __CLASS__, 'wrapCondition' ), $params['conditions'] ) ), |
| 26 | + array_map( array( __CLASS__, 'printeoutFromString' ), $params['printeouts'] ) |
| 27 | + ); |
24 | 28 | |
25 | 29 | $this->addQueryResult( $this->getQueryResult( $query ) ); |
26 | 30 | } |
| 31 | + |
| 32 | + public static function wrapCondition( $c ) { |
| 33 | + return "[[$c]]"; |
| 34 | + } |
| 35 | + |
| 36 | + public static function printeoutFromString( $printeout ) { |
| 37 | + return new SMWPrintRequest( |
| 38 | + SMWPrintRequest::PRINT_PROP, |
| 39 | + $printeout, |
| 40 | + SMWPropertyValue::makeUserProperty( $printeout ) |
| 41 | + ); |
| 42 | + } |
27 | 43 | |
28 | 44 | public function getAllowedParams() { |
29 | 45 | return array( |
— | — | @@ -64,7 +80,7 @@ |
65 | 81 | |
66 | 82 | protected function getExamples() { |
67 | 83 | return array( |
68 | | - 'api.php?action=askargs&conditions=Modification date::+&printeouts=Modification date¶meters=|sort%3DModification date|order%3Ddesc', |
| 84 | + 'api.php?action=askargs&conditions=Modification date::%2B&printeouts=Modification date¶meters=|sort%3DModification date|order%3Ddesc', |
69 | 85 | ); |
70 | 86 | } |
71 | 87 | |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php |
— | — | @@ -34,9 +34,14 @@ |
35 | 35 | * |
36 | 36 | * @return SMWQuery |
37 | 37 | */ |
38 | | - protected function getQuery( $queryString ) { |
39 | | - // SMWQueryProcessor::processFunctionParams( $rawparams, $queryString, $m_params, $m_printouts); |
40 | | - return SMWQueryProcessor::createQuery( $queryString, SMWQueryProcessor::getProcessedParams( $this->parameters ), SMWQueryProcessor::SPECIAL_PAGE ); |
| 38 | + protected function getQuery( $queryString, array $printeouts ) { |
| 39 | + return SMWQueryProcessor::createQuery( |
| 40 | + $queryString, |
| 41 | + SMWQueryProcessor::getProcessedParams( $this->parameters ), |
| 42 | + SMWQueryProcessor::SPECIAL_PAGE, |
| 43 | + '', |
| 44 | + $printeouts |
| 45 | + ); |
41 | 46 | } |
42 | 47 | |
43 | 48 | /** |
— | — | @@ -46,11 +51,12 @@ |
47 | 52 | * @return SMWQueryResult |
48 | 53 | */ |
49 | 54 | protected function getQueryResult( SMWQuery $query ) { |
50 | | - smwfGetStore()->getQueryResult( $query ); |
| 55 | + return smwfGetStore()->getQueryResult( $query ); |
51 | 56 | } |
52 | 57 | |
53 | 58 | protected function addQueryResult( SMWQueryResult $queryResult ) { |
54 | 59 | // TODO: create general SMWQueryResult serialization method that can then also be used for JSON printer |
| 60 | + $this->getResult()->addValue( 'result', null, $queryResult->serializeToArray() ); |
55 | 61 | } |
56 | 62 | |
57 | 63 | public function getPossibleErrors() { |
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php |
— | — | @@ -17,6 +17,8 @@ |
18 | 18 | public function execute() { |
19 | 19 | $params = $this->extractRequestParams(); |
20 | 20 | $this->requireParameters( $params, array( 'query' ) ); |
| 21 | + |
| 22 | + // SMWQueryProcessor::processFunctionParams( $rawparams, $queryString, $m_params, $m_printouts); |
21 | 23 | |
22 | 24 | $queryResult = $this->getQueryResult( $this->getQuery( $params['query'] ) ); |
23 | 25 | $this->addQueryResult( $queryResult ); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -45,6 +45,8 @@ |
46 | 46 | smwfRegisterSpecialPages(); |
47 | 47 | |
48 | 48 | $wgAPIModules['smwinfo'] = 'ApiSMWInfo'; |
| 49 | + $wgAPIModules['ask'] = 'ApiAsk'; |
| 50 | + $wgAPIModules['askargs'] = 'ApiAskArgs'; |
49 | 51 | |
50 | 52 | $wgFooterIcons['poweredby']['semanticmediawiki'] = array( |
51 | 53 | 'src' => null, |
— | — | @@ -339,9 +341,10 @@ |
340 | 342 | $wgAutoloadClasses['SMWRefreshJob'] = $smwgIP . 'includes/jobs/SMW_RefreshJob.php'; |
341 | 343 | |
342 | 344 | // API modules |
343 | | - //$wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php'; |
344 | | - //$wgAPIModules['smwquery'] = 'ApiSMWQuery'; |
345 | | - $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php'; |
| 345 | + $wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php'; |
| 346 | + $wgAutoloadClasses['ApiAsk'] = $smwgIP . 'includes/api/ApiAsk.php'; |
| 347 | + $wgAutoloadClasses['ApiAskArgs'] = $smwgIP . 'includes/api/ApiAskArgs.php'; |
| 348 | + $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php'; |
346 | 349 | |
347 | 350 | // Other extensions |
348 | 351 | $wgAutoloadClasses['SMWPageSchemas'] = $smwgIP . 'includes/SMW_PageSchemas.php'; |