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