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