Permalink
Browse files

work on passing full param objects to the printers

Change-Id: Ibde22f947cd76aad334b0ea3c7985b0de889f0ad
  • Loading branch information...
1 parent 297b324 commit c73bcd0aaad6340c1ca7bd4949ac1be2cf507644 @JeroenDeDauw committed May 27, 2012
@@ -29,17 +29,18 @@ class SMWQueryProcessor {
* param name (string) => param value (mixed)
*
* @since 1.6.2
+ * The return value changed in SMW 1.8 from an array with result values to an array with IParam objects.
*
* @param array $params
* @param array $printRequests
* @param boolean $unknownInvalid
*
- * @return array
+ * @return array of IParam
*/
public static function getProcessedParams( array $params, array $printRequests = null, $unknownInvalid = true ) {
$validator = self::getValidatorForParams( $params, $printRequests, $unknownInvalid );
$validator->validateParameters();
- return $validator->getParameterValues();
+ return $validator->getParameters();
}
/**
@@ -77,25 +78,25 @@ public static function getValidatorForParams( array $params, array $printRequest
* known. Otherwise it will be determined from the parameters when
* needed. This parameter is just for optimisation in a common case.
*
- * @param string $querystring
+ * @param string $queryString
* @param array $params These need to be the result of a list fed to getProcessedParams
* @param $context
* @param string $format
- * @param array $extraprintouts
+ * @param array $extraPrintouts
*
* @return SMWQuery
*/
- static public function createQuery( $querystring, array $params, $context = self::INLINE_QUERY, $format = '', array $extraprintouts = array() ) {
+ static public function createQuery( $queryString, array $params, $context = self::INLINE_QUERY, $format = '', array $extraPrintouts = array() ) {
global $smwgQDefaultNamespaces, $smwgQFeatures, $smwgQConceptFeatures;
// parse query:
$queryfeatures = ( $context == self::CONCEPT_DESC ) ? $smwgQConceptFeatures : $smwgQFeatures;
$qp = new SMWQueryParser( $queryfeatures );
$qp->setDefaultNamespaces( $smwgQDefaultNamespaces );
- $desc = $qp->getQueryDescription( $querystring );
+ $desc = $qp->getQueryDescription( $queryString );
if ( $format === '' || is_null( $format ) ) {
- $format = $params['format'];
+ $format = $params['format']->getValue();
}
if ( $format == 'count' ) {
@@ -108,25 +109,25 @@ static public function createQuery( $querystring, array $params, $context = self
}
$query = new SMWQuery( $desc, ( $context != self::SPECIAL_PAGE ), ( $context == self::CONCEPT_DESC ) );
- $query->setQueryString( $querystring );
- $query->setExtraPrintouts( $extraprintouts );
- $query->setMainLabel( $params['mainlabel'] );
+ $query->setQueryString( $queryString );
+ $query->setExtraPrintouts( $extraPrintouts );
+ $query->setMainLabel( $params['mainlabel']->getValue() );
$query->addErrors( $qp->getErrors() ); // keep parsing errors for later output
// set mode, limit, and offset:
$query->querymode = $querymode;
- if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset'] + 0 ) ) ) {
- $query->setOffset( max( 0, trim( $params['offset'] ) + 0 ) );
+ if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset']->getValue() + 0 ) ) ) {
+ $query->setOffset( max( 0, trim( $params['offset']->getValue() ) + 0 ) );
}
if ( $query->querymode == SMWQuery::MODE_COUNT ) { // largest possible limit for "count", even inline
global $smwgQMaxLimit;
$query->setOffset( 0 );
$query->setLimit( $smwgQMaxLimit, false );
} else {
- if ( ( array_key_exists( 'limit', $params ) ) && ( is_int( trim( $params['limit'] ) + 0 ) ) ) {
- $query->setLimit( max( 0, trim( $params['limit'] ) + 0 ) );
- if ( ( trim( $params['limit'] ) + 0 ) < 0 ) { // limit < 0: always show further results link only
+ if ( ( array_key_exists( 'limit', $params ) ) && ( is_int( trim( $params['limit']->getValue() ) + 0 ) ) ) {
+ $query->setLimit( max( 0, trim( $params['limit']->getValue() ) + 0 ) );
+ if ( ( trim( $params['limit']->getValue() ) + 0 ) < 0 ) { // limit < 0: always show further results link only
$query->querymode = SMWQuery::MODE_NONE;
}
} else {
@@ -136,7 +137,7 @@ static public function createQuery( $querystring, array $params, $context = self
}
$defaultSort = $format === 'rss' ? 'DESC' : 'ASC';
- $sort = self::getSortKeys( $params['sort'], $params['order'], $defaultSort );
+ $sort = self::getSortKeys( $params['sort']->getValue(), $params['order']->getValue(), $defaultSort );
$query->sortkeys = $sort['keys'];
$query->addErrors( $sort['errors'] );
@@ -374,7 +375,7 @@ static public function getResultFromQueryString( $querystring, array $params, $e
wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' );
$query = self::createQuery( $querystring, $params, $context, '', $extraPrintouts );
- $result = self::getResultFromQuery( $query, $params, $extraPrintouts, $outputMode, $context );
+ $result = self::getResultFromQuery( $query, $params, $outputMode, $context );
wfProfileOut( 'SMWQueryProcessor::getResultFromQueryString (SMW)' );
@@ -386,13 +387,12 @@ static public function getResultFromQueryString( $querystring, array $params, $e
*
* @param SMWQuery $query
* @param array $params These need to be the result of a list fed to getProcessedParams
- * @param $extraPrintouts
- * @param $outputmode
+ * @param $outputMode
* @param $context
*
* @return string
*/
- static public function getResultFromQuery( SMWQuery $query, array $params, $extraPrintouts, $outputmode, $context = self::INLINE_QUERY ) {
+ protected static function getResultFromQuery( SMWQuery $query, array $params, $outputMode, $context = self::INLINE_QUERY ) {
wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' );
// Query routing allows extensions to provide alternative stores as data sources
@@ -413,7 +413,7 @@ static public function getResultFromQuery( SMWQuery $query, array $params, $extr
wfProfileIn( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' );
$printer = self::getResultPrinter( $params['format']->getValue(), $context, $res );
- $result = $printer->getResult( $res, $params, $outputmode );
+ $result = $printer->getResult( $res, $params, $outputMode );
wfProfileOut( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' );
wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' );
@@ -34,10 +34,11 @@
*/
protected function getQuery( $queryString, array $printouts ) {
SMWQueryProcessor::addThisPrintout( $printouts, $this->parameters );
+ $this->parameters = SMWQueryProcessor::getProcessedParams( $this->parameters, $printouts );
return SMWQueryProcessor::createQuery(
$queryString,
- SMWQueryProcessor::getProcessedParams( $this->parameters, $printouts ),
+ $this->parameters,
SMWQueryProcessor::SPECIAL_PAGE,
'',
$printouts
@@ -85,9 +86,15 @@ protected function addQueryResult( SMWQueryResult $queryResult ) {
if ( $queryResult->hasFurtherResults() ) {
$result->disableSizeCheck();
+
// TODO: right now this returns an offset that we can use for continuation, just like done
// in other places in SMW. However, this is not efficient, so we should change this at some point.
- $result->addValue( null, 'query-continue-offset', $this->parameters['offset'] + $queryResult->getCount() );
+ $result->addValue(
+ null,
+ 'query-continue-offset',
+ $this->parameters['offset']->getValue() + $queryResult->getCount()
+ );
+
$result->enableSizeCheck();
}
}
@@ -109,7 +109,7 @@ public function render( array $parameters ) {
}
if ( in_array( $parameters['parameters'], array( 'all', 'specific' ) ) ) {
- $params = array_merge( $params, $this->getFormatParameters( $parameters['format'] ) );
+ $params = array_merge( $params, $this->getFormatParameters( $parameters['format']->getValue() ) );
}
return $this->getParameterTable( $params );
@@ -352,7 +352,7 @@ public function execute() {
// FIXME: this is a hack
SMWQueryProcessor::addThisPrintout( $this->printOuts, $this->parameters );
$params = SMWQueryProcessor::getProcessedParams( $this->parameters, $this->printOuts );
- $this->parameters['format'] = $params['format'];
+ $this->parameters['format'] = $params['format']->getValue();
$this->params = $params;
$query = SMWQueryProcessor::createQuery(
@@ -204,7 +204,7 @@ protected function makeHTMLResult() {
// FIXME: this is a hack
SMWQueryProcessor::addThisPrintout( $this->m_printouts, $this->m_params );
$params = SMWQueryProcessor::getProcessedParams( $this->m_params, $this->m_printouts );
- $this->m_params['format'] = $params['format'];
+ $this->m_params['format'] = $params['format']->getValue();
$queryobj = SMWQueryProcessor::createQuery(
$this->m_querystring,
@@ -369,8 +369,15 @@ private function getNearbyResults( $count, $greater = true ) {
$printouts = array( $printrequest );
SMWQueryProcessor::addThisPrintout( $printouts, $params );
- $params = SMWQueryProcessor::getProcessedParams( $params, $printouts );
- $queryobj = SMWQueryProcessor::createQuery( $querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, 'ul', $printouts );
+
+ $queryobj = SMWQueryProcessor::createQuery(
+ $querystring,
+ SMWQueryProcessor::getProcessedParams( $params, $printouts ),
+ SMWQueryProcessor::SPECIAL_PAGE,
+ 'ul',
+ $printouts
+ );
+
$queryobj->querymode = SMWQuery::MODE_INSTANCES;
$queryobj->setLimit( $this->limit );
$queryobj->setOffset( $count );

0 comments on commit c73bcd0

Please sign in to comment.