Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinkedcategories.php
1 <?php
2 /**
3 * Implements Special:Mostlinkedcategories
4 *
5 * Copyright © 2005, Ævar Arnfjörð Bjarmason
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup SpecialPage
24 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
25 */
26
27 use Wikimedia\Rdbms\ResultWrapper;
28
29 /**
30 * A querypage to show categories ordered in descending order by the pages in them
31 *
32 * @ingroup SpecialPage
33 */
34 class MostlinkedCategoriesPage extends QueryPage {
35 function __construct( $name = 'Mostlinkedcategories' ) {
36 parent::__construct( $name );
37 }
38
39 function isSyndicated() {
40 return false;
41 }
42
43 public function getQueryInfo() {
44 return [
45 'tables' => [ 'category' ],
46 'fields' => [ 'title' => 'cat_title',
47 'namespace' => NS_CATEGORY,
48 'value' => 'cat_pages' ],
49 'conds' => [ 'cat_pages > 0' ],
50 ];
51 }
52
53 function sortDescending() {
54 return true;
55 }
56
57 /**
58 * Fetch user page links and cache their existence
59 *
60 * @param IDatabase $db
61 * @param ResultWrapper $res
62 */
63 function preprocessResults( $db, $res ) {
64 $this->executeLBFromResultWrapper( $res );
65 }
66
67 /**
68 * @param Skin $skin
69 * @param object $result Result row
70 * @return string
71 */
72 function formatResult( $skin, $result ) {
73 global $wgContLang;
74
75 $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
76 if ( !$nt ) {
77 return Html::element(
78 'span',
79 [ 'class' => 'mw-invalidtitle' ],
80 Linker::getInvalidTitleDescription(
81 $this->getContext(),
82 NS_CATEGORY,
83 $result->title )
84 );
85 }
86
87 $text = $wgContLang->convert( $nt->getText() );
88 $plink = $this->getLinkRenderer()->makeLink( $nt, $text );
89 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
90
91 return $this->getLanguage()->specialList( $plink, $nlinks );
92 }
93
94 protected function getGroupName() {
95 return 'highuse';
96 }
97 }