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