コード例 #1
0
ファイル: ApiAsk.php プロジェクト: yusufchang/app
 public function execute()
 {
     $params = $this->extractRequestParams();
     $rawParams = preg_split("/(?<=[^\\|])\\|(?=[^\\|])/", $params['query']);
     list($queryString, $this->parameters, $printouts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawParams, false);
     $queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
     $this->addQueryResult($queryResult);
 }
コード例 #2
0
 public function testUriQueryFromRawParameters()
 {
     $property = $this->fixturesProvider->getProperty('url');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $this->subjects[] = $semanticData->getSubject();
     $dataValue = $this->dataValueFactory->newPropertyObjectValue($property, 'http://example.org/api.php?action=Foo');
     $semanticData->addDataValue($dataValue);
     $dataValue = $this->dataValueFactory->newPropertyObjectValue($property, 'http://example.org/Bar 42');
     $semanticData->addDataValue($dataValue);
     $this->getStore()->updateData($semanticData);
     /**
      * @query [[Url::http://example.org/api.php?action=Foo]][[Url::http://example.org/Bar 42]]
      */
     $rawParams = array('[[Url::http://example.org/api.php?action=Foo]][[Url::http://example.org/Bar 42]]', '?Url', 'limit=1');
     list($queryString, $parameters, $printouts) = QueryProcessor::getComponentsFromFunctionParams($rawParams, false);
     $description = $this->queryParser->getQueryDescription($queryString);
     $query = new Query($description, false, false);
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultHasSubjects($semanticData->getSubject(), $queryResult);
 }
コード例 #3
0
ファイル: Collection.php プロジェクト: albbas/Collection
 protected function getResults($input)
 {
     $query = "[[Collection::" . $input . "]]|?Expression|?Language";
     $rawParams = explode('|', $query);
     list($queryString, $parameters, $printouts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawParams, false);
     SMWQueryProcessor::addThisPrintout($printouts, $parameters);
     $smwQuery = SMWQueryProcessor::createQuery($queryString, SMWQueryProcessor::getProcessedParams($parameters, $printouts), SMWQueryProcessor::SPECIAL_PAGE, '', $printouts);
     $smwQuery->setUnboundLimit(50000);
     $smwQueryResult = smwfGetStore()->getQueryResult($smwQuery);
     $results = $smwQueryResult->toArray()['results'];
     $modified_results = array();
     foreach (array_keys($results) as $key) {
         $short_key = explode("#", $key)[0];
         $lang = $results[$key]['printouts']['Language'][0];
         $langs[$lang] = null;
         $expression = explode(":", $results[$key]['printouts']['Expression'][0]['fulltext'])[1];
         $modified_results[$short_key][$lang][] = $expression;
     }
     return array('data' => $modified_results, 'langs' => array_keys($langs));
 }
コード例 #4
0
ファイル: SMW_SpecialAsk.php プロジェクト: Tjorriemorrie/app
 /**
  * This code rather hacky since there are many ways to call that special page, the most involved of
  * which is the way that this page calls itself when data is submitted via the form (since the shape
  * of the parameters then is governed by the UI structure, as opposed to being governed by reason).
  *
  * TODO: most of this can probably be killed now we are using Validator
  *
  * @param string $p
  */
 protected function extractQueryParameters($p)
 {
     global $wgRequest, $smwgQMaxInlineLimit;
     // First make all inputs into a simple parameter list that can again be parsed into components later.
     if ($wgRequest->getCheck('q')) {
         // called by own Special, ignore full param string in that case
         $query_val = $wgRequest->getVal('p');
         if (!empty($query_val)) {
             // p is used for any additional parameters in certain links.
             $rawparams = SMWInfolink::decodeParameters($query_val, false);
         } else {
             $query_values = $wgRequest->getArray('p');
             if (is_array($query_values)) {
                 foreach ($query_values as $key => $val) {
                     if (empty($val)) {
                         unset($query_values[$key]);
                     }
                 }
             }
             // p is used for any additional parameters in certain links.
             $rawparams = SMWInfolink::decodeParameters($query_values, false);
         }
     } else {
         // called from wiki, get all parameters
         $rawparams = SMWInfolink::decodeParameters($p, true);
     }
     // Check for q= query string, used whenever this special page calls itself (via submit or plain link):
     $this->m_querystring = $wgRequest->getText('q');
     if ($this->m_querystring !== '') {
         $rawparams[] = $this->m_querystring;
     }
     // Check for param strings in po (printouts), appears in some links and in submits:
     $paramstring = $wgRequest->getText('po');
     if ($paramstring !== '') {
         // parameters from HTML input fields
         $ps = explode("\n", $paramstring);
         // params separated by newlines here (compatible with text-input for printouts)
         foreach ($ps as $param) {
             // add initial ? if omitted (all params considered as printouts)
             $param = trim($param);
             if ($param !== '' && $param[0] != '?') {
                 $param = '?' . $param;
             }
             $rawparams[] = $param;
         }
     }
     // Now parse parameters and rebuilt the param strings for URLs.
     list($this->m_querystring, $this->m_params, $this->m_printouts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawparams, false);
     // Try to complete undefined parameter values from dedicated URL params.
     if (!array_key_exists('format', $this->m_params)) {
         $this->m_params['format'] = 'broadtable';
     }
     if (!array_key_exists('order', $this->m_params)) {
         $order_values = $wgRequest->getArray('order');
         if (is_array($order_values)) {
             $this->m_params['order'] = '';
             foreach ($order_values as $order_value) {
                 if ($order_value === '') {
                     $order_value = 'ASC';
                 }
                 $this->m_params['order'] .= ($this->m_params['order'] !== '' ? ',' : '') . $order_value;
             }
         }
     }
     $this->m_num_sort_values = 0;
     if (!array_key_exists('sort', $this->m_params)) {
         $sort_values = $wgRequest->getArray('sort');
         if (is_array($sort_values)) {
             $this->m_params['sort'] = implode(',', $sort_values);
             $this->m_num_sort_values = count($sort_values);
         }
     }
     if (!array_key_exists('offset', $this->m_params)) {
         $this->m_params['offset'] = $wgRequest->getVal('offset');
         if ($this->m_params['offset'] === '') {
             $this->m_params['offset'] = 0;
         }
     }
     if (!array_key_exists('limit', $this->m_params)) {
         $this->m_params['limit'] = $wgRequest->getVal('limit');
         if ($this->m_params['limit'] === '') {
             $this->m_params['limit'] = $this->m_params['format'] == 'rss' ? 10 : 20;
             // Standard limit for RSS.
         }
     }
     $this->m_params['limit'] = min($this->m_params['limit'], $smwgQMaxInlineLimit);
     $this->m_editquery = $wgRequest->getVal('eq') == 'yes' || $this->m_querystring === '';
 }
コード例 #5
0
 /**
  * Processes the QueryString, Params, and PrintOuts.
  *
  * @todo Combine this method with execute() or remove it altogether.
  */
 public function extractParameters($p)
 {
     if ($this->context == self::SPECIAL_PAGE) {
         // assume setParams(), setPintouts and setQueryString have been called
         $rawParams = array_merge($this->parameters, array($this->queryString), $this->printOutStrings);
     } else {
         // context is WIKI_LINK
         $rawParams = SMWInfolink::decodeParameters($p, true);
         // calling setParams to fill in missing parameters
         $this->setParams($rawParams);
         $rawParams = $this->parameters;
     }
     list($this->queryString, $this->parameters, $this->m_printOuts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawParams, false);
 }