Merge "Handle missing namespace prefix in XML dumps more gracefully"
[lhc/web/wiklou.git] / includes / specials / SpecialMostcategories.php
1 <?php
2 /**
3 * Implements Special:Mostcategories
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 special page that list pages that have highest category count
31 *
32 * @ingroup SpecialPage
33 */
34 class MostcategoriesPage extends QueryPage {
35 function __construct( $name = 'Mostcategories' ) {
36 parent::__construct( $name );
37 }
38
39 public function isExpensive() {
40 return true;
41 }
42
43 function isSyndicated() {
44 return false;
45 }
46
47 public function getQueryInfo() {
48 return [
49 'tables' => [ 'categorylinks', 'page' ],
50 'fields' => [
51 'namespace' => 'page_namespace',
52 'title' => 'page_title',
53 'value' => 'COUNT(*)'
54 ],
55 'conds' => [ 'page_namespace' => MWNamespace::getContentNamespaces() ],
56 'options' => [
57 'HAVING' => 'COUNT(*) > 1',
58 'GROUP BY' => [ 'page_namespace', 'page_title' ]
59 ],
60 'join_conds' => [
61 'page' => [
62 'LEFT JOIN',
63 'page_id = cl_from'
64 ]
65 ]
66 ];
67 }
68
69 /**
70 * @param IDatabase $db
71 * @param ResultWrapper $res
72 */
73 function preprocessResults( $db, $res ) {
74 $this->executeLBFromResultWrapper( $res );
75 }
76
77 /**
78 * @param Skin $skin
79 * @param object $result Result row
80 * @return string
81 */
82 function formatResult( $skin, $result ) {
83 $title = Title::makeTitleSafe( $result->namespace, $result->title );
84 if ( !$title ) {
85 return Html::element(
86 'span',
87 [ 'class' => 'mw-invalidtitle' ],
88 Linker::getInvalidTitleDescription(
89 $this->getContext(),
90 $result->namespace,
91 $result->title
92 )
93 );
94 }
95
96 $linkRenderer = $this->getLinkRenderer();
97 if ( $this->isCached() ) {
98 $link = $linkRenderer->makeLink( $title );
99 } else {
100 $link = $linkRenderer->makeKnownLink( $title );
101 }
102
103 $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
104
105 return $this->getLanguage()->specialList( $link, $count );
106 }
107
108 protected function getGroupName() {
109 return 'highuse';
110 }
111 }