Index: trunk/extensions/SemanticMediaWiki/includes/SMW_InlineQueries.php |
— | — | @@ -184,6 +184,8 @@ |
185 | 185 | private $mConditionCount; // count the number of conditions used so far |
186 | 186 | private $mTableCount; // count the number of tables joined so far |
187 | 187 | private $mPrintoutCount; // count the number of fields selected for separate printout so far |
| 188 | + private $mFurtherResults=false; // true if not all results to the query were shown |
| 189 | + private $mDisplayCount=0; // number of results that were displayed |
188 | 190 | |
189 | 191 | // fields used for output formatting: |
190 | 192 | private $mHeaderText; // text to be printed before the output of the results |
— | — | @@ -286,6 +288,22 @@ |
287 | 289 | } |
288 | 290 | |
289 | 291 | /** |
| 292 | + * Returns true if a query was executed and the chosen limit did not |
| 293 | + * allow all results to be displayed |
| 294 | + */ |
| 295 | + function hasFurtherResults() { |
| 296 | + return $this->mFurtherResults; |
| 297 | + } |
| 298 | + |
| 299 | + /** |
| 300 | + * After a query was executed, this function returns the number of results that have been |
| 301 | + * displayed (which is different from the overall number of results that exist). |
| 302 | + */ |
| 303 | + function getDisplayCount() { |
| 304 | + return $this->mDisplayCount; |
| 305 | + } |
| 306 | + |
| 307 | + /** |
290 | 308 | * Main entry point for parsing, executing, and printing a given query text. |
291 | 309 | */ |
292 | 310 | function getHTMLResult( $text ) { |
— | — | @@ -315,7 +333,7 @@ |
316 | 334 | $sq->mSelect[1] .= ' AS page_title'; |
317 | 335 | $sq->mSelect[2] .= ' AS page_namespace'; |
318 | 336 | |
319 | | - $sql_options = array('LIMIT' => $this->mLimit, 'OFFSET' => $this->mOffset); // additional options (order by, limit) |
| 337 | + $sql_options = array('LIMIT' => $this->mLimit + 1, 'OFFSET' => $this->mOffset); // additional options (order by, limit) |
320 | 338 | if ( $smwgIQSortingEnabled ) { |
321 | 339 | if ( NULL == $sq->mOrderBy ) { |
322 | 340 | $sql_options['ORDER BY'] = "page_title $this->mOrder "; // default |
— | — | @@ -361,19 +379,22 @@ |
362 | 380 | $result = $this->mHeaderText; |
363 | 381 | |
364 | 382 | // Print main content (if any results were returned) |
365 | | - $firstrow = true; |
366 | 383 | $row = $this->dbr->fetchRow( $res ); |
367 | | - while ( $row ) { |
| 384 | + $this->mDisplayCount = 0; |
| 385 | + while ( $row && ( $this->mDisplayCount < $this->mLimit ) ) { |
368 | 386 | $nextrow = $this->dbr->fetchRow( $res ); // look ahead |
369 | | - if (!$firstrow) { |
370 | | - if ($nextrow) |
| 387 | + $this->mDisplayCount++; |
| 388 | + if ($this->mDisplayCount > 1) { |
| 389 | + if ($nextrow && $this->mDisplayCount < $this->mLimit) |
371 | 390 | $result .= $this->mRowSep; |
372 | 391 | else $result .= $this->mLastRowSep; |
373 | 392 | } |
374 | 393 | $result .= $this->makeRow($row, $sq->mPrint); |
375 | 394 | $row = $nextrow; |
376 | | - $firstrow = false; |
377 | 395 | } |
| 396 | + if ($row) // there are more results |
| 397 | + $this->mFurtherResults = true; |
| 398 | + |
378 | 399 | $this->dbr->freeResult($res); // Things that should be free: #42 "Possibly large query results" |
379 | 400 | |
380 | 401 | $result .= $this->mFooterText; |
— | — | @@ -899,6 +920,7 @@ |
900 | 921 | $result .= '---'; |
901 | 922 | break; |
902 | 923 | } |
| 924 | + $firstcol = false; |
903 | 925 | } |
904 | 926 | return $result; |
905 | 927 | } |