in extensions/SMWAskAPI/api/SMWAsk_API.php [58:132]
public function execute() {
global $wgUser;
$params = $this->extractRequestParams();
if (is_null($params[SMWAskAPI::$PARAM_QUERY]))
$this->dieUsage('Must specify a semantic query (' . SMWAskAPI::$PARAM_QUERY . ')', 0);
$query = $params[SMWAskAPI::$PARAM_QUERY];
if (!is_null($params[SMWAskAPI::$PARAM_PRINTOUTS])) {
$props = explode("|", $params[SMWAskAPI::$PARAM_PRINTOUTS]);
} else {
$props = array();
}
if( !isset($params[SMWAskAPI::$PARAM_LIMIT]) || is_null($limit = $params[SMWAskAPI::$PARAM_LIMIT]) || $limit == '' ){
$limit = null;// null = 'infinity'
}else if ( ($limit=intval($limit)) < 0 ){
$this->dieUsage('Invalid ' . SMWAskAPI::$PARAM_LIMIT . '='.$limit.': if set, must be a non-negative integer. 0 value means default', 0);
}
if( !isset($params[SMWAskAPI::$PARAM_OFFSET]) || is_null($offset = $params[SMWAskAPI::$PARAM_OFFSET]) ){
$offset = 0;// 0 is default value
}else if ( ($offset=intval($offset)) < 0 ){
$this->dieUsage('Invalid ' . SMWAskAPI::$PARAM_OFFSET . '='.$offset.': if set, must be a non-negative integer. Default value is 0', 0);
}
$res = $this->ask($query, $props, $limit, $offset);
$result = array();
$ask_errors = $res->getErrors();
if (empty($ask_errors)) {
$result['result'] = 'Success';
} else {
$result['result'] = 'Error';
$this->getResult()->setIndexedTagName($ask_errors, 'list-item');
$this->getResult()->addValue(array($this->ACTION_NAME), 'errors', $ask_errors);
}
$this->getResult()->addValue(array($this->ACTION_NAME, 'query'), SMWAskAPI::$PARAM_QUERY, $query);
if (count($props) > 0) {
$this->getResult()->setIndexedTagName($props, 'list-item');
$this->getResult()->addValue(array($this->ACTION_NAME, 'query'), SMWAskAPI::$PARAM_PRINTOUTS, $props);
}
if( ! is_null($limit) ){
$this->getResult()->addValue(array($this->ACTION_NAME, 'query'), SMWAskAPI::$PARAM_LIMIT, $limit);
}
if( $offset!=0 ){
$this->getResult()->addValue(array($this->ACTION_NAME, 'query'), SMWAskAPI::$PARAM_OFFSET, $offset);
}
if ( $res->getCount() > 0 || $res->hasFurtherResults() ) {
// We set the num of *displayed* results
$this->getResult()->addValue(array($this->ACTION_NAME, 'results'), 'count', $res->getCount());
// If more results can be found, say it
if( $res->hasFurtherResults() ){
$this->getResult()->addValue(array($this->ACTION_NAME, 'results'), 'hasMore', 'true');
}
$items = array();
while (( $r = $res->getNext() ) !== false) {
$items[] = $this->resultToItem($r);
}
$this->getResult()->setIndexedTagName($items, 'list-item');
$this->getResult()->addValue(array($this->ACTION_NAME, 'results'), 'items', $items);
}
$this->getResult()->addValue(null, $this->ACTION_NAME, $result);
}