r71940 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71939‎ | r71940 | r71941 >
Date:11:22, 30 August 2010
Author:mkroetzsch
Status:ok (Comments)
Tags:
Comment:
some cleanup in createQuery() code
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -34,21 +34,15 @@
3535 */
3636 static public function createQuery( $querystring, array $params, $context = SMWQueryProcessor::INLINE_QUERY, $format = '', $extraprintouts = array() ) {
3737 global $smwgQDefaultNamespaces, $smwgQFeatures, $smwgQConceptFeatures;
 38+ if ( $format == '' ) {
 39+ $format = SMWQueryProcessor::getResultFormat( $params );
 40+ }
3841
3942 // parse query:
40 - if ( $context == SMWQueryProcessor::CONCEPT_DESC ) {
41 - $queryfeatures = $smwgQConceptFeatures;
42 - } else {
43 - $queryfeatures = $smwgQFeatures;
44 - }
45 -
 43+ $queryfeatures = ( $context == SMWQueryProcessor::CONCEPT_DESC ) ? $smwgQConceptFeatures : $smwgQFeatures;
4644 $qp = new SMWQueryParser( $queryfeatures );
4745 $qp->setDefaultNamespaces( $smwgQDefaultNamespaces );
4846 $desc = $qp->getQueryDescription( $querystring );
49 -
50 - if ( $format == '' ) {
51 - $format = SMWQueryProcessor::getResultFormat( $params );
52 - }
5347
5448 if ( $format == 'count' ) {
5549 $querymode = SMWQuery::MODE_COUNT;
@@ -60,13 +54,9 @@
6155 }
6256
6357 $mainlabel = array_key_exists( 'mainlabel', $params ) ? $params['mainlabel'] : '';
64 -
6558 if ( ( $querymode == SMWQuery::MODE_NONE ) ||
66 - ( ( !$desc->isSingleton() ||
67 - ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 )
68 - ) && ( $mainlabel != '-' )
69 - )
70 - ) {
 59+ ( ( !$desc->isSingleton() || ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 ) )
 60+ && ( $mainlabel != '-' ) ) ) {
7161 $desc->prependPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, $mainlabel ) );
7262 }
7363
@@ -75,7 +65,7 @@
7666 $query->setExtraPrintouts( $extraprintouts );
7767 $query->addErrors( $qp->getErrors() ); // keep parsing errors for later output
7868
79 - // set query parameters:
 69+ // set mode, limit, and offset:
8070 $query->querymode = $querymode;
8171 if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset'] + 0 ) ) ) {
8272 $query->setOffset( max( 0, trim( $params['offset'] ) + 0 ) );
@@ -83,7 +73,6 @@
8474
8575 if ( $query->querymode == SMWQuery::MODE_COUNT ) { // largest possible limit for "count", even inline
8676 global $smwgQMaxLimit;
87 -
8877 $query->setOffset( 0 );
8978 $query->setLimit( $smwgQMaxLimit, false );
9079 } else {
@@ -125,7 +114,6 @@
126115 foreach ( explode( ',', trim( $params['sort'] ) ) as $sort ) {
127116 $sort = smwfNormalTitleDBKey( trim( $sort ) ); // slight normalisation
128117 $order = current( $orders );
129 -
130118 if ( $order === false ) { // default
131119 $order = 'ASC';
132120 }

Comments

#Comment by Jeroen De Dauw (talk | contribs)   09:59, 31 August 2010

Yay - less lines of code :D

Status & tagging log