r63603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63602‎ | r63603 | r63604 >
Date:15:30, 11 March 2010
Author:yaron
Status:deferred
Tags:
Comment:
Fix for whitespaces in queries; fix to avoid duplicate results with SMW 1.5
Modified paths:
  • /trunk/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php
@@ -24,7 +24,7 @@
2525 for ( $i = 0; $i < strlen( $param ); $i++ ) {
2626 $c = $param[$i];
2727 if ( ( $c == ';' ) && ( $uncompleted_square_brackets <= 0 ) ) {
28 - $sub_params[] = $sub_param;
 28+ $sub_params[] = trim($sub_param);
2929 $sub_param = "";
3030 } else {
3131 $sub_param .= $c;
@@ -34,7 +34,7 @@
3535 $uncompleted_square_brackets--;
3636 }
3737 }
38 - $sub_params[] = $sub_param;
 38+ $sub_params[] = trim($sub_param);
3939 return $sub_params;
4040 }
4141
@@ -57,7 +57,7 @@
5858 $sub_params = SCQQueryProcessor::getSubParams( $param );
5959 $next_result = SCQQueryProcessor::getQueryResultFromFunctionParams( $sub_params, SMW_OUTPUT_WIKI );
6060 if (method_exists($next_result, 'getResults')) { // SMW 1.5+
61 - $results = array_merge($results, $next_result->getResults());
 61+ $results = self::mergeSMWQueryResults($results, $next_result->getResults());
6262 } else {
6363 if ( $query_result == null )
6464 $query_result = new SCQQueryResult( $next_result->getPrintRequests(), new SMWQuery() );
@@ -86,26 +86,22 @@
8787 }
8888
8989 /**
90 - * Combine the values from two SMWQueryResult objects into one
 90+ * Combine two arrays of SMWWikiPageValue objects into one
9191 */
9292 static function mergeSMWQueryResults( $result1, $result2 ) {
9393 if ( $result1 == null ) {
94 - $result1 = new SMWQueryResult( $result2->getPrintRequests(), new SMWQuery() );
 94+ return $result2;
9595 }
9696 $existing_page_names = array();
97 - while ( $row = $result1->getNext() ) {
98 - if ( $row[0] instanceof SMWResultArray ) {
99 - $content = $row[0]->getContent();
100 - $existing_page_names[] = $content[0]->getLongText( SMW_OUTPUT_WIKI );
 97+ foreach ($result1 as $r1) {
 98+ $existing_page_names[] = $r1->getWikiValue();
 99+ }
 100+ foreach ($result2 as $r2) {
 101+ $page_name = $r2->getWikiValue();
 102+ if (! in_array($page_name, $existing_page_names)) {
 103+ $result1[] = $r2;
101104 }
102105 }
103 - while ( ( $row = $result2->getNext() ) !== false ) {
104 - $row[0]->display_options = $result2->display_options;
105 - $content = $row[0]->getContent();
106 - $page_name = $content[0]->getLongText( SMW_OUTPUT_WIKI );
107 - if ( ! in_array( $page_name, $existing_page_names ) )
108 - $result1->addRow( $row );
109 - }
110106 return $result1;
111107 }
112108
@@ -168,4 +164,3 @@
169165 return $result;
170166 }
171167 }
172 -

Status & tagging log