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