Index: trunk/extensions/SemanticMediaWiki/includes/SMW_InlineQueries.php |
— | — | @@ -167,7 +167,8 @@ |
168 | 168 | * mainlabel -- Label to use for the column that shows the main subjects. Also used to indicate that |
169 | 169 | * the subject should be displayed in cases where it would normally be hidden. |
170 | 170 | * format -- Either 'list', 'ul' (for unordered bullet list), 'ol' (ordered and numbered list), |
171 | | - * 'table', 'broadtable', 'timeline', 'eventline', 'embedded', 'template' or 'auto' (default). |
| 171 | + * 'table', 'broadtable', 'timeline', 'eventline', 'embedded', 'template', 'count', |
| 172 | + * 'debug', or 'auto' (default). |
172 | 173 | * Some formats have additional parameters: |
173 | 174 | * sep (list only) -- Customized separator string. |
174 | 175 | */ |
— | — | @@ -178,7 +179,7 @@ |
179 | 180 | * formats. The formats 'table' and 'list' are defaults that cannot be disabled. The format 'broadtable' |
180 | 181 | * should not be disabled either in order not to break Special:ask. |
181 | 182 | */ |
182 | | - static $formats = array('table','list','ol','ul','broadtable','embedded','timeline','eventline','template'); |
| 183 | + static $formats = array('table', 'list', 'ol', 'ul', 'broadtable', 'embedded', 'timeline', 'eventline', 'template', 'count', 'debug'); |
183 | 184 | |
184 | 185 | private $mInline; // is this really an inline query, i.e. are results used in an article or not? (bool) |
185 | 186 | |
— | — | @@ -197,7 +198,6 @@ |
198 | 199 | private $mDefault; // default return value for empty queries |
199 | 200 | private $mShowHeaders; // should the headers (property names) be printed? |
200 | 201 | private $mMainLabel; // label used for displaying the subject, or NULL if none was given |
201 | | - private $mShowDebug; // should debug output be generated? |
202 | 202 | |
203 | 203 | // fields used during query processing: |
204 | 204 | private $mQueryText; // the original query text for future reference |
— | — | @@ -235,7 +235,6 @@ |
236 | 236 | $this->mDefault = ''; |
237 | 237 | $this->mShowHeaders = true; |
238 | 238 | $this->mMainLabel = NULL; |
239 | | - $this->mShowDebug = false; |
240 | 239 | |
241 | 240 | $this->mLinker = new Linker(); |
242 | 241 | |
— | — | @@ -319,9 +318,6 @@ |
320 | 319 | if (array_key_exists('mainlabel', $param)) { |
321 | 320 | $this->mMainLabel = htmlspecialchars($param['mainlabel']); |
322 | 321 | } |
323 | | - if (array_key_exists('debug', $param)) { |
324 | | - $this->mShowDebug = true; |
325 | | - } |
326 | 322 | } |
327 | 323 | |
328 | 324 | /** |
— | — | @@ -489,20 +485,26 @@ |
490 | 486 | $this->mPrintoutCount = 0; |
491 | 487 | $sq = $this->parseQuery($text); |
492 | 488 | |
493 | | - $sq->mSelect[0] .= ' AS page_id'; |
494 | | - $sq->mSelect[1] .= ' AS page_title'; |
495 | | - $sq->mSelect[2] .= ' AS page_namespace'; |
496 | | - |
497 | | - $sql_options = array('LIMIT' => $this->mLimit + 1, 'OFFSET' => $this->mOffset); // additional options (order by, limit) |
498 | | - if ( $smwgIQSortingEnabled ) { |
499 | | - if ( NULL == $sq->mOrderBy ) { |
500 | | - $sql_options['ORDER BY'] = "page_title $this->mOrder "; // default |
501 | | - } else { |
502 | | - $sql_options['ORDER BY'] = "$sq->mOrderBy $this->mOrder "; |
| 489 | + $sql_options = array(); |
| 490 | + if ($this->mFormat == 'count') { |
| 491 | + $sq->mSelect = array('COUNT(' . $sq->mSelect[0] . ') AS count'); // just count |
| 492 | + } else { |
| 493 | + $sq->mSelect[0] .= ' AS page_id'; |
| 494 | + $sq->mSelect[1] .= ' AS page_title'; |
| 495 | + $sq->mSelect[2] .= ' AS page_namespace'; |
| 496 | + |
| 497 | + $sql_options['LIMIT'] = $this->mLimit + 1; |
| 498 | + $sql_options['OFFSET'] = $this->mOffset; |
| 499 | + if ( $smwgIQSortingEnabled ) { |
| 500 | + if ( NULL == $sq->mOrderBy ) { |
| 501 | + $sql_options['ORDER BY'] = "page_title $this->mOrder "; // default |
| 502 | + } else { |
| 503 | + $sql_options['ORDER BY'] = "$sq->mOrderBy $this->mOrder "; |
| 504 | + } |
503 | 505 | } |
504 | 506 | } |
505 | 507 | |
506 | | - if ($this->mShowDebug) { |
| 508 | + if ($this->mFormat == 'debug') { |
507 | 509 | return $sq->mDebug; // DEBUG |
508 | 510 | } |
509 | 511 | |
— | — | @@ -519,6 +521,16 @@ |
520 | 522 | //No results, TODO: is there a better way than calling numRows (which counts all results)? |
521 | 523 | if ( (!$this->mQueryResult) || (0 == $this->dbr->numRows( $this->mQueryResult )) ) return $this->mDefault; |
522 | 524 | |
| 525 | + if ($this->mFormat == 'count') { |
| 526 | + $row = $this->dbr->fetchRow( $this->mQueryResult ); |
| 527 | + if ($row['count'] !== '0') { |
| 528 | + return $this->mIntro . $row['count']; |
| 529 | + } else { |
| 530 | + if ($this->mDefault === '') $this->mDefault = '0'; |
| 531 | + return $this->mDefault; |
| 532 | + } |
| 533 | + } |
| 534 | + |
523 | 535 | $this->mDisplayCount = min($this->mLimit, $this->dbr->numRows( $this->mQueryResult )); |
524 | 536 | |
525 | 537 | // Cases in which to print the subject: |
— | — | @@ -530,7 +542,7 @@ |
531 | 543 | } |
532 | 544 | } |
533 | 545 | |
534 | | - //Determine format if 'auto', also for backwards compatibility |
| 546 | + // Guess suitable format if 'auto' is selected |
535 | 547 | if ( 'auto' == $this->mFormat ) { |
536 | 548 | if ( (count($sq->mPrint)>1) && ($this->mLimit > 0) ) |
537 | 549 | $this->mFormat = 'table'; |