850256f071989b84c9c4498c9af60fcc1b964eb0
[lhc/web/wiklou.git] / includes / CategoryPage.php
1 <?php
2 /**
3 * Class for viewing MediaWiki category description pages.
4 * Modelled after ImagePage.php.
5 *
6 * @file
7 */
8
9 if ( !defined( 'MEDIAWIKI' ) )
10 die( 1 );
11
12 /**
13 * Special handling for category description pages, showing pages,
14 * subcategories and file that belong to the category
15 */
16 class CategoryPage extends Article {
17 # Subclasses can change this to override the viewer class.
18 protected $mCategoryViewerClass = 'CategoryViewer';
19
20 protected function newPage( Title $title ) {
21 // Overload mPage with a category-specific page
22 return new WikiCategoryPage( $title );
23 }
24
25 /**
26 * Constructor from a page id
27 * @param $id Int article ID to load
28 */
29 public static function newFromID( $id ) {
30 $t = Title::newFromID( $id );
31 # @todo FIXME: Doesn't inherit right
32 return $t == null ? null : new self( $t );
33 # return $t == null ? null : new static( $t ); // PHP 5.3
34 }
35
36 function view() {
37 global $wgRequest, $wgUser;
38
39 $diff = $wgRequest->getVal( 'diff' );
40 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
41
42 if ( isset( $diff ) && $diffOnly ) {
43 return parent::view();
44 }
45
46 if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) {
47 return;
48 }
49
50 if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
51 $this->openShowCategory();
52 }
53
54 parent::view();
55
56 if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
57 $this->closeShowCategory();
58 }
59 }
60
61 function openShowCategory() {
62 # For overloading
63 }
64
65 function closeShowCategory() {
66 global $wgOut, $wgRequest;
67
68 // Use these as defaults for back compat --catrope
69 $oldFrom = $wgRequest->getVal( 'from' );
70 $oldUntil = $wgRequest->getVal( 'until' );
71
72 $from = $until = array();
73 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
74 $from[$type] = $wgRequest->getVal( "{$type}from", $oldFrom );
75 $until[$type] = $wgRequest->getVal( "{$type}until", $oldUntil );
76 }
77
78 $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $wgRequest->getValues() );
79 $wgOut->addHTML( $viewer->getHTML() );
80 }
81 }
82
83 class CategoryViewer {
84 var $limit, $from, $until,
85 $articles, $articles_start_char,
86 $children, $children_start_char,
87 $showGallery, $imgsNoGalley,
88 $imgsNoGallery_start_char,
89 $imgsNoGallery;
90
91 /**
92 * @var
93 */
94 var $nextPage;
95
96 /**
97 * @var Array
98 */
99 var $flip;
100
101 /**
102 * @var Title
103 */
104 var $title;
105
106 /**
107 * @var Collation
108 */
109 var $collation;
110
111 /**
112 * @var ImageGallery
113 */
114 var $gallery;
115
116 /**
117 * Category object for this page
118 * @var Category
119 */
120 private $cat;
121
122 /**
123 * The original query array, to be used in generating paging links.
124 * @var array
125 */
126 private $query;
127
128 function __construct( $title, $from = '', $until = '', $query = array() ) {
129 global $wgCategoryPagingLimit;
130 $this->title = $title;
131 $this->from = $from;
132 $this->until = $until;
133 $this->limit = $wgCategoryPagingLimit;
134 $this->cat = Category::newFromTitle( $title );
135 $this->query = $query;
136 $this->collation = Collation::singleton();
137 unset( $this->query['title'] );
138 }
139
140 /**
141 * Format the category data list.
142 *
143 * @return string HTML output
144 */
145 public function getHTML() {
146 global $wgOut, $wgCategoryMagicGallery, $wgContLang;
147 wfProfileIn( __METHOD__ );
148
149 $this->showGallery = $wgCategoryMagicGallery && !$wgOut->mNoGallery;
150
151 $this->clearCategoryState();
152 $this->doCategoryQuery();
153 $this->finaliseCategoryState();
154
155 $r = $this->getSubcategorySection() .
156 $this->getPagesSection() .
157 $this->getImageSection();
158
159 if ( $r == '' ) {
160 // If there is no category content to display, only
161 // show the top part of the navigation links.
162 // @todo FIXME: Cannot be completely suppressed because it
163 // is unknown if 'until' or 'from' makes this
164 // give 0 results.
165 $r = $r . $this->getCategoryTop();
166 } else {
167 $r = $this->getCategoryTop() .
168 $r .
169 $this->getCategoryBottom();
170 }
171
172 // Give a proper message if category is empty
173 if ( $r == '' ) {
174 $r = wfMsgExt( 'category-empty', array( 'parse' ) );
175 }
176
177 $pageLang = $this->title->getPageLanguage();
178 $langAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
179 # close the previous div, show the headings in user language,
180 # then open a new div with the page content language again
181 $r = '</div>' . $r . Html::openElement( 'div', $langAttribs );
182
183 wfProfileOut( __METHOD__ );
184 return $wgContLang->convert( $r );
185 }
186
187 function clearCategoryState() {
188 $this->articles = array();
189 $this->articles_start_char = array();
190 $this->children = array();
191 $this->children_start_char = array();
192 if ( $this->showGallery ) {
193 $this->gallery = new ImageGallery();
194 $this->gallery->setHideBadImages();
195 } else {
196 $this->imgsNoGallery = array();
197 $this->imgsNoGallery_start_char = array();
198 }
199 }
200
201 /**
202 * Add a subcategory to the internal lists, using a Category object
203 */
204 function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
205 // Subcategory; strip the 'Category' namespace from the link text.
206 $title = $cat->getTitle();
207
208 $link = Linker::link( $title, htmlspecialchars( $title->getText() ) );
209 if ( $title->isRedirect() ) {
210 // This didn't used to add redirect-in-category, but might
211 // as well be consistent with the rest of the sections
212 // on a category page.
213 $link = '<span class="redirect-in-category">' . $link . '</span>';
214 }
215 $this->children[] = $link;
216
217 $this->children_start_char[] =
218 $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
219 }
220
221 /**
222 * Add a subcategory to the internal lists, using a title object
223 * @deprecated since 1.17 kept for compatibility, please use addSubcategoryObject instead
224 */
225 function addSubcategory( Title $title, $sortkey, $pageLength ) {
226 $this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength );
227 }
228
229 /**
230 * Get the character to be used for sorting subcategories.
231 * If there's a link from Category:A to Category:B, the sortkey of the resulting
232 * entry in the categorylinks table is Category:A, not A, which it SHOULD be.
233 * Workaround: If sortkey == "Category:".$title, than use $title for sorting,
234 * else use sortkey...
235 *
236 * @param Title $title
237 * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever).
238 */
239 function getSubcategorySortChar( $title, $sortkey ) {
240 global $wgContLang;
241
242 if ( $title->getPrefixedText() == $sortkey ) {
243 $word = $title->getDBkey();
244 } else {
245 $word = $sortkey;
246 }
247
248 $firstChar = $this->collation->getFirstLetter( $word );
249
250 return $wgContLang->convert( $firstChar );
251 }
252
253 /**
254 * Add a page in the image namespace
255 */
256 function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
257 global $wgContLang;
258 if ( $this->showGallery ) {
259 $flip = $this->flip['file'];
260 if ( $flip ) {
261 $this->gallery->insert( $title );
262 } else {
263 $this->gallery->add( $title );
264 }
265 } else {
266 $link = Linker::link( $title );
267 if ( $isRedirect ) {
268 // This seems kind of pointless given 'mw-redirect' class,
269 // but keeping for back-compatibility with user css.
270 $link = '<span class="redirect-in-category">' . $link . '</span>';
271 }
272 $this->imgsNoGallery[] = $link;
273
274 $this->imgsNoGallery_start_char[] = $wgContLang->convert(
275 $this->collation->getFirstLetter( $sortkey ) );
276 }
277 }
278
279 /**
280 * Add a miscellaneous page
281 */
282 function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
283 global $wgContLang;
284
285 $link = Linker::link( $title );
286 if ( $isRedirect ) {
287 // This seems kind of pointless given 'mw-redirect' class,
288 // but keeping for back-compatiability with user css.
289 $link = '<span class="redirect-in-category">' . $link . '</span>';
290 }
291 $this->articles[] = $link;
292
293 $this->articles_start_char[] = $wgContLang->convert(
294 $this->collation->getFirstLetter( $sortkey ) );
295 }
296
297 function finaliseCategoryState() {
298 if ( $this->flip['subcat'] ) {
299 $this->children = array_reverse( $this->children );
300 $this->children_start_char = array_reverse( $this->children_start_char );
301 }
302 if ( $this->flip['page'] ) {
303 $this->articles = array_reverse( $this->articles );
304 $this->articles_start_char = array_reverse( $this->articles_start_char );
305 }
306 if ( !$this->showGallery && $this->flip['file'] ) {
307 $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
308 $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
309 }
310 }
311
312 function doCategoryQuery() {
313 $dbr = wfGetDB( DB_SLAVE, 'category' );
314
315 $this->nextPage = array(
316 'page' => null,
317 'subcat' => null,
318 'file' => null,
319 );
320 $this->flip = array( 'page' => false, 'subcat' => false, 'file' => false );
321
322 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
323 # Get the sortkeys for start/end, if applicable. Note that if
324 # the collation in the database differs from the one
325 # set in $wgCategoryCollation, pagination might go totally haywire.
326 $extraConds = array( 'cl_type' => $type );
327 if ( $this->from[$type] !== null ) {
328 $extraConds[] = 'cl_sortkey >= '
329 . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
330 } elseif ( $this->until[$type] !== null ) {
331 $extraConds[] = 'cl_sortkey < '
332 . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
333 $this->flip[$type] = true;
334 }
335
336 $res = $dbr->select(
337 array( 'page', 'categorylinks', 'category' ),
338 array( 'page_id', 'page_title', 'page_namespace', 'page_len',
339 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
340 'cat_subcats', 'cat_pages', 'cat_files',
341 'cl_sortkey_prefix', 'cl_collation' ),
342 array_merge( array( 'cl_to' => $this->title->getDBkey() ), $extraConds ),
343 __METHOD__,
344 array(
345 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ),
346 'LIMIT' => $this->limit + 1,
347 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
348 ),
349 array(
350 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ),
351 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY )
352 )
353 );
354
355 $count = 0;
356 foreach ( $res as $row ) {
357 $title = Title::newFromRow( $row );
358 if ( $row->cl_collation === '' ) {
359 // Hack to make sure that while updating from 1.16 schema
360 // and db is inconsistent, that the sky doesn't fall.
361 // See r83544. Could perhaps be removed in a couple decades...
362 $humanSortkey = $row->cl_sortkey;
363 } else {
364 $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
365 }
366
367 if ( ++$count > $this->limit ) {
368 # We've reached the one extra which shows that there
369 # are additional pages to be had. Stop here...
370 $this->nextPage[$type] = $humanSortkey;
371 break;
372 }
373
374 if ( $title->getNamespace() == NS_CATEGORY ) {
375 $cat = Category::newFromRow( $row, $title );
376 $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
377 } elseif ( $title->getNamespace() == NS_FILE ) {
378 $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
379 } else {
380 $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
381 }
382 }
383 }
384 }
385
386 function getCategoryTop() {
387 $r = $this->getCategoryBottom();
388 return $r === ''
389 ? $r
390 : "<br style=\"clear:both;\"/>\n" . $r;
391 }
392
393 function getSubcategorySection() {
394 # Don't show subcategories section if there are none.
395 $r = '';
396 $rescnt = count( $this->children );
397 $dbcnt = $this->cat->getSubcatCount();
398 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
399
400 if ( $rescnt > 0 ) {
401 # Showing subcategories
402 $r .= "<div id=\"mw-subcategories\">\n";
403 $r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n";
404 $r .= $countmsg;
405 $r .= $this->getSectionPagingLinks( 'subcat' );
406 $r .= $this->formatList( $this->children, $this->children_start_char );
407 $r .= $this->getSectionPagingLinks( 'subcat' );
408 $r .= "\n</div>";
409 }
410 return $r;
411 }
412
413 function getPagesSection() {
414 $ti = htmlspecialchars( $this->title->getText() );
415 # Don't show articles section if there are none.
416 $r = '';
417
418 # @todo FIXME: Here and in the other two sections: we don't need to bother
419 # with this rigamarole if the entire category contents fit on one page
420 # and have already been retrieved. We can just use $rescnt in that
421 # case and save a query and some logic.
422 $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
423 - $this->cat->getFileCount();
424 $rescnt = count( $this->articles );
425 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
426
427 if ( $rescnt > 0 ) {
428 $r = "<div id=\"mw-pages\">\n";
429 $r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n";
430 $r .= $countmsg;
431 $r .= $this->getSectionPagingLinks( 'page' );
432 $r .= $this->formatList( $this->articles, $this->articles_start_char );
433 $r .= $this->getSectionPagingLinks( 'page' );
434 $r .= "\n</div>";
435 }
436 return $r;
437 }
438
439 function getImageSection() {
440 $r = '';
441 $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
442 if ( $rescnt > 0 ) {
443 $dbcnt = $this->cat->getFileCount();
444 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
445
446 $r .= "<div id=\"mw-category-media\">\n";
447 $r .= '<h2>' . wfMsg( 'category-media-header', htmlspecialchars( $this->title->getText() ) ) . "</h2>\n";
448 $r .= $countmsg;
449 $r .= $this->getSectionPagingLinks( 'file' );
450 if ( $this->showGallery ) {
451 $r .= $this->gallery->toHTML();
452 } else {
453 $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
454 }
455 $r .= $this->getSectionPagingLinks( 'file' );
456 $r .= "\n</div>";
457 }
458 return $r;
459 }
460
461 /**
462 * Get the paging links for a section (subcats/pages/files), to go at the top and bottom
463 * of the output.
464 *
465 * @param $type String: 'page', 'subcat', or 'file'
466 * @return String: HTML output, possibly empty if there are no other pages
467 */
468 private function getSectionPagingLinks( $type ) {
469 if ( $this->until[$type] !== null ) {
470 return $this->pagingLinks( $this->nextPage[$type], $this->until[$type], $type );
471 } elseif ( $this->nextPage[$type] !== null || $this->from[$type] !== null ) {
472 return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
473 } else {
474 return '';
475 }
476 }
477
478 function getCategoryBottom() {
479 return '';
480 }
481
482 /**
483 * Format a list of articles chunked by letter, either as a
484 * bullet list or a columnar format, depending on the length.
485 *
486 * @param $articles Array
487 * @param $articles_start_char Array
488 * @param $cutoff Int
489 * @return String
490 * @private
491 */
492 function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
493 $list = '';
494 if ( count ( $articles ) > $cutoff ) {
495 $list = self::columnList( $articles, $articles_start_char );
496 } elseif ( count( $articles ) > 0 ) {
497 // for short lists of articles in categories.
498 $list = self::shortList( $articles, $articles_start_char );
499 }
500
501 $pageLang = $this->title->getPageLanguage();
502 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
503 'class' => 'mw-content-'.$pageLang->getDir() );
504 $list = Html::rawElement( 'div', $attribs, $list );
505
506 return $list;
507 }
508
509 /**
510 * Format a list of articles chunked by letter in a three-column
511 * list, ordered vertically.
512 *
513 * TODO: Take the headers into account when creating columns, so they're
514 * more visually equal.
515 *
516 * More distant TODO: Scrap this and use CSS columns, whenever IE finally
517 * supports those.
518 *
519 * @param $articles Array
520 * @param $articles_start_char Array
521 * @return String
522 * @private
523 */
524 static function columnList( $articles, $articles_start_char ) {
525 $columns = array_combine( $articles, $articles_start_char );
526 # Split into three columns
527 $columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
528
529 $ret = '<table width="100%"><tr valign="top"><td>';
530 $prevchar = null;
531
532 foreach ( $columns as $column ) {
533 $colContents = array();
534
535 # Kind of like array_flip() here, but we keep duplicates in an
536 # array instead of dropping them.
537 foreach ( $column as $article => $char ) {
538 if ( !isset( $colContents[$char] ) ) {
539 $colContents[$char] = array();
540 }
541 $colContents[$char][] = $article;
542 }
543
544 $first = true;
545 foreach ( $colContents as $char => $articles ) {
546 $ret .= '<h3>' . htmlspecialchars( $char );
547 if ( $first && $char === $prevchar ) {
548 # We're continuing a previous chunk at the top of a new
549 # column, so add " cont." after the letter.
550 $ret .= ' ' . wfMsgHtml( 'listingcontinuesabbrev' );
551 }
552 $ret .= "</h3>\n";
553
554 $ret .= '<ul><li>';
555 $ret .= implode( "</li>\n<li>", $articles );
556 $ret .= '</li></ul>';
557
558 $first = false;
559 $prevchar = $char;
560 }
561
562 $ret .= "</td>\n<td>";
563 }
564
565 $ret .= '</td></tr></table>';
566 return $ret;
567 }
568
569 /**
570 * Format a list of articles chunked by letter in a bullet list.
571 * @param $articles Array
572 * @param $articles_start_char Array
573 * @return String
574 * @private
575 */
576 static function shortList( $articles, $articles_start_char ) {
577 $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
578 $r .= '<ul><li>' . $articles[0] . '</li>';
579 for ( $index = 1; $index < count( $articles ); $index++ ) {
580 if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
581 $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
582 }
583
584 $r .= "<li>{$articles[$index]}</li>";
585 }
586 $r .= '</ul>';
587 return $r;
588 }
589
590 /**
591 * Create paging links, as a helper method to getSectionPagingLinks().
592 *
593 * @param $first String The 'until' parameter for the generated URL
594 * @param $last String The 'from' parameter for the genererated URL
595 * @param $type String A prefix for parameters, 'page' or 'subcat' or
596 * 'file'
597 * @return String HTML
598 */
599 private function pagingLinks( $first, $last, $type = '' ) {
600 global $wgLang;
601
602 $limitText = $wgLang->formatNum( $this->limit );
603
604 $prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
605
606 if ( $first != '' ) {
607 $prevQuery = $this->query;
608 $prevQuery["{$type}until"] = $first;
609 unset( $prevQuery["{$type}from"] );
610 $prevLink = Linker::linkKnown(
611 $this->addFragmentToTitle( $this->title, $type ),
612 $prevLink,
613 array(),
614 $prevQuery
615 );
616 }
617
618 $nextLink = wfMsgExt( 'nextn', array( 'escape', 'parsemag' ), $limitText );
619
620 if ( $last != '' ) {
621 $lastQuery = $this->query;
622 $lastQuery["{$type}from"] = $last;
623 unset( $lastQuery["{$type}until"] );
624 $nextLink = Linker::linkKnown(
625 $this->addFragmentToTitle( $this->title, $type ),
626 $nextLink,
627 array(),
628 $lastQuery
629 );
630 }
631
632 return "($prevLink) ($nextLink)";
633 }
634
635 /**
636 * Takes a title, and adds the fragment identifier that
637 * corresponds to the correct segment of the category.
638 *
639 * @param Title $title: The title (usually $this->title)
640 * @param String $section: Which section
641 */
642 private function addFragmentToTitle( $title, $section ) {
643 switch ( $section ) {
644 case 'page':
645 $fragment = 'mw-pages';
646 break;
647 case 'subcat':
648 $fragment = 'mw-subcategories';
649 break;
650 case 'file':
651 $fragment = 'mw-category-media';
652 break;
653 default:
654 throw new MWException( __METHOD__ .
655 " Invalid section $section." );
656 }
657
658 return Title::makeTitle( $title->getNamespace(),
659 $title->getDBkey(), $fragment );
660 }
661 /**
662 * What to do if the category table conflicts with the number of results
663 * returned? This function says what. Each type is considered independently
664 * of the other types.
665 *
666 * Note for grepping: uses the messages category-article-count,
667 * category-article-count-limited, category-subcat-count,
668 * category-subcat-count-limited, category-file-count,
669 * category-file-count-limited.
670 *
671 * @param $rescnt Int: The number of items returned by our database query.
672 * @param $dbcnt Int: The number of items according to the category table.
673 * @param $type String: 'subcat', 'article', or 'file'
674 * @return String: A message giving the number of items, to output to HTML.
675 */
676 private function getCountMessage( $rescnt, $dbcnt, $type ) {
677 global $wgLang;
678 # There are three cases:
679 # 1) The category table figure seems sane. It might be wrong, but
680 # we can't do anything about it if we don't recalculate it on ev-
681 # ery category view.
682 # 2) The category table figure isn't sane, like it's smaller than the
683 # number of actual results, *but* the number of results is less
684 # than $this->limit and there's no offset. In this case we still
685 # know the right figure.
686 # 3) We have no idea.
687
688 # Check if there's a "from" or "until" for anything
689
690 // This is a little ugly, but we seem to use different names
691 // for the paging types then for the messages.
692 if ( $type === 'article' ) {
693 $pagingType = 'page';
694 } else {
695 $pagingType = $type;
696 }
697
698 $fromOrUntil = false;
699 if ( $this->from[$pagingType] !== null || $this->until[$pagingType] !== null ) {
700 $fromOrUntil = true;
701 }
702
703 if ( $dbcnt == $rescnt || ( ( $rescnt == $this->limit || $fromOrUntil )
704 && $dbcnt > $rescnt ) ) {
705 # Case 1: seems sane.
706 $totalcnt = $dbcnt;
707 } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
708 # Case 2: not sane, but salvageable. Use the number of results.
709 # Since there are fewer than 200, we can also take this opportunity
710 # to refresh the incorrect category table entry -- which should be
711 # quick due to the small number of entries.
712 $totalcnt = $rescnt;
713 $this->cat->refreshCounts();
714 } else {
715 # Case 3: hopeless. Don't give a total count at all.
716 return wfMsgExt( "category-$type-count-limited", 'parse',
717 $wgLang->formatNum( $rescnt ) );
718 }
719 return wfMsgExt(
720 "category-$type-count",
721 'parse',
722 $wgLang->formatNum( $rescnt ),
723 $wgLang->formatNum( $totalcnt )
724 );
725 }
726 }