r97324 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97323‎ | r97324 | r97325 >
Date:19:23, 16 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on ask api
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php
@@ -226,6 +226,27 @@
227227
228228 return $result;
229229 }
 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+ }
230251
231252 }
232253
@@ -497,5 +518,5 @@
498519
499520 return $options;
500521 }
501 -
 522+
502523 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAskArgs.php
@@ -18,11 +18,27 @@
1919 public function execute() {
2020 $params = $this->extractRequestParams();
2121 $this->requireParameters( $params, array( 'conditions' ) );
 22+ $this->parameters = $params['parameters'];
2223
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+ );
2428
2529 $this->addQueryResult( $this->getQueryResult( $query ) );
2630 }
 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+ }
2743
2844 public function getAllowedParams() {
2945 return array(
@@ -64,7 +80,7 @@
6581
6682 protected function getExamples() {
6783 return array(
68 - 'api.php?action=askargs&conditions=Modification date::+&printeouts=Modification date&parameters=|sort%3DModification date|order%3Ddesc',
 84+ 'api.php?action=askargs&conditions=Modification date::%2B&printeouts=Modification date&parameters=|sort%3DModification date|order%3Ddesc',
6985 );
7086 }
7187
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWQuery.php
@@ -34,9 +34,14 @@
3535 *
3636 * @return SMWQuery
3737 */
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+ );
4146 }
4247
4348 /**
@@ -46,11 +51,12 @@
4752 * @return SMWQueryResult
4853 */
4954 protected function getQueryResult( SMWQuery $query ) {
50 - smwfGetStore()->getQueryResult( $query );
 55+ return smwfGetStore()->getQueryResult( $query );
5156 }
5257
5358 protected function addQueryResult( SMWQueryResult $queryResult ) {
5459 // TODO: create general SMWQueryResult serialization method that can then also be used for JSON printer
 60+ $this->getResult()->addValue( 'result', null, $queryResult->serializeToArray() );
5561 }
5662
5763 public function getPossibleErrors() {
Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiAsk.php
@@ -17,6 +17,8 @@
1818 public function execute() {
1919 $params = $this->extractRequestParams();
2020 $this->requireParameters( $params, array( 'query' ) );
 21+
 22+ // SMWQueryProcessor::processFunctionParams( $rawparams, $queryString, $m_params, $m_printouts);
2123
2224 $queryResult = $this->getQueryResult( $this->getQuery( $params['query'] ) );
2325 $this->addQueryResult( $queryResult );
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -45,6 +45,8 @@
4646 smwfRegisterSpecialPages();
4747
4848 $wgAPIModules['smwinfo'] = 'ApiSMWInfo';
 49+ $wgAPIModules['ask'] = 'ApiAsk';
 50+ $wgAPIModules['askargs'] = 'ApiAskArgs';
4951
5052 $wgFooterIcons['poweredby']['semanticmediawiki'] = array(
5153 'src' => null,
@@ -339,9 +341,10 @@
340342 $wgAutoloadClasses['SMWRefreshJob'] = $smwgIP . 'includes/jobs/SMW_RefreshJob.php';
341343
342344 // 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';
346349
347350 // Other extensions
348351 $wgAutoloadClasses['SMWPageSchemas'] = $smwgIP . 'includes/SMW_PageSchemas.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r97358Follow up to r97324; fixed serializationjeroendedauw02:17, 17 September 2011