Merge "Use pg_result_error, not pg_last_error, as the latter gives false negatives."
[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 $langAttribs = [ 'lang' => $lang->getHtmlCode(), 'dir' => $lang->getDir() ];
142 # put a div around the headings which are in the user language
143 $r = Html::openElement( 'div', $langAttribs ) . $r . '</div>';
144
145 return $r;
146 }
147
148 function clearCategoryState() {
149 $this->articles = [];
150 $this->articles_start_char = [];
151 $this->children = [];
152 $this->children_start_char = [];
153 if ( $this->showGallery ) {
154 // Note that null for mode is taken to mean use default.
155 $mode = $this->getRequest()->getVal( 'gallerymode', null );
156 try {
157 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
158 } catch ( Exception $e ) {
159 // User specified something invalid, fallback to default.
160 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
161 }
162
163 $this->gallery->setHideBadImages();
164 } else {
165 $this->imgsNoGallery = [];
166 $this->imgsNoGallery_start_char = [];
167 }
168 }
169
170 /**
171 * Add a subcategory to the internal lists, using a Category object
172 * @param Category $cat
173 * @param string $sortkey
174 * @param int $pageLength
175 */
176 function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
177 // Subcategory; strip the 'Category' namespace from the link text.
178 $title = $cat->getTitle();
179
180 $this->children[] = $this->generateLink(
181 'subcat',
182 $title,
183 $title->isRedirect(),
184 htmlspecialchars( $title->getText() )
185 );
186
187 $this->children_start_char[] =
188 $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
189 }
190
191 function generateLink( $type, Title $title, $isRedirect, $html = null ) {
192 $link = null;
193 Hooks::run( 'CategoryViewer::generateLink', [ $type, $title, $html, &$link ] );
194 if ( $link === null ) {
195 $link = Linker::link( $title, $html );
196 }
197 if ( $isRedirect ) {
198 $link = '<span class="redirect-in-category">' . $link . '</span>';
199 }
200
201 return $link;
202 }
203
204 /**
205 * Get the character to be used for sorting subcategories.
206 * If there's a link from Category:A to Category:B, the sortkey of the resulting
207 * entry in the categorylinks table is Category:A, not A, which it SHOULD be.
208 * Workaround: If sortkey == "Category:".$title, than use $title for sorting,
209 * else use sortkey...
210 *
211 * @param Title $title
212 * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever).
213 * @return string
214 */
215 function getSubcategorySortChar( $title, $sortkey ) {
216 global $wgContLang;
217
218 if ( $title->getPrefixedText() == $sortkey ) {
219 $word = $title->getDBkey();
220 } else {
221 $word = $sortkey;
222 }
223
224 $firstChar = $this->collation->getFirstLetter( $word );
225
226 return $wgContLang->convert( $firstChar );
227 }
228
229 /**
230 * Add a page in the image namespace
231 * @param Title $title
232 * @param string $sortkey
233 * @param int $pageLength
234 * @param bool $isRedirect
235 */
236 function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
237 global $wgContLang;
238 if ( $this->showGallery ) {
239 $flip = $this->flip['file'];
240 if ( $flip ) {
241 $this->gallery->insert( $title );
242 } else {
243 $this->gallery->add( $title );
244 }
245 } else {
246 $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
247
248 $this->imgsNoGallery_start_char[] = $wgContLang->convert(
249 $this->collation->getFirstLetter( $sortkey ) );
250 }
251 }
252
253 /**
254 * Add a miscellaneous page
255 * @param Title $title
256 * @param string $sortkey
257 * @param int $pageLength
258 * @param bool $isRedirect
259 */
260 function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
261 global $wgContLang;
262
263 $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
264
265 $this->articles_start_char[] = $wgContLang->convert(
266 $this->collation->getFirstLetter( $sortkey ) );
267 }
268
269 function finaliseCategoryState() {
270 if ( $this->flip['subcat'] ) {
271 $this->children = array_reverse( $this->children );
272 $this->children_start_char = array_reverse( $this->children_start_char );
273 }
274 if ( $this->flip['page'] ) {
275 $this->articles = array_reverse( $this->articles );
276 $this->articles_start_char = array_reverse( $this->articles_start_char );
277 }
278 if ( !$this->showGallery && $this->flip['file'] ) {
279 $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
280 $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
281 }
282 }
283
284 function doCategoryQuery() {
285 $dbr = wfGetDB( DB_SLAVE, 'category' );
286
287 $this->nextPage = [
288 'page' => null,
289 'subcat' => null,
290 'file' => null,
291 ];
292 $this->prevPage = [
293 'page' => null,
294 'subcat' => null,
295 'file' => null,
296 ];
297
298 $this->flip = [ 'page' => false, 'subcat' => false, 'file' => false ];
299
300 foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
301 # Get the sortkeys for start/end, if applicable. Note that if
302 # the collation in the database differs from the one
303 # set in $wgCategoryCollation, pagination might go totally haywire.
304 $extraConds = [ 'cl_type' => $type ];
305 if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
306 $extraConds[] = 'cl_sortkey >= '
307 . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
308 } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
309 $extraConds[] = 'cl_sortkey < '
310 . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
311 $this->flip[$type] = true;
312 }
313
314 $res = $dbr->select(
315 [ 'page', 'categorylinks', 'category' ],
316 [ 'page_id', 'page_title', 'page_namespace', 'page_len',
317 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
318 'cat_subcats', 'cat_pages', 'cat_files',
319 'cl_sortkey_prefix', 'cl_collation' ],
320 array_merge( [ 'cl_to' => $this->title->getDBkey() ], $extraConds ),
321 __METHOD__,
322 [
323 'USE INDEX' => [ 'categorylinks' => 'cl_sortkey' ],
324 'LIMIT' => $this->limit + 1,
325 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
326 ],
327 [
328 'categorylinks' => [ 'INNER JOIN', 'cl_from = page_id' ],
329 'category' => [ 'LEFT JOIN', [
330 'cat_title = page_title',
331 'page_namespace' => NS_CATEGORY
332 ] ]
333 ]
334 );
335
336 Hooks::run( 'CategoryViewer::doCategoryQuery', [ $type, $res ] );
337
338 $count = 0;
339 foreach ( $res as $row ) {
340 $title = Title::newFromRow( $row );
341 if ( $row->cl_collation === '' ) {
342 // Hack to make sure that while updating from 1.16 schema
343 // and db is inconsistent, that the sky doesn't fall.
344 // See r83544. Could perhaps be removed in a couple decades...
345 $humanSortkey = $row->cl_sortkey;
346 } else {
347 $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
348 }
349
350 if ( ++$count > $this->limit ) {
351 # We've reached the one extra which shows that there
352 # are additional pages to be had. Stop here...
353 $this->nextPage[$type] = $humanSortkey;
354 break;
355 }
356 if ( $count == $this->limit ) {
357 $this->prevPage[$type] = $humanSortkey;
358 }
359
360 if ( $title->getNamespace() == NS_CATEGORY ) {
361 $cat = Category::newFromRow( $row, $title );
362 $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
363 } elseif ( $title->getNamespace() == NS_FILE ) {
364 $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
365 } else {
366 $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
367 }
368 }
369 }
370 }
371
372 /**
373 * @return string
374 */
375 function getCategoryTop() {
376 $r = $this->getCategoryBottom();
377 return $r === ''
378 ? $r
379 : "<br style=\"clear:both;\"/>\n" . $r;
380 }
381
382 /**
383 * @return string
384 */
385 function getSubcategorySection() {
386 # Don't show subcategories section if there are none.
387 $r = '';
388 $rescnt = count( $this->children );
389 $dbcnt = $this->cat->getSubcatCount();
390 // This function should be called even if the result isn't used, it has side-effects
391 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
392
393 if ( $rescnt > 0 ) {
394 # Showing subcategories
395 $r .= "<div id=\"mw-subcategories\">\n";
396 $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
397 $r .= $countmsg;
398 $r .= $this->getSectionPagingLinks( 'subcat' );
399 $r .= $this->formatList( $this->children, $this->children_start_char );
400 $r .= $this->getSectionPagingLinks( 'subcat' );
401 $r .= "\n</div>";
402 }
403 return $r;
404 }
405
406 /**
407 * @return string
408 */
409 function getPagesSection() {
410 $ti = wfEscapeWikiText( $this->title->getText() );
411 # Don't show articles section if there are none.
412 $r = '';
413
414 # @todo FIXME: Here and in the other two sections: we don't need to bother
415 # with this rigmarole if the entire category contents fit on one page
416 # and have already been retrieved. We can just use $rescnt in that
417 # case and save a query and some logic.
418 $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
419 - $this->cat->getFileCount();
420 $rescnt = count( $this->articles );
421 // This function should be called even if the result isn't used, it has side-effects
422 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
423
424 if ( $rescnt > 0 ) {
425 $r = "<div id=\"mw-pages\">\n";
426 $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
427 $r .= $countmsg;
428 $r .= $this->getSectionPagingLinks( 'page' );
429 $r .= $this->formatList( $this->articles, $this->articles_start_char );
430 $r .= $this->getSectionPagingLinks( 'page' );
431 $r .= "\n</div>";
432 }
433 return $r;
434 }
435
436 /**
437 * @return string
438 */
439 function getImageSection() {
440 $r = '';
441 $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
442 $dbcnt = $this->cat->getFileCount();
443 // This function should be called even if the result isn't used, it has side-effects
444 $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
445
446 if ( $rescnt > 0 ) {
447 $r .= "<div id=\"mw-category-media\">\n";
448 $r .= '<h2>' .
449 $this->msg(
450 'category-media-header',
451 wfEscapeWikiText( $this->title->getText() )
452 )->text() .
453 "</h2>\n";
454 $r .= $countmsg;
455 $r .= $this->getSectionPagingLinks( 'file' );
456 if ( $this->showGallery ) {
457 $r .= $this->gallery->toHTML();
458 } else {
459 $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
460 }
461 $r .= $this->getSectionPagingLinks( 'file' );
462 $r .= "\n</div>";
463 }
464 return $r;
465 }
466
467 /**
468 * Get the paging links for a section (subcats/pages/files), to go at the top and bottom
469 * of the output.
470 *
471 * @param string $type 'page', 'subcat', or 'file'
472 * @return string HTML output, possibly empty if there are no other pages
473 */
474 private function getSectionPagingLinks( $type ) {
475 if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
476 // The new value for the until parameter should be pointing to the first
477 // result displayed on the page which is the second last result retrieved
478 // from the database.The next link should have a from parameter pointing
479 // to the until parameter of the current page.
480 if ( $this->nextPage[$type] !== null ) {
481 return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type );
482 } else {
483 // If the nextPage variable is null, it means that we have reached the first page
484 // and therefore the previous link should be disabled.
485 return $this->pagingLinks( null, $this->until[$type], $type );
486 }
487 } elseif ( $this->nextPage[$type] !== null
488 || ( isset( $this->from[$type] ) && $this->from[$type] !== null )
489 ) {
490 return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
491 } else {
492 return '';
493 }
494 }
495
496 /**
497 * @return string
498 */
499 function getCategoryBottom() {
500 return '';
501 }
502
503 /**
504 * Format a list of articles chunked by letter, either as a
505 * bullet list or a columnar format, depending on the length.
506 *
507 * @param array $articles
508 * @param array $articles_start_char
509 * @param int $cutoff
510 * @return string
511 * @private
512 */
513 function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
514 $list = '';
515 if ( count( $articles ) > $cutoff ) {
516 $list = self::columnList( $articles, $articles_start_char );
517 } elseif ( count( $articles ) > 0 ) {
518 // for short lists of articles in categories.
519 $list = self::shortList( $articles, $articles_start_char );
520 }
521
522 $pageLang = $this->title->getPageLanguage();
523 $attribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
524 'class' => 'mw-content-' . $pageLang->getDir() ];
525 $list = Html::rawElement( 'div', $attribs, $list );
526
527 return $list;
528 }
529
530 /**
531 * Format a list of articles chunked by letter in a three-column
532 * list, ordered vertically.
533 *
534 * TODO: Take the headers into account when creating columns, so they're
535 * more visually equal.
536 *
537 * TODO: shortList and columnList are similar, need merging
538 *
539 * @param array $articles
540 * @param string[] $articles_start_char
541 * @return string
542 * @private
543 */
544 static function columnList( $articles, $articles_start_char ) {
545 $columns = array_combine( $articles, $articles_start_char );
546
547 $ret = Html::openElement( 'div', [ 'class' => 'mw-category' ] );
548
549 $colContents = [];
550
551 # Kind of like array_flip() here, but we keep duplicates in an
552 # array instead of dropping them.
553 foreach ( $columns as $article => $char ) {
554 if ( !isset( $colContents[$char] ) ) {
555 $colContents[$char] = [];
556 }
557 $colContents[$char][] = $article;
558 }
559
560 foreach ( $colContents as $char => $articles ) {
561 # Change space to non-breaking space to keep headers aligned
562 $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
563
564 $ret .= '<div class="mw-category-group"><h3>' . $h3char;
565 $ret .= "</h3>\n";
566
567 $ret .= '<ul><li>';
568 $ret .= implode( "</li>\n<li>", $articles );
569 $ret .= '</li></ul></div>';
570
571 }
572
573 $ret .= Html::closeElement( 'div' );
574 return $ret;
575 }
576
577 /**
578 * Format a list of articles chunked by letter in a bullet list.
579 * @param array $articles
580 * @param string[] $articles_start_char
581 * @return string
582 * @private
583 */
584 static function shortList( $articles, $articles_start_char ) {
585 $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
586 $r .= '<ul><li>' . $articles[0] . '</li>';
587 $articleCount = count( $articles );
588 for ( $index = 1; $index < $articleCount; $index++ ) {
589 if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
590 $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
591 }
592
593 $r .= "<li>{$articles[$index]}</li>";
594 }
595 $r .= '</ul>';
596 return $r;
597 }
598
599 /**
600 * Create paging links, as a helper method to getSectionPagingLinks().
601 *
602 * @param string $first The 'until' parameter for the generated URL
603 * @param string $last The 'from' parameter for the generated URL
604 * @param string $type A prefix for parameters, 'page' or 'subcat' or
605 * 'file'
606 * @return string HTML
607 */
608 private function pagingLinks( $first, $last, $type = '' ) {
609 $prevLink = $this->msg( 'prev-page' )->text();
610
611 if ( $first != '' ) {
612 $prevQuery = $this->query;
613 $prevQuery["{$type}until"] = $first;
614 unset( $prevQuery["{$type}from"] );
615 $prevLink = Linker::linkKnown(
616 $this->addFragmentToTitle( $this->title, $type ),
617 $prevLink,
618 [],
619 $prevQuery
620 );
621 }
622
623 $nextLink = $this->msg( 'next-page' )->text();
624
625 if ( $last != '' ) {
626 $lastQuery = $this->query;
627 $lastQuery["{$type}from"] = $last;
628 unset( $lastQuery["{$type}until"] );
629 $nextLink = Linker::linkKnown(
630 $this->addFragmentToTitle( $this->title, $type ),
631 $nextLink,
632 [],
633 $lastQuery
634 );
635 }
636
637 return $this->msg( 'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
638 }
639
640 /**
641 * Takes a title, and adds the fragment identifier that
642 * corresponds to the correct segment of the category.
643 *
644 * @param Title $title The title (usually $this->title)
645 * @param string $section Which section
646 * @throws MWException
647 * @return Title
648 */
649 private function addFragmentToTitle( $title, $section ) {
650 switch ( $section ) {
651 case 'page':
652 $fragment = 'mw-pages';
653 break;
654 case 'subcat':
655 $fragment = 'mw-subcategories';
656 break;
657 case 'file':
658 $fragment = 'mw-category-media';
659 break;
660 default:
661 throw new MWException( __METHOD__ .
662 " Invalid section $section." );
663 }
664
665 return Title::makeTitle( $title->getNamespace(),
666 $title->getDBkey(), $fragment );
667 }
668
669 /**
670 * What to do if the category table conflicts with the number of results
671 * returned? This function says what. Each type is considered independently
672 * of the other types.
673 *
674 * @param int $rescnt The number of items returned by our database query.
675 * @param int $dbcnt The number of items according to the category table.
676 * @param string $type 'subcat', 'article', or 'file'
677 * @return string A message giving the number of items, to output to HTML.
678 */
679 private function getCountMessage( $rescnt, $dbcnt, $type ) {
680 // There are three cases:
681 // 1) The category table figure seems sane. It might be wrong, but
682 // we can't do anything about it if we don't recalculate it on ev-
683 // ery category view.
684 // 2) The category table figure isn't sane, like it's smaller than the
685 // number of actual results, *but* the number of results is less
686 // than $this->limit and there's no offset. In this case we still
687 // know the right figure.
688 // 3) We have no idea.
689
690 // Check if there's a "from" or "until" for anything
691
692 // This is a little ugly, but we seem to use different names
693 // for the paging types then for the messages.
694 if ( $type === 'article' ) {
695 $pagingType = 'page';
696 } else {
697 $pagingType = $type;
698 }
699
700 $fromOrUntil = false;
701 if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
702 ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
703 ) {
704 $fromOrUntil = true;
705 }
706
707 if ( $dbcnt == $rescnt ||
708 ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
709 ) {
710 // Case 1: seems sane.
711 $totalcnt = $dbcnt;
712 } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
713 // Case 2: not sane, but salvageable. Use the number of results.
714 // Since there are fewer than 200, we can also take this opportunity
715 // to refresh the incorrect category table entry -- which should be
716 // quick due to the small number of entries.
717 $totalcnt = $rescnt;
718 $category = $this->cat;
719 DeferredUpdates::addCallableUpdate( function () use ( $category ) {
720 $category->refreshCounts();
721 } );
722 } else {
723 // Case 3: hopeless. Don't give a total count at all.
724 // Messages: category-subcat-count-limited, category-article-count-limited,
725 // category-file-count-limited
726 return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
727 }
728 // Messages: category-subcat-count, category-article-count, category-file-count
729 return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
730 }
731 }