Merge "In ParserCache, respect $useOutdated"
[lhc/web/wiklou.git] / includes / CategoryViewer.php
1 <?php
2 /**
3 * List and paging of category members.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 class CategoryViewer extends ContextSource {
24 /** @var int */
25 public $limit;
26
27 /** @var array */
28 public $from;
29
30 /** @var array */
31 public $until;
32
33 /** @var string[] */
34 public $articles;
35
36 /** @var array */
37 public $articles_start_char;
38
39 /** @var array */
40 public $children;
41
42 /** @var array */
43 public $children_start_char;
44
45 /** @var bool */
46 public $showGallery;
47
48 /** @var array */
49 public $imgsNoGallery_start_char;
50
51 /** @var array */
52 public $imgsNoGallery;
53
54 /** @var array */
55 public $nextPage;
56
57 /** @var array */
58 protected $prevPage;
59
60 /** @var array */
61 public $flip;
62
63 /** @var Title */
64 public $title;
65
66 /** @var Collation */
67 public $collation;
68
69 /** @var ImageGallery */
70 public $gallery;
71
72 /** @var Category Category object for this page. */
73 private $cat;
74
75 /** @var array The original query array, to be used in generating paging links. */
76 private $query;
77
78 /**
79 * @since 1.19 $context is a second, required parameter
80 * @param Title $title
81 * @param IContextSource $context
82 * @param array $from An array with keys page, subcat,
83 * and file for offset of results of each section (since 1.17)
84 * @param array $until An array with 3 keys for until of each section (since 1.17)
85 * @param array $query
86 */
87 function __construct( $title, IContextSource $context, $from = [],
88 $until = [], $query = []
89 ) {
90 $this->title = $title;
91 $this->setContext( $context );
92 $this->getOutput()->addModuleStyles( [
93 'mediawiki.action.view.categoryPage.styles'
94 ] );
95 $this->from = $from;
96 $this->until = $until;
97 $this->limit = $context->getConfig()->get( 'CategoryPagingLimit' );
98 $this->cat = Category::newFromTitle( $title );
99 $this->query = $query;
100 $this->collation = Collation::singleton();
101 unset( $this->query['title'] );
102 }
103
104 /**
105 * Format the category data list.
106 *
107 * @return string HTML output
108 */
109 public function getHTML() {
110
111 $this->showGallery = $this->getConfig()->get( 'CategoryMagicGallery' )
112 && !$this->getOutput()->mNoGallery;
113
114 $this->clearCategoryState();
115 $this->doCategoryQuery();
116 $this->finaliseCategoryState();
117
118 $r = $this->getSubcategorySection() .
119 $this->getPagesSection() .
120 $this->getImageSection();
121
122 if ( $r == '' ) {
123 // If there is no category content to display, only
124 // show the top part of the navigation links.
125 // @todo FIXME: Cannot be completely suppressed because it
126 // is unknown if 'until' or 'from' makes this
127 // give 0 results.
128 $r = $r . $this->getCategoryTop();
129 } else {
130 $r = $this->getCategoryTop() .
131 $r .
132 $this->getCategoryBottom();
133 }
134
135 // Give a proper message if category is empty
136 if ( $r == '' ) {
137 $r = $this->msg( 'category-empty' )->parseAsBlock();
138 }
139
140 $lang = $this->getLanguage();
141 $attribs = [
142 'class' => 'mw-category-generated',
143 'lang' => $lang->getHtmlCode(),
144 'dir' => $lang->getDir()
145 ];
146 # put a div around the headings which are in the user language
147 $r = Html::openElement( 'div', $attribs ) . $r . '</div>';
148
149 return $r;
150 }
151
152 function clearCategoryState() {
153 $this->articles = [];
154 $this->articles_start_char = [];
155 $this->children = [];
156 $this->children_start_char = [];
157 if ( $this->showGallery ) {
158 // Note that null for mode is taken to mean use default.
159 $mode = $this->getRequest()->getVal( 'gallerymode', null );
160 try {
161 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
162 } catch ( Exception $e ) {
163 // User specified something invalid, fallback to default.
164 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
165 }
166
167 $this->gallery->setHideBadImages();
168 } else {
169 $this->imgsNoGallery = [];
170 $this->imgsNoGallery_start_char = [];
171 }
172 }
173
174 /**
175 * Add a subcategory to the internal lists, using a Category object
176 * @param Category $cat
177 * @param string $sortkey
178 * @param int $pageLength
179 */
180 function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
181 // Subcategory; strip the 'Category' namespace from the link text.
182 $title = $cat->getTitle();
183
184 $this->children[] = $this->generateLink(
185 'subcat',
186 $title,
187 $title->isRedirect(),
188 htmlspecialchars( $title->getText() )
189 );
190
191 $this->children_start_char[] =
192 $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
193 }
194
195 function generateLink( $type, Title $title, $isRedirect, $html = null ) {
196 $link = null;
197 Hooks::run( 'CategoryViewer::generateLink', [ $type, $title, $html, &$link ] );
198 if ( $link === null ) {
199 $link = Linker::link( $title, $html );
200 }
201 if ( $isRedirect ) {
202 $link = '<span class="redirect-in-category">' . $link . '</span>';
203 }
204
205 return $link;
206 }
207
208 /**
209 * Get the character to be used for sorting subcategories.
210 * If there's a link from Category:A to Category:B, the sortkey of the resulting
211 * entry in the categorylinks table is Category:A, not A, which it SHOULD be.
212 * Workaround: If sortkey == "Category:".$title, than use $title for sorting,
213 * else use sortkey...
214 *
215 * @param Title $title
216 * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever).
217 * @return string
218 */
219 function getSubcategorySortChar( $title, $sortkey ) {
220 global $wgContLang;
221
222 if ( $title->getPrefixedText() == $sortkey ) {
223 $word = $title->getDBkey();
224 } else {
225 $word = $sortkey;
226 }
227
228 $firstChar = $this->collation->getFirstLetter( $word );
229
230 return $wgContLang->convert( $firstChar );
231 }
232
233 /**
234 * Add a page in the image namespace
235 * @param Title $title
236 * @param string $sortkey
237 * @param int $pageLength
238 * @param bool $isRedirect
239 */
240 function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
241 global $wgContLang;
242 if ( $this->showGallery ) {
243 $flip = $this->flip['file'];
244 if ( $flip ) {
245 $this->gallery->insert( $title );
246 } else {
247 $this->gallery->add( $title );
248 }
249 } else {
250 $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
251
252 $this->imgsNoGallery_start_char[] = $wgContLang->convert(
253 $this->collation->getFirstLetter( $sortkey ) );
254 }
255 }
256
257 /**
258 * Add a miscellaneous page
259 * @param Title $title
260 * @param string $sortkey
261 * @param int $pageLength
262 * @param bool $isRedirect
263 */
264 function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
265 global $wgContLang;
266
267 $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
268
269 $this->articles_start_char[] = $wgContLang->convert(
270 $this->collation->getFirstLetter( $sortkey ) );
271 }
272
273 function finaliseCategoryState() {
274 if ( $this->flip['subcat'] ) {
275 $this->children = array_reverse( $this->children );
276 $this->children_start_char = array_reverse( $this->children_start_char );
277 }
278 if ( $this->flip['page'] ) {
279 $this->articles = array_reverse( $this->articles );
280 $this->articles_start_char = array_reverse( $this->articles_start_char );
281 }
282 if ( !$this->showGallery && $this->flip['file'] ) {
283 $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
284 $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
285 }
286 }
287
288 function doCategoryQuery() {
289 $dbr = wfGetDB( DB_SLAVE, 'category' );
290
291 $this->nextPage = [
292 'page' => null,
293 'subcat' => null,
294 'file' => null,
295 ];
296 $this->prevPage = [
297 'page' => null,
298 'subcat' => null,
299 'file' => null,
300 ];
301
302 $this->flip = [ 'page' => false, 'subcat' => false, 'file' => false ];
303
304 foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
305 # Get the sortkeys for start/end, if applicable. Note that if
306 # the collation in the database differs from the one
307 # set in $wgCategoryCollation, pagination might go totally haywire.
308 $extraConds = [ 'cl_type' => $type ];
309 if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
310 $extraConds[] = 'cl_sortkey >= '
311 . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
312 } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
313 $extraConds[] = 'cl_sortkey < '
314 . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
315 $this->flip[$type] = true;
316 }
317
318 $res = $dbr->select(
319 [ 'page', 'categorylinks', 'category' ],
320 [ 'page_id', 'page_title', 'page_namespace', 'page_len',
321 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
322 'cat_subcats', 'cat_pages', 'cat_files',
323 'cl_sortkey_prefix', 'cl_collation' ],
324 array_merge( [ 'cl_to' => $this->title->getDBkey() ], $extraConds ),
325 __METHOD__,
326 [
327 'USE INDEX' => [ 'categorylinks' => 'cl_sortkey' ],
328 'LIMIT' => $this->limit + 1,
329 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
330 ],
331 [
332 'categorylinks' => [ 'INNER JOIN', 'cl_from = page_id' ],
333 'category' => [ 'LEFT JOIN', [
334 'cat_title = page_title',
335 'page_namespace' => NS_CATEGORY
336 ] ]
337 ]
338 );
339
340 Hooks::run( 'CategoryViewer::doCategoryQuery', [ $type, $res ] );
341
342 $count = 0;
343 foreach ( $res as $row ) {
344 $title = Title::newFromRow( $row );
345 if ( $row->cl_collation === '' ) {
346 // Hack to make sure that while updating from 1.16 schema
347 // and db is inconsistent, that the sky doesn't fall.
348 // See r83544. Could perhaps be removed in a couple decades...
349 $humanSortkey = $row->cl_sortkey;
350 } else {
351 $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
352 }
353
354 if ( ++$count > $this->limit ) {
355 # We've reached the one extra which shows that there
356 # are additional pages to be had. Stop here...
357 $this->nextPage[$type] = $humanSortkey;
358 break;
359 }
360 if ( $count == $this->limit ) {
361 $this->prevPage[$type] = $humanSortkey;
362 }
363
364 if ( $title->getNamespace() == NS_CATEGORY ) {
365 $cat = Category::newFromRow( $row, $title );
366 $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
367 } elseif ( $title->getNamespace() == NS_FILE ) {
368 $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
369 } else {
370 $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
371 }
372 }
373 }
374 }
375
376 /**
377 * @return string
378 */
379 function getCategoryTop() {
380 $r = $this->getCategoryBottom();
381 return $r === ''
382 ? $r
383 : "<br style=\"clear:both;\"/>\n" . $r;
384 }
385
386 /**
387 * @return string
388 */
389 function getSubcategorySection() {
390 # Don't show subcategories section if there are none.
391 $r = '';
392 $rescnt = count( $this->children );
393 $dbcnt = $this->cat->getSubcatCount();
394 // This function should be called even if the result isn't used, it has side-effects
395 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
396
397 if ( $rescnt > 0 ) {
398 # Showing subcategories
399 $r .= "<div id=\"mw-subcategories\">\n";
400 $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
401 $r .= $countmsg;
402 $r .= $this->getSectionPagingLinks( 'subcat' );
403 $r .= $this->formatList( $this->children, $this->children_start_char );
404 $r .= $this->getSectionPagingLinks( 'subcat' );
405 $r .= "\n</div>";
406 }
407 return $r;
408 }
409
410 /**
411 * @return string
412 */
413 function getPagesSection() {
414 $ti = wfEscapeWikiText( $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 rigmarole 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 // This function should be called even if the result isn't used, it has side-effects
426 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
427
428 if ( $rescnt > 0 ) {
429 $r = "<div id=\"mw-pages\">\n";
430 $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
431 $r .= $countmsg;
432 $r .= $this->getSectionPagingLinks( 'page' );
433 $r .= $this->formatList( $this->articles, $this->articles_start_char );
434 $r .= $this->getSectionPagingLinks( 'page' );
435 $r .= "\n</div>";
436 }
437 return $r;
438 }
439
440 /**
441 * @return string
442 */
443 function getImageSection() {
444 $r = '';
445 $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
446 $dbcnt = $this->cat->getFileCount();
447 // This function should be called even if the result isn't used, it has side-effects
448 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
449
450 if ( $rescnt > 0 ) {
451 $r .= "<div id=\"mw-category-media\">\n";
452 $r .= '<h2>' .
453 $this->msg(
454 'category-media-header',
455 wfEscapeWikiText( $this->title->getText() )
456 )->text() .
457 "</h2>\n";
458 $r .= $countmsg;
459 $r .= $this->getSectionPagingLinks( 'file' );
460 if ( $this->showGallery ) {
461 $r .= $this->gallery->toHTML();
462 } else {
463 $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
464 }
465 $r .= $this->getSectionPagingLinks( 'file' );
466 $r .= "\n</div>";
467 }
468 return $r;
469 }
470
471 /**
472 * Get the paging links for a section (subcats/pages/files), to go at the top and bottom
473 * of the output.
474 *
475 * @param string $type 'page', 'subcat', or 'file'
476 * @return string HTML output, possibly empty if there are no other pages
477 */
478 private function getSectionPagingLinks( $type ) {
479 if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
480 // The new value for the until parameter should be pointing to the first
481 // result displayed on the page which is the second last result retrieved
482 // from the database.The next link should have a from parameter pointing
483 // to the until parameter of the current page.
484 if ( $this->nextPage[$type] !== null ) {
485 return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type );
486 } else {
487 // If the nextPage variable is null, it means that we have reached the first page
488 // and therefore the previous link should be disabled.
489 return $this->pagingLinks( null, $this->until[$type], $type );
490 }
491 } elseif ( $this->nextPage[$type] !== null
492 || ( isset( $this->from[$type] ) && $this->from[$type] !== null )
493 ) {
494 return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
495 } else {
496 return '';
497 }
498 }
499
500 /**
501 * @return string
502 */
503 function getCategoryBottom() {
504 return '';
505 }
506
507 /**
508 * Format a list of articles chunked by letter, either as a
509 * bullet list or a columnar format, depending on the length.
510 *
511 * @param array $articles
512 * @param array $articles_start_char
513 * @param int $cutoff
514 * @return string
515 * @private
516 */
517 function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
518 $list = '';
519 if ( count( $articles ) > $cutoff ) {
520 $list = self::columnList( $articles, $articles_start_char );
521 } elseif ( count( $articles ) > 0 ) {
522 // for short lists of articles in categories.
523 $list = self::shortList( $articles, $articles_start_char );
524 }
525
526 $pageLang = $this->title->getPageLanguage();
527 $attribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
528 'class' => 'mw-content-' . $pageLang->getDir() ];
529 $list = Html::rawElement( 'div', $attribs, $list );
530
531 return $list;
532 }
533
534 /**
535 * Format a list of articles chunked by letter in a three-column
536 * list, ordered vertically.
537 *
538 * TODO: Take the headers into account when creating columns, so they're
539 * more visually equal.
540 *
541 * TODO: shortList and columnList are similar, need merging
542 *
543 * @param array $articles
544 * @param string[] $articles_start_char
545 * @return string
546 * @private
547 */
548 static function columnList( $articles, $articles_start_char ) {
549 $columns = array_combine( $articles, $articles_start_char );
550
551 $ret = Html::openElement( 'div', [ 'class' => 'mw-category' ] );
552
553 $colContents = [];
554
555 # Kind of like array_flip() here, but we keep duplicates in an
556 # array instead of dropping them.
557 foreach ( $columns as $article => $char ) {
558 if ( !isset( $colContents[$char] ) ) {
559 $colContents[$char] = [];
560 }
561 $colContents[$char][] = $article;
562 }
563
564 foreach ( $colContents as $char => $articles ) {
565 # Change space to non-breaking space to keep headers aligned
566 $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
567
568 $ret .= '<div class="mw-category-group"><h3>' . $h3char;
569 $ret .= "</h3>\n";
570
571 $ret .= '<ul><li>';
572 $ret .= implode( "</li>\n<li>", $articles );
573 $ret .= '</li></ul></div>';
574
575 }
576
577 $ret .= Html::closeElement( 'div' );
578 return $ret;
579 }
580
581 /**
582 * Format a list of articles chunked by letter in a bullet list.
583 * @param array $articles
584 * @param string[] $articles_start_char
585 * @return string
586 * @private
587 */
588 static function shortList( $articles, $articles_start_char ) {
589 $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
590 $r .= '<ul><li>' . $articles[0] . '</li>';
591 $articleCount = count( $articles );
592 for ( $index = 1; $index < $articleCount; $index++ ) {
593 if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
594 $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
595 }
596
597 $r .= "<li>{$articles[$index]}</li>";
598 }
599 $r .= '</ul>';
600 return $r;
601 }
602
603 /**
604 * Create paging links, as a helper method to getSectionPagingLinks().
605 *
606 * @param string $first The 'until' parameter for the generated URL
607 * @param string $last The 'from' parameter for the generated URL
608 * @param string $type A prefix for parameters, 'page' or 'subcat' or
609 * 'file'
610 * @return string HTML
611 */
612 private function pagingLinks( $first, $last, $type = '' ) {
613 $prevLink = $this->msg( 'prev-page' )->text();
614
615 if ( $first != '' ) {
616 $prevQuery = $this->query;
617 $prevQuery["{$type}until"] = $first;
618 unset( $prevQuery["{$type}from"] );
619 $prevLink = Linker::linkKnown(
620 $this->addFragmentToTitle( $this->title, $type ),
621 $prevLink,
622 [],
623 $prevQuery
624 );
625 }
626
627 $nextLink = $this->msg( 'next-page' )->text();
628
629 if ( $last != '' ) {
630 $lastQuery = $this->query;
631 $lastQuery["{$type}from"] = $last;
632 unset( $lastQuery["{$type}until"] );
633 $nextLink = Linker::linkKnown(
634 $this->addFragmentToTitle( $this->title, $type ),
635 $nextLink,
636 [],
637 $lastQuery
638 );
639 }
640
641 return $this->msg( 'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
642 }
643
644 /**
645 * Takes a title, and adds the fragment identifier that
646 * corresponds to the correct segment of the category.
647 *
648 * @param Title $title The title (usually $this->title)
649 * @param string $section Which section
650 * @throws MWException
651 * @return Title
652 */
653 private function addFragmentToTitle( $title, $section ) {
654 switch ( $section ) {
655 case 'page':
656 $fragment = 'mw-pages';
657 break;
658 case 'subcat':
659 $fragment = 'mw-subcategories';
660 break;
661 case 'file':
662 $fragment = 'mw-category-media';
663 break;
664 default:
665 throw new MWException( __METHOD__ .
666 " Invalid section $section." );
667 }
668
669 return Title::makeTitle( $title->getNamespace(),
670 $title->getDBkey(), $fragment );
671 }
672
673 /**
674 * What to do if the category table conflicts with the number of results
675 * returned? This function says what. Each type is considered independently
676 * of the other types.
677 *
678 * @param int $rescnt The number of items returned by our database query.
679 * @param int $dbcnt The number of items according to the category table.
680 * @param string $type 'subcat', 'article', or 'file'
681 * @return string A message giving the number of items, to output to HTML.
682 */
683 private function getCountMessage( $rescnt, $dbcnt, $type ) {
684 // There are three cases:
685 // 1) The category table figure seems sane. It might be wrong, but
686 // we can't do anything about it if we don't recalculate it on ev-
687 // ery category view.
688 // 2) The category table figure isn't sane, like it's smaller than the
689 // number of actual results, *but* the number of results is less
690 // than $this->limit and there's no offset. In this case we still
691 // know the right figure.
692 // 3) We have no idea.
693
694 // Check if there's a "from" or "until" for anything
695
696 // This is a little ugly, but we seem to use different names
697 // for the paging types then for the messages.
698 if ( $type === 'article' ) {
699 $pagingType = 'page';
700 } else {
701 $pagingType = $type;
702 }
703
704 $fromOrUntil = false;
705 if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
706 ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
707 ) {
708 $fromOrUntil = true;
709 }
710
711 if ( $dbcnt == $rescnt ||
712 ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
713 ) {
714 // Case 1: seems sane.
715 $totalcnt = $dbcnt;
716 } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
717 // Case 2: not sane, but salvageable. Use the number of results.
718 // Since there are fewer than 200, we can also take this opportunity
719 // to refresh the incorrect category table entry -- which should be
720 // quick due to the small number of entries.
721 $totalcnt = $rescnt;
722 $category = $this->cat;
723 DeferredUpdates::addCallableUpdate( function () use ( $category ) {
724 $category->refreshCounts();
725 } );
726 } else {
727 // Case 3: hopeless. Don't give a total count at all.
728 // Messages: category-subcat-count-limited, category-article-count-limited,
729 // category-file-count-limited
730 return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
731 }
732 // Messages: category-subcat-count, category-article-count, category-file-count
733 return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
734 }
735 }